/* ============================================================
   POLISHPATH - STYLES
   Dark navy + teal, Babbel-inspired glassmorphism
   ============================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --font-scale: 1;
    --bg: #1a0e10;
    --bg-gradient: radial-gradient(ellipse at 20% 50%, #3a1620 0%, #1a0e10 70%);
    --glass: rgba(255, 255, 255, 0.06);
    --glass-hover: rgba(255, 255, 255, 0.12);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-light: rgba(255, 255, 255, 0.12);
    --primary: #e6394f;
    --primary-dim: rgba(230, 57, 79, 0.15);
    --primary-glow: rgba(230, 57, 79, 0.18);
    --success: #2ecc71;
    --success-dim: rgba(46, 204, 113, 0.15);
    --error: #e8823c;
    --error-dim: rgba(232, 130, 60, 0.15);
    --streak: #f2a93b;
    --text: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.5);
    --text-dim: rgba(255, 255, 255, 0.25);
    --blur: 16px;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 24px;
}

[data-theme="light"] {
    --bg: #faf1ec;
    --bg-gradient: radial-gradient(ellipse at 20% 50%, #fbe2dd 0%, #faf1ec 70%);
    --glass: rgba(35, 15, 15, 0.045);
    --glass-hover: rgba(35, 15, 15, 0.09);
    --glass-border: rgba(35, 15, 15, 0.09);
    --glass-border-light: rgba(35, 15, 15, 0.14);
    --primary: #c81e37;
    --primary-dim: rgba(200, 30, 55, 0.12);
    --primary-glow: rgba(200, 30, 55, 0.17);
    --success: #1e8449;
    --success-dim: rgba(30, 132, 73, 0.15);
    --error: #b8591f;
    --error-dim: rgba(184, 89, 31, 0.15);
    --streak: #b3760a;
    --text: #241012;
    --text-muted: rgba(36, 16, 18, 0.62);
    --text-dim: rgba(36, 16, 18, 0.35);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

.app-shell {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg-gradient);
}

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ===== GLASS ===== */
.glass {
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
}

/* ===== TOPBAR ===== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.brand-name {
    font-size: calc(19px * var(--font-scale));
    font-weight: 800;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text);
    cursor: pointer;
}

.icon-btn:active {
    background: var(--glass-hover);
}

.icon-btn .material-symbols-outlined {
    font-size: calc(19px * var(--font-scale)) !important;
}

.header-right .streak {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: calc(15px * var(--font-scale));
    font-weight: 700;
    color: var(--streak);
}

/* ===== MAIN / PAGES ===== */
main {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px 90px 14px;
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 16px;
    font-size: calc(14px * var(--font-scale));
}

/* ===== LEVEL FILTER PILLS (shared: home / words / grammar) ===== */
.home-level-filter,
.level-filter-words,
.level-filter-grammar,
.level-filter-lessons {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
}

.home-level-btn,
.level-filter-btn,
.grammar-filter-btn,
.lessons-level-btn {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--glass-border);
    background: var(--glass);
    color: var(--text-muted);
    font-weight: 700;
    font-size: calc(14px * var(--font-scale));
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.home-level-btn.active,
.level-filter-btn.active,
.grammar-filter-btn.active,
.lessons-level-btn.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 4px 14px var(--primary-glow);
}

.home-level-btn:active,
.level-filter-btn:active,
.grammar-filter-btn:active,
.lessons-level-btn:active {
    transform: scale(0.96);
}

/* ===== STATS GRID (Home) ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}

.stat-card {
    border-radius: var(--radius);
    padding: 18px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

.stat-card .material-symbols-outlined {
    color: var(--primary);
    font-size: calc(26px * var(--font-scale));
}

.stat-num {
    font-size: calc(26px * var(--font-scale));
    font-weight: 800;
}

.stat-label {
    font-size: calc(11px * var(--font-scale));
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== BACKUP REMINDER ===== */
.backup-reminder {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px 12px 14px;
    margin-bottom: 12px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--primary-dim);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius);
}

