      :root {
    --primary: #1a4731;
    --primary-dark: #1b4332;
    --primary-light: #2d6a4f;
    --accent: #40916c;
    --accent-dark: #2d6a4f;
    --bg-app: #faf6f1; 
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --text-primary: #1b4332; 
    --text-secondary: #2d6a4f;
    --text-tertiary: #40916c;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --success: #52b788;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #40916c;
    
    --gradient-primary: linear-gradient(135deg, #1a4731, #2d6a4f);
    --gradient-accent: linear-gradient(135deg, #40916c, #52b788);
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 10px 20px rgba(0, 0, 0, 0.05); 
    --radius: 16px;
    --radius-sm: 8px;
    --nav-height: 68px;
    --header-height: 64px;
    --spacing: 16px;
    --radius-lg: 20px;
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
    
    --bg-app:         #1c1c1e;
    --bg-surface:     #2c2c2e;
    --bg-elevated:    #3a3a3c;
    
    --text-primary:   #e8e8e2;
    --text-secondary: #aeaeaa;
    --text-tertiary:  #6e6e6a;
    
    --border:         #3a3a3c;
    --border-light:   #2c2c2e;
    
    --primary:        #4a9270;
    --primary-dark:   #3a7258;
    --primary-light:  #5aaa82;
    --accent:         #5aaa82;
    --accent-dark:    #4a9270;
    --success:        #5aaa82;
    --info:           #5aaa82;
    --danger:         #f06a6a;
    --warning:        #f0a050;
    --gradient-primary: linear-gradient(135deg, #3a7258, #4a9270);
    --gradient-accent:  linear-gradient(135deg, #4a9270, #5aaa82);
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.35);
    --shadow:    0 4px 16px rgba(0,0,0,0.30);
    --shadow-xl: 0 12px 32px rgba(0,0,0,0.45);
}

        * {
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
            margin: 0;
            padding: 0;
        }

        body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

header {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.85); 
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: none;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04), 0 1px 0 rgba(0, 0, 0, 0.02); 
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing);
    z-index: 100;
    position: sticky; 
    top: 0;
}

[data-theme="dark"] header {
    background: rgba(28, 28, 30, 0.85);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.05);
}

