/* ═══════════════════════════════════════════════════════
   CEFR English Trainer — Premium Design System
   Ocean-blue inspired · Clean · Elegant · Functional
   ═══════════════════════════════════════════════════════ */

:root {
    /* ── Color Palette ── */
    --primary: #1a6b8a;
    --primary-light: #2589ad;
    --primary-dark: #134f66;
    --primary-glow: #4ab8db;
    --teal: #0d9488;
    --teal-light: #14b8a6;
    --teal-lighter: #e6faf7;
    --amber: #b45309;
    --amber-light: #d97706;
    --amber-lighter: #fef3e2;
    --ink: #1a1d23;
    --ink-light: #3a3f4a;
    --ink-muted: #6b7280;
    --ink-faint: #9ca3af;
    --cream: #faf7f2;
    --cream-dark: #f0ebe3;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #e8e3db;
    --border-light: #f0ebe3;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --warning: #d97706;
    --warning-light: #fffbeb;

    /* ── Shadows ── */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 50px -12px rgba(0,0,0,0.15);
    --shadow-primary: 0 4px 14px -3px rgba(26,107,138,0.35);
    --shadow-teal: 0 4px 14px -3px rgba(13,148,136,0.3);

    /* ── Radii ── */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* ── Typography ── */
    --font-th: 'Noto Sans Thai', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-en: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* ── Transitions ── */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration: 250ms;
    --duration-slow: 400ms;
    --duration-flip: 550ms;

    /* ── Gradients ── */
    --gradient-primary: linear-gradient(135deg, var(--primary), var(--primary-light));
    --gradient-teal: linear-gradient(135deg, var(--teal), var(--teal-light));
    --gradient-amber: linear-gradient(135deg, var(--amber), var(--amber-light));
    --gradient-hero: linear-gradient(135deg, rgba(26,107,138,0.06), rgba(13,148,136,0.06));
}

/* ── Dark Mode ── */
[data-theme="dark"] {
    --ink: #e8e6e3;
    --ink-light: #c4c1bc;
    --ink-muted: #9a9690;
    --ink-faint: #6b6760;
    --cream: #13151a;
    --cream-dark: #1c1e25;
    --surface: #1a1d24;
    --surface-raised: #21242c;
    --border: #2a2d36;
    --border-light: #232630;
    --teal-lighter: #0f2622;
    --amber-lighter: #2a2010;
    --danger-light: #2a1618;
    --warning-light: #2a2216;
    --gradient-hero: linear-gradient(135deg, rgba(26,107,138,0.1), rgba(13,148,136,0.08));
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.35), 0 8px 10px -6px rgba(0,0,0,0.2);
    --shadow-xl: 0 20px 50px -12px rgba(0,0,0,0.5);
}

/* ── Reset & Base ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-en);
    background: var(--cream);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
}

.container {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ══════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════ */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid var(--border);
}

.header-right { display: flex; gap: 6px; }

.logo {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
    letter-spacing: -0.01em;
}

.logo-char {
    font-family: var(--font-en);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--surface);
    background: var(--gradient-primary);
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-primary);
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--ink-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
}

.btn-icon:hover {
    background: var(--cream-dark);
    color: var(--ink);
}

.btn-icon:active { transform: scale(0.92); }

/* ══════════════════════════════════════════════════════
   SCREENS
   ══════════════════════════════════════════════════════ */
.screen {
    display: none;
    padding-bottom: 48px;
    animation: screenIn var(--duration-slow) var(--ease-out);
}

.screen.active { display: block; }

@keyframes screenIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════════════════════
   LEVEL SELECT
   ══════════════════════════════════════════════════════ */
.hero-section {
    position: relative;
    padding: 48px 24px 40px;
    text-align: center;
}

.hero-content { position: relative; z-index: 1; }

.hero-bg {
    position: absolute;
    inset: 0;
    background-image: url('/images/hero-bg.png');
    background-size: cover;
    background-position: center;
    opacity: 0.25;
    z-index: 0;
}

.hero-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 0%, var(--cream) 100%);
}