.backup-reminder-icon {
    font-size: calc(20px * var(--font-scale)) !important;
    color: var(--primary);
    flex-shrink: 0;
}

.backup-reminder-text {
    flex: 1;
    min-width: 0;
}

.backup-reminder-title {
    font-size: calc(13px * var(--font-scale));
    font-weight: 700;
}

.backup-reminder-sub {
    font-size: calc(11px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 1px;
}

.backup-reminder-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: calc(12px * var(--font-scale));
    font-weight: 700;
    cursor: pointer;
}

.backup-reminder-dismiss {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
}

.backup-reminder-dismiss .material-symbols-outlined {
    font-size: calc(16px * var(--font-scale)) !important;
}

/* ===== HOME SHORTCUTS ===== */
.streak-calendar {
    padding: 14px;
    margin-bottom: 16px;
}

.streak-calendar-title {
    font-size: calc(12px * var(--font-scale));
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.streak-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
}

.streak-day {
    aspect-ratio: 1;
    border-radius: 5px;
    background: var(--glass-hover);
}

.streak-day.active {
    background: var(--primary);
}

.streak-day.today {
    box-shadow: 0 0 0 2px var(--text) inset;
}
.home-shortcuts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.shortcut-card {
    border-radius: var(--radius);
    padding: 20px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: calc(13px * var(--font-scale));
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s ease;
}

.shortcut-card:active {
    background: var(--glass-hover);
}

.shortcut-card .material-symbols-outlined {
    font-size: calc(26px * var(--font-scale));
    color: var(--primary);
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 40;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-label {
    font-size: calc(10px * var(--font-scale));
    font-weight: 700;
}

/* ===== SWIPE HINT BANNER ===== */
.swipe-hint-banner {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    margin-bottom: 10px;
    background: var(--primary-dim);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: calc(12px * var(--font-scale));
    font-weight: 600;
    transition: opacity 0.5s ease;
}

.swipe-hint-banner.fade-out {
    opacity: 0;
}

/* ===== WORDS SUB-TABS ===== */
.words-subtabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 4px;
}

.words-subtab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 10px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font-weight: 700;
    font-size: calc(13px * var(--font-scale));
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.words-subtab-btn.active {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 4px 14px var(--primary-glow);
}

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

/* ===== LEARNED SEARCH ===== */
.learned-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin-bottom: 10px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.learned-search-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
}

.learned-search-icon {
    font-size: calc(20px * var(--font-scale)) !important;
    color: var(--text-muted);
    flex-shrink: 0;
}

.learned-search-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: calc(14px * var(--font-scale));
    font-family: inherit;
}

.learned-search-input::placeholder {
    color: var(--text-dim);
}

.learned-search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--glass-hover);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
}

.learned-search-clear .material-symbols-outlined {
    font-size: calc(15px * var(--font-scale)) !important;
}

/* ===== QUICK QUIZ WIDGET ===== */
.quick-quiz-row {
    display: flex;
    flex-direction: column;
}

.quick-quiz-widget {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--primary-dim), var(--glass));
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--primary-dim);
    border-radius: var(--radius);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.quick-quiz-widget:active {
    background: linear-gradient(135deg, var(--primary-glow), var(--glass-hover));
}

.quick-quiz-icon {
    font-size: calc(22px * var(--font-scale)) !important;
    color: var(--primary);
    flex-shrink: 0;
}

.quick-quiz-text {
    flex: 1;
    min-width: 0;
}

.quick-quiz-title {
    font-size: calc(14px * var(--font-scale));
    font-weight: 800;
}

.quick-quiz-sub {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 2px;
}

.quick-quiz-chevron {
    font-size: calc(20px * var(--font-scale)) !important;
    color: var(--text-dim);
    flex-shrink: 0;
}

/* ===== LEARNED WORDS LIST ===== */
.learned-words-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.learned-word-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    border-left: 3px solid var(--success);
}

.learned-word-item .lw-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

/* ===== WORD DETAIL ===== */
.word-detail {
    text-align: center;
    padding: 20px 8px;
}