.header-title {
    font-family: 'Outfit', system-ui, sans-serif; 
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em; 
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 42px; 
    height: 42px;
    border-radius: 12px; 
    border: none;
    background: var(--bg-app);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.icon-btn:hover {
    background: rgba(64, 145, 108, 0.1); 
    color: var(--primary);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: scale(0.92);
    background: rgba(64, 145, 108, 0.15);
}

.icon-btn svg {
    width: 22px; 
    height: 22px;
    fill: currentColor;
}

        .header-actions {
            display: flex;
            gap: 8px;
            align-items: center;
        }

        .sync-status {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--text-tertiary);
            position: absolute;
            top: 8px;
            right: 8px;
        }

        .sync-status.syncing { background: var(--warning); animation: pulse 1s infinite; }
        .sync-status.synced { background: var(--success); }
        .sync-status.error { background: var(--danger); }

        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }

        .app-wrapper {
            display: flex;
            flex-direction: column;
            flex: 1;
            min-height: 0;
            overflow: hidden;
        }

        main {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            position: relative;
            padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 16px) + 24px);
        }

        .view {
            display: none;
            animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .view.active {
            display: block;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateX(20px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        .container {
            padding: var(--spacing);
            padding-left: max(var(--spacing), env(safe-area-inset-left, var(--spacing)));
            padding-right: max(var(--spacing), env(safe-area-inset-right, var(--spacing)));
            max-width: 768px;
            margin: 0 auto;
            box-sizing: border-box;
        }

      
.card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 0; 
    margin-bottom: var(--spacing);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    flex-direction: column; 
    overflow: visible;
}

.card:active {
    transform: scale(0.99);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 16px 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.5;
    white-space: normal; 
    word-break: break-word; 
}

.progress-container {
    padding: 0 16px;
    margin-bottom: 8px;
}

.card-actions {
    background: var(--bg-app);
    border-top: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between; 
    align-items: center;
    margin-top: auto;
}

.card-actions-buttons {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid transparent; 
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:active {
    background: var(--border);
    transform: scale(0.95);
}

        .card:active {
            transform: scale(0.98);
            box-shadow: var(--shadow-sm);
        }

        .card-subtitle {
            font-size: 0.875rem;
            color: var(--text-secondary);
            margin-top: 4px;
        }

        .card-meta {
            font-size: 0.75rem;
            color: var(--text-tertiary);
            display: flex;
            gap: 12px;
            margin-top: 8px;
        }

        .action-btn.edit { color: var(--info); }
        .action-btn.delete { color: var(--danger); }
        .action-btn.move { color: var(--warning); }

        .action-btn.reset { color: var(--warning); }

        .action-btn svg {
            width: 16px;
            height: 16px;
            fill: currentColor;
        }

        .badge {
            display: inline-flex;
            align-items: center;
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.75rem;
            font-weight: 600;
            background: var(--bg-app);
            color: var(--text-secondary);
        }

        .badge.primary { background: var(--primary); color: white; }
        .badge.success { background: var(--success); color: white; }
        .badge.warning { background: var(--warning); color: white; }
        .badge.danger { background: var(--danger); color: white; }
        .badge.new { background: var(--info); color: white; }

        .progress-header {
            display: flex;
            justify-content: space-between;
            font-size: 0.75rem;
            color: var(--text-tertiary);
            margin-bottom: 6px;
        }

        .progress-bar-bg {
            height: 8px;
            background: var(--border);
            border-radius: 4px;
            overflow: hidden;
        }

        .progress-bar-fill {
    height: 100%;
    background: linear-gradient(135deg, #40916c, #52b788);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 4px;
}

        .circular-progress {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background: conic-gradient(var(--primary) calc(var(--progress) * 1%), var(--border) 0);
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }

        .circular-progress::before {
            content: '';
            position: absolute;
            width: 48px;
            height: 48px;
            border-radius: 50%;
            background: var(--bg-surface);
        }

        .circular-progress-text {
            position: relative;
            z-index: 1;
            font-weight: 700;
            font-size: 0.875rem;
        }

        .breadcrumb {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: var(--spacing);
            font-size: 0.875rem;
            color: var(--text-secondary);
            background: var(--bg-surface);
            border-bottom: 1px solid var(--border);
            overflow-x: auto;
            white-space: nowrap;
        }

        .breadcrumb-item {
            cursor: pointer;
            transition: color 0.2s;
        }

        .breadcrumb-item:hover {
            color: var(--primary);
        }

        .breadcrumb-sep {
            color: var(--text-tertiary);
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
            margin-bottom: 20px;
        }

        .stat-card {
            background: var(--bg-surface);
            border-radius: var(--radius);
            padding: 16px;
            text-align: center;
            border: 1px solid var(--border);
        }

        .stat-value {
            font-size: 2rem;
            font-weight: 800;
            background: linear-gradient(135deg, var(--primary), var(--accent));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .stat-label {
            font-size: 0.75rem;
            color: var(--text-tertiary);
            margin-top: 4px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        .chart-container {
            background: var(--bg-surface);
            border-radius: var(--radius);
            padding: 20px;
            border: 1px solid var(--border);
            margin-bottom: 20px;
        }

        .chart-title {
            font-weight: 700;
            margin-bottom: 16px;
        }

        canvas {
            max-width: 100%;
        }

        .deck-detail-header {
    background: linear-gradient(135deg, #1a4731, #2d6a4f);
    color: white;
    padding: 18px 16px;
    border-radius: var(--radius);
    margin: var(--spacing) var(--spacing) 0;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

        .deck-name-large {
            font-size: 1.75rem;
            font-weight: 800;
            margin-bottom: 8px;
        }

        .deck-description {
            opacity: 0.9;
            font-size: 0.9375rem;
        }

        .action-buttons {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
            padding: 0 var(--spacing);
            margin-bottom: 20px;
        }

        .btn-action {
            padding: 14px;
            border-radius: var(--radius-sm);
            border: none;
            font-weight: 700;
            font-size: 0.9375rem;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .btn-action:active {
            transform: scale(0.98);
        }

        .btn-learn {
            background: var(--primary);
            color: white;
            box-shadow: var(--shadow);
        }

        .btn-review {
            background: var(--success);
            color: white;
            box-shadow: var(--shadow);
        }

        .btn-browse {
            background: var(--bg-surface);
            color: var(--text-primary);
            border: 1px solid var(--border);
        }

        .btn-stats {
            background: var(--bg-surface);
            color: var(--text-primary);
            border: 1px solid var(--border);
        }

        .card-list-item {
            background: var(--bg-surface);
            border-radius: var(--radius-sm);
            padding: 16px;
            margin-bottom: 12px;
            border: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .card-content {
            flex: 1;
        }

        .card-front-text {
            font-weight: 600;
            margin-bottom: 4px;
        }

        .card-back-text {
            font-size: 0.875rem;
            color: var(--text-secondary);
        }

        .next-review {
            font-size: 0.75rem;
            color: var(--text-tertiary);
            margin-top: 4px;
        }

        .next-review.due {
            color: var(--danger);
            font-weight: 600;
        }

        .next-review.soon {
            color: var(--warning);
            font-weight: 600;
        }

        .reader-toolbar {
            display: flex;
            gap: 8px;
            padding: 10px 12px;
            background: var(--bg-surface);
            border-bottom: 1px solid var(--border);
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            scroll-snap-type: x mandatory;
            position: sticky;
            top: 0;
            z-index: 50;
            scrollbar-width: none;
        }
        .reader-toolbar::-webkit-scrollbar { display: none; }

        .toolbar-btn {
            padding: 10px 16px;
            min-height: 44px;
            border-radius: 22px;
            border: 1px solid var(--border);
            background: var(--bg-app);
            color: var(--text-secondary);
            font-size: 0.875rem;
            font-weight: 600;
            white-space: nowrap;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            gap: 6px;
            scroll-snap-align: start;
            flex-shrink: 0;
        }

        .toolbar-btn:active {
            transform: scale(0.95);
        }

        .toolbar-btn.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .content-reader {
            padding: var(--spacing);
            font-family: 'Merriweather', Georgia, serif;
            font-size: 1.0625rem;
            line-height: 1.8;
            color: var(--text-primary);
        }

        .content-reader h1 {
            font-family: 'Outfit', sans-serif;
            font-size: 2rem;
            font-weight: 800;
            margin: 1.5em 0 0.5em;
            color: var(--text-primary);
            line-height: 1.3;
        }

        .content-reader h2 {
            font-family: 'Outfit', sans-serif;
            font-size: 1.5rem;
            font-weight: 700;
            margin: 1.2em 0 0.4em;
            color: var(--primary);
        }

        .content-reader h3 {
            font-family: 'Outfit', sans-serif;
            font-size: 1.25rem;
            font-weight: 600;
            margin: 1em 0 0.3em;
        }

        .content-reader p {
            margin: 1em 0;
        }

        .content-reader ul, .content-reader ol {
            margin: 1em 0;
            padding-left: 1.5em;
        }

        .content-reader li {
            margin: 0.5em 0;
        }

        .content-reader strong {
            font-weight: 700;
            color: var(--text-primary);
        }

        .content-reader em {
            font-style: italic;
        }

        .content-reader mark {
            background: rgba(251, 191, 36, 0.3);
            padding: 2px 4px;
            border-radius: 3px;
        }

        
        .editor-container {
            background: var(--bg-surface);
            border-radius: var(--radius);
            border: 1.5px solid var(--border);
            overflow: hidden;
            transition: border-color 0.2s;
        }
        .editor-container:focus-within {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
        }

        
        .editor-toolbar {
            display: flex;
            flex-direction: column;
            background: var(--bg-app);
            border-bottom: 1.5px solid var(--border);
        }
        .tb-row {
            display: flex;
            flex-wrap: nowrap;
            overflow-x: auto;
            gap: 2px;
            padding: 5px 8px;
            scrollbar-width: none;
            align-items: center;
        }
        .tb-row:not(:last-child) {
            border-bottom: 1px solid var(--border);
        }
        .tb-row::-webkit-scrollbar { display: none; }

        
        .editor-btn {
            flex-shrink: 0;
            min-width: 32px;
            height: 30px;
            padding: 0 6px;
            border-radius: 6px;
            border: none;
            background: transparent;
            color: var(--text-secondary);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: background 0.15s, color 0.15s;
            font-size: 14px;
            font-weight: 600;
            white-space: nowrap;
        }
        .editor-btn:hover { background: var(--border); color: var(--text-primary); }
        .editor-btn:active { transform: scale(0.92); }
        .editor-btn.active, .editor-btn.eb-active { background: var(--primary); color: white; }

        
        .eb-block { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em; min-width: 36px; }
        .eb-h1 { font-size: 1rem; }
        .eb-h2 { font-size: 0.85rem; }
        .eb-h3 { font-size: 0.75rem; }

        
        .editor-separator, .eb-sep {
            flex-shrink: 0;
            width: 1px;
            height: 18px;
            background: var(--border);
            margin: 0 4px;
        }

        
        .eb-color {
            width: 20px;
            height: 20px;
            min-width: 20px;
            border-radius: 50%;
            border: 2px solid transparent;
            cursor: pointer;
            transition: transform 0.15s, border-color 0.15s;
            margin: 0 2px;
        }
        .eb-color:hover { transform: scale(1.2); border-color: var(--text-secondary); }

        
        .editor-content {
            cursor: text;
            min-height: 220px;
            padding: 16px;
            outline: none;
            font-family: 'Merriweather', Georgia, serif;
            font-size: 1rem;
            line-height: 1.85;
            unicode-bidi: plaintext;
        }
        .editor-content:empty::before {
            content: attr(data-placeholder);
            color: var(--text-tertiary);
            font-style: italic;
            pointer-events: none;
        }
        
        .editor-content h1 { font-family:'Outfit',sans-serif; font-size:1.6rem; font-weight:800; margin:0.6em 0 0.2em; }
        .editor-content h2 { font-family:'Outfit',sans-serif; font-size:1.25rem; font-weight:700; color:var(--primary); margin:0.5em 0 0.2em; }
        .editor-content h3 { font-family:'Outfit',sans-serif; font-size:1rem; font-weight:700; margin:0.4em 0 0.2em; }
        .editor-content blockquote { border-left:4px solid var(--primary); margin:0.6em 0; padding:4px 12px; color:var(--text-secondary); font-style:italic; background:var(--bg-app); border-radius:0 6px 6px 0; }
        .editor-content code, .inline-code { font-family:monospace; background:var(--bg-app); color:var(--primary); padding:2px 6px; border-radius:4px; font-size:0.9em; border:1px solid var(--border); }
        .editor-content mark { background:rgba(251,191,36,0.35); padding:1px 3px; border-radius:3px; }
        .editor-content strong { font-weight:700; }
        .editor-content em { font-style:italic; }

        
        .fmt-hint-bar {
            display: flex;
            gap: 6px;
            padding: 6px 12px;
            background: var(--bg-app);
            border-top: 1px solid var(--border);
            overflow-x: auto;
            scrollbar-width: none;
            flex-wrap: nowrap;
        }
        .fmt-hint-bar::-webkit-scrollbar { display: none; }
        .fmt-chip {
            flex-shrink: 0;
            font-family: monospace;
            font-size: 0.72rem;
            padding: 2px 7px;
            background: var(--bg-surface);
            border: 1px solid var(--border);
            border-radius: 10px;
            color: var(--text-tertiary);
            cursor: default;
            white-space: nowrap;
        }
        .fmt-chip b { color: var(--primary); font-weight: 800; }
        .fmt-chip-label {
            font-size: 0.68rem;
            color: var(--text-tertiary);
            align-self: center;
            flex-shrink: 0;
            margin-right: 2px;
        }

        
        .sort-bar { display:flex; align-items:center; gap:8px; padding:0 0 14px 0; }
        .sort-trigger {
            display:flex; align-items:center; gap:7px;
            padding:7px 14px; border:1.5px solid var(--border);
            border-radius:12px; background:var(--bg-surface);
            color:var(--text-secondary); font-size:0.82rem; font-weight:600;
            cursor:pointer; transition:all 0.18s; white-space:nowrap;
            box-shadow: var(--shadow-sm);
        }
        .sort-trigger:active { transform:scale(0.97); }
        .sort-trigger.has-sort { border-color:var(--primary); color:var(--primary); background:rgba(26,71,49,0.06); }
        .sort-trigger svg { width:15px; height:15px; fill:currentColor; flex-shrink:0; }
        .sort-chevron { width:13px !important; height:13px !important; transition:transform 0.2s; }
        .sort-trigger.open .sort-chevron { transform:rotate(180deg); }

        .sort-panel-wrap { position:relative; }
        .sort-panel {
            display:none; position:absolute; top:calc(100% + 6px); left:0; z-index:500;
            background:var(--bg-surface); border:1.5px solid var(--border);
            border-radius:16px; box-shadow:var(--shadow-xl);
            min-width:220px; overflow:hidden;
            animation: sortPanelIn 0.18s cubic-bezier(0.4,0,0.2,1);
        }
        .sort-panel.open { display:block; }
        @keyframes sortPanelIn {
            from { opacity:0; transform:translateY(-6px) scale(0.97); }
            to   { opacity:1; transform:translateY(0) scale(1); }
        }
        .sort-panel-section { padding:6px 6px; }
        .sort-panel-label {
            font-size:0.65rem; font-weight:800; letter-spacing:0.08em;
            text-transform:uppercase; color:var(--text-tertiary);
            padding:6px 10px 4px;
        }
        .sort-option {
            display:flex; align-items:center; gap:10px;
            padding:9px 12px; border-radius:10px; cursor:pointer;
            transition:background 0.13s; font-size:0.86rem;
            font-weight:600; color:var(--text-secondary);
        }
        .sort-option:hover { background:var(--bg-app); color:var(--text-primary); }
        .sort-option.active { background:rgba(26,71,49,0.1); color:var(--primary); }
        .sort-option svg { width:17px; height:17px; fill:currentColor; flex-shrink:0; opacity:0.7; }
        .sort-option.active svg { opacity:1; }
        .sort-option-check { margin-left:auto; width:15px; height:15px; fill:var(--primary); opacity:0; flex-shrink:0; }
        .sort-option.active .sort-option-check { opacity:1; }
        .sort-sep { height:1px; background:var(--border); margin:2px 8px; }
        .drag-handle { cursor:grab; color:var(--text-tertiary); opacity:0.35; padding:4px 6px; flex-shrink:0; display:flex; align-items:center; transition:opacity 0.15s; touch-action:none; }
        .drag-handle:hover { opacity:1; color:var(--primary); }
        .drag-handle svg { width:16px; height:16px; fill:currentColor; }
        .card.dragging { opacity:0.4; box-shadow:0 8px 30px rgba(0,0,0,0.25); }
        .card.drag-over-top { border-top:3px solid var(--primary) !important; }
        .card.drag-over-bottom { border-bottom:3px solid var(--primary) !important; }
        
        .simple-theme-card { border-left:4px solid var(--primary) !important; }
        .simple-badge { font-size:0.7rem; font-weight:700; background:var(--primary); color:white; padding:2px 7px; border-radius:10px; letter-spacing:0.04em; }

        .exercise-card {
            background: var(--bg-app);
            border-radius: var(--radius);
            padding: 20px;
            margin: 16px 0;
            border-left: 4px solid var(--primary);
        }

        .cloze-sentence {
            font-size: 1.125rem;
            line-height: 2;
            margin: 12px 0;
        }

        .cloze-input {
            border: none;
            border-bottom: 2px solid var(--text-tertiary);
            background: transparent;
            color: var(--primary);
            font-weight: 700;
            text-align: center;
            min-width: 100px;
            padding: 4px 8px;
            font-size: 1.125rem;
            margin: 0 4px;
            transition: all 0.3s;
        }

        .cloze-input:focus {
            outline: none;
            border-color: var(--primary);
        }

        .cloze-input.correct {
            border-color: var(--success);
            color: var(--success);
            animation: correctAnim 0.5s;
        }

        .cloze-input.wrong {
            border-color: var(--danger);
            color: var(--danger);
            animation: shake 0.5s;
        }

        @keyframes correctAnim {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.1); }
        }

        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-4px); }
            75% { transform: translateX(4px); }
        }

        #review-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: var(--bg-app);
            z-index: 1000;
            display: none;
            flex-direction: column;
        }

        .review-header {
            padding: var(--spacing);
            background: var(--bg-surface);
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .review-progress {
            flex: 1;
            text-align: center;
            font-weight: 700;
            font-size: 1.125rem;
        }

        .progress-bar-container {
            height: 4px;
            background: var(--border);
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
        }

        .progress-bar {
            height: 100%;
            background: linear-gradient(90deg, var(--primary), var(--accent));
            transition: width 0.3s;
        }
        
        .progress-bar-fill, .progress-bar {
    height: 100%;
    background: var(--gradient-accent) !important;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 4px;
}

        .flashcard-stage {
            flex: 1;
            min-height: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: var(--spacing);
            overflow: hidden;
        }

        .flashcard-wrapper {
            width: 100%;
            max-width: 420px;
            min-height: 220px;
            max-height: calc(100vh - 240px);
            perspective: 1200px;
        }

        .flashcard {
            width: 100%;
            min-height: 220px;
            max-height: calc(100vh - 240px);
            position: relative;
            transform-style: preserve-3d;
            transition: transform 0.65s cubic-bezier(0.34, 1.56, 0.64, 1);
            cursor: pointer;
        }

        .flashcard.flipped {
            transform: rotateY(180deg);
        }

        .card-face {
            position: absolute;
            width: 100%;
            min-height: 220px;
            max-height: calc(100vh - 240px);
            backface-visibility: hidden;
            -webkit-backface-visibility: hidden;
            border-radius: var(--radius-lg);
            box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 8px 20px rgba(0,0,0,0.1);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            padding: clamp(20px, 5vw, 44px) clamp(16px, 4vw, 36px);
            text-align: center;
            overflow-y: auto;
        }

        .card-face-front {
            background: var(--bg-surface);
            border: 2px solid var(--border);
        }
        
.card-face-back {
    background: #ffffff;
    border: 2px solid var(--success);
    transform: rotateY(180deg);
    color: var(--text-primary);
    box-shadow: 0 15px 35px rgba(82, 183, 136, 0.25);
    position: relative;
    overflow: hidden;
}

.card-face-back::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 6px;
    background: linear-gradient(90deg, var(--primary), var(--success));
}

.card-face-back .card-face-label { 
    color: var(--success); 
    top: 22px;
}

.card-face-back .card-back {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1.3;
    margin-bottom: 12px;
}

.card-face-back .card-context { 
    color: var(--text-secondary); 
    background: var(--bg-app);
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 600;
}

.card-face-back .card-flip-hint { color: var(--text-tertiary); }

.card-face-back .card-watermark {
    color: var(--success);
    opacity: 0.08;
}

        .card-face-label {
            position: absolute;
            top: 18px;
            left: 20px;
            font-size: 0.65rem;
            font-weight: 800;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            opacity: 0.5;
        }

        .card-face-front .card-face-label { color: var(--text-tertiary); }
        .card-face-back .card-face-label { color: rgba(255,255,255,0.6); }

        .card-watermark {
            position: absolute;
            bottom: 16px;
            right: 20px;
            font-size: 1.8rem;
            opacity: 0.06;
            user-select: none;
        }

        .card-front {
            font-size: clamp(1.4rem, 6vw, 2.4rem);
            font-weight: 800;
            color: var(--text-primary);
            line-height: 1.2;
            margin-bottom: 8px;
        }

        .card-back {
            font-size: 2rem;
            font-weight: 700;
            color: white;
            line-height: 1.3;
            margin-bottom: 8px;
        }

        .card-context {
            font-size: 0.9rem;
            opacity: 0.6;
            font-style: italic;
            margin-top: 8px;
        }

        .card-face-front .card-context { color: var(--text-secondary); }
        .card-face-back .card-context { color: rgba(255,255,255,0.7); }

        .card-flip-hint {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 0.7rem;
            opacity: 0.4;
            display: flex;
            align-items: center;
            gap: 4px;
            white-space: nowrap;
        }

        .card-face-front .card-flip-hint { color: var(--text-tertiary); }
        .card-face-back .card-flip-hint { color: rgba(255,255,255,0.5); }

        .review-controls {
            padding: 20px var(--spacing);
            padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom, 0px)));
            background: var(--bg-surface);
            border-top: 1px solid var(--border);
            flex-shrink: 0;
        }

        .btn-primary {
    width: 100%;
    padding: 16px;
    border-radius: var(--radius);
    border: none;
    background: linear-gradient(135deg, #1a4731, #2d6a4f);
    color: white;
    font-weight: 700;
    font-size: 1.0625rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 8px 25px rgba(26, 71, 49, 0.2);
}

        .btn-primary:active {
            transform: scale(0.98);
            box-shadow: var(--shadow-sm);
        }

        .srs-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
        }

        .btn-srs {
            padding: 16px;
            border-radius: var(--radius);
            border: none;
            color: white;
            font-weight: 700;
            font-size: 0.9375rem;
            cursor: pointer;
            transition: all 0.2s;
            box-shadow: var(--shadow);
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 4px;
        }

        .btn-srs:active {
            transform: scale(0.95);
        }

        .btn-srs.again { background: var(--danger); }
        .btn-srs.hard { background: var(--warning); }
        .btn-srs.good { background: var(--success); }
        .btn-srs.easy { background: var(--primary); }

        .srs-interval {
            font-size: 0.75rem;
            opacity: 0.9;
        }

        .md-editor-wrap {
            display: flex;
            flex-direction: column;
            gap: 0;
            border: 1.5px solid var(--border);
            border-radius: var(--radius-sm);
            overflow: hidden;
            background: var(--bg-surface);
        }
        .md-editor-tabs {
            display: flex;
            background: var(--bg-app);
            border-bottom: 1px solid var(--border);
        }
        .md-tab {
            padding: 10px 18px;
            font-size: 0.82rem;
            font-weight: 700;
            border: none;
            background: transparent;
            cursor: pointer;
            color: var(--text-tertiary);
            transition: all 0.15s;
        }
        .md-tab.active {
            color: var(--primary);
            border-bottom: 2.5px solid var(--primary);
            background: var(--bg-surface);
        }
        .md-toolbar {
            display: flex;
            gap: 2px;
            padding: 6px 10px;
            background: var(--bg-app);
            border-bottom: 1px solid var(--border);
            flex-wrap: wrap;
        }
        .md-tool-btn {
            padding: 5px 10px;
            border: none;
            background: transparent;
            border-radius: 5px;
            cursor: pointer;
            font-size: 0.8rem;
            font-weight: 700;
            color: var(--text-secondary);
            transition: background 0.15s;
        }
        .md-tool-btn:hover { background: var(--border); }
        .md-tool-sep { width: 1px; background: var(--border); margin: 4px 4px; }
        .md-editor-textarea {
            width: 100%;
            min-height: 180px;
            max-height: 55vh;
            padding: 16px;
            border: none;
            background: var(--bg-surface);
            color: var(--text-primary);
            font-family: 'Courier New', monospace;
            font-size: 0.9rem;
            line-height: 1.7;
            resize: none;
            outline: none;
            overflow-y: auto;
            box-sizing: border-box;
            transition: height 0.1s;
        }
        .md-color-row {
            display: flex;
            gap: 6px;
            padding: 6px 10px;
            background: var(--bg-app);
            border-bottom: 1px solid var(--border);
            align-items: center;
            flex-wrap: wrap;
        }
        .md-color-label {
            font-size: 0.7rem;
            color: var(--text-tertiary);
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            margin-right: 2px;
        }
        .md-color-dot {
            width: 22px;
            height: 22px;
            border-radius: 50%;
            cursor: pointer;
            border: 2.5px solid transparent;
            transition: transform 0.15s, border-color 0.15s;
            flex-shrink: 0;
            position: relative;
        }
        .md-color-dot:active { transform: scale(1.25); }
        .md-color-dot.selected { border-color: var(--text-primary); transform: scale(1.15); }
        .md-preview {
            padding: 16px;
            min-height: 200px;
            font-family: 'Merriweather', Georgia, serif;
            font-size: 1rem;
            line-height: 1.8;
            color: var(--text-primary);
        }
        .md-preview h1 { font-size: 1.7rem; font-weight: 800; margin: 1.2em 0 0.4em; color: var(--primary); }
        .md-preview h2 { font-size: 1.4rem; font-weight: 700; margin: 1em 0 0.35em; color: var(--primary); }
        .md-preview h3 { font-size: 1.15rem; font-weight: 600; margin: 0.8em 0 0.3em; }
        .md-preview p { margin: 0.8em 0; }
        .md-preview ul, .md-preview ol { padding-left: 1.5em; margin: 0.8em 0; }
        .md-preview li { margin: 0.35em 0; }
        .md-preview strong { font-weight: 700; }
        .md-preview em { font-style: italic; }
        .md-preview code { background: var(--bg-app); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 0.88em; }
        .md-preview pre { background: var(--bg-app); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 1em 0; }
        .md-preview blockquote { border-left: 4px solid var(--accent); padding-left: 16px; color: var(--text-secondary); margin: 1em 0; }
        .md-preview mark { background: rgba(251,191,36,0.3); padding: 2px 4px; border-radius: 3px; }
        .md-preview table { border-collapse: collapse; width: 100%; margin: 1em 0; }
        .md-preview th, .md-preview td { border: 1px solid var(--border); padding: 8px 12px; }
        .md-preview th { background: var(--bg-app); font-weight: 700; }

        .wizard-step { display: none; }
        .wizard-step.active { display: block; }

        .mode-card {
            background: var(--bg-app);
            border: 2px solid var(--border);
            border-radius: var(--radius);
            padding: 16px 18px;
            margin-bottom: 12px;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
            display: flex;
            align-items: center;
            gap: 14px;
        }
        .mode-card:active { transform: scale(0.98); border-color: var(--accent); }
        .mode-card:hover { border-color: var(--accent); background: rgba(64,145,108,0.06); }
        .mode-card-icon {
            width: 44px; height: 44px; border-radius: 12px;
            display: flex; align-items: center; justify-content: center;
            font-size: 1.4rem; flex-shrink: 0;
            background: linear-gradient(135deg, var(--primary), var(--accent));
        }
        .mode-card-body { flex: 1; }
        .mode-card-title { font-weight: 700; font-size: 1rem; color: var(--text-primary); }
        .mode-card-desc { font-size: 0.78rem; color: var(--text-secondary); margin-top: 3px; line-height: 1.4; }
        .mode-card-path { font-size: 0.72rem; color: var(--text-tertiary); margin-top: 5px; font-style: italic; }
        .wizard-progress {
            display: flex;
            align-items: center;
            gap: 0;
            margin-bottom: 24px;
        }
        .wizard-dot {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 0.8rem;
            flex-shrink: 0;
            transition: all 0.3s;
            border: 2px solid var(--border);
            background: var(--bg-app);
            color: var(--text-tertiary);
        }
        .wizard-dot.active { background: var(--primary); border-color: var(--primary); color: white; }
        .wizard-dot.done { background: var(--success); border-color: var(--success); color: white; }
        .wizard-line {
            flex: 1;
            height: 2px;
            background: var(--border);
            transition: background 0.3s;
        }
        .wizard-line.done { background: var(--success); }
        .wizard-option {
            display: flex;
            align-items: center;
            padding: 14px 16px;
            border-radius: var(--radius-sm);
            border: 1.5px solid var(--border);
            margin-bottom: 8px;
            cursor: pointer;
            transition: all 0.2s;
            background: var(--bg-app);
            gap: 12px;
        }
        .wizard-option:active, .wizard-option.selected {
            border-color: var(--primary);
            background: rgba(26,71,49,0.06);
        }
        .wizard-option-icon { font-size: 1.4rem; flex-shrink: 0; }
        .wizard-option-text { flex: 1; }
        .wizard-option-name { font-weight: 700; font-size: 0.95rem; }
        .wizard-option-sub { font-size: 0.78rem; color: var(--text-tertiary); margin-top: 2px; }
        .wizard-new-item {
            border-style: dashed;
            border-color: var(--primary);
            color: var(--primary);
            background: rgba(26,71,49,0.03);
        }
        .quick-inline-form {
            background: rgba(26,71,49,0.06);
            border-radius: var(--radius-sm);
            padding: 16px;
            margin-top: 12px;
            border: 1.5px solid var(--primary);
        }

        nav {
            height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
            padding-bottom: env(safe-area-inset-bottom, 0px);
            background: var(--bg-surface);
            border-top: 1px solid var(--border);
            display: flex;
            justify-content: space-around;
            align-items: center;
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            z-index: 100;
            box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
        }

        .nav-item {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            color: var(--text-tertiary);
            font-size: 0.6875rem;
            font-weight: 600;
            gap: 6px;
            cursor: pointer;
            transition: all 0.2s;
            position: relative;
        }

        .nav-item::before {
            content: '';
            position: absolute;
            top: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 0;
            height: 3px;
            background: linear-gradient(90deg, var(--primary), var(--accent));
            border-radius: 0 0 3px 3px;
            transition: width 0.3s;
        }

        .nav-item.active::before {
            width: 60%;
        }

        .nav-item.active {
            color: var(--primary);
        }

        .nav-item svg {
            width: 26px;
            height: 26px;
            fill: currentColor;
            transition: transform 0.2s;
        }

        .nav-item.active svg {
            transform: scale(1.1);
        }

        .fab {
    position: fixed;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
    right: max(20px, env(safe-area-inset-right, 20px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #40916c, #52b788);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 25px rgba(26, 71, 49, 0.2);
    border: none;
    z-index: 90;
    cursor: pointer;
    transition: all 0.3s;
}

        .fab:active {
            transform: scale(0.9);
        }

        .fab svg {
            width: 28px;
            height: 28px;
            fill: white;
        }

        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 500;
            display: none;
            align-items: flex-end;
            animation: fadeIn 0.2s;
        }

        .modal.open {
            display: flex;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        .bottom-sheet {
            background: var(--bg-surface);
            width: 100%;
            border-radius: var(--radius-lg) var(--radius-lg) 0 0;
            max-height: calc(92vh - env(safe-area-inset-bottom, 0px));
            display: flex;
            flex-direction: column;
            overflow: hidden;
            animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .sheet-scroll-body {
            flex: 1 1 auto;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            padding: 0 24px 8px;
            min-height: 0;
        }

        .bottom-sheet > .form-actions {
            flex-shrink: 0;
            margin-top: auto !important;
            padding: 14px 24px calc(14px + env(safe-area-inset-bottom, 0px));
            background: var(--bg-surface);
            border-top: 1px solid var(--border);
        }
        
        .bottom-sheet > .sheet-handle,
        .bottom-sheet > .sheet-title,
        .bottom-sheet > .form-group,
        .bottom-sheet > div:not(.sheet-scroll-body):not(.form-actions) {
            padding-left: 24px;
            padding-right: 24px;
        }
        .bottom-sheet > .sheet-handle {
            padding: 0;
            width: 40px;
            height: 4px;
            background: var(--border);
            border-radius: 2px;
            margin: 16px auto 4px;
        }
        .bottom-sheet > .sheet-title {
            padding-top: 0;
            margin-bottom: 20px;
        }
        
        .bottom-sheet:not(:has(.sheet-scroll-body)) {
            overflow-y: auto;
        }

        @keyframes slideUp {
            from {
                transform: translateY(100%);
            }
            to {
                transform: translateY(0);
            }
        }

        .sheet-handle {
            width: 40px;
            height: 4px;
            background: var(--border);
            border-radius: 2px;
            margin: 16px auto 8px;
            flex-shrink: 0;
        }

        .sheet-title {
            font-size: 1.5rem;
            font-weight: 700;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-size: 0.875rem;
            font-weight: 600;
            color: var(--text-secondary);
        }

        .form-input, .form-textarea, .form-select {
            width: 100%;
            padding: 14px 16px;
            border-radius: var(--radius-sm);
            border: 1px solid var(--border);
            background: var(--bg-app);
            color: var(--text-primary);
            font-family: inherit;
            font-size: 1rem;
            transition: all 0.2s;
        }

        .form-input:focus, .form-textarea:focus, .form-select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
        }

        .form-textarea {
            min-height: 120px;
            resize: vertical;
            font-family: 'Merriweather', Georgia, serif;
            line-height: 1.6;
        }

        .form-actions {
            display: flex;
            gap: 12px;
            margin-top: 24px;
        }

        .btn {
            flex: 1;
            padding: 14px;
            border-radius: var(--radius-sm);
            border: none;
            font-weight: 700;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.2s;
        }

        .btn-secondary {
            background: var(--bg-app);
            color: var(--text-secondary);
        }

        .btn-secondary:active {
            background: var(--border);
        }

        .btn-danger {
            background: var(--danger);
            color: white;
        }

        .btn-danger:active {
            opacity: 0.9;
        }

        .confirm-dialog {
            background: var(--bg-surface);
            border-radius: var(--radius-lg);
            padding: 24px;
            max-width: 90%;
            width: 360px;
            box-shadow: var(--shadow-xl);
        }

        .confirm-title {
            font-size: 1.25rem;
            font-weight: 700;
            margin-bottom: 12px;
        }

        .confirm-message {
            color: var(--text-secondary);
            margin-bottom: 24px;
        }

        .toast {
            position: fixed;
            top: 88px;
            left: 50%;
            width: calc(100% - 32px);
            max-width: 360px;
            transform: translateX(-50%) translateY(-20px);
            background: var(--text-primary);
            color: var(--bg-surface);
            padding: 14px 20px;
            border-radius: 14px;
            font-size: 0.9375rem;
            font-weight: 600;
            opacity: 0;
            transition: opacity 0.25s ease, transform 0.25s ease;
            pointer-events: none;
            z-index: 2000;
            box-shadow: var(--shadow-xl);
            text-align: center;
        }

        .toast.show {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }

        .toast.success { background: var(--success); }
        .toast.error { background: var(--danger); }
        .toast.warning { background: var(--warning); }

        .dialogue-container {
            padding: 16px;
            max-width: 600px;
            margin: 0 auto;
        }

        .dialogue-gen-bar {
            display: flex;
            gap: 10px;
            align-items: center;
            background: var(--bg-surface);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 14px;
            margin-bottom: 20px;
        }

        .dialogue-gen-bar input {
            flex: 1;
            border: none;
            background: transparent;
            font-size: 0.9375rem;
            color: var(--text-primary);
            outline: none;
        }

        .dialogue-gen-bar input::placeholder { color: var(--text-tertiary); }

        .dialogue-gen-btn {
            background: linear-gradient(135deg, var(--primary), var(--accent));
            color: white;
            border: none;
            border-radius: var(--radius-sm);
            padding: 10px 16px;
            font-weight: 700;
            cursor: pointer;
            white-space: nowrap;
            font-size: 0.875rem;
            transition: all 0.2s;
        }

        .dialogue-gen-btn:active { transform: scale(0.97); }
        .dialogue-gen-btn:disabled { opacity: 0.6; cursor: not-allowed; }

        .dialogue-bubble {
            display: flex;
            gap: 10px;
            margin-bottom: 16px;
            align-items: flex-end;
        }

        .dialogue-bubble.right {
            flex-direction: row-reverse;
        }

        .dialogue-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.25rem;
            flex-shrink: 0;
            background: var(--border);
        }

        .dialogue-text {
            max-width: 75%;
            padding: 12px 16px;
            border-radius: 16px;
            font-size: 0.9375rem;
            line-height: 1.5;
            position: relative;
        }

        .dialogue-bubble.left .dialogue-text {
            background: var(--bg-surface);
            border: 1px solid var(--border);
            border-bottom-left-radius: 4px;
            color: var(--text-primary);
        }

        .dialogue-bubble.right .dialogue-text {
            background: var(--primary);
            border-bottom-right-radius: 4px;
            color: white;
        }

        .dialogue-speaker {
            font-size: 0.7rem;
            font-weight: 700;
            color: var(--text-tertiary);
            margin-bottom: 4px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        .dialogue-translation {
            font-size: 0.8rem;
            color: var(--text-tertiary);
            font-style: italic;
            margin-top: 4px;
        }

        .dialogue-srs-section {
            background: var(--bg-surface);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 16px;
            margin-top: 20px;
        }

        .dialogue-srs-title {
            font-weight: 700;
            margin-bottom: 12px;
            font-size: 0.9375rem;
        }

        .dialogue-card-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 0;
            border-bottom: 1px solid var(--border-light);
        }

        .dialogue-card-item:last-child { border-bottom: none; }

        .dialogue-card-phrase {
            font-weight: 600;
            font-size: 0.9rem;
        }

        .dialogue-card-translation {
            font-size: 0.8rem;
            color: var(--text-secondary);
            margin-top: 2px;
        }

        .btn-add-card-small {
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 6px;
            padding: 6px 12px;
            font-size: 0.8rem;
            font-weight: 600;
            cursor: pointer;
            white-space: nowrap;
            transition: all 0.2s;
        }

        .btn-add-card-small:active { transform: scale(0.95); }
        .btn-add-card-small.added { background: var(--success); }

        .dialogue-loading {
            text-align: center;
            padding: 40px 20px;
            color: var(--text-secondary);
        }

        .loading-dots {
            display: inline-flex;
            gap: 6px;
        }

        .loading-dots span {
            width: 8px;
            height: 8px;
            background: var(--primary);
            border-radius: 50%;
            animation: bounce 1.2s infinite;
        }

        .loading-dots span:nth-child(2) { animation-delay: 0.2s; }
        .loading-dots span:nth-child(3) { animation-delay: 0.4s; }

        @keyframes bounce {
            0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
            40% { transform: scale(1.2); opacity: 1; }
        }

        .select-bar {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 16px;
            background: var(--primary);
            color: white;
            position: sticky;
            top: 0;
            z-index: 60;
            border-radius: 0;
        }

        .select-bar-count {
            font-weight: 700;
            font-size: 0.95rem;
            flex: 1;
        }

        .select-bar-btn {
            background: rgba(255,255,255,0.2);
            border: none;
            border-radius: 8px;
            color: white;
            padding: 7px 12px;
            font-weight: 600;
            font-size: 0.8rem;
            cursor: pointer;
            white-space: nowrap;
            transition: background 0.15s;
        }

        .select-bar-btn:active { background: rgba(255,255,255,0.35); }
        .select-bar-btn.danger { background: rgba(239,68,68,0.7); }

        .selectable-item {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .item-checkbox {
            width: 22px;
            height: 22px;
            border: 2px solid var(--border);
            border-radius: 6px;
            background: var(--bg-surface);
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            cursor: pointer;
            transition: all 0.15s;
        }

        .item-checkbox.checked {
            background: var(--primary);
            border-color: var(--primary);
        }

        .item-checkbox.checked::after {
            content: '';
            width: 12px;
            height: 8px;
            border-left: 2px solid white;
            border-bottom: 2px solid white;
            transform: rotate(-45deg) translateY(-1px);
            display: block;
        }

        .select-mode-toggle {
            background: var(--bg-app);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 7px 12px;
            font-size: 0.8rem;
            }

        .tag-chip {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 4px 10px;
            border-radius: 20px;
            background: var(--primary);
            color: white;
            font-size: 0.72rem;
            font-weight: 700;
            letter-spacing: .02em;
        }
        .tag-chip .tag-remove {
            cursor: pointer;
            opacity: 0.7;
            font-weight: 900;
            margin-left: 2px;
            line-height: 1;
        }
        .tag-chip .tag-remove:hover { opacity: 1; }

        .tag-chip-filter {
            display: inline-flex;
            align-items: center;
            padding: 5px 12px;
            border-radius: 20px;
            background: var(--bg-app);
            border: 1.5px solid var(--border);
            color: var(--text-secondary);
            font-size: 0.75rem;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.15s;
            user-select: none;
        }
        .tag-chip-filter.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .browse-filter-btn {
            padding: 6px 12px;
            border-radius: 20px;
            border: 1.5px solid var(--border);
            background: var(--bg-app);
            color: var(--text-secondary);
            font-size: 0.75rem;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.15s;
            white-space: nowrap;
        }
        .browse-filter-btn.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .card-tags {
            display: flex;
            gap: 4px;
            flex-wrap: wrap;
            margin-top: 6px;
        }
        .card-tag-badge {
            padding: 2px 8px;
            border-radius: 10px;
            background: rgba(26,71,49,0.12);
            color: var(--primary);
            font-size: 0.68rem;
            font-weight: 700;
        }

        .select-mode-toggle.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        #schedule-table-wrap {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            padding: 0 0 100px;
            position: relative;
        }

        #schedule-table-wrap::after {
            content: '';
            position: sticky;
            right: 0;
            top: 0;
            width: 28px;
            height: 100%;
            background: linear-gradient(to right, transparent, rgba(0,0,0,0.06));
            pointer-events: none;
            display: block;
            float: right;
            margin-top: -100%;
        }

        .schedule-table {
            border-collapse: collapse;
            width: max-content;
            min-width: 100%;
            font-size: 0.8rem;
            table-layout: fixed;
        }

        .schedule-table th {
            background: var(--primary);
            color: white;
            padding: 10px 4px;
            text-align: center;
            font-weight: 700;
            white-space: nowrap;
            position: sticky;
            top: 0;
            z-index: 10;
            font-size: 0.75rem;
            width: 90px;
        }

        .schedule-table th.time-header {
            background: var(--bg-elevated);
            color: var(--text-tertiary);
            width: 60px;
            min-width: 60px;
            position: sticky;
            left: 0;
            z-index: 20;
            border-right: 2px solid var(--border);
        }

        .schedule-table .time-cell {
            background: var(--bg-elevated);
            color: var(--text-tertiary);
            padding: 6px 4px;
            text-align: center;
            font-size: 0.68rem;
            font-weight: 600;
            white-space: nowrap;
            border-right: 2px solid var(--border);
            position: sticky;
            left: 0;
            z-index: 5;
            width: 60px;
        }

        .schedule-table td.sched-cell {
            border: 1px solid var(--border);
            padding: 0;
            width: 90px;
            height: 52px;
            vertical-align: top;
            cursor: pointer;
            transition: filter 0.15s;
            position: relative;
        }

        .schedule-table td.sched-cell:active {
            filter: brightness(0.88);
        }

        .sched-cell-inner {
            width: 100%;
            height: 100%;
            padding: 4px 5px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center; 
            text-align: center; 
            gap: 2px;
            min-height: 52px;
        }

        .sched-cell-text {
            font-weight: 600;
            font-size: 0.72rem;
            line-height: 1.25;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        .sched-cell-empty {
            color: var(--border);
            font-size: 1.1rem;
            text-align: center;
        }

        .schedule-today-badge {
            display: inline-block;
            width: 6px;
            height: 6px;
            background: white;
            border-radius: 50%;
            margin-left: 3px;
            vertical-align: 1px;
            opacity: 0.9;
        }

        .sched-day-label {
            display: inline-block;
            max-width: 80px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            vertical-align: middle;
        }

        @media (max-width: 360px) {
            .sched-day-label {
                max-width: 40px;
            }
        }

        @media (min-width: 480px) {
            .schedule-table th,
            .schedule-table td.sched-cell {
                width: 110px;
            }
            .schedule-table th.time-header,
            .schedule-table .time-cell {
                width: 70px;
                min-width: 70px;
            }
        }

        .color-swatch {
            width: 28px;
            height: 28px;
            border-radius: 50%;
            cursor: pointer;
            border: 3px solid transparent;
            transition: all 0.15s;
            flex-shrink: 0;
        }

        .color-swatch.selected {
            border-color: var(--text-primary);
            transform: scale(1.15);
        }

        @keyframes spin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        .hidden {
            display: none !important;
        }

        .ui-toggle {
            display: flex;
            align-items: flex-start;
            gap: 14px;
            cursor: pointer;
            user-select: none;
            width: 100%;
            -webkit-tap-highlight-color: transparent;
        }
        .ui-toggle input[type="checkbox"] {
            position: absolute;
            opacity: 0;
            width: 0;
            height: 0;
        }
        .ui-toggle-track {
            position: relative;
            width: 50px;
            height: 28px;
            border-radius: 14px;
            background: var(--border);
            transition: background 0.22s;
            flex-shrink: 0;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .ui-toggle-track::after {
            content: '';
            position: absolute;
            top: 4px;
            left: 4px;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: white;
            box-shadow: 0 2px 5px rgba(0,0,0,.28);
            transition: transform 0.22s;
        }
        .ui-toggle-track.on { background: var(--primary); }
        .ui-toggle-track.on::after { transform: translateX(22px); }
        .ui-toggle-info { flex: 1; padding-top: 3px; }
        .ui-toggle-info strong { display:block; font-weight:600; font-size:0.9rem; color:var(--text-primary); line-height:1.3; }
        .ui-toggle-info small { font-size:0.76rem; color:var(--text-tertiary); line-height:1.5; margin-top:2px; display:block; }

        .reader-edit-bar {
            display: flex;
            gap: 8px;
            align-items: center;
            padding: 10px 16px;
            background: linear-gradient(135deg,rgba(26,71,49,.06),rgba(45,106,79,.06));
            border-bottom: 2px solid var(--primary);
            position: sticky;
            top: 0;
            z-index: 40;
            flex-wrap: wrap;
        }
        .reader-edit-title-input {
            flex: 1;
            min-width: 140px;
            font-size: 1rem;
            font-weight: 700;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: var(--bg-surface);
            color: var(--text-primary);
            font-family: inherit;
            outline: none;
            padding: 8px 12px;
        }
        .reader-edit-title-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,71,49,.1); }
        .tab-content-editable { cursor: text; outline: none; min-height: 80px; }
        .tab-content-editable:focus { outline: 2px solid var(--primary); outline-offset:6px; border-radius:8px; }
        .reader-save-btn {
            background: var(--primary); color: white; border: none;
            border-radius: 10px; padding: 9px 18px; font-weight: 700;
            font-size: 0.875rem; cursor: pointer; display:flex;
            align-items: center; gap: 6px; transition: all 0.2s; white-space: nowrap;
        }
        .reader-save-btn:active { transform: scale(0.96); opacity:.9; }
        .reader-cancel-btn {
            background: var(--bg-app); color: var(--text-secondary); border: 1px solid var(--border);
            border-radius: 10px; padding: 9px 14px; font-weight: 600;
            font-size: 0.875rem; cursor: pointer; white-space: nowrap;
        }
        .reader-edit-hint { font-size:0.75rem; color:var(--text-tertiary); padding:4px 16px 8px; font-style:italic; }

        .tab-edit-fab {
    position: fixed; 
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 20px);
    right: 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(26,71,49,.35);
    z-index: 150; 
    transition: all .2s;
    -webkit-tap-highlight-color: transparent;
}
        .tab-edit-fab:active { transform: scale(0.95); }
        .tab-edit-fab.editing {
            background: var(--success);
        }

        button svg, a svg, .nav-item svg { pointer-events: none; flex-shrink: 0; }

        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: var(--text-tertiary);
        }

        .empty-icon {
            font-size: 3rem;
            margin-bottom: 16px;
            opacity: 0.5;
            display: flex;
            justify-content: center;
        }

        .empty-text {
            font-size: 1.125rem;
            font-weight: 600;
            margin-bottom: 8px;
        }

        .empty-subtext {
            font-size: 0.9375rem;
        }

        .divider {
            height: 1px;
            background: var(--border);
            margin: 20px 0;
        }

        @media (min-width: 768px) {
            :root {
                --spacing: 24px;
            }

            .container {
                padding: 24px;
            }

            .stats-grid {
                grid-template-columns: repeat(4, 1fr);
            }
        }
