/*
==================================================
TCM FLASH CARDS - MODERNÍ STYLY (2025)
==================================================

Design System:
- Design tokens (CSS custom properties)
- Sémantické povrchové tokeny pro light/dark theme
- Inter font family
- 4px spacing scale
- Layered shadow system
- Mobile-first responsive design
*/

/* ==================================================
   1. DESIGN TOKENS
   ================================================== */

:root {
    /* === Color Palette === */
    --color-brand-50: #eef7f1;
    --color-brand-100: #dceee2;
    --color-brand-200: #b8dcc4;
    --color-brand-300: #8fc3a2;
    --color-brand-400: #5f9f78;
    --color-brand-500: #3f7f5d;
    --color-brand-600: #2f6548;
    --color-brand-700: #244d38;
    --color-accent-400: #4f9a91;
    --color-accent-500: #327b73;
    --color-warm-50: #fbfaf6;
    --color-warm-100: #f2efe6;

    /* Semantic Colors */
    --color-success: #34c759;
    --color-warning: #f5a623;
    --color-error: #ef4444;
    --color-info: #3b82f6;

    /* Rating Colors */
    --color-again: #f87171;
    --color-hard: #fb923c;
    --color-good: #4ade80;
    --color-easy: #60a5fa;

    /* Neutrals */
    --color-gray-50: #fafafa;
    --color-gray-100: #f4f4f5;
    --color-gray-200: #e4e4e7;
    --color-gray-300: #d4d4d8;
    --color-gray-400: #a1a1aa;
    --color-gray-500: #71717a;
    --color-gray-600: #52525b;
    --color-gray-700: #3f3f46;
    --color-gray-800: #27272a;
    --color-gray-900: #18181b;

    /* === Spacing Scale (4px base) === */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* === Typography === */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* === Shadows (layered) === */
    --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 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.03);

    /* === Border Radius (shadcn: 0.5rem base) === */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* === 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-normal: 250ms;
    --duration-slow: 400ms;

    /* === Semantic Surface Tokens (light theme) === */
    --surface-page:
        radial-gradient(circle at 18% 12%, rgba(143, 195, 162, 0.46), transparent 34%),
        radial-gradient(circle at 82% 0%, rgba(79, 154, 145, 0.24), transparent 30%),
        linear-gradient(145deg, #f4faf5 0%, #e5f1e8 48%, #d7e9df 100%);
    --surface-card: rgba(255, 255, 255, 0.88);
    --surface-card-hover: var(--color-gray-50);
    --surface-flashcard: rgba(250, 252, 249, 0.84);
    --surface-flashcard-flipped: #edf7f1;
    --text-primary: var(--color-gray-900);
    --text-secondary: var(--color-gray-500);
    --text-tertiary: var(--color-gray-400);
    --border-default: rgba(47, 101, 72, 0.14);
    --border-active: var(--color-brand-400);
}

/* ==================================================
   2. DARK THEME (semantic token overrides)
   ================================================== */

.dark-theme {
    --surface-page:
        radial-gradient(circle at 14% 10%, rgba(63, 127, 93, 0.24), transparent 32%),
        radial-gradient(circle at 88% 6%, rgba(50, 123, 115, 0.18), transparent 28%),
        linear-gradient(145deg, #101813 0%, #142119 48%, #17251f 100%);
    --surface-card: rgba(22, 31, 26, 0.9);
    --surface-card-hover: #1d2b23;
    --surface-flashcard: rgba(28, 40, 33, 0.88);
    --surface-flashcard-flipped: #1d3428;
    --text-primary: #edf4ee;
    --text-secondary: #b0beb4;
    --text-tertiary: #7e8e83;
    --border-default: rgba(184, 220, 196, 0.14);
    --border-active: #8fc3a2;
    --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 15px -3px rgba(0, 0, 0, 0.35), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

/* ==================================================
   3. GLOBAL RESET & BASE
   ================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--surface-page);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--space-6) var(--space-3);
    transition: background var(--duration-slow) var(--ease-out),
                color var(--duration-normal) var(--ease-out);
}

/* ==================================================
   4. APP CONTAINER
   ================================================== */

.app-container {
    background: var(--surface-card);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(31, 78, 54, 0.18);
    padding: var(--space-4);
    max-width: 1160px;
    width: 100%;
    text-align: center;
    position: relative;
    margin: 0 auto;
    border: 1px solid var(--border-default);
    transition: background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease,
                box-shadow var(--duration-normal) ease;
}

@media (min-width: 768px) {
    .app-container {
        max-width: 1160px;
        padding: var(--space-6);
    }
}

@media (min-width: 1024px) {
    .app-container {
        max-width: 1180px;
        padding: var(--space-8);
    }
}

.app-shell {
    display: block;
}

.app-container,
.dashboard-collapsed .app-container {
    max-width: 860px;
}

.study-panel {
    min-width: 0;
}

.side-dashboard {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    width: min(380px, calc(100vw - 24px));
    max-height: none;
    overflow: auto;
    padding: var(--space-4);
    border: 1px solid var(--border-default);
    border-radius: 18px 0 0 18px;
    background: #f8fbf7;
    box-shadow: -20px 0 60px rgba(31, 78, 54, 0.22);
    text-align: left;
    transform: translateX(105%);
    transition: transform var(--duration-normal) var(--ease-out);
    display: flex;
    flex-direction: column;
}

.side-dashboard.open,
.dashboard-open .side-dashboard {
    transform: translateX(0);
}

.side-dashboard-top {
    position: sticky;
    top: calc(-1 * var(--space-4));
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-default);
    background: #f8fbf7;
}

.side-dashboard-kicker,
.dashboard-section-title {
    color: var(--text-tertiary);
    font-size: 0.625rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.side-dashboard h2 {
    margin-top: 2px;
    color: var(--text-primary);
    font-size: var(--text-lg);
    line-height: 1.2;
}

.dashboard-close {
    display: inline-flex;
}

.dashboard-section {
    order: 2;
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border-default);
}

#settings-section {
    order: 1;
    border-top: none;
    padding-top: 0;
}

.dashboard-section-title {
    margin-bottom: var(--space-2);
}

.preset-grid,
.dashboard-filter-grid,
.data-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.mobile-dashboard-fab {
    display: none !important;
}

.dashboard-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(12, 20, 15, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-normal) ease;
}

.dashboard-backdrop.show,
.dashboard-open .dashboard-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.section-highlight {
    border-color: var(--color-brand-400);
    background: rgba(95, 159, 120, 0.08);
    border-radius: var(--radius-md);
    padding-left: var(--space-2);
    padding-right: var(--space-2);
    transition: background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease;
}

/* ==================================================
   5. HEADER
   ================================================== */

.header {
    margin-bottom: var(--space-4);
}

/* Header Top: title + action buttons */
.header-top {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
    margin-bottom: var(--space-5);
    position: relative;
}

.header-top h1 {
    font-size: clamp(1.35rem, 2.2vw, 1.85rem);
    font-weight: 700;
    letter-spacing: 0;
    color: var(--text-primary);
    margin: 0;
    padding: 0 112px;
    transition: color var(--duration-normal) var(--ease-out);
}

.header-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

/* Vertical separator between action groups */
.header-separator {
    width: 1px;
    height: 16px;
    background: var(--border-default);
    margin: 0 6px;
}

/*
 * GHOST BUTTON (shadcn ghost variant)
 * Used for: language-toggle, theme-toggle, data-btn, icon-btn
 * h-8 (32px), rounded-md, ghost hover
 */
