/* ===== Arabic Learning App Styles ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --gold: #f59e0b;
    --gold-light: #fcd34d;
    --gold-dark: #d97706;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #273449;
    --surface3: #2e3f58;
    --border: #334155;
    --border2: #3f536e;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --accent: #10b981;
    --accent-light: #34d399;
    --accent-dim: rgba(16, 185, 129, 0.15);
    --correct: #22c55e;
    --wrong: #ef4444;
    --correct-bg: rgba(34, 197, 94, 0.12);
    --wrong-bg: rgba(239, 68, 68, 0.12);
}

html, body {
    height: 100%;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ===== APP SHELL ===== */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ===== HEADER ===== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    font-size: 0.85rem;
    transition: color 0.15s, background 0.15s;
    text-decoration: none;
    flex-shrink: 0;
}
.btn-back:hover { color: var(--text); background: var(--surface2); }

.header-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.header-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.header-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    direction: rtl;
}

.header-right {
    width: 60px; /* balance the back button */
    flex-shrink: 0;
}

/* ===== STICKY CONTROLS (nav tabs + lesson filter together) ===== */
.sticky-controls {
    position: sticky;
    top: 56px;
    z-index: 90;
    background: var(--bg);
}

/* ===== NAV TABS ===== */
.nav-tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    font-family: inherit;
    margin-bottom: -1px;
}

.nav-tab:hover { color: var(--text); }

.nav-tab.active {
    color: var(--accent-light);
    border-bottom-color: var(--accent);
}

.tab-count {
    background: var(--surface2);
    color: var(--text-dim);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
}
.nav-tab.active .tab-count {
    background: var(--accent-dim);
    color: var(--accent-light);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    padding: 1.25rem 1rem 2rem;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
}

/* ===== MODE SELECTOR ===== */
.mode-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.mode-btn:hover { border-color: var(--border2); color: var(--text); }
.mode-btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent-light);
}

/* ===== LESSON FILTER ===== */
.filter-bar {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.filter-chip {
    padding: 0.3rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.filter-chip:hover { border-color: var(--border2); color: var(--text); }
.filter-chip.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent-light);
}

/* ===== BROWSE MODE — VOCAB GRID ===== */
.vocab-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.vocab-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 0.75rem 0.9rem;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    text-align: center;
    user-select: none;
    position: relative;
}
.vocab-card:hover {
    transform: translateY(-2px);
    border-color: var(--border2);
    box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}