.icon-inline {
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.18em;
    fill: currentColor;
    display: inline-block;
    flex-shrink: 0;
}

.empty-icon svg {
    width: 64px;
    height: 64px;
    fill: var(--text-tertiary);
    opacity: 0.5;
}

.dialogue-avatar svg {
    width: 24px;
    height: 24px;
    fill: var(--text-secondary);
}
.btn:active {
    transform: scale(0.98);
    opacity: 0.8;
}

header {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(255,255,255,0.92);
    box-shadow: 0 1px 0 var(--border), 0 4px 16px rgba(0,0,0,0.04);
}
[data-theme="dark"] header {
    background: rgba(26, 71, 49, 0.92);
}

.icon-btn:hover {
    background: var(--border-light);
    color: var(--primary);
}

.card {
    box-shadow: 0 2px 8px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.07), 0 2px 6px rgba(0,0,0,0.04);
}

.bottom-sheet {
    box-shadow: 0 -8px 40px rgba(0,0,0,0.13), 0 -2px 8px rgba(0,0,0,0.06);
    border-radius: 24px 24px 0 0;
}
.sheet-handle {
    width: 44px;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    margin: 14px auto 8px;
}
.sheet-title {
    font-size: 1.3rem;
    padding: 0 4px;
}

.modal {
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.confirm-dialog {
    border-radius: 20px;
    padding: 28px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.2);
}