.icon-btn,
.language-toggle,
.theme-toggle,
.data-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background-color var(--duration-fast) ease,
                color var(--duration-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover,
.language-toggle:hover,
.theme-toggle:hover,
.data-btn:hover {
    background: var(--color-gray-100);
    color: var(--text-primary);
}

.dark-theme .icon-btn:hover,
.dark-theme .language-toggle:hover,
.dark-theme .theme-toggle:hover,
.dark-theme .data-btn:hover {
    background: rgba(184, 220, 196, 0.1);
}

.icon-btn:active,
.language-toggle:active,
.theme-toggle:active,
.data-btn:active {
    transform: scale(0.93);
    transition-duration: 50ms;
}

.icon-btn svg,
.theme-toggle svg,
.data-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* Language toggle - slightly wider for text */
.language-toggle {
    width: auto;
    min-width: 32px;
    padding: 0 8px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* Undo button in filters uses same ghost style */
.undo-btn svg {
    width: 14px;
    height: 14px;
}

/* ==================================================
   6. MERIDIAN FILTER (shadcn Select style)
   ================================================== */

.primary-controls {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

.controls-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 0;
    min-width: 0;
}

.meridian-filter {
    flex: 1;
}

.meridian-filter select {
    width: 100%;
    height: 40px;
    padding: 0 32px 0 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-family: var(--font-family);
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.5);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: border-color var(--duration-fast) ease,
                box-shadow var(--duration-fast) ease,
                background-color var(--duration-normal) ease,
                color var(--duration-normal) ease;
}

.meridian-filter select:hover {
    border-color: rgba(47, 101, 72, 0.28);
}

.dark-theme .meridian-filter select:hover {
    border-color: rgba(184, 220, 196, 0.26);
}

.meridian-filter select:focus {
    outline: none;
    border-color: var(--color-brand-400);
    box-shadow: 0 0 0 2px rgba(95, 159, 120, 0.18);
}

.dark-theme .meridian-filter select {
    background-color: rgba(16, 24, 19, 0.34);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.dark-theme .search-row input,
.dark-theme .dashboard-item,
.dark-theme .prompt-panel,
.dark-theme .settings-panel label,
.dark-theme .meridian-card,
.dark-theme .typed-answer-row input {
    background: rgba(16, 24, 19, 0.34);
}

.dark-theme .side-dashboard,
.dark-theme .side-dashboard-top {
    background: #142119;
}

.dark-theme .meridian-badge {
    background: rgba(143, 195, 162, 0.14);
    color: #b8dcc4;
}

.search-row {
    margin-bottom: var(--space-3);
}

.search-row input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-sm);
    transition: border-color var(--duration-fast) ease,
                box-shadow var(--duration-fast) ease,
                background-color var(--duration-normal) ease;
}

.search-row input::placeholder {
    color: var(--text-tertiary);
}

.search-row input:focus {
    border-color: var(--color-brand-400);
    box-shadow: 0 0 0 2px rgba(95, 159, 120, 0.18);
}

/* ==================================================
   7. FILTER BAR (shadcn Badge outline variant)
   ================================================== */

.filters-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 6px;
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

/* Base chip style shared by filter-checkbox and mode-btn */
.filter-checkbox,
.mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-default);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.6875rem;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background-color var(--duration-fast) ease,
                border-color var(--duration-fast) ease,
                color var(--duration-fast) ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.filter-checkbox:hover,
.mode-btn:hover {
    background: var(--color-gray-100);
    color: var(--text-primary);
}

.dark-theme .filter-checkbox:hover,
.dark-theme .mode-btn:hover {
    background: rgba(184, 220, 196, 0.1);
    color: var(--text-primary);
}

.secondary-filter {
    display: none;
}

.mode-btn.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--surface-card);
}

.dark-theme .mode-btn.active {
    background: var(--text-primary);
    color: var(--color-gray-900);
}

.filter-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--color-brand-400);
    margin: 0;
}

/* Undo button — ghost icon, no border */
.undo-btn {
    border: none;
    width: 28px;
    height: 28px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
}

.undo-btn:hover {
    background: var(--color-gray-100);
    color: var(--text-primary);
    border: none;
}

.dark-theme .undo-btn:hover {
    background: rgba(184, 220, 196, 0.1);
}

/* ==================================================
   8. STATISTICS BAR
   ================================================== */

.stats {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    padding: var(--space-3) 0;
    margin-bottom: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-flashcard);
    transition: background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease;
}

.dashboard {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.dashboard-item {
    min-width: 0;
    padding: var(--space-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.36);
    text-align: center;
    transition: background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease;
}

.dashboard-value {
    display: block;
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    white-space: nowrap;
}

.dashboard-label {
    display: block;
    margin-top: 2px;
    color: var(--text-tertiary);
    font-size: 0.5625rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.2;
    text-transform: uppercase;
}

.daily-plan {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2);
    margin-bottom: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-flashcard);
    transition: background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease;
}

.daily-plan-main {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
    color: var(--text-secondary);
    font-size: 0.6875rem;
    white-space: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.daily-plan-main::-webkit-scrollbar {
    display: none;
}

.daily-plan-title {
    color: var(--text-primary);
    font-weight: 700;
}

.daily-plan-action {
    flex-shrink: 0;
    height: 30px;
    border-radius: var(--radius-md);
}

.daily-plan-action:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.settings-panel {
    display: grid;
    grid-template-columns: 0.8fr 1fr 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.side-dashboard .settings-panel {
    grid-template-columns: 1fr;
}

.side-dashboard .settings-panel select,
.side-dashboard .settings-panel input[type="number"] {
    width: 142px;
}

.settings-panel label {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.3);
    color: var(--text-secondary);
    font-size: 0.6875rem;
    font-weight: 600;
}

.settings-panel input[type="number"],
.settings-panel select {
    min-width: 0;
    width: 86px;
    height: 28px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: 0.6875rem;
    padding: 0 7px;
}

.settings-panel select {
    width: 128px;
}

.settings-panel input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-brand-500);
}

.meridian-overview {
    margin-bottom: var(--space-3);
    text-align: left;
}

.meridian-overview-title {
    margin-bottom: var(--space-2);
    color: var(--text-tertiary);
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.meridian-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--space-2);
}

.side-dashboard .meridian-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.meridian-card {
    display: grid;
    gap: 2px;
    min-width: 0;
    padding: var(--space-2);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.26);
    color: var(--text-secondary);
    font-family: var(--font-family);
    text-align: left;
    cursor: pointer;
    transition: background-color var(--duration-fast) ease,
                border-color var(--duration-fast) ease,
                transform var(--duration-fast) ease;
}

.meridian-card:hover {
    border-color: rgba(47, 101, 72, 0.28);
    background: rgba(255, 255, 255, 0.44);
}

.meridian-card.active {
    border-color: var(--color-brand-400);
    background: rgba(95, 159, 120, 0.12);
}

.meridian-card-code {
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 800;
    line-height: 1;
}

.meridian-card-count {
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.2;
}

.meridian-card-meta {
    color: var(--text-tertiary);
    font-size: 0.5625rem;
    line-height: 1.2;
    white-space: nowrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    flex: 1;
    padding: 4px 0;
}

.stat-divider {
    width: 1px;
    height: 28px;
    background: var(--border-default);
    flex-shrink: 0;
    transition: background-color var(--duration-normal) ease;
}

.stat-number {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    transition: color var(--duration-normal) ease;
}

.stat-label,
.stat-item span:not(.stat-number) {
    font-size: 0.625rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
    transition: color var(--duration-normal) ease;
}

.stat-bump {
    animation: statBump 0.3s var(--ease-spring);
}