.vocab-card.flipped {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.vocab-emoji {
    font-size: 2.25rem;
    line-height: 1;
    margin-bottom: 0.6rem;
    display: block;
}

.vocab-arabic {
    font-size: 1.25rem;
    font-weight: 600;
    direction: rtl;
    color: var(--gold-light);
    margin-bottom: 0.2rem;
    line-height: 1.3;
    font-family: 'Noto Naskh Arabic', 'Scheherazade New', serif;
}

.vocab-trans {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-bottom: 0.15rem;
    font-style: italic;
}

.vocab-english {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.vocab-detail {
    display: none;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-dim);
}
.vocab-card.flipped .vocab-detail { display: block; }

.lesson-tag {
    display: inline-block;
    background: var(--surface2);
    color: var(--text-dim);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ===== FLASHCARD MODE ===== */
.flashcard-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.flashcard-progress {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.flashcard-scene {
    width: 100%;
    max-width: 320px;
    height: 280px;
    perspective: 800px;
    cursor: pointer;
}

.flashcard-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.flashcard-scene.flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.flashcard-front {
    background: var(--surface);
}

.flashcard-back {
    background: var(--surface2);
    border-color: var(--accent);
    transform: rotateY(180deg);
}

.flashcard-scene .fc-emoji {
    font-size: 3.5rem;
    line-height: 1;
}

.flashcard-scene .fc-arabic {
    font-size: 2rem;
    font-weight: 700;
    direction: rtl;
    color: var(--gold-light);
    text-align: center;
    font-family: 'Noto Naskh Arabic', 'Scheherazade New', serif;
}

.flashcard-scene .fc-hint {
    font-size: 0.78rem;
    color: var(--text-dim);
}

.flashcard-scene .fc-trans {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

.flashcard-scene .fc-english {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-light);
}

.flashcard-scene .fc-lesson {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.flashcard-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.fc-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.fc-nav-btn:hover:not(:disabled) { border-color: var(--border2); color: var(--text); background: var(--surface2); }
.fc-nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.fc-counter {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 60px;
    text-align: center;
    font-weight: 600;
}

.fc-flip-hint {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ===== QUIZ MODE ===== */
.quiz-wrap {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.quiz-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.quiz-score-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
    font-weight: 600;
    font-size: 0.8rem;
}

.quiz-progress-bar {
    height: 4px;
    background: var(--surface2);
    border-radius: 2px;
    overflow: hidden;
}
.quiz-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.quiz-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.quiz-prompt-emoji {
    font-size: 4rem;
    line-height: 1;
}

.quiz-prompt-english {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
}

.quiz-prompt-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 0.25rem;
}

.quiz-choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    width: 100%;
}

.quiz-choice {
    padding: 0.9rem 0.75rem;
    background: var(--surface2);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--gold-light);
    font-size: 1.15rem;
    font-weight: 600;
    direction: rtl;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    font-family: 'Noto Naskh Arabic', 'Scheherazade New', serif;
    line-height: 1.3;
}
.quiz-choice:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.quiz-choice:disabled { cursor: default; }
.quiz-choice.correct {
    border-color: var(--correct);
    background: var(--correct-bg);
    color: #86efac;
}
.quiz-choice.wrong {
    border-color: var(--wrong);
    background: var(--wrong-bg);
    color: #fca5a5;
}
.quiz-choice.reveal {
    border-color: var(--correct);
    background: var(--correct-bg);
    color: #86efac;
    animation: pulse-correct 0.4s ease;
}

@keyframes pulse-correct {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

.quiz-feedback {
    min-height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}
.quiz-feedback.correct { color: var(--correct); }
.quiz-feedback.wrong { color: var(--wrong); }

/* ===== QUIZ COMPLETE ===== */
.quiz-complete {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 2rem 1rem;
    text-align: center;
}

.qc-icon { font-size: 3.5rem; }

.qc-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
}

.qc-stats {
    display: flex;
    gap: 1rem;
}

.qc-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.qc-stat-val {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--accent-light);
}

.qc-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.qc-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* ===== MATCH MODE ===== */
.match-wrap {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.match-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.match-instructions {
    font-size: 0.82rem;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.65rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.match-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem 1rem;
    align-items: start;
}

.match-col-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
    text-align: center;
}

.match-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.match-item {
    padding: 0.75rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    user-select: none;
}

.match-item.arabic {
    direction: rtl;
    font-size: 1.2rem;
    color: var(--gold-light);
    font-family: 'Noto Naskh Arabic', 'Scheherazade New', serif;
    line-height: 1.3;
}

.match-item:hover:not(.matched):not(:disabled) {
    border-color: var(--border2);
    color: var(--text);
    background: var(--surface2);
}

.match-item.selected {
    border-color: var(--accent);
    background: var(--accent-dim);
    color: var(--accent-light);
}

.match-item.matched {
    border-color: var(--correct);
    background: var(--correct-bg);
    color: #86efac;
    cursor: default;
    opacity: 0.7;
}

.match-item.wrong-flash {
    border-color: var(--wrong);
    background: var(--wrong-bg);
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

/* ===== MATCH COMPLETE ===== */
.match-complete {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    text-align: center;
}

/* ===== SHARED BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.25rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    font-family: inherit;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light); }

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-outline:hover { border-color: var(--border2); color: var(--text); background: var(--surface2); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 420px) {
    .vocab-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .quiz-choices {
        grid-template-columns: 1fr;
    }

    .qc-stats { flex-direction: column; align-items: center; }

    .match-item.arabic { font-size: 1.05rem; }
}