.word-detail-stars {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 10px;
}

.word-detail-pl {
    font-size: calc(32px * var(--font-scale));
    font-weight: 800;
}

.word-detail-en {
    font-size: calc(18px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 4px;
}

.word-detail-audio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    padding: 10px 18px;
    color: var(--primary);
    font-weight: 700;
}

.word-detail-example {
    margin-top: 28px;
    padding: 16px;
    background: var(--glass);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    text-align: left;
}

.word-detail-example-pl {
    font-size: calc(15px * var(--font-scale));
    font-style: italic;
}

.word-detail-example-en {
    font-size: calc(13px * var(--font-scale));
    color: var(--text-dim);
    margin-top: 4px;
}

.word-detail-example .word-detail-audio {
    margin-top: 12px;
    padding: 8px 14px;
    font-size: calc(13px * var(--font-scale));
}

.learned-word-item .lw-pl {
    font-weight: 700;
    font-size: calc(15px * var(--font-scale));
}

.learned-word-item .lw-en {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
}

.learned-word-item .lw-stars {
    display: flex;
    gap: 2px;
    margin-top: 3px;
}

.lw-star {
    font-size: calc(13px * var(--font-scale)) !important;
    color: var(--text-dim);
    font-variation-settings: 'FILL' 0;
}

.lw-star.filled {
    color: #f2c14e;
    font-variation-settings: 'FILL' 1;
}

.learned-word-item .lw-audio {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: pointer;
    color: var(--text);
}

/* ===== FLIPCARD ===== */
#wordArea {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 400px;
}

.flip-wrap {
    position: relative;
    perspective: 800px;
    cursor: pointer;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    flex-shrink: 0;
    padding: 4px;
    touch-action: pan-y;
    user-select: none;
}

.swipe-stamp {
    position: absolute;
    top: 18px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: calc(13px * var(--font-scale));
    font-weight: 800;
    letter-spacing: 0.5px;
    opacity: 0;
    pointer-events: none;
    border: 2px solid currentColor;
    transform: rotate(-12deg);
}

.stamp-know {
    left: 18px;
    color: var(--success);
    background: var(--success-dim);
}

.stamp-dontknow {
    right: 18px;
    color: var(--error);
    background: var(--error-dim);
    transform: rotate(12deg);
}

.flip-wrap .inner {
    position: relative;
    width: 100%;
    padding-bottom: 75%;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.flip-wrap.flipped .inner {
    transform: rotateY(180deg);
}

.flip-wrap .front,
.flip-wrap .back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    background: linear-gradient(160deg, var(--primary-dim), rgba(255,255,255,0.04));
    border: 1px solid var(--glass-border-light);
}

.flip-wrap .back {
    transform: rotateY(180deg);
    background: linear-gradient(160deg, var(--primary-glow), rgba(255,255,255,0.04));
}

.word-pl {
    font-size: calc(30px * var(--font-scale));
    font-weight: 800;
    margin-bottom: 8px;
}

.word-en {
    font-size: calc(16px * var(--font-scale));
    color: var(--text-muted);
}

.tap-hint {
    position: absolute;
    bottom: 14px;
    font-size: calc(11px * var(--font-scale));
    color: var(--text-dim);
}

.example-pl {
    font-size: calc(19px * var(--font-scale));
    font-weight: 700;
    margin-bottom: 8px;
}

.example-en {
    font-size: calc(14px * var(--font-scale));
    color: var(--text-muted);
}

.flip-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 18px;
}

.glass-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
}

.glass-btn:active {
    background: var(--glass-hover);
}

/* Icon + text pill button (e.g. "Show Translation") - distinct from the
   icon-only circular .glass-btn used for prev/next/audio controls. */
.pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    height: auto;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text);
    font-size: calc(13px * var(--font-scale));
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.pill-btn:active {
    background: var(--glass-hover);
}

.counter {
    font-size: calc(13px * var(--font-scale));
    font-weight: 700;
    color: var(--text-muted);
    min-width: 56px;
    text-align: center;
}