.btn {
    border-radius: 12px;
    font-size: 0.9375rem;
    min-height: 48px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn-primary {
    box-shadow: 0 4px 12px rgba(26,71,49,0.25);
}
.btn-primary:hover {
    box-shadow: 0 6px 18px rgba(26,71,49,0.3);
    transform: translateY(-1px);
}

.btn-inline {
    flex: 0 0 auto !important;
    min-width: unset !important;
    width: auto !important;
}
.btn-secondary {
    border: 1px solid var(--border);
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    box-shadow: 0 0 0 3px rgba(26,71,49,0.15);
    border-color: var(--primary);
}

nav {
    box-shadow: 0 -1px 0 var(--border), 0 -4px 20px rgba(0,0,0,0.05);
}
.nav-item {
    gap: 4px;
    padding: 4px 0;
    border-radius: 12px;
    margin: 0 4px;
    transition: background 0.2s, color 0.2s;
}
.nav-item:active {
    background: rgba(26,71,49,0.08);
}

.fab {
    box-shadow: 0 4px 20px rgba(26,71,49,0.3), 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.fab:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 28px rgba(26,71,49,0.35);
}

.progress-bar-bg {
    height: 6px;
    border-radius: 3px;
}
.progress-bar-fill {
    border-radius: 3px;
}

.stat-card {
    border-radius: 16px;
    padding: 18px 14px;
    transition: transform 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.07);
}