.hero-title {
    font-family: var(--font-en);
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.hero-title .accent {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1rem;
    color: var(--ink-muted);
    font-weight: 400;
    font-family: var(--font-th);
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 24px;
}

.hero-stat { text-align: center; }

.hero-stat-num {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.hero-stat-label {
    font-size: 0.75rem;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
    margin-top: 2px;
}

/* Level Grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding-top: 8px;
}

.level-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 20px 20px;
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
    position: relative;
    overflow: hidden;
}

.level-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    opacity: 0;
    transition: opacity var(--duration) var(--ease-out);
}

.level-card:nth-child(1)::before { background: var(--gradient-teal); }
.level-card:nth-child(2)::before { background: var(--gradient-primary); }
.level-card:nth-child(3)::before { background: var(--gradient-amber); }
.level-card:nth-child(4)::before { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.level-card:nth-child(5)::before { background: linear-gradient(135deg, #dc2626, #f87171); }
.level-card:nth-child(6)::before { background: linear-gradient(135deg, #1a1d23, #4a5568); }

.level-card:hover {
    border-color: transparent;
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.level-card:hover::before { opacity: 1; }
.level-card:active { transform: translateY(-2px); }

.level-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.level-card-num {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--ink);
    font-family: var(--font-en);
    line-height: 1;
}

.level-card-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 3px 7px;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.level-card:nth-child(1) .level-card-badge { background: var(--teal-lighter); color: var(--teal); }
.level-card:nth-child(2) .level-card-badge { background: rgba(26,107,138,0.1); color: var(--primary); }
.level-card:nth-child(3) .level-card-badge { background: var(--amber-lighter); color: var(--amber); }
.level-card:nth-child(4) .level-card-badge { background: #f5f3ff; color: #7c3aed; }
.level-card:nth-child(5) .level-card-badge { background: var(--danger-light); color: #dc2626; }
.level-card:nth-child(6) .level-card-badge { background: #f1f5f9; color: #475569; }

.level-card-desc {
    font-size: 0.8rem;
    color: var(--ink-muted);
    margin-bottom: 16px;
    line-height: 1.4;
}

.level-card-count {
    font-size: 0.85rem;
    color: var(--ink-light);
    font-weight: 500;
    margin-bottom: 10px;
}

.progress-bar {
    height: 5px;
    background: var(--cream-dark);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.6s var(--ease-out);
}

.level-card:nth-child(1) .progress-bar-fill { background: var(--gradient-teal); }
.level-card:nth-child(2) .progress-bar-fill { background: var(--gradient-primary); }
.level-card:nth-child(3) .progress-bar-fill { background: var(--gradient-amber); }
.level-card:nth-child(4) .progress-bar-fill { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.level-card:nth-child(5) .progress-bar-fill { background: linear-gradient(135deg, #dc2626, #f87171); }
.level-card:nth-child(6) .progress-bar-fill { background: linear-gradient(135deg, #1a1d23, #4a5568); }

.progress-label {
    font-size: 0.72rem;
    color: var(--ink-faint);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

/* ══════════════════════════════════════════════════════
   FLASHCARD
   ══════════════════════════════════════════════════════ */
.flashcard-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0 12px;
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 4px;
    border: none;
    background: none;
    color: var(--ink-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: all var(--duration) var(--ease-out);
}

.btn-back:hover { background: var(--cream-dark); color: var(--ink); }

.card-counter {
    font-size: 0.85rem;
    color: var(--ink-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    font-variant-numeric: tabular-nums;
}

#current-level-label {
    font-weight: 600;
    color: var(--primary);
}

.counter-divider { color: var(--border); }

.flashcard-progress-track {
    width: 100%;
    height: 3px;
    background: var(--cream-dark);
    border-radius: var(--radius-full);
    margin-bottom: 20px;
    overflow: hidden;
}

.flashcard-progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    transition: width 0.4s var(--ease-out);
}

/* Card 3D */
.flashcard-wrapper {
    perspective: 1200px;
    margin-bottom: 20px;
}

.flashcard {
    position: relative;
    width: 100%;
    min-height: 340px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform var(--duration-flip) var(--ease-out);
}

.flashcard.flipped { transform: rotateY(180deg); }

.card-front, .card-back {
    position: absolute;
    width: 100%;
    min-height: 340px;
    backface-visibility: hidden;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Card Front ── */
.card-front {
    align-items: center;
    justify-content: center;
    padding: 32px 32px 24px;
}

.card-pos {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--surface);
    background: var(--gradient-primary);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    margin-bottom: 16px;
}

.card-word {
    font-family: var(--font-en);
    font-size: 4rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.15;
    text-align: center;
    margin-bottom: 8px;
}

.card-phonetic {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: 400;
    letter-spacing: 1px;
    margin-bottom: 16px;
    font-family: var(--font-mono);
}

.card-tap-hint {
    margin-top: auto;
    font-size: 0.78rem;
    color: var(--ink-faint);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--cream);
    border-radius: var(--radius-full);
    animation: tapPulse 2.5s ease-in-out infinite;
}

@keyframes tapPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.card-tap-hint svg { opacity: 0.5; }

/* ── Card Back ── */
.card-back {
    transform: rotateY(180deg);
    align-items: stretch;
    overflow-y: auto;
    max-height: 78vh;
    padding: 0;
}

.card-back-header {
    padding: 28px 28px 20px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
    background: var(--gradient-hero);
}