.flip-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    width: 100%;
    max-width: 420px;
}

.btn-dontknow,
.btn-know {
    flex: 1;
    width: auto;
    height: auto;
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 700;
    font-size: calc(14px * var(--font-scale));
}

.btn-dontknow {
    color: var(--error);
    border-color: var(--error);
}

.btn-know {
    color: var(--success);
    border-color: var(--success);
}

.word-progress {
    margin-top: 16px;
    font-size: calc(13px * var(--font-scale));
    color: var(--text-muted);
    font-weight: 600;
}

/* ===== LESSONS LIST ===== */
.lessons-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lesson-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s ease;
}

.lesson-item:active {
    background: var(--glass-hover);
}

.lesson-item.done {
    border-left: 3px solid var(--success);
}

.lesson-item.locked {
    opacity: 0.45;
    cursor: not-allowed;
}

.lesson-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.lesson-icon .material-symbols-outlined {
    color: var(--primary);
    font-size: calc(22px * var(--font-scale));
}

.lesson-item.done .lesson-icon .material-symbols-outlined {
    color: var(--success);
}

.lesson-info {
    flex: 1;
    min-width: 0;
}

.lesson-title {
    font-weight: 700;
    font-size: calc(15px * var(--font-scale));
}

.lesson-subtitle {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 2px;
}

.lesson-arrow {
    color: var(--text-dim);
}

/* ===== GRAMMAR LIST ===== */
.grammar-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.grammar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: calc(15px * var(--font-scale));
    transition: background 0.2s ease;
}

.grammar-item:active {
    background: var(--glass-hover);
}

.grammar-item.done {
    border-left-color: var(--success);
}

.grammar-item .tag {
    font-size: calc(11px * var(--font-scale));
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--primary-dim);
    color: var(--primary);
}

.grammar-item.done .tag {
    color: var(--success);
    background: var(--success-dim);
}

/* ===== MODALS (full-screen pages) ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 500;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-panel {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-gradient);
    transform: translateY(14px);
    transition: transform 0.25s ease;
}

.modal-overlay.active .modal-panel {
    transform: translateY(0);
}

.modal-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--glass-border);
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
}

.modal-back {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.modal-back:active {
    background: var(--glass-hover);
}

.modal-topbar-title {
    font-size: calc(16px * var(--font-scale));
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}

.modal-body .body {
    font-size: calc(15px * var(--font-scale));
    line-height: 1.7;
    color: var(--text);
}

.modal-body .body p {
    margin-bottom: 10px;
}

.modal-body .body strong {
    color: var(--primary);
}

.modal-body .body .ex {
    margin: 10px 0;
    padding: 12px 14px;
    background: var(--glass);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
}

.modal-body .body .ex-pl {
    font-weight: 700;
}

.modal-body .body .ex-en {
    color: var(--text-muted);
    font-size: calc(13px * var(--font-scale));
    margin-top: 2px;
}

.modal-body .body h1,
.modal-body .body h2,
.modal-body .body h3,
.modal-body .body h4 {
    color: var(--text);
    margin: 18px 0 8px;
    font-weight: 800;
}

.modal-body .body h1 { font-size: calc(22px * var(--font-scale)); }
.modal-body .body h2 { font-size: calc(19px * var(--font-scale)); }
.modal-body .body h3 { font-size: calc(16px * var(--font-scale)); }
.modal-body .body h4 { font-size: calc(14px * var(--font-scale)); }

/* ===== SETTINGS MODAL ===== */
.settings-section {
    margin-bottom: 24px;
}

.settings-section-title {
    font-size: calc(12px * var(--font-scale));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding: 0 4px;
}

.settings-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    margin-bottom: 8px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.settings-row:active {
    background: var(--glass-hover);
}

.settings-row:disabled {
    opacity: 0.5;
    cursor: default;
}

.settings-row-static {
    cursor: default;
}

.settings-row-icon {
    font-size: calc(22px * var(--font-scale)) !important;
    color: var(--primary);
    flex-shrink: 0;
}