@keyframes statBump {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ==================================================
   9. PROGRESS BAR
   ================================================== */

.progress-bar {
    background: var(--color-gray-100);
    border-radius: var(--radius-full);
    height: 3px;
    margin-bottom: var(--space-5);
    overflow: hidden;
    transition: background-color var(--duration-normal) ease;
}

.dark-theme .progress-bar {
    background: var(--color-gray-700);
}

.progress-fill {
    background: var(--color-brand-400);
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.4s var(--ease-out);
    width: 0%;
}

/* ==================================================
   10. FLASHCARD
   ================================================== */

#flashcard-container {
    perspective: 1200px;
}

.flashcard {
    background: var(--surface-flashcard);
    border-radius: 18px;
    min-height: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-5);
    cursor: pointer;
    border: 1px solid var(--border-default);
    position: relative;
    padding: var(--space-6);
    box-shadow: 0 14px 42px rgba(31, 78, 54, 0.08);
    transform-style: preserve-3d;
    -webkit-tap-highlight-color: transparent;

    /* Default idle transition (hover, bg changes) */
    transition: transform 0.25s var(--ease-out),
                box-shadow 0.25s var(--ease-out),
                background-color var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out);
}

.flashcard:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.flashcard:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.flashcard.flipped {
    background: var(--surface-flashcard-flipped);
    border-color: var(--border-active);
}

/*
 * TWO-PHASE FLIP SYSTEM
 *
 * Phase 1 (.flip-out): card rotates to edge (90°) + lifts up
 * — JS swaps content at transitionend —
 * Phase 2 (.flip-in):  card rotates from edge back to face (0°) + settles
 *
 * No keyframes. No setTimeout guessing. transitionend drives everything.
 */

/* Phase 1: rotate to edge, lift, shrink slightly */
.flashcard.flip-out {
    transition: transform 0.28s cubic-bezier(0.4, 0, 1, 1),
                box-shadow 0.28s cubic-bezier(0.4, 0, 1, 1);
    transform: rotateY(90deg) translateY(-10px) scale(0.96);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.2),
                0 12px 20px -8px rgba(0, 0, 0, 0.1);
}

/* Phase 2: rotate back to face, settle with micro-bounce via spring easing */
.flashcard.flip-in {
    transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1),
                box-shadow 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    transform: rotateY(0deg) translateY(0) scale(1);
    box-shadow: var(--shadow-sm);
}

/* Kill hover transform while flipping */
.flashcard.flip-out:hover,
.flashcard.flip-in:hover {
    transform: none;
}
.flashcard.flip-out:hover {
    transform: rotateY(90deg) translateY(-10px) scale(0.96);
}
.flashcard.flip-in:hover {
    transform: rotateY(0deg) translateY(0) scale(1);
}

/* Card content */
.card-content {
    width: 100%;
    text-align: center;
    transition: opacity 0.12s ease;
}

/* Hide content at the edge to avoid visible swap */
.flashcard.flip-out .card-content {
    opacity: 0;
    transition: opacity 0.08s ease 0.18s;
}

/* Reveal content on return */
.flashcard.flip-in .card-content {
    opacity: 1;
    transition: opacity 0.15s ease 0.08s;
}

/* Entrance animation for new cards */
.card-enter {
    animation: cardEnter 0.35s var(--ease-out);
}

@keyframes cardEnter {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Meridian badge — shadcn Badge default variant */
.meridian-badge {
    background: rgba(63, 127, 93, 0.12);
    color: var(--color-brand-600);
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: var(--space-3);
    display: inline-block;
    line-height: 1.4;
    transition: background-color var(--duration-normal) ease,
                color var(--duration-normal) ease;
}

/* Card text hierarchy */
.point-code {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: var(--space-1);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition: color var(--duration-normal) ease;
}

.point-name {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    letter-spacing: 0;
    transition: color var(--duration-normal) ease;
}

.point-translation {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: var(--space-2);
    transition: color var(--duration-normal) ease;
}

.point-chinese {
    font-size: var(--text-xl);
    color: var(--text-tertiary);
    margin-bottom: var(--space-3);
    transition: color var(--duration-normal) ease;
}

.point-pronunciation {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    font-style: italic;
    margin-bottom: var(--space-4);
    transition: color var(--duration-normal) ease;
}

.question-label {
    color: var(--text-tertiary);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    margin-bottom: var(--space-3);
    text-transform: uppercase;
}

.point-code-large {
    color: var(--text-primary);
    font-size: var(--text-3xl);
    margin: var(--space-4) 0;
}

.point-chinese-large {
    color: var(--text-primary);
    font-size: 3rem;
    line-height: 1.1;
    margin: var(--space-4) 0 var(--space-2);
}

.prompt-panel {
    width: 100%;
    max-width: 560px;
    margin: var(--space-3) auto;
    padding: var(--space-4);
    border: 1px solid var(--border-default);
    border-left: 2px solid var(--color-brand-400);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.36);
    color: var(--text-primary);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    text-align: left;
}

.typed-prompt {
    margin-bottom: var(--space-2);
}

.typed-answer-row {
    display: flex;
    gap: var(--space-2);
    width: 100%;
    max-width: 360px;
    margin: var(--space-3) auto var(--space-2);
}

.typed-answer-row input {
    flex: 1;
    min-width: 0;
    height: 40px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-primary);
    font: inherit;
    font-weight: 700;
    padding: 0 var(--space-3);
    text-transform: uppercase;
}

.typed-check-btn {
    height: 40px;
    border-radius: var(--radius-md);
}

.typed-answer-hint {
    max-width: 460px;
    margin: 0 auto;
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    line-height: var(--leading-relaxed);
}

.typed-feedback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    margin-bottom: var(--space-2);
    padding: 0 var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 800;
}

.typed-feedback--ok {
    background: rgba(22, 163, 74, 0.12);
    color: #15803d;
}

.typed-feedback--miss {
    background: rgba(234, 88, 12, 0.12);
    color: #c2410c;
}

/* Back side info sections — card style with left accent */
.point-location,
.point-functions,
.weak-note {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: var(--space-3);
    text-align: left;
    padding: var(--space-3);
    background: var(--surface-flashcard);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    border-left: 2px solid var(--color-brand-400);
    transition: color var(--duration-normal) ease,
                background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease;
}

.section-header {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.click-hint {
    position: absolute;
    bottom: var(--space-3);
    right: var(--space-4);
    font-size: 0.625rem;
    color: var(--text-tertiary);
    font-style: normal;
    letter-spacing: 0.02em;
    transition: color var(--duration-normal) ease;
}

/* ==================================================
   11. RATING BUTTONS
   ================================================== */

.controls {
    display: none;
    flex-wrap: nowrap;
    gap: var(--space-2);
    justify-content: center;
    margin-bottom: var(--space-5);
    padding: 0 var(--space-2);
}

.controls.show {
    display: flex;
    animation: slideUp 0.3s var(--ease-out);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.btn {
    height: 40px;
    padding: 0 var(--space-3);
    border: 1px solid;
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background-color var(--duration-fast) ease,
                color var(--duration-fast) ease,
                border-color var(--duration-fast) ease;
    min-width: 70px;
    flex: 1;
    max-width: 110px;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
}

.btn-again {
    color: #dc2626;
    border-color: rgba(220, 38, 38, 0.3);
}
.btn-again:hover {
    background: rgba(220, 38, 38, 0.08);
    border-color: rgba(220, 38, 38, 0.5);
}

.btn-hard {
    color: #ea580c;
    border-color: rgba(234, 88, 12, 0.3);
}
.btn-hard:hover {
    background: rgba(234, 88, 12, 0.08);
    border-color: rgba(234, 88, 12, 0.5);
}

.btn-good {
    color: #16a34a;
    border-color: rgba(22, 163, 74, 0.3);
}
.btn-good:hover {
    background: rgba(22, 163, 74, 0.08);
    border-color: rgba(22, 163, 74, 0.5);
}

.btn-easy {
    color: #2563eb;
    border-color: rgba(37, 99, 235, 0.3);
}
.btn-easy:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.5);
}