.card-word-small {
    font-family: var(--font-en);
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.card-phonetic-small {
    font-size: 0.9rem;
    color: var(--primary);
    margin-top: 2px;
    letter-spacing: 0.5px;
    font-family: var(--font-mono);
}

.card-definition {
    font-size: 0.95rem;
    color: var(--text-secondary, #666);
    font-style: italic;
    margin-top: 8px;
    line-height: 1.4;
}

.card-thai {
    font-family: var(--font-th);
    font-size: 1.3rem;
    color: var(--teal);
    font-weight: 600;
    margin-top: 8px;
}

.card-back-body {
    padding: 24px 28px 28px;
}

/* Mnemonic */
.mnemonic-box {
    background: var(--amber-lighter);
    border: 1px solid rgba(180,83,9,0.15);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 24px;
}

.mnemonic-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--amber);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mnemonic-text {
    font-size: 0.9rem;
    color: var(--ink-light);
    line-height: 1.65;
    font-family: var(--font-th);
}

/* Examples */
.examples-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin-bottom: 14px;
}

.examples-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.example-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--cream);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
    border: 1px solid transparent;
}

.example-item:hover {
    background: var(--cream-dark);
    border-color: var(--border);
}

.example-num {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.example-en {
    font-family: var(--font-en);
    font-size: 1rem;
    color: var(--ink);
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.example-en .speak-sm {
    opacity: 0;
    transition: opacity var(--duration) var(--ease-out);
    flex-shrink: 0;
    color: var(--primary);
}

.example-item:hover .speak-sm { opacity: 1; }

.example-th {
    font-size: 0.88rem;
    color: var(--ink-muted);
    font-family: var(--font-th);
}

/* ══════════════════════════════════════════════════════
   ACTION BUTTONS
   ══════════════════════════════════════════════════════ */
.card-actions {
    display: flex;
    justify-content: center;
    margin-bottom: 14px;
}

.btn-speak {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 28px;
    border: none;
    background: var(--gradient-primary);
    color: var(--surface);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
    box-shadow: var(--shadow-primary);
}

.btn-speak:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-primary), 0 0 0 3px rgba(26,107,138,0.12);
}

.btn-speak:active { transform: translateY(0) scale(0.97); }

.btn-speak.speaking {
    animation: speakPulse 0.8s ease-in-out infinite;
}

@keyframes speakPulse {
    0%, 100% { box-shadow: var(--shadow-primary); }
    50% { box-shadow: var(--shadow-primary), 0 0 0 8px rgba(26,107,138,0.15); }
}

/* Nav buttons */
.nav-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.btn-nav {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--ink-light);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
}

.btn-nav:hover {
    border-color: var(--ink-faint);
    background: var(--cream);
    color: var(--ink);
}

.btn-nav:active { transform: scale(0.97); }

.btn-shuffle { flex: 0.5; }

/* Mastery */
.mastery-buttons {
    display: flex;
    gap: 8px;
}

.btn-mastery {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 16px;
    border: none;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--duration) var(--ease-out);
}

.btn-known {
    background: var(--teal);
    color: var(--surface);
    box-shadow: var(--shadow-teal);
}

.btn-known:hover {
    background: var(--teal-light);
    transform: translateY(-1px);
}

.btn-known:active { transform: translateY(0) scale(0.97); }

.btn-unknown {
    background: var(--cream-dark);
    color: var(--ink-muted);
    border: 1.5px solid var(--border);
}

.btn-unknown:hover {
    background: var(--warning-light);
    border-color: var(--warning);
    color: var(--warning);
}

.btn-unknown:active { transform: scale(0.97); }

/* Keyboard hint bar */
.keyboard-hints {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.keyboard-hints span {
    font-size: 0.7rem;
    color: var(--ink-faint);
    display: flex;
    align-items: center;
    gap: 4px;
}

.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-family: var(--font-mono);
    background: var(--surface);
    color: var(--ink-muted);
}

/* ══════════════════════════════════════════════════════
   SEARCH OVERLAY
   ══════════════════════════════════════════════════════ */
.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(26,29,35,0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
    animation: overlayIn var(--duration) var(--ease-out);
}

.search-overlay.active { display: flex; }

@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.search-container {
    width: 92%;
    max-width: 560px;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    max-height: 65vh;
    display: flex;
    flex-direction: column;
    animation: slideDown var(--duration-slow) var(--ease-out);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-light);
    color: var(--ink-faint);
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1.05rem;
    color: var(--ink);
    background: none;
    font-family: var(--font-en);
}

.search-input::placeholder { color: var(--ink-faint); }