.settings-row-text {
    flex: 1;
    min-width: 0;
}

.settings-row-title {
    font-size: calc(14px * var(--font-scale));
    font-weight: 700;
}

.settings-row-sub {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 2px;
}

.settings-row-chevron {
    font-size: calc(20px * var(--font-scale)) !important;
    color: var(--text-dim);
    flex-shrink: 0;
}

.settings-hint {
    font-size: calc(12px * var(--font-scale));
    line-height: 1.5;
    color: var(--text-muted);
    padding: 4px 4px 0;
}

.theme-toggle-row {
    display: flex;
    gap: 8px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 4px;
}

.theme-option-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    opacity: 0.6;
    font-size: calc(13px * var(--font-scale));
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
}

.theme-option-btn .material-symbols-outlined {
    font-size: calc(17px * var(--font-scale)) !important;
}

.theme-option-btn.active {
    background: var(--primary);
    color: #fff;
    opacity: 1;
}

/* ===== SWITCH TOGGLE (Dark Mode on/off) ===== */
.switch-toggle {
    position: relative;
    flex-shrink: 0;
    width: 48px;
    height: 28px;
    padding: 0;
    border-radius: 999px;
    background: var(--glass-hover);
    border: 1px solid var(--glass-border);
    cursor: pointer;
}

.switch-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: transform 0.2s ease, background 0.2s ease;
}

.switch-toggle.on {
    background: var(--primary-dim);
    border-color: var(--primary);
}

.switch-toggle.on .switch-toggle-thumb {
    transform: translateX(20px);
    background: var(--primary);
}

.modal-body .body ul,
.modal-body .body ol {
    margin: 6px 0 12px 20px;
}

.modal-body .body li {
    margin-bottom: 5px;
}

/* Tables inside grammar / lesson content (declension, conjugation, etc.) */
.table-scroll {
    width: 100%;
    overflow-x: auto;
    margin: 14px 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    -webkit-overflow-scrolling: touch;
}

.table-scroll table {
    width: 100%;
    min-width: 420px;
    border-collapse: collapse;
    font-size: calc(13px * var(--font-scale));
}

.table-scroll th,
.table-scroll td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.table-scroll th {
    background: var(--primary-dim);
    color: var(--primary);
    font-weight: 700;
    font-size: calc(11px * var(--font-scale));
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.table-scroll tr:last-child td {
    border-bottom: none;
}

.table-scroll tr:nth-child(even) td {
    background: var(--glass);
}

/* ===== LESSON STEP ===== */
.lesson-step-progress {
    margin-bottom: 16px;
}

.progress-track {
    width: 100%;
    height: 6px;
    background: var(--glass);
    border-radius: 4px;
    overflow: hidden;
}

.progress-track .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #4fd8bd);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.step-title {
    font-size: calc(20px * var(--font-scale));
    margin-bottom: 14px;
}

.step-next {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    font-size: calc(15px * var(--font-scale));
    cursor: pointer;
    box-shadow: 0 6px 18px var(--primary-glow);
}

.step-next:active {
    transform: scale(0.98);
}

/* Vocabulary grid inside lesson */
.vocab-group-progress {
    margin-bottom: 14px;
}