.toast {
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    font-size: 0.9rem;
    padding: 13px 20px;
}

.toolbar-btn {
    border-radius: 24px;
    padding: 9px 16px;
    min-height: 40px;
}
.toolbar-btn.active {
    box-shadow: 0 2px 8px rgba(26,71,49,0.2);
}

.badge {
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.72rem;
}

.empty-state {
    padding: 48px 24px;
}

.sort-panel {
    border-radius: 18px;
}

.btn-action {
    border-radius: 14px;
    font-size: 0.875rem;
    min-height: 52px;
    gap: 8px;
}

#modal-sync-menu .bottom-sheet button[onclick] {
    border-radius: 16px;
    transition: background 0.18s, border-color 0.18s, transform 0.15s;
}
#modal-sync-menu .bottom-sheet button[onclick]:active {
    transform: scale(0.98);
    filter: brightness(0.96);
}

@media (max-width: 480px) {
    :root {
        --spacing: 12px;
        --radius: 14px;
        --radius-lg: 18px;
    }

    .container {
        padding: 12px;
    }

    .header-title {
        font-size: 1.25rem;
    }

    .card-title {
        font-size: 1rem;
    }

    .sheet-title {
        font-size: 1.15rem;
    }

    .btn {
        min-height: 46px;
        font-size: 0.9rem;
    }

    .action-btn {
        width: 42px;
        height: 42px;
    }

    .deck-name-large {
        font-size: 1.4rem;
    }

    .flashcard-wrapper {
        min-height: 280px;
    }
    .flashcard, .card-face {
        min-height: 280px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-value {
        font-size: 1.6rem;
    }

    .breadcrumb {
        padding: 10px 12px;
        font-size: 0.82rem;
    }

    .form-input, .form-textarea, .form-select {
        font-size: 1rem;
        min-height: 46px;
        padding: 11px 14px;
    }

    .toolbar-btn {
        padding: 8px 13px;
        font-size: 0.82rem;
    }

    .btn-action {
        padding: 12px 10px;
        font-size: 0.82rem;
    }

    .deck-detail-header {
        margin: 12px;
        padding: 18px;
    }

    .chart-container {
        padding: 14px;
    }

    .srs-grid {
        gap: 8px;
    }

    .nav-item {
        font-size: 0.6rem;
        gap: 3px;
    }

    .nav-item svg {
        width: 22px;
        height: 22px;
    }

    .fab {
        width: 52px;
        height: 52px;
        bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
        right: max(14px, env(safe-area-inset-right, 14px));
    }
}

@media (max-width: 360px) {
    :root {
        --spacing: 10px;
    }
    .action-buttons {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 0 10px;
    }
    .btn-action {
        padding: 10px 8px;
        font-size: 0.78rem;
        min-height: 48px;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    header {
        height: 52px;
    }
    :root {
        --header-height: 52px;
        --nav-height: 54px;
    }
    .bottom-sheet {
        max-height: 95dvh;
    }
}

::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

button:focus-visible, a:focus-visible, input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.view {
    animation: slideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#v-welcome {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 24px;
    text-align: center;
    background: var(--bg-app);
    z-index: 9999;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
}
.welcome-logo {
    width: 100px;
    height: 100px;
    background: var(--gradient-primary);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: var(--shadow-xl);
}
.welcome-logo svg {
    width: 60px;
    height: 60px;
    fill: white;
}

@media (min-width: 768px) {
    body {
        flex-direction: row;
    }
    .nav-brand {
        display: block !important;
    }
    nav {
        width: 200px;
        height: 100dvh;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 16px 8px;
        padding-bottom: 16px;
        border-top: none;
        border-right: 1px solid var(--border);
        box-shadow: 2px 0 8px rgba(0,0,0,0.04);
        position: relative;
        bottom: unset;
        left: unset;
        right: unset;
        overflow-y: auto;
        order: -1; 
    }
    .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        height: auto;
        padding: 12px 14px;
        border-radius: 12px;
        gap: 12px;
        font-size: 0.85rem;
        margin: 2px 0;
    }
    .nav-item::before {
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        width: 3px !important;
        height: 0;
        border-radius: 0 3px 3px 0;
    }
    .nav-item.active::before {
        width: 3px !important;
        height: 60%;
    }
    .nav-item svg {
        width: 22px;
        height: 22px;
    }
    .nav-item.active svg {
        transform: none;
    }
    .app-wrapper {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }
    main {
        padding-bottom: 24px; 
    }
    .fab {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }
    .container {
        max-width: 860px;
        padding: 20px 24px;
    }
    header {
        padding: 0 24px;
    }
    .filter-bar {
        flex-direction: row !important;
    }
}

@media (min-width: 1024px) {
    nav {
        width: 220px;
    }
    .container {
        max-width: 960px;
    }
}

.store-hero {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius);
    padding: 16px 14px;
    color: white;
    margin-bottom: 14px;
    text-align: center;
}
.store-hero h2 { font-size: 1.15rem; font-weight: 800; margin-bottom: 3px; }
.store-hero p { font-size: 0.82rem; opacity: 0.9; margin: 0; }
.store-trust {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.store-trust-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,0.18);
    border-radius: 20px;
    padding: 4px 9px;
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
}
.store-pack-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}
.store-pack-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
.store-pack-top {
    padding: 14px 14px 10px;
}
.store-pack-cat {
    display: inline-flex;
    align-items: center;
    background: #e8f5fe;
    color: #1e40af;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.store-pack-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.3;
}
.store-pack-desc {
    font-size: 0.83rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 10px;
}
.store-pack-price-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    background: var(--bg-app);
    border-top: 1px solid var(--border);
}
.store-pack-price {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary);
}
.store-pack-preview {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    text-align: right;
    max-width: 120px;
}
.store-buy-zone {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
}
.store-buy-zone.collapsed { display: none; }
.store-buy-btn {
    width: 100%;
    padding: 12px 10px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(26, 71, 49, 0.2);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px; 
}
.store-buy-btn:hover { background: var(--primary-light); }
.store-buy-btn:active { transform: scale(0.98); }
.store-buy-btn:disabled { opacity: 0.6; cursor: default; }
.store-buy-btn.owned {
    background: var(--success);
    cursor: default;
}
.store-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--bg-app);
    color: var(--text-primary);
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 8px;
}
.store-input:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(26, 71, 49, 0.1);
}
.store-step {
    display: none;
}
.store-step.active { display: block; }
.store-otp-box {
    background: linear-gradient(135deg, #f0fdf4, #dcfce7);
    border: 1.5px solid #bbf7d0;
    border-radius: 12px;
    padding: 16px;
}
.store-otp-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #166534;
    margin-bottom: 4px;
}
.store-otp-hint { font-size: 0.78rem; color: #15803d; margin-bottom: 12px; }
.store-timer {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-align: center;
    margin-top: 10px;
}
.store-hint-link { font-size: 0.72rem; color: var(--text-tertiary); margin-bottom: 10px; }
.store-hint-link a { color: var(--primary); text-decoration: none; font-weight: 600; }
.store-progress {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}
.store-progress-step {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.3s;
}
.store-progress-step.done { background: var(--success); }
.store-progress-step.active { background: var(--primary); }
.store-owned-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0fdf4;
    border: 1.5px solid #bbf7d0;
    border-radius: 10px;
    padding: 12px 14px;
    color: #166534;
    font-weight: 700;
    font-size: 0.9rem;
}