/* Dark theme: slightly brighter text for rating buttons */
.dark-theme .btn-again { color: #f87171; border-color: rgba(248, 113, 113, 0.3); }
.dark-theme .btn-again:hover { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.4); }
.dark-theme .btn-hard { color: #fb923c; border-color: rgba(251, 146, 60, 0.3); }
.dark-theme .btn-hard:hover { background: rgba(251, 146, 60, 0.1); border-color: rgba(251, 146, 60, 0.4); }
.dark-theme .btn-good { color: #4ade80; border-color: rgba(74, 222, 128, 0.3); }
.dark-theme .btn-good:hover { background: rgba(74, 222, 128, 0.1); border-color: rgba(74, 222, 128, 0.4); }
.dark-theme .btn-easy { color: #60a5fa; border-color: rgba(96, 165, 250, 0.3); }
.dark-theme .btn-easy:hover { background: rgba(96, 165, 250, 0.1); border-color: rgba(96, 165, 250, 0.4); }

.btn:active {
    transform: scale(0.96);
    transition-duration: 50ms;
}

.btn-flash {
    animation: buttonFlash 0.15s ease-out;
}

@keyframes buttonFlash {
    0% { filter: brightness(1.2); }
    100% { filter: brightness(1); }
}

.btn-interval {
    display: block;
    font-size: 0.625rem;
    font-weight: 400;
    opacity: 0.6;
    margin-top: 1px;
}

/* ==================================================
   12. SESSION COMPLETE
   ================================================== */

.session-complete {
    display: none;
    text-align: center;
    padding: var(--space-10) var(--space-6);
}

.session-complete.show {
    display: block;
    animation: fadeIn 0.4s var(--ease-out);
}

.session-complete::before {
    content: '\1F389';
    display: block;
    font-size: 3rem;
    margin-bottom: var(--space-4);
    animation: celebrationBounce 0.6s var(--ease-spring);
}

@keyframes celebrationBounce {
    0% { transform: scale(0) rotate(-20deg); }
    60% { transform: scale(1.2) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.session-complete h2 {
    color: var(--color-success);
    margin-bottom: var(--space-2);
    font-size: var(--text-2xl);
    font-weight: 700;
}

.session-complete p {
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    margin: var(--space-5) 0;
}

.summary-item {
    background: var(--surface-flashcard);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-3);
    text-align: center;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
    transition: background-color var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out),
                color var(--duration-normal) var(--ease-out);
}

.summary-num {
    display: block;
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--color-brand-400);
    margin-bottom: var(--space-1);
    font-variant-numeric: tabular-nums;
}

/* shadcn default button variant */
.restart-btn {
    background: var(--text-primary);
    color: var(--surface-card);
    height: 36px;
    padding: 0 var(--space-5);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    margin-top: var(--space-4);
    transition: opacity var(--duration-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.restart-btn:hover {
    opacity: 0.85;
}

.restart-btn:active {
    transform: scale(0.97);
    transition-duration: 50ms;
}

/* ==================================================
   13. EMPTY STATE
   ================================================== */

.empty-state {
    padding: var(--space-10) var(--space-4);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.6;
}

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-hint {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

/* ==================================================
   14. TOAST NOTIFICATIONS
   ================================================== */

.toast-container {
    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
    max-width: 420px;
    width: calc(100% - var(--space-8));
}

.toast {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-family: var(--font-family);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    animation: toastIn 0.35s var(--ease-spring);
    background: rgba(24, 24, 27, 0.92);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.toast--success { border-left: 3px solid var(--color-success); }
.toast--error { border-left: 3px solid var(--color-error); }
.toast--info { border-left: 3px solid var(--color-info); }
.toast--warning { border-left: 3px solid var(--color-warning); }

.toast-exit {
    animation: toastOut 0.25s var(--ease-out) forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(8px) scale(0.95); }
}

/* ==================================================
   15. RESPONSIVE - MOBILE
   ================================================== */

@media (max-width: 900px) {
    .app-container {
        max-width: 760px;
    }

    .dashboard-collapsed .app-container {
        max-width: 760px;
    }

    .side-dashboard {
        top: 0;
        right: 0;
        bottom: 0;
        border-radius: 18px 0 0 18px;
        transform: translateX(105%);
    }

    .mobile-dashboard-fab {
        display: none !important;
        align-items: center;
        justify-content: center;
        position: fixed;
        right: var(--space-4);
        bottom: var(--space-4);
        z-index: 1000;
        width: 48px;
        height: 48px;
        border: 1px solid var(--border-default);
        border-radius: var(--radius-full);
        background: var(--text-primary);
        color: var(--surface-card);
        box-shadow: var(--shadow-lg);
    }
}

@media (max-width: 480px) {
    body {
        padding: var(--space-3) var(--space-2);
    }

    .app-container {
        padding: var(--space-4);
        margin: 0;
        border-radius: var(--radius-lg);
    }

    .header-top {
        align-items: flex-start;
        justify-content: flex-start;
        min-height: 72px;
    }

    .header-top h1,
    .header h1 {
        font-size: var(--text-lg);
        padding: 0;
        text-align: left;
        max-width: 190px;
    }

    .header-actions {
        right: 0;
        top: 0;
        transform: none;
    }

    .primary-controls {
        grid-template-columns: 1fr;
    }

    .flashcard {
        min-height: 280px;
        padding: var(--space-4);
    }

    .point-name {
        font-size: var(--text-xl);
    }

    .point-code {
        font-size: var(--text-base);
    }

    .stat-number {
        font-size: var(--text-sm);
    }

    .controls {
        gap: var(--space-2);
        padding: 0;
    }

    .btn {
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-xs);
        min-width: 65px;
        min-height: 44px;
    }

    .header-separator {
        display: none;
    }

    .dashboard {
        grid-template-columns: repeat(2, 1fr);
    }

    .daily-plan {
        align-items: stretch;
        flex-direction: column;
    }

    .daily-plan-main {
        justify-content: flex-start;
    }

    .settings-panel {
        grid-template-columns: 1fr;
    }

    .settings-panel select,
    .settings-panel input[type="number"] {
        width: 140px;
    }

    .meridian-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .typed-answer-row {
        flex-direction: column;
    }

    .point-chinese-large {
        font-size: 2.5rem;
    }

    .prompt-panel {
        padding: var(--space-3);
        font-size: var(--text-sm);
    }
}

.completion-actions {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-top: var(--space-4);
    flex-wrap: wrap;
}

.restart-btn.secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}

.restart-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

@media (max-width: 360px) {
    .app-container {
        padding: var(--space-3);
    }

    .flashcard {
        min-height: 250px;
        padding: var(--space-3);
    }

    .point-name {
        font-size: var(--text-lg);
    }

    .point-location,
    .point-functions {
        font-size: var(--text-xs);
    }

    .btn {
        padding: var(--space-1) var(--space-2);
        font-size: var(--text-xs);
        min-width: 55px;
        min-height: 40px;
    }

    .filters-row {
        gap: 4px;
    }

    .meridian-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}

/* ==================================================
   16. SAFE AREA SUPPORT
   ================================================== */

@supports (padding: env(safe-area-inset-bottom)) {
    .toast-container {
        bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
    }

    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ==================================================
   17. ACCESSIBILITY
   ================================================== */

:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-brand-400);
    outline-offset: 2px;
}

.flashcard:focus-visible {
    outline: 3px solid var(--color-brand-400);
    outline-offset: 3px;
}

@media (prefers-contrast: high) {
    .point-chinese,
    .point-pronunciation {
        color: var(--text-secondary);
    }

    .click-hint {
        color: var(--text-secondary);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==================================================
   18. UTILITY CLASSES
   ================================================== */

.fade-in {
    animation: fadeIn 0.3s var(--ease-out);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.pulse {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ==================================================
   19. DESIGNER UI REFRESH
   ================================================== */

:root {
    --surface-page:
        linear-gradient(135deg, rgba(248, 246, 239, 0.96), rgba(229, 241, 232, 0.92)),
        repeating-linear-gradient(90deg, rgba(36, 77, 56, 0.035) 0 1px, transparent 1px 72px),
        repeating-linear-gradient(0deg, rgba(36, 77, 56, 0.03) 0 1px, transparent 1px 72px);
    --surface-card: rgba(255, 255, 250, 0.94);
    --surface-flashcard: #fffefa;
    --surface-flashcard-flipped: #fbf7ec;
    --text-primary: #20231f;
    --text-secondary: #656b63;
    --text-tertiary: #90988e;
    --border-default: rgba(32, 35, 31, 0.11);
    --border-active: #2f7d62;
    --shadow-xl: 0 28px 70px rgba(32, 35, 31, 0.14);
    --shadow-card: 0 22px 58px rgba(48, 56, 48, 0.12);
}

.dark-theme {
    --surface-page:
        linear-gradient(135deg, #111511, #172018 54%, #1c211d),
        repeating-linear-gradient(90deg, rgba(237, 244, 238, 0.035) 0 1px, transparent 1px 72px),
        repeating-linear-gradient(0deg, rgba(237, 244, 238, 0.03) 0 1px, transparent 1px 72px);
    --surface-card: rgba(20, 24, 21, 0.94);
    --surface-flashcard: #181d19;
    --surface-flashcard-flipped: #1d241f;
    --text-primary: #f3f0e8;
    --text-secondary: #b8b8af;
    --text-tertiary: #85897f;
    --border-default: rgba(243, 240, 232, 0.12);
    --border-active: #8fc3a2;
}

body {
    align-items: flex-start;
    padding: 28px 18px;
    color: var(--text-primary);
}

.app-container,
.dashboard-collapsed .app-container {
    max-width: 1040px;
    padding: 0;
    overflow: hidden;
    text-align: left;
    border-radius: 28px;
    background: var(--surface-card);
    box-shadow: var(--shadow-xl);
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

.study-panel {
    padding: 26px;
    position: relative;
}

.header {
    display: grid;
    gap: 16px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    padding: 0;
}

.brand-lockup {
    display: grid;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.brand-kicker {
    color: var(--color-accent-500);
    font-size: 0.73rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dark-theme .brand-kicker {
    color: var(--color-brand-300);
}

.header h1 {
    margin: 0;
    color: var(--text-primary);
    font-size: clamp(1.55rem, 2.8vw, 2.2rem);
    line-height: 1;
    text-align: left;
}

.header-actions {
    gap: 8px;
}

.language-toggle,
.theme-toggle,
.data-btn,
.icon-btn {
    border-radius: 12px;
    border-color: rgba(32, 35, 31, 0.12);
    background: rgba(255, 255, 255, 0.62);
    color: var(--text-secondary);
    box-shadow: none;
}

.dark-theme .language-toggle,
.dark-theme .theme-toggle,
.dark-theme .data-btn,
.dark-theme .icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.11);
}

.primary-controls {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr);
    gap: 10px;
}

.controls-row,
.study-mode-row {
    margin: 0;
}

.meridian-filter select,
.search-row input,
.settings-panel select,
.settings-panel input[type="number"],
.typed-answer-row input {
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid rgba(32, 35, 31, 0.12);
    background: rgba(255, 255, 255, 0.72);
    color: var(--text-primary);
    font-weight: 650;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.68);
}

.meridian-filter select,
.settings-panel select {
    appearance: none;
    -webkit-appearance: none;
    color-scheme: light;
    padding-right: 44px;
    background-image: url("data:image/svg+xml,%3Csvg width='18' height='18' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m6 9 6 6 6-6' stroke='%23656b63' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 18px 18px;
}

.meridian-filter option,
.settings-panel option {
    background-color: #fffefa;
    color: #20231f;
}

.search-row input {
    padding-left: 44px;
    background-image:
        url("data:image/svg+xml,%3Csvg width='18' height='18' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='11' cy='11' r='7' stroke='%23717872' stroke-width='2'/%3E%3Cpath d='m20 20-3.5-3.5' stroke='%23717872' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-position: 16px center;
    background-repeat: no-repeat;
}

.dark-theme .meridian-filter select,
.dark-theme .search-row input,
.dark-theme .settings-panel select,
.dark-theme .settings-panel input[type="number"],
.dark-theme .typed-answer-row input {
    background-color: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.12);
}

.dark-theme .meridian-filter select,
.dark-theme .settings-panel select {
    color-scheme: dark;
    background-image: url("data:image/svg+xml,%3Csvg width='18' height='18' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m6 9 6 6 6-6' stroke='%23b8b8af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.dark-theme .meridian-filter option,
.dark-theme .settings-panel option {
    background-color: #141815;
    color: #f3f0e8;
}

.dark-theme .meridian-filter option:checked,
.dark-theme .settings-panel option:checked {
    background-color: #26372b;
    color: #f3f0e8;
}

.filters-row {
    justify-content: flex-start;
    gap: 8px;
    margin: 0;
}

.mode-btn,
.filter-checkbox {
    min-height: 36px;
    border-radius: 999px;
    border-color: rgba(32, 35, 31, 0.11);
    background: rgba(255, 255, 255, 0.62);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 750;
}

.mode-btn.active,
.filter-checkbox:has(input:checked) {
    border-color: rgba(47, 125, 98, 0.28);
    background: #e8f2ec;
    color: #23563f;
}

.dark-theme .mode-btn,
.dark-theme .filter-checkbox {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.1);
}

.dark-theme .mode-btn.active,
.dark-theme .filter-checkbox:has(input:checked) {
    background: rgba(143, 195, 162, 0.18);
    color: #d9f0df;
}

.stats,
.dashboard {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding: 0;
    border: 0;
    background: transparent;
}

.dashboard {
    display: none;
}

.stat-divider {
    display: none;
}

.stat-item,
.dashboard-item {
    min-height: 72px;
    padding: 14px 12px;
    border: 1px solid rgba(32, 35, 31, 0.1);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.58);
    text-align: left;
}

.stat-number,
.dashboard-value {
    color: var(--text-primary);
    font-size: 1.42rem;
    font-weight: 850;
    line-height: 1;
}

.stat-item span:last-child,
.dashboard-label {
    margin-top: 8px;
    color: var(--text-tertiary);
    font-size: 0.68rem;
    font-weight: 850;
    letter-spacing: 0.05em;
}

.daily-plan {
    display: grid;
    gap: 12px;
    border: 1px solid rgba(32, 35, 31, 0.1);
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(251, 247, 236, 0.74));
    padding: 12px;
}

.habit-strip {
    display: grid;
    gap: 10px;
}

.habit-meter {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(32, 35, 31, 0.08);
}

.habit-meter span {
    display: block;
    height: 100%;
    min-width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #2f7d62, #2f6fb1, #d39b37);
    transition: width 220ms var(--ease-out);
}

.habit-strip--done .habit-meter span {
    background: linear-gradient(90deg, #2f7d62, #47a66f);
}

.habit-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.habit-metric {
    display: grid;
    gap: 4px;
    min-width: 0;
    padding: 10px;
    border: 1px solid rgba(32, 35, 31, 0.08);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.46);
}

.habit-metric span {
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1;
}

.habit-metric small {
    overflow: hidden;
    color: var(--text-tertiary);
    font-size: 0.62rem;
    font-weight: 850;
    letter-spacing: 0.05em;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.habit-metric-status span {
    color: #2f7d62;
}

.daily-plan-main {
    color: var(--text-secondary);
    gap: 12px;
}

.daily-plan-title {
    color: var(--text-primary);
    font-weight: 850;
}

.progress-bar {
    height: 8px;
    margin: 18px 26px 0;
    border-radius: 999px;
    background: rgba(32, 35, 31, 0.08);
}

.progress-fill {
    border-radius: inherit;
    background: linear-gradient(90deg, #2f7d62, #2f6fb1, #d39b37);
}

#flashcard-container {
    padding-top: 18px;
}

.flashcard {
    min-height: clamp(350px, 55vh, 500px);
    border: 1px solid rgba(32, 35, 31, 0.12);
    border-radius: 26px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.9)),
        var(--surface-flashcard);
    box-shadow: var(--shadow-card);
}

.flashcard::before {
    content: "";
    position: absolute;
    inset: 18px auto 18px 18px;
    width: 4px;
    border-radius: 999px;
    background: linear-gradient(180deg, #2f7d62, #2f6fb1, #d39b37);
    opacity: 0.9;
}

.flashcard.flipped {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(251, 247, 236, 0.86)),
        var(--surface-flashcard-flipped);
}

.card-content {
    width: min(100%, 680px);
    margin: 0 auto;
}

.meridian-badge {
    min-width: 38px;
    border-radius: 999px;
    background: #e5f1e8;
    color: #2f6548;
    font-weight: 850;
    letter-spacing: 0.03em;
}

.card-meta-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 14px;
}

.card-state {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid rgba(32, 35, 31, 0.09);
    background: rgba(255, 255, 255, 0.74);
    color: var(--text-tertiary);
    font-size: 0.68rem;
    font-weight: 850;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.card-state--new { color: #2f6fb1; }
.card-state--due { color: #9a651b; }
.card-state--weak { color: #bd3e43; }
.card-state--mastered { color: #24704f; }

.point-code {
    color: var(--text-tertiary);
    font-size: clamp(1.1rem, 2.2vw, 1.45rem);
    font-weight: 800;
}

.point-name {
    color: var(--text-primary);
    font-size: clamp(2.05rem, 5vw, 4.3rem);
    line-height: 0.98;
    letter-spacing: 0;
}

.point-translation,
.point-pronunciation {
    color: var(--text-secondary);
    font-weight: 650;
}

.point-chinese {
    color: rgba(32, 35, 31, 0.22);
    font-size: clamp(2rem, 5vw, 3.8rem);
    font-weight: 650;
}

.question-label {
    color: #2f7d62;
    font-weight: 850;
    letter-spacing: 0.07em;
}

.prompt-panel,
.point-location,
.point-functions,
.weak-note {
    border-radius: 18px;
    border: 1px solid rgba(32, 35, 31, 0.09);
    background: rgba(255, 255, 255, 0.66);
    color: var(--text-primary);
    text-align: left;
}

.section-header {
    color: var(--text-tertiary);
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.click-hint {
    right: 26px;
    bottom: 22px;
    color: var(--text-tertiary);
    font-weight: 700;
}

.controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.btn {
    min-height: 58px;
    border-radius: 16px;
    border: 0;
    color: white;
    font-weight: 850;
    box-shadow: 0 12px 24px rgba(32, 35, 31, 0.14);
}

.btn-again { background: linear-gradient(135deg, #d94f4f, #bd3e43); }
.btn-hard { background: linear-gradient(135deg, #d98a32, #b46c25); }
.btn-good { background: linear-gradient(135deg, #2f8b62, #24704f); }
.btn-easy { background: linear-gradient(135deg, #2f6fb1, #245b91); }

.btn-interval {
    color: rgba(255, 255, 255, 0.82);
    font-weight: 800;
}

.side-dashboard {
    border-left: 1px solid rgba(32, 35, 31, 0.1);
    background: rgba(255, 255, 250, 0.96);
}

.side-dashboard-top {
    background: transparent;
}

.dashboard-section {
    border-radius: 18px;
    border-color: rgba(32, 35, 31, 0.1);
    background: rgba(255, 255, 255, 0.56);
}

.auth-panel {
    display: grid;
    gap: 10px;
}

.auth-status {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 850;
    overflow-wrap: anywhere;
}

.auth-copy {
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.45;
}

.auth-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.auth-form input {
    min-width: 0;
    min-height: 38px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(32, 35, 31, 0.11);
    background: rgba(255, 255, 255, 0.68);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 650;
}

.auth-signout {
    justify-self: start;
    display: none;
}

.auth-panel--signed-in .auth-form {
    display: none;
}

.auth-panel--signed-in .auth-signout {
    display: inline-flex;
}

.auth-panel--disabled .auth-form {
    opacity: 0.55;
}

.meridian-card {
    border-radius: 14px;
    text-align: left;
}

.toast {
    border-radius: 14px;
}

.mobile-tabbar {
    display: none;
}

.search-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1500;
    background: rgba(15, 20, 17, 0.22);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.search-dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 1510;
    display: grid;
    width: min(520px, calc(100vw - 28px));
    gap: 14px;
    padding: 28px;
    border: 1px solid rgba(32, 35, 31, 0.12);
    border-radius: 26px;
    background: #fffefa;
    box-shadow: 0 28px 78px rgba(28, 38, 31, 0.22);
    opacity: 0;
    pointer-events: none;
    text-align: center;
    transform: translate(-50%, -47%) scale(0.97);
    transition: opacity 180ms ease, transform 180ms ease;
}

.search-dialog-open .search-dialog-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.search-dialog-open .search-dialog {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.search-dialog-close {
    position: absolute;
    right: 14px;
    top: 14px;
}

.search-dialog-icon {
    display: inline-flex;
    width: 68px;
    height: 68px;
    align-items: center;
    justify-content: center;
    justify-self: center;
    border-radius: 24px;
    background: #e8f2ec;
    color: #2f7d62;
}

.search-dialog h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.45rem;
    line-height: 1.1;
}

.search-dialog p {
    margin: -4px 0 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.45;
}

.search-row-dialog {
    margin: 0;
}

.search-clear-btn {
    justify-self: center;
}

.onboarding-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1520;
    background: rgba(15, 20, 17, 0.28);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.onboarding-dialog {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 1530;
    display: grid;
    width: min(680px, calc(100vw - 28px));
    max-height: calc(100svh - 28px);
    gap: 18px;
    padding: 30px;
    overflow-y: auto;
    border: 1px solid rgba(32, 35, 31, 0.12);
    border-radius: 28px;
    background: #fffefa;
    box-shadow: 0 30px 82px rgba(28, 38, 31, 0.24);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -47%) scale(0.97);
    transition: opacity 180ms ease, transform 180ms ease;
}

.onboarding-open .onboarding-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.onboarding-open .onboarding-dialog {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.onboarding-close {
    position: absolute;
    right: 14px;
    top: 14px;
}

.onboarding-mark {
    display: inline-flex;
    width: 68px;
    height: 68px;
    align-items: center;
    justify-content: center;
    border-radius: 24px;
    background: #e8f2ec;
    color: #2f7d62;
}

.onboarding-heading {
    display: grid;
    gap: 4px;
}

.onboarding-heading p {
    margin: 0;
    color: var(--text-tertiary);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.onboarding-heading h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.7rem;
    line-height: 1.05;
}

.onboarding-form {
    display: grid;
    gap: 16px;
}

.onboarding-group {
    display: grid;
    gap: 10px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.onboarding-group legend {
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 850;
}

.onboarding-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.onboarding-choice {
    position: relative;
    display: grid;
    gap: 6px;
    min-height: 94px;
    align-content: center;
    padding: 14px;
    border: 1px solid rgba(32, 35, 31, 0.1);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.6);
    cursor: pointer;
}

.onboarding-choice input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.onboarding-choice span {
    color: var(--text-primary);
    font-weight: 850;
    line-height: 1.15;
}

.onboarding-choice small {
    color: var(--text-tertiary);
    font-size: 0.72rem;
    font-weight: 750;
}

.onboarding-choice:has(input:checked) {
    border-color: rgba(47, 125, 98, 0.36);
    background: #e8f2ec;
    box-shadow: inset 0 0 0 1px rgba(47, 125, 98, 0.16);
}

.onboarding-toggle {
    display: flex;
    min-height: 48px;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid rgba(32, 35, 31, 0.1);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.55);
    color: var(--text-primary);
    font-weight: 800;
}

.onboarding-toggle input {
    width: 18px;
    height: 18px;
    accent-color: #2f7d62;
}

.onboarding-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 4px;
}

.dark-theme .search-dialog {
    background: #141815;
    border-color: rgba(255, 255, 255, 0.12);
}

.dark-theme .onboarding-dialog {
    background: #141815;
    border-color: rgba(255, 255, 255, 0.12);
}

.dark-theme .onboarding-backdrop {
    background: rgba(0, 0, 0, 0.38);
}

.dark-theme .onboarding-mark,
.dark-theme .onboarding-choice:has(input:checked) {
    background: rgba(143, 195, 162, 0.14);
    color: #d9f0df;
}

.dark-theme .onboarding-choice,
.dark-theme .onboarding-toggle {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.11);
}

.dark-theme .search-dialog-backdrop {
    background: rgba(0, 0, 0, 0.32);
}

.dark-theme .search-dialog-icon {
    background: rgba(143, 195, 162, 0.14);
    color: #d9f0df;
}

.dark-theme .stat-item,
.dark-theme .dashboard-item,
.dark-theme .daily-plan,
.dark-theme .prompt-panel,
.dark-theme .point-location,
.dark-theme .point-functions,
.dark-theme .weak-note,
.dark-theme .dashboard-section,
.dark-theme .auth-form input {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.11);
}

.dark-theme .daily-plan {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.065), rgba(211, 155, 55, 0.08));
}

.dark-theme .habit-meter {
    background: rgba(255, 255, 255, 0.08);
}

.dark-theme .habit-metric {
    background: rgba(255, 255, 255, 0.045);
    border-color: rgba(255, 255, 255, 0.09);
}

.dark-theme .habit-metric-status span {
    color: #d9f0df;
}

.dark-theme .flashcard,
.dark-theme .flashcard.flipped {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)), var(--surface-flashcard);
    border-color: rgba(255, 255, 255, 0.12);
}

.dark-theme .point-chinese {
    color: rgba(243, 240, 232, 0.22);
}

.dark-theme .meridian-badge {
    background: rgba(143, 195, 162, 0.18);
    color: #d9f0df;
}

.dark-theme .card-state {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.dark-theme .side-dashboard {
    background: rgba(20, 24, 21, 0.96);
    border-left-color: rgba(255, 255, 255, 0.1);
}

.dashboard-backdrop {
    opacity: 0 !important;
    pointer-events: none !important;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.dashboard-open .study-panel::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 80;
    background: rgba(15, 20, 17, 0.18);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    pointer-events: none;
}

.dark-theme.dashboard-open .study-panel::after {
    background: rgba(0, 0, 0, 0.24);
}

.side-dashboard {
    z-index: 1300;
    background: #fffefa;
    border-left: 1px solid rgba(32, 35, 31, 0.12);
    box-shadow: -26px 0 70px rgba(28, 38, 31, 0.2);
    isolation: isolate;
}

.side-dashboard-top {
    background: #fffefa;
}

.dark-theme .side-dashboard,
.dark-theme .side-dashboard-top {
    background: #141815;
}

@media (min-width: 1180px) {
    .dashboard-open .app-container {
        max-width: 1320px;
    }

    .dashboard-open .app-shell {
        grid-template-columns: minmax(0, 1fr) 360px;
    }

    .dashboard-open .side-dashboard {
        position: static;
        transform: none;
        height: auto;
        max-height: none;
        box-shadow: none;
    }

    .dashboard-open .dashboard-backdrop,
    .dashboard-backdrop.show {
        opacity: 0;
        pointer-events: none;
    }

    .dashboard-open .study-panel::after {
        display: none;
    }
}

@media (max-width: 720px) {
    body {
        padding: 0;
        min-height: 100svh;
        overscroll-behavior-y: none;
    }

    .app-container {
        min-height: 100svh;
        border-radius: 0;
        border: 0;
    }

    .study-panel {
        padding: 14px 12px 96px;
    }

    .mobile-tabbar {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        z-index: 1350;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px;
        max-width: 560px;
        margin: 0 auto;
        padding: 6px;
        border: 1px solid rgba(32, 35, 31, 0.1);
        border-radius: 24px;
        background: rgba(255, 255, 250, 0.92);
        box-shadow: 0 18px 42px rgba(32, 35, 31, 0.18);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    .mobile-tabbar-btn {
        display: inline-flex;
        min-width: 0;
        min-height: 52px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: 0;
        border-radius: 18px;
        background: transparent;
        color: var(--text-secondary);
        font: inherit;
        font-size: 0.68rem;
        font-weight: 800;
    }

    .mobile-tabbar-btn.active,
    .mobile-tabbar-btn:active {
        background: rgba(47, 125, 98, 0.12);
        color: var(--border-active);
    }

    .header-top {
        align-items: center;
        gap: 10px;
    }

    .header {
        gap: 10px;
        margin-bottom: 12px;
    }

    .brand-kicker {
        display: none;
    }

    .header h1 {
        font-size: 1.45rem;
        max-width: none;
        white-space: nowrap;
    }

    .primary-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stats {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .stat-item,
    .dashboard-item {
        min-height: 54px;
        padding: 10px 8px;
        text-align: center;
    }

    .stat-number,
    .dashboard-value {
        font-size: 1.12rem;
    }

    .stat-item span:last-child,
    .dashboard-label {
        margin-top: 6px;
        font-size: 0.56rem;
    }

    .daily-plan {
        display: flex;
        gap: 10px;
        align-items: stretch;
        padding: 10px;
        flex-direction: column;
    }

    .habit-metrics {
        gap: 6px;
    }

    .habit-metric {
        padding: 9px 7px;
        text-align: center;
    }

    .habit-metric span {
        font-size: 0.94rem;
    }

    .habit-metric small {
        font-size: 0.52rem;
    }

    .daily-plan-main {
        overflow-x: auto;
        scrollbar-width: none;
        white-space: nowrap;
    }

    .daily-plan-main::-webkit-scrollbar {
        display: none;
    }

    .progress-bar {
        margin-inline: 18px;
        margin-top: 12px;
    }

    #flashcard-container {
        padding-top: 12px;
    }

    .flashcard {
        min-height: clamp(320px, 48svh, 430px);
        border-radius: 22px;
        touch-action: manipulation;
    }

    .flashcard::before {
        inset: 16px auto 16px 16px;
    }

    .controls.show {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        z-index: 1400;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 560px;
        margin: 0 auto;
        padding: 8px;
        border-radius: 22px;
        background: rgba(255, 255, 250, 0.9);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        box-shadow: 0 16px 38px rgba(32, 35, 31, 0.16);
    }

    .side-dashboard {
        top: 8px;
        right: 8px;
        bottom: 8px;
        width: min(430px, calc(100vw - 16px));
        border-radius: 22px;
    }

    .dark-theme .controls.show {
        background: rgba(20, 24, 21, 0.88);
    }

    .dark-theme .mobile-tabbar {
        background: rgba(20, 24, 21, 0.9);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .search-dialog {
        padding: 24px 18px 18px;
        border-radius: 24px;
    }

    .search-dialog-icon {
        width: 60px;
        height: 60px;
        border-radius: 21px;
    }
}

@media (max-width: 420px) {
    .study-panel {
        padding: 14px;
    }

    .header-actions {
        gap: 5px;
    }

    .header h1 {
        font-size: 1.22rem;
    }

    .language-toggle,
    .theme-toggle,
    .data-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }

    .primary-controls {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-item {
        min-height: 50px;
    }

    .daily-plan {
        align-items: stretch;
        flex-direction: column;
    }

    .daily-plan-action {
        width: 100%;
    }

    .filters-row {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 2px;
    }

    .mode-btn,
    .filter-checkbox {
        white-space: nowrap;
    }

    .point-name {
        font-size: 2rem;
    }

    .flashcard {
        min-height: clamp(300px, 46svh, 390px);
    }

    .auth-form {
        grid-template-columns: 1fr;
    }
}

/* ==================================================
   20. MOBILE PRODUCT POLISH
   ================================================== */

@media (max-width: 720px) {
    body {
        background: var(--surface-page);
        color-scheme: light;
    }

    .dark-theme {
        color-scheme: dark;
    }

    .app-container,
    .dashboard-collapsed .app-container {
        width: 100%;
        max-width: none;
        min-height: 100svh;
        box-shadow: none;
    }

    .study-panel {
        display: flex;
        min-height: 100svh;
        flex-direction: column;
        padding: 12px 12px calc(92px + env(safe-area-inset-bottom, 0px));
    }

    .header {
        position: sticky;
        top: 0;
        z-index: 90;
        margin: -12px -12px 10px;
        padding: 12px 12px 10px;
        border-bottom: 1px solid rgba(32, 35, 31, 0.08);
        background:
            linear-gradient(180deg, rgba(255, 255, 250, 0.94), rgba(255, 255, 250, 0.82)),
            var(--surface-page);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    .dark-theme .header {
        border-bottom-color: rgba(255, 255, 255, 0.08);
        background:
            linear-gradient(180deg, rgba(20, 24, 21, 0.94), rgba(20, 24, 21, 0.78)),
            var(--surface-page);
    }

    .header-top {
        min-height: 42px;
    }

    .brand-lockup {
        align-self: center;
    }

    .header h1 {
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .header-actions {
        flex-shrink: 0;
    }

    .dashboard-toggle {
        display: none;
    }

    .primary-controls {
        gap: 8px;
    }

    .meridian-filter select,
    .settings-panel select,
    .settings-panel input[type="number"] {
        min-height: 42px;
        border-radius: 13px;
        font-size: 0.82rem;
    }

    .filters-row {
        margin: 0 -12px;
        padding: 0 12px 2px;
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
        scroll-padding-inline: 12px;
    }

    .filters-row::-webkit-scrollbar {
        display: none;
    }

    .mode-btn,
    .filter-checkbox {
        min-height: 34px;
        padding-inline: 12px;
        flex: 0 0 auto;
    }

    .stats {
        grid-template-columns: repeat(4, minmax(66px, 1fr));
        gap: 7px;
    }

    .stat-item,
    .dashboard-item {
        border-radius: 14px;
    }

    .daily-plan {
        min-height: 48px;
    }

    .progress-bar {
        height: 6px;
        margin: 10px 4px 0;
    }

    #flashcard-container {
        display: flex;
        min-height: 0;
        flex: 1;
        flex-direction: column;
        justify-content: center;
        padding-top: 10px;
    }

    .flashcard {
        width: 100%;
        min-height: clamp(310px, 52svh, 460px);
        max-height: calc(100svh - 265px);
        margin-bottom: 0;
        padding: 24px 22px 54px;
        overflow-y: auto;
        border-radius: 24px;
        overscroll-behavior: contain;
        scrollbar-width: thin;
    }

    .flashcard.flipped {
        justify-content: flex-start;
    }

    .flashcard::before {
        width: 3px;
        inset: 18px auto 18px 14px;
    }

    .card-content {
        align-self: stretch;
    }

    .card-meta-row {
        margin-bottom: 12px;
    }

    .point-name {
        overflow-wrap: anywhere;
    }

    .prompt-panel,
    .point-location,
    .point-functions,
    .weak-note {
        padding: 13px 14px;
        font-size: 0.88rem;
    }

    .typed-answer-row {
        max-width: none;
    }

    .click-hint {
        left: 50%;
        right: auto;
        bottom: 16px;
        display: inline-flex;
        min-height: 28px;
        align-items: center;
        justify-content: center;
        padding: 0 11px;
        border: 1px solid rgba(32, 35, 31, 0.08);
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.66);
        transform: translateX(-50%);
        white-space: nowrap;
    }

    .dark-theme .click-hint {
        border-color: rgba(255, 255, 255, 0.09);
        background: rgba(255, 255, 255, 0.055);
    }

    .mobile-tabbar {
        transition: transform 180ms ease, opacity 180ms ease;
    }

    .rating-panel-open .mobile-tabbar {
        opacity: 0;
        pointer-events: none;
        transform: translateY(calc(100% + 18px));
    }

    .controls.show {
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
        padding: 7px;
        border: 1px solid rgba(32, 35, 31, 0.1);
    }

    .controls.show .btn {
        min-width: 0;
        min-height: 58px;
        padding: 8px 6px;
        border-radius: 17px;
        font-size: 0.78rem;
    }

    .btn-interval {
        margin-top: 5px;
        font-size: 0.66rem;
    }

    .side-dashboard {
        max-height: calc(100svh - 16px);
        overflow-y: auto;
    }

    .search-dialog {
        width: min(420px, calc(100vw - 24px));
    }

    .onboarding-dialog {
        width: min(430px, calc(100vw - 20px));
        padding: 24px 18px 18px;
        border-radius: 24px;
    }

    .onboarding-mark {
        width: 58px;
        height: 58px;
        border-radius: 20px;
    }

    .onboarding-heading h2 {
        font-size: 1.38rem;
    }

    .onboarding-options {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .onboarding-options-compact {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .onboarding-choice {
        min-height: 76px;
        border-radius: 16px;
        padding: 12px;
    }

    .onboarding-actions {
        display: grid;
        grid-template-columns: 1fr 1.25fr;
    }

    .onboarding-actions .mode-btn,
    .onboarding-actions .restart-btn {
        width: 100%;
        min-height: 46px;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .controls.show {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .controls.show .btn {
        min-height: 54px;
    }
}

@media (max-width: 380px) {
    .header h1 {
        max-width: 38vw;
        font-size: 1.08rem;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .flashcard {
        min-height: clamp(280px, 48svh, 390px);
        max-height: calc(100svh - 292px);
    }

    .mobile-tabbar-btn span {
        font-size: 0.62rem;
    }
}
