:root {
    --bg-color: #fcfbf4;
    --text-color: #1a1a1a;
    --btn-color: #2c3e50;
    --card-bg: #fff;
    --border-color: #ddd;
    --highlight: #f1c40f; 
    --tooltip-bg: #222;
    --font-primary: 'Crimson Pro', serif;
    --font-header: 'Merriweather', serif;
    --font-arabic: 'IBM Plex Sans Arabic', sans-serif;
    --font-artistic: 'Aref Ruqaa', serif;
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --btn-color: #3498db; 
    --card-bg: #1e1e1e;
    --border-color: #333;
    --highlight: #f39c12;
    --tooltip-bg: #333;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-primary);
    margin: 0; padding: 0;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Text Selection */
::selection { background: var(--highlight); color: #000; text-shadow: none; }
::-moz-selection { background: var(--highlight); color: #000; }

/* Background Icons */
.bg-icons { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; opacity: 0.03; pointer-events: none; }
body.dark-mode .bg-icons i { color: #fff; opacity: 0.05; } 
.bg-icons i { position: absolute; font-size: 3rem; color: #000; animation: float 15s infinite ease-in-out; }
.bg-icons i:nth-child(1) { top: 10%; left: 10%; animation-duration: 14s; }
.bg-icons i:nth-child(2) { top: 20%; right: 15%; font-size: 4rem; animation-delay: 2s; animation-duration: 18s; }
.bg-icons i:nth-child(3) { bottom: 15%; left: 20%; animation-delay: 4s; animation-duration: 16s; }
.bg-icons i:nth-child(4) { bottom: 30%; right: 10%; animation-delay: 1s; }
.bg-icons i:nth-child(5) { top: 50%; left: 50%; font-size: 5rem; opacity: 0.02; animation-delay: 5s; animation-duration: 25s; }
.bg-icons i:nth-child(6) { top: 5%; right: 40%; font-size: 2rem; animation-delay: 3s; }
.bg-icons i:nth-child(7) { bottom: 5%; left: 5%; font-size: 2.5rem; animation-delay: 0s; animation-duration: 20s; }
.bg-icons i:nth-child(8) { top: 40%; left: 5%; font-size: 2rem; animation-delay: 6s; }

@keyframes float { 0%,100%{transform:translateY(0) rotate(0deg);} 50%{transform:translateY(-20px) rotate(5deg);} }

.container { max-width: 800px; margin: 40px auto; padding: 0 25px; min-height: 90vh; }

/* --- Top Controls & User Profile --- */
.top-controls { position: absolute; top: 20px; right: 20px; display: flex; align-items: flex-start; gap: 10px; z-index: 100; }
.control-icon-btn { 
    background: transparent; border: none; font-size: 1.5rem; 
    color: var(--text-color); cursor: pointer; transition: 0.3s; 
    width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.control-icon-btn:hover { background: rgba(0,0,0,0.05); transform: scale(1.1); }

/* USER PROFILE STYLE */
.user-profile-container {
    display: flex; flex-direction: column; align-items: center;
    cursor: pointer; margin-left: 5px; transition: 0.3s;
}
.user-profile-container:hover { opacity: 0.8; transform: translateY(1px); }
.profile-avatar {
    width: 35px; height: 35px; background: var(--btn-color); color: #fff;
    border-radius: 50%; display: flex; justify-content: center; align-items: center;
    font-size: 1rem; box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
#profile-name-text {
    font-size: 0.7rem; font-weight: bold; margin-top: 2px;
    max-width: 60px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--text-color);
}

/* --- Language Badge --- */
.lang-bar-container { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; padding: 0 5px; }
.lang-badge {
    display: flex; align-items: center; gap: 8px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    padding: 6px 12px; border-radius: 8px;
    font-family: 'Merriweather', serif; font-size: 0.8rem; font-weight: bold;
    color: var(--text-color); box-shadow: 0 2px 5px rgba(0,0,0,0.03);
}
.lang-code { opacity: 0.7; }
.lang-code.ar { color: var(--btn-color); opacity: 1; }
.lang-sep { width: 1px; height: 12px; background: #ddd; display: inline-block; }
.lang-badge i { font-size: 0.7rem; color: #999; }
.artistic-tagline { font-family: var(--font-artistic); font-size: 1.4rem; color: var(--btn-color); display: flex; align-items: center; gap: 8px; transform: rotate(-2deg); }

/* Sidebar */
.sidebar {
    position: fixed; top: 0; right: 0; width: 320px; height: 100%;
    background: var(--card-bg); box-shadow: -5px 0 25px rgba(0,0,0,0.15);
    z-index: 2500; transform: translateX(100%); transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex; flex-direction: column;
}
.sidebar.open { transform: translateX(0); }
.sidebar-header {
    padding: 25px; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: flex-start;
    background: var(--bg-color);
}
.artistic-title {
    font-family: var(--font-artistic); margin: 0; font-size: 2rem; color: var(--btn-color); line-height: 1;
}
.sidebar-subtitle { font-size: 0.8rem; color: #888; text-transform: uppercase; letter-spacing: 1px; }
.close-sidebar-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-color); transition: 0.2s; }
.close-sidebar-btn:hover { color: #e74c3c; transform: rotate(90deg); }
.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.3); z-index: 2400; backdrop-filter: blur(3px);
}
.vocab-list-container { padding: 20px; overflow-y: auto; flex: 1; }
.vocab-item {
    background: var(--card-bg); border: 1px solid var(--border-color);
    padding: 15px; margin-bottom: 12px; border-radius: 8px;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03); transition: transform 0.2s, box-shadow 0.2s;
    position: relative; overflow: hidden;
}
.vocab-item:hover { transform: translateY(-2px); box-shadow: 0 5px 12px rgba(0,0,0,0.08); }
.vocab-item::before { content: ''; position: absolute; left: 0; top: 0; height: 100%; width: 4px; background: var(--btn-color); }
.vocab-text { display: flex; flex-direction: column; gap: 4px; }
.v-word { font-weight: 700; font-family: var(--font-primary); font-size: 1.1rem; color: var(--text-color); }
.v-trans { font-family: var(--font-arabic); color: var(--btn-color); font-size: 1rem; }
.delete-vocab-btn { background: none; border: none; color: #ccc; cursor: pointer; transition: 0.2s; font-size: 1rem; }
.delete-vocab-btn:hover { color: #e74c3c; }

/* Header & Input */
header { text-align: center; margin-bottom: 30px; border-bottom: 1px solid rgba(0,0,0,0.05); padding-bottom: 20px; }
h1 { font-family: var(--font-header); font-size: 2.5rem; color: var(--btn-color); margin: 0; }
.version { font-size: 0.4em; vertical-align: super; color: #888; background: #eee; padding: 2px 6px; border-radius: 4px; }
.subtitle { font-family: sans-serif; color: #999; font-size: 0.75rem; letter-spacing: 3px; text-transform: uppercase; margin-top: 8px; }

textarea { 
    width: 100%; height: 200px; padding: 20px; padding-right: 40px;
    border: 1px solid var(--border-color); border-radius: 12px; 
    font-family: var(--font-primary); background: var(--card-bg);
    font-size: 18px; line-height: 1.6;
    color: var(--text-color); outline: none; resize: none; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.02); box-sizing: border-box; transition: 0.3s; 
}
textarea:focus { border-color: var(--btn-color); box-shadow: 0 6px 20px rgba(0,0,0,0.08); }

.radio-group { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.radio-card input { display: none; }
.card-content { 
    display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 10px;
    padding: 15px; 
    border: 1px solid var(--border-color); border-radius: 10px; background: var(--card-bg); transition: 0.2s; cursor: pointer;
}
.icon-box { width: 30px; height: 30px; background: #f0f0f0; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #555; }
.text-box { display: flex; flex-direction: column; text-align: left; }
.model-name { font-weight: 700; font-family: sans-serif; font-size: 0.9rem; color: var(--text-color); }
.model-desc { font-size: 0.7rem; color: #888; }
.radio-card input:checked + .card-content { border: 2px solid var(--btn-color); background: rgba(44, 62, 80, 0.03); }
body.dark-mode .radio-card input:checked + .card-content { background: rgba(52, 152, 219, 0.1); }

.action-btn { background: var(--btn-color); color: white; border: none; width: 100%; padding: 15px; border-radius: 10px; font-size: 1.1rem; font-weight: 600; cursor: pointer; margin-top: 25px; display: flex; justify-content: center; gap: 10px; transition: 0.2s; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
.action-btn:hover { transform: translateY(-3px); box-shadow: 0 6px 20px rgba(0,0,0,0.15); opacity: 0.95; }

.content-box {
    font-family: 'Crimson Pro', serif;
    font-size: 22px; line-height: 1.9;
    color: var(--text-color); text-align: justify; text-justify: inter-word;
    padding: 0 5px;
    -webkit-user-select: text; user-select: text; 
    -webkit-touch-callout: none;
}
.content-box p { margin-bottom: 28px; text-indent: 1.5em; }

.word { cursor: pointer; border-radius: 3px; transition: background 0.1s; padding: 2px 0; }
.word:hover { background: rgba(0,0,0,0.05); }
.active-word { background: var(--highlight) !important; box-shadow: 0 0 0 2px var(--highlight); color: #000; border-radius: 4px; }

/* --- TOOLTIP & CONTENT HANDLING (Improved) --- */
.tooltip { 
    position: absolute; background: var(--tooltip-bg); color: white; 
    padding: 12px 20px; border-radius: 8px; 
    font-family: var(--font-arabic); font-size: 1.1rem; 
    z-index: 1000; transform: translate(-50%, -120%); 
    box-shadow: 0 10px 25px rgba(0,0,0,0.3); transition: opacity 0.2s; 
    min-width: 120px; text-align: center;
}
.tooltip::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--tooltip-bg); }

/* Prevent overflow in translations */
.tooltip-content {
    display: flex; flex-direction: column; align-items: center;
    width: 100%; max-height: 300px; overflow-y: auto; scrollbar-width: thin;
}

#translated-text {
    font-family: var(--font-arabic); font-weight: 600; color: #ff9627;;
    line-height: 1.5; text-align: center; margin: 8px 0;
    word-wrap: break-word; white-space: pre-wrap; width: 100%;
    font-size: clamp(1rem, 4vw, 1.4rem); /* Responsive font size */
   
}

/* Save Button Default */
.save-btn { 
    background: transparent; border: 1px solid rgba(255,255,255,0.3); color: #fff; 
    border-radius: 4px; cursor: pointer; font-size: 0.9rem; padding: 4px 12px; margin-top: 8px;
    transition: 0.2s; width: 100%;
}
.save-btn:hover { background: rgba(255,255,255,0.2); }

.flying-clone {
    position: fixed; z-index: 9999; font-family: var(--font-arabic);
    color: var(--btn-color); font-weight: bold; pointer-events: none;
    transition: all 0.8s cubic-bezier(0.19, 1, 0.22, 1);
}

/* --- TOAST --- */
#custom-toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: var(--btn-color); color: #fff;
    padding: 12px 25px; border-radius: 30px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    font-family: sans-serif; font-size: 0.95rem;
    display: flex; align-items: center; gap: 10px;
    opacity: 0; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10000;
}
#custom-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- AUTH MODAL --- */
.auth-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(5px);
    z-index: 9999; display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s;
}
.auth-overlay.hidden { opacity: 0; pointer-events: none; }
.auth-box {
    background: var(--card-bg); padding: 40px; border-radius: 16px;
    width: 90%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    text-align: center; border: 1px solid var(--border-color); position: relative;
}
.auth-logo { font-family: var(--font-header); color: var(--btn-color); margin-bottom: 20px; font-size: 2.5rem; }
.auth-subtitle { font-family: sans-serif; color: #888; margin-bottom: 25px; font-size: 0.95rem; }
.auth-input {
    width: 100%; padding: 12px; margin-bottom: 12px;
    border: 1px solid var(--border-color); border-radius: 8px;
    background: var(--bg-color); color: var(--text-color); box-sizing: border-box; font-size: 1rem;
    transition: 0.3s;
}
.auth-input:focus { border-color: var(--btn-color); outline: none; box-shadow: 0 0 0 3px rgba(0,0,0,0.05); }
.auth-switch { margin-top: 20px; font-size: 0.9rem; color: #777; }
.auth-switch span { color: var(--btn-color); cursor: pointer; font-weight: bold; text-decoration: underline; }
.auth-error { color: #e74c3c; font-size: 0.9rem; margin-top: 15px; font-weight: bold; }
.close-overlay-btn { position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #999; transition: 0.2s; }
.close-overlay-btn:hover { color: var(--btn-color); transform: rotate(90deg); }


/* --- Footer & Admin --- */
.footer-simple { text-align: center; margin-top: 50px; padding: 20px; border-top: 1px solid rgba(0,0,0,0.05); color: #888; }
.dev-line { font-family: sans-serif; font-size: 0.9rem; margin-bottom: 5px; }
.dev-name { color: var(--btn-color); font-weight: bold; }
.dev-role { font-family: serif; font-style: italic; font-size: 0.85rem; opacity: 0.8; margin-top: 0; }
.social-icons { margin-top: 15px; display: flex; justify-content: center; gap: 20px; }
.social-icons a { color: #888; font-size: 1.2rem; transition: 0.3s; }
.social-icons a:hover { color: var(--btn-color); transform: translateY(-3px); }

#admin-toggle-btn { position: fixed; bottom: 20px; right: 20px; background: transparent; border: none; color: #ccc; font-size: 1.2rem; opacity: 0.3; transition: 0.3s; z-index: 1000; }
#admin-toggle-btn:hover { opacity: 1; color: var(--btn-color); }
.admin-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 5000; display: flex; justify-content: center; align-items: center; }
.admin-box { background: var(--card-bg); width: 90%; max-width: 600px; padding: 30px; border-radius: 10px; position: relative; max-height: 80vh; overflow-y: auto; }
.large-box { max-width: 800px; }
.close-btn { position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-color); }
.admin-input { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; background: var(--bg-color); color: var(--text-color); }
.table-wrapper { overflow-x: auto; margin-top: 15px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { border: 1px solid var(--border-color); padding: 8px; text-align: left; }
th { background: rgba(0,0,0,0.05); }
.danger-btn { background: #e74c3c; color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; }
.secondary-btn { background: var(--card-bg); border: 1px solid var(--border-color); color: var(--text-color); padding: 8px 15px; border-radius: 5px; cursor: pointer; }
.log-text-display { white-space: pre-wrap; background: rgba(0,0,0,0.03); padding: 15px; border-radius: 5px; font-family: monospace; max-height: 300px; overflow-y: auto; font-size: 0.9rem; color: var(--text-color); }

.hidden { display: none !important; }
.fade-in-up { animation: fadeInUp 0.5s ease forwards; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.spinner-modern { width: 30px; height: 30px; border: 3px solid #eee; border-top-color: var(--btn-color); border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { 100% { transform: rotate(360deg); } }
.spinner-dots span { width: 5px; height: 5px; background: #fff; border-radius: 50%; display: inline-block; animation: bounce 1.4s infinite ease-in-out both; margin: 0 2px; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* =========================================
   MOBILE OPTIMIZATIONS & BOTTOM SHEET
   ========================================= */
@media (max-width: 1024px) {
    
    /* 1. Fix Header Icons */
    .container { margin: 80px auto 20px; padding: 0 20px; width: 100%; box-sizing: border-box; }
    
    .top-controls { 
        top: 15px; right: 15px; 
        gap: 12px; 
        background: rgba(255,255,255,0.8); 
        padding: 5px 10px;
        border-radius: 20px;
        backdrop-filter: blur(5px);
    }
    
    .control-icon-btn { font-size: 1.3rem; width: 35px; height: 35px; }
    h1 { font-size: 1.8rem; margin-top: 10px; }
    
    /* 2. Modern Bottom Sheet */
    .tooltip {
        position: fixed !important; top: auto !important; bottom: 0 !important; left: 0 !important;
        transform: none !important; width: 100% !important; max-width: 100% !important;
        background: var(--card-bg);
        border-radius: 24px 24px 0 0 !important;
        padding: 25px 20px 30px 20px; 
        box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
        z-index: 10000; border: 1px solid var(--border-color); border-bottom: none;
        display: flex; flex-direction: column; align-items: center; gap: 15px;
        transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        max-height: 50vh !important; /* Safety height */
    }
    .tooltip::after { display: none; } 
    .tooltip-content { max-height: 40vh; } /* Enable internal scrolling */

    /* Header (English Word) */
    .tooltip-header { width: 100%; text-align: center; border-bottom: 1px solid rgba(0,0,0,0.05); padding-bottom: 10px; }
    #target-word-display { font-family: var(--font-primary); color: #999; font-size: 1rem; font-weight: bold; }

    /* Translated Text */
    #translated-text { 
        font-size: 1.3rem; /* Slightly smaller for long text */
        padding: 0 10px;
    }

    /* Save Button (Small Circle 45px) */
    .save-btn {
        display: flex !important; align-items: center; justify-content: center;
        width: 45px; height: 45px; border-radius: 50%;
        background: var(--btn-color); color: #fff;
        font-size: 1.2rem; border: none;
        box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        margin-top: 5px; transition: transform 0.2s, box-shadow 0.2s;
    }
    .save-btn:active { transform: scale(0.9); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
    
    body.dark-mode .top-controls { background: rgba(0,0,0,0.5); }
    .content-box { font-size: 1.2rem; padding-bottom: 250px; }
}