#store-admin-panel {
    display: none;
    margin-top: 20px;
    border: 2px dashed #e2e8f0;
    border-radius: var(--radius);
    overflow: hidden;
}
.admin-header {
    background: linear-gradient(135deg, #1e293b, #334155);
    color: white;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}
.admin-header h3 { font-size: 0.9rem; font-weight: 700; margin: 0; }
.admin-body { background: var(--bg-surface); padding: 16px; }
.admin-section { margin-bottom: 20px; }
.admin-section h4 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    font-weight: 700;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.admin-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    background: var(--bg-app);
    color: var(--text-primary);
    box-sizing: border-box;
    margin-bottom: 8px;
    outline: none;
}
.admin-input:focus { border-color: var(--primary); }
.admin-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: opacity 0.2s;
}
.admin-btn:hover { opacity: 0.85; }
.admin-btn-primary { background: var(--primary); color: white; }
.admin-btn-danger { background: var(--danger); color: white; }
.admin-btn-warning { background: var(--warning); color: white; }
.admin-btn-slate { background: #475569; color: white; }
.admin-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.83rem;
    gap: 10px;
}
.admin-item-row:last-child { border-bottom: none; }
.admin-sales-box {
    font-size: 0.78rem;
    max-height: 180px;
    overflow-y: auto;
    background: var(--bg-app);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.sale-row {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light);
}
.sale-row:last-child { border-bottom: none; }