.search-hint {
    font-size: 0.7rem;
    color: var(--ink-faint);
    background: var(--cream);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

.search-results {
    overflow-y: auto;
    padding: 8px;
}

.search-empty {
    padding: 32px 20px;
    text-align: center;
    color: var(--ink-faint);
    font-size: 0.9rem;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.search-result-item:hover {
    background: var(--cream);
    transform: translateX(4px);
}

.search-result-item:active {
    background: var(--cream-dark);
    transform: translateX(2px) scale(0.99);
}

.search-result-word {
    font-family: var(--font-en);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
    min-width: 100px;
}

.search-result-info { flex: 1; }

.search-result-phonetic {
    font-size: 0.8rem;
    color: var(--primary);
    font-family: var(--font-mono);
}

.search-result-thai {
    font-size: 0.82rem;
    color: var(--ink-muted);
    font-family: var(--font-th);
}

.search-result-level {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-full);
    background: rgba(26,107,138,0.1);
    color: var(--primary);
    letter-spacing: 0.03em;
}

/* ══════════════════════════════════════════════════════
   STATS MODAL
   ══════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(26,29,35,0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    animation: overlayIn var(--duration) var(--ease-out);
}

.modal-overlay.active { display: flex; }

.modal {
    width: 92%;
    max-width: 480px;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: slideDown var(--duration-slow) var(--ease-out);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 24px 18px;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
}

.modal-body { padding: 24px; }

.stat-row {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.stat-row:last-child { border-bottom: none; }

.stat-label {
    font-weight: 600;
    color: var(--ink);
    min-width: 40px;
    font-size: 0.9rem;
}

.stat-bar {
    flex: 1;
    margin: 0 16px;
    height: 6px;
    background: var(--cream-dark);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background: var(--gradient-teal);
    border-radius: var(--radius-full);
    transition: width 0.6s var(--ease-out);
}

.stat-value {
    font-weight: 600;
    color: var(--teal);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    min-width: 90px;
    text-align: right;
}

.stat-total {
    margin-top: 12px;
    padding-top: 16px;
    border-top: 2px solid var(--border);
}

/* ══════════════════════════════════════════════════════
   MASTERY INDICATOR
   ══════════════════════════════════════════════════════ */
.mastery-indicator {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    z-index: 2;
    animation: popIn var(--duration) var(--ease-spring);
}

@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

.mastery-known {
    background: var(--teal);
    color: var(--surface);
    box-shadow: var(--shadow-teal);
}

.mastery-unknown {
    background: var(--warning);
    color: var(--surface);
}

/* ══════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════ */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--ink);
    color: var(--surface);
    padding: 10px 24px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-xl);
    transition: transform var(--duration-slow) var(--ease-spring);
    z-index: 300;
    pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ══════════════════════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════════════════════ */
.card-back::-webkit-scrollbar,
.search-results::-webkit-scrollbar { width: 5px; }

.card-back::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track { background: transparent; }

.card-back::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .header { padding: 0 16px; height: 54px; }
    .container { padding: 0 16px; }
    .hero-section { padding: 32px 16px 28px; }
    .hero-title { font-size: 1.6rem; }
    .hero-stats { gap: 20px; }
    .hero-stat-num { font-size: 1.2rem; }
    .level-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .level-card { padding: 18px 16px 16px; }
    .level-card-num { font-size: 1.2rem; }
    .level-card-desc {
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        font-size: 0.75rem;
        margin-bottom: 12px;
    }
    .card-word { font-size: 3rem; }
    .card-front { padding: 36px 24px; }
    .card-back-header { padding: 22px 20px 16px; }
    .card-back-body { padding: 20px; }
    .flashcard { min-height: 300px; }
    .card-front, .card-back { min-height: 300px; }
    .keyboard-hints { display: none; }
    .search-container { width: 96%; }
}

@media (max-width: 380px) {
    .level-grid { grid-template-columns: 1fr; }
    .hero-stats { flex-direction: column; gap: 8px; }
}

/* ── Dark Mode Overrides ── */
[data-theme="dark"] .header { background: rgba(19,21,26,0.88); }

[data-theme="dark"] .hero-bg { opacity: 0.12; }

[data-theme="dark"] .hero-bg::after {
    background: linear-gradient(180deg, transparent 0%, var(--cream) 100%);
}

[data-theme="dark"] .search-overlay,
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.7); }

[data-theme="dark"] .btn-icon:hover,
[data-theme="dark"] .search-hint { background: var(--cream-dark); }

[data-theme="dark"] .toast {
    background: var(--surface-raised);
    color: var(--ink);
    border: 1px solid var(--border);
}

[data-theme="dark"] .mnemonic-text { color: #d4cfc8; }
[data-theme="dark"] .mnemonic-box { border-color: rgba(180,83,9,0.35); }
[data-theme="dark"] .mnemonic-label { color: var(--amber-light); }

[data-theme="dark"] .level-card:nth-child(4) .level-card-badge { background: #1e1e3a; }
[data-theme="dark"] .level-card:nth-child(5) .level-card-badge { background: #2a1618; }
[data-theme="dark"] .level-card:nth-child(6) .level-card-badge { background: #1e2028; }