.vocab-group-progress .label {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.vocab-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.vocab-item {
    padding: 32px 20px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    text-align: center;
}

.vocab-item .pl {
    font-size: calc(32px * var(--font-scale));
    font-weight: 800;
}

.vocab-item .en {
    font-size: calc(18px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 4px;
}

.vocab-item .word-detail-audio {
    margin-top: 16px;
}

.vocab-item .word-detail-example {
    margin-top: 24px;
    text-align: left;
}

/* Story step */
.story-box {
    padding: 16px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    line-height: 1.8;
}

.story-pl p {
    font-weight: 600;
    margin-bottom: 6px;
}

.story-en {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--glass-border);
    color: var(--text-muted);
}

.story-en p {
    margin-bottom: 6px;
}

/* Grammar step inside lesson */
.grammar-step-body {
    font-size: calc(15px * var(--font-scale));
    line-height: 1.7;
    color: var(--text);
}

.grammar-step-body .ex {
    margin: 10px 0;
    padding: 12px 14px;
    background: var(--glass);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
}

.grammar-step-body strong {
    color: var(--primary);
}

.grammar-step-body h1,
.grammar-step-body h2,
.grammar-step-body h3,
.grammar-step-body h4 {
    color: var(--text);
    margin: 16px 0 8px;
    font-weight: 800;
}

.grammar-step-body h1 { font-size: calc(20px * var(--font-scale)); }
.grammar-step-body h2 { font-size: calc(18px * var(--font-scale)); }
.grammar-step-body h3 { font-size: calc(15px * var(--font-scale)); }

.grammar-step-body ul,
.grammar-step-body ol {
    margin: 6px 0 12px 20px;
}

.grammar-step-body li {
    margin-bottom: 5px;
}

/* Quiz */
.quiz-question .q-counter {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 8px;
}

.quiz-question .q-text {
    font-size: calc(18px * var(--font-scale));
    font-weight: 700;
    margin-bottom: 16px;
}

.q-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ===== WORD MATCHING (lesson step) ===== */
.matching-hint {
    text-align: center;
    font-size: calc(13px * var(--font-scale));
    color: var(--text-muted);
    margin-bottom: 16px;
}

.matching-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.matching-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.matching-tile {
    padding: 12px 10px;
    text-align: center;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: calc(13px * var(--font-scale));
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.matching-tile.selected {
    border-color: var(--primary);
    background: var(--primary-dim);
    color: var(--primary);
}

.matching-tile.matched {
    border-color: var(--success);
    background: var(--success-dim);
    color: var(--success);
    opacity: 0.6;
}

.matching-tile.wrong {
    border-color: var(--error);
    background: var(--error-dim);
    color: var(--error);
}

.q-option {
    padding: 14px 16px;
    text-align: left;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: calc(14px * var(--font-scale));
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.q-option.correct {
    border-color: var(--success);
    background: var(--success-dim);
    color: var(--success);
}

.q-option.incorrect {
    border-color: var(--error);
    background: var(--error-dim);
    color: var(--error);
}

/* ===== TYPE-IN ANSWER (Quick Quiz) ===== */
.type-answer-input {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--glass);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1.5px solid var(--glass-border-light);
    border-radius: var(--radius);
    color: var(--text);
    font-size: calc(16px * var(--font-scale));
    font-family: inherit;
    text-align: center;
}

.type-answer-input:focus {
    outline: none;
    border-color: var(--primary);
}

.type-answer-input.correct {
    border-color: var(--success);
    color: var(--success);
}

.type-answer-input.incorrect {
    border-color: var(--error);
    color: var(--error);
}

.dialogue-feedback-slot {
    min-height: 32px;
    margin-top: 10px;
}

.dialogue-feedback {
    text-align: center;
    font-size: calc(13px * var(--font-scale));
    font-weight: 700;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.dialogue-feedback.ok {
    color: var(--success);
    background: var(--success-dim);
}

.dialogue-feedback.warn {
    color: var(--error);
    background: var(--error-dim);
}

/* ===== SENTENCE PRACTICE (after lesson quiz) ===== */
.quiz-result {
    text-align: center;
    padding: 40px 16px;
}

.quiz-result h3 {
    margin-top: 12px;
    font-size: calc(20px * var(--font-scale));
}

.lesson-complete {
    text-align: center;
    padding: 40px 16px;
}

.lesson-complete h2 {
    margin-top: 12px;
    font-size: calc(22px * var(--font-scale));
}

.lesson-complete p {
    margin-top: 8px;
    color: var(--text-muted);
}

.level-complete-icon {
    font-size: calc(72px * var(--font-scale)) !important;
    color: var(--streak);
    display: inline-block;
    animation: levelPopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.level-complete h2 {
    background: linear-gradient(135deg, var(--streak), var(--primary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

@keyframes levelPopIn {
    0% { transform: scale(0.3) rotate(-15deg); opacity: 0; }
    60% { transform: scale(1.15) rotate(5deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); }
}

/* ===== MICRO FEEDBACK (small delight on a correct swipe) ===== */
.micro-feedback {
    position: fixed;
    top: 30%;
    left: 50%;
    z-index: 700;
    padding: 10px 20px;
    background: var(--success);
    color: #fff;
    font-size: calc(15px * var(--font-scale));
    font-weight: 800;
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    animation: microFeedbackPop 0.9s ease forwards;
}

@keyframes microFeedbackPop {
    0% { transform: translate(-50%, 10px) scale(0.7); opacity: 0; }
    20% { transform: translate(-50%, 0) scale(1.05); opacity: 1; }
    35% { transform: translate(-50%, 0) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -14px) scale(1); opacity: 0; }
}

/* ===== UPDATE TOAST ===== */
.update-toast {
    position: fixed;
    left: 50%;
    bottom: calc(90px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--primary);
    color: #fff;
    border-radius: 999px;
    font-size: calc(13px * var(--font-scale));
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.update-toast button {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: calc(12px * var(--font-scale));
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
}

@media (min-width: 1024px) {
    .update-toast {
        left: calc(240px + (100% - 240px) / 2);
        bottom: 32px;
    }
}

/* ===== RESPONSIVE ===== */

/* Tablet: same mobile app UI, but full device width — nav bar and pages both
   stretch edge to edge — with larger type sizes to fill the extra room. */
@media (min-width: 700px) {
    body {
        font-size: calc(16px * var(--font-scale));
    }
    .topbar {
        padding: 18px 28px;
    }
    main {
        padding: 18px 28px 110px;
    }
    .bottom-nav {
        padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    }
    .brand-name {
        font-size: calc(19px * var(--font-scale));
    }
    .nav-label {
        font-size: calc(12px * var(--font-scale));
    }
    .modal-topbar-title {
        font-size: calc(18px * var(--font-scale));
    }
    .modal-body {
        padding: 20px 28px 40px;
    }
    .q-text,
    .modal-body .body,
    .grammar-step-body {
        font-size: calc(17px * var(--font-scale));
    }
    .lesson-complete h2,
    .quiz-result h3 {
        font-size: calc(24px * var(--font-scale));
    }
    .stat-num {
        font-size: calc(28px * var(--font-scale));
    }
    .step-next {
        font-size: calc(16px * var(--font-scale));
        padding: 17px;
    }
}

/* Desktop: a different shape, not just a wider tablet. Bottom nav becomes a
   fixed left sidebar; pages fill the remaining width (no content cap); modals
   become centered dialog cards over a dimmed backdrop instead of full pages. */
@media (min-width: 1024px) {
    .app-shell {
        padding-left: 240px;
    }
    body {
        font-size: calc(17px * var(--font-scale));
    }
    .topbar {
        padding: 24px 40px;
    }
    main {
        padding: 24px 40px 60px;
    }

    .bottom-nav {
        top: 0;
        left: 0;
        bottom: 0;
        right: auto;
        width: 240px;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        transform: none;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 6px;
        padding: 28px 16px calc(16px + env(safe-area-inset-bottom));
        border-radius: 0;
        border-right: 1px solid var(--glass-border);
    }
    .nav-btn {
        flex-direction: row;
        justify-content: flex-start;
        gap: 12px;
        padding: 14px 16px;
        border-radius: var(--radius);
    }
    .nav-btn.active {
        background: var(--primary-dim);
    }
    .nav-btn .material-symbols-outlined {
        font-size: calc(22px * var(--font-scale));
    }
    .nav-label {
        font-size: calc(15px * var(--font-scale));
    }

    .lessons-list,
    .grammar-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        align-content: start;
    }

    .modal-overlay {
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.55);
    }
    .modal-panel {
        max-width: 720px;
        height: auto;
        max-height: 88vh;
        border-radius: var(--radius-lg);
        overflow: hidden;
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
    }
}