.danger-zone {
    margin-top: 20px;
    padding: 14px;
    background: #fff5f5;
    border: 1.5px solid #fecaca;
    border-radius: 10px;
}
[data-theme="dark"] .danger-zone {
    background: rgba(239,68,68,0.08);
    border-color: rgba(239,68,68,0.3);
}
.danger-zone-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--danger);
    margin-bottom: 8px;
}
.danger-zone-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.btn-danger-full {
    width: 100%;
    padding: 11px;
    background: transparent;
    border: 1.5px solid var(--danger);
    color: var(--danger);
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-danger-full:hover {
    background: var(--danger);
    color: white;
}

@media (max-width: 380px) {
    .store-trust { gap: 4px; }
    .store-trust-badge { font-size: 0.62rem; padding: 3px 7px; }
    .store-pack-title { font-size: 0.95rem; }
    .store-pack-price { font-size: 1.1rem; }
    .store-buy-btn { font-size: 0.85rem; padding: 11px 8px; }
    .store-progress-step { height: 3px; }
}

.deck-detail-header {
    padding: 18px 20px !important;
}
.deck-name-large {
    font-size: clamp(1.2rem, 5vw, 1.75rem) !important;
}

.store-pack-row {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    transition: all 0.2s;
}
.store-pack-row:active { transform: scale(0.98); }
.store-pack-row-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg,#f59e0b,#fbbf24);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.store-pack-row-info { flex: 1; min-width: 0; }
.store-pack-row-title { 
    font-weight: 700; 
    font-size: 0.95rem; 
    color: var(--text-primary); 
    line-height: 1.3;
    margin-bottom: 4px;
    word-break: break-word;
}
.store-pack-row-meta { 
    font-size: 0.78rem; 
    color: var(--text-secondary); 
    margin-top: 2px; 
    line-height: 1.4;
}
.store-pack-row-price {
    font-weight: 800;
    font-size: 0.88rem;
    color: var(--primary);
    flex-shrink: 0;
    text-align: right;
}
.store-pack-row-action {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: 8px;
    border: none;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}
.store-pack-row-action.owned  { background: #dcfce7; color: #166534; }
.store-pack-row-action.buy    { background: var(--primary); color: white; }
.store-pack-row-action.expand { background: var(--bg-app); color: var(--text-secondary); border: 1px solid var(--border); }
.store-pack-row-action:active { transform: scale(0.95); }


.scroll-hint {
    position: sticky;
    right: 0;
    margin-left: auto; 
    z-index: 30;
    background: var(--primary);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: bounceRight 1.5s infinite;
    pointer-events: none;
    transition: opacity 0.3s;
    font-weight: bold;
    flex-shrink: 0;
    align-self: center; 
}

.schedule-scroll-container {
    display: flex;
    align-items: center;
    overflow-x: auto;
    width: 100%;
    padding-right: 10px; 
}

@keyframes bounceRight {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(6px); }
}

.is-today {
    background: var(--accent) !important;
    color: white;
}

.btn-tts-bubble {
    background: rgba(0,0,0,0.08);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: inherit;
    flex-shrink: 0;
    margin-top: 2px;
    transition: transform 0.15s, background 0.2s;
}
.btn-tts-bubble:hover { background: rgba(0,0,0,0.15); }
.btn-tts-bubble:active { transform: scale(0.9); }
.dialogue-bubble.right .btn-tts-bubble { background: rgba(255,255,255,0.25); }
.dialogue-bubble.right .btn-tts-bubble:hover { background: rgba(255,255,255,0.35); }

.inline-tts-btn {
    background: rgba(45, 106, 79, 0.1); 
    color: var(--primary);
    border: 1px solid rgba(45, 106, 79, 0.3);
    border-radius: 8px; 
    padding: 6px 10px 6px 8px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    vertical-align: middle;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); 
}

.inline-tts-btn:hover {
    background: rgba(45, 106, 79, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
}

.inline-tts-btn:active {
    transform: translateY(0) scale(0.96);
    background: var(--primary);
    color: white;
}

.inline-tts-btn svg { 
    width: 16px; 
    height: 16px; 
    fill: currentColor; 
}

body.modal-open .tab-edit-fab,
body.modal-open .fab {
    display: none !important;
}

.cart-checkbox {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-app);
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
    user-select: none;
}

.cart-checkbox.checked {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(26, 71, 49, 0.25);
}

.cart-checkbox:active {
    transform: scale(0.95);
}

.store-cart-bar {
    position: fixed;
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    width: calc(100% - 40px);
    max-width: 400px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    padding: 16px 20px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(26, 71, 49, 0.4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 100;
}

.store-cart-bar.visible {
    transform: translateX(-50%) translateY(0);
}

.store-checkout-btn {
    background: white;
    color: var(--primary);
    border: none;
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 800;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: transform 0.2s;
}

.store-checkout-btn:active {
    transform: scale(0.95);
}

.operator-grid { 
    display: flex; justify-content: space-between; gap: 8px; 
    margin-top: 15px; margin-bottom: 15px; 
}
.operator-card {
    position: relative;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.operator-card.active {
    border-color: var(--primary) !important;
    background: rgba(26, 71, 49, 0.05) !important;
    color: var(--primary);
}

.operator-card .checkmark {
    display: none; 
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 10px;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-surface);
}

.operator-card.active .checkmark {
    display: flex; 
}
.operator-card svg { height: 32px; width: auto; margin-bottom: 2px; }
.operator-card span { font-size: 0.75rem; font-weight: 700; }
.operator-card.active { 
    border-color: var(--primary); 
    background: rgba(26, 71, 49, 0.05); 
    color: var(--primary); 
}
.checkmark { 
    display: none; position: absolute; top: 4px; right: 4px; 
    width: 16px; height: 16px; background-color: var(--primary); 
    color: white; border-radius: 50%; 
}
.operator-card.active .checkmark { 
    display: flex; align-items: center; justify-content: center; 
}

.receipt { 
    background: var(--bg-app); border: 1px solid var(--border); 
    border-radius: 8px; padding: 12px; margin-bottom: 15px; text-align: left; 
}
.receipt-row { 
    display: flex; justify-content: space-between; font-size: 0.8rem; 
    margin-bottom: 6px; color: var(--text-secondary); 
}
.receipt-row strong { color: var(--text-primary); font-weight: 600; }
.receipt-total { 
    display: flex; justify-content: space-between; font-size: 1rem; 
    font-weight: 800; color: var(--primary); margin-top: 8px; 
    padding-top: 8px; border-top: 1px solid var(--border); 
}

.micro-guide { 
    background: rgba(14, 165, 233, 0.1); border-left: 3px solid #0EA5E9; 
    padding: 10px 12px; font-size: 0.75rem; color: #0369A1; 
    margin-bottom: 5px; border-radius: 0 6px 6px 0; text-align: left; 
}
.micro-guide p { margin: 0 0 5px 0; font-weight: 600; }
.micro-guide ol { margin: 0; padding-left: 20px; }

.secure-badge { 
    text-align: center; font-size: 0.7rem; color: var(--text-tertiary); 
    margin-top: 10px; display: flex; justify-content: center; 
    align-items: center; gap: 4px; 
}

[data-theme="dark"] .operator-card.active {
    background: rgba(64, 145, 108, 0.15);
}
[data-theme="dark"] .micro-guide {
    background: rgba(14, 165, 233, 0.1);
    color: #38bdf8;
}

.explore-section-title {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 18px 0 10px 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.hub-tab-btn {
    padding: 8px 6px; 
    font-size: 0.8rem;
}

.paywall-container {
    position: relative;
    padding: 20px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-top: 10px;
    overflow: hidden;
}

.paywall-blur-text {
    font-family: 'Merriweather', Georgia, serif;
    color: var(--text-primary);
    line-height: 1.8;
    filter: blur(4px);
    opacity: 0.6;
    pointer-events: none;
    user-select: none;
}

.paywall-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 250px;
    background: linear-gradient(to bottom, transparent, var(--bg-surface) 50%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding: 20px;
    text-align: center;
}

.preview-flashcard {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.preview-tab-content {
    display: none; 
    padding: 20px;
}
.preview-tab-content.active {
    display: block;
}
#preview-tab-cards {
    padding: 20px;
}

.inline-tts-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(26, 71, 49, 0.08);
    color: var(--primary);
    border: 1px solid rgba(26, 71, 49, 0.2);
    border-radius: 8px;
    padding: 4px 10px 4px 8px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    vertical-align: middle;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 3px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    -webkit-tap-highlight-color: transparent; 
}

.inline-tts-btn:hover {
    background: rgba(26, 71, 49, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
}

.inline-tts-btn:active {
    transform: translateY(0) scale(0.96);
    background: var(--primary);
    color: white;
}

.inline-tts-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0; 
    transition: transform 0.3s;
}

.inline-tts-btn span {
    display: inline-block;
}

.inline-tts-btn.playing {
    background: var(--primary);
    color: white;
    animation: soundPulse 1s ease-out;
}

.inline-tts-btn.playing svg {
    animation: speakerVibrate 0.3s infinite alternate;
}

@keyframes soundPulse {
    0% { box-shadow: 0 0 0 0 rgba(26, 71, 49, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(26, 71, 49, 0); }
    100% { box-shadow: 0 0 0 0 rgba(26, 71, 49, 0); }
}

@keyframes speakerVibrate {
    0% { transform: scale(1); }
    100% { transform: scale(1.15) translateX(1px); }
}

.member-only {
    position: relative;
}

.member-only::after {
    content: '★';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    background: #f59e0b;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 1.5px solid var(--bg-surface);
    z-index: 5;
    pointer-events: none;
}

body.is-pro .member-only::after {
    display: none !important;
}

:root {
    --heatmap-0: rgba(150,150,150,0.1);
    --heatmap-1: #dcfce7;
    --heatmap-2: #86efac;
    --heatmap-3: #22c55e;
    --heatmap-4: #166534;
}

.analytics-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.heatmap-container {
    overflow-x: auto;
    padding: 10px 0;
    display: flex;
    justify-content: flex-start;
}

.heatmap-weeks {
    display: flex;
    gap: 3px;
}

.heatmap-week {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.heatmap-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: var(--heatmap-0);
}

.sched-current-slot {
    background: rgba(34, 197, 94, 0.05);
    border-left: 4px solid #22c55e;
}

.sched-now-pill {
    background: #22c55e;
    color: white;
    font-size: 0.6rem;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 800;
}

.plan-grid { display: flex; gap: 8px; margin-bottom: 10px; }
.plan-card {
    flex: 1;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px 8px 12px 8px; 
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-app);
    position: relative;
    overflow: visible; 
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 80px;
}

.plan-card .badge {
    position: absolute;
    top: -8px;
    right: 8px;
    background: #EF4444;
    color: white;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 900;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
    z-index: 5;
    white-space: nowrap;
}
.plan-duration {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.plan-price {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 700;
}
.plan-card.active {
    border-color: var(--primary);
    background: rgba(26, 71, 49, 0.05);
    box-shadow: 0 4px 12px rgba(26, 71, 49, 0.1);
}
[data-theme="dark"] .plan-card.active { background: rgba(74, 162, 113, 0.15); }

.member-only {
    position: relative;
    overflow: visible !important; 
}

.member-only::after {
    content: '★';
    position: absolute;
    top: -4px; 
    right: -4px;
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    color: white;
    border-radius: 50%;
    
    font-size: 8px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border: 1px solid white;
    z-index: 20;
    
    pointer-events: none; 
}

.nav-item.member-only::after {
    top: 2px;
    right: 25%; 
    width: 16px;
    height: 16px;
    font-size: 10px;
}

.pdf-container {
    width: 100%;
    height: calc(100vh - var(--header-height) - 56px - var(--nav-height) - 20px);
    height: calc(100dvh - var(--header-height) - 56px - var(--nav-height) - 20px);
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
}

.pdf-iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex-grow: 1;
}

.pdf-actions {
    padding: 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    text-align: center;
}

.pdf-download-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}