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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f0;
    --bg-input: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #888888;
    --border: #e0e0e0;
    --border-focus: #6366f1;

    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #e0e1fc;
    --success: #22c55e;
    --success-light: #dcfce7;
    --error: #ef4444;
    --error-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;

    --easy: #22c55e;
    --medium: #f59e0b;
    --hard: #ef4444;

    --status-new: #94a3b8;
    --status-learning: #f59e0b;
    --status-mature: #22c55e;
    --status-due: #ef4444;

    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;
    --text-3xl: 2.5rem;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg-primary: #1a1b2e;
        --bg-secondary: #222440;
        --bg-card: #262950;
        --bg-hover: #2e3160;
        --bg-input: #222440;
        --text-primary: #e8e8f0;
        --text-secondary: #a8a8c0;
        --text-muted: #6e6e8a;
        --border: #3a3d5c;
        --border-focus: #818cf8;
        --accent-light: #2e2b5e;
        --success-light: #1a3a2a;
        --error-light: #3d1f2f;
        --warning-light: #3a2d1a;
        --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
        --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
        --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
    }
}

[data-theme="dark"] {
    --bg-primary: #1a1b2e;
    --bg-secondary: #222440;
    --bg-card: #262950;
    --bg-hover: #2e3160;
    --bg-input: #222440;
    --text-primary: #e8e8f0;
    --text-secondary: #a8a8c0;
    --text-muted: #6e6e8a;
    --border: #3a3d5c;
    --border-focus: #818cf8;
    --accent-light: #2e2b5e;
    --success-light: #1a3a2a;
    --error-light: #3d1f2f;
    --warning-light: #3a2d1a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

html {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== Header & Nav ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.nav {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-sm) var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: var(--space-sm);
}

.nav-link {
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

/* ===== Main ===== */
.main {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md);
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
}

.card + .card {
    margin-top: var(--space-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: 600;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge--easy { background: var(--success-light); color: var(--easy); }
.badge--medium { background: var(--warning-light); color: var(--medium); }
.badge--hard { background: var(--error-light); color: var(--hard); }
.badge--new { background: var(--bg-secondary); color: var(--status-new); }
.badge--learning { background: var(--warning-light); color: var(--status-learning); }
.badge--mature { background: var(--success-light); color: var(--status-mature); }
.badge--due { background: var(--error-light); color: var(--status-due); }

.badge--coding { background: var(--accent-light); color: var(--accent); }
.badge--system-design { background: var(--warning-light); color: var(--warning); }
.badge--concept { background: var(--success-light); color: var(--success); }
.badge--pattern-signal { background: var(--error-light); color: var(--error); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 40px;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--accent);
    color: #ffffff;
}

.btn--primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

.btn--ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn--success {
    background: var(--success);
    color: #ffffff;
}

.btn--danger {
    background: var(--error);
    color: #ffffff;
}

.btn--warning {
    background: var(--warning);
    color: #ffffff;
}

.btn--accent {
    background: var(--accent);
    color: #ffffff;
}

.btn--large {
    padding: var(--space-md) var(--space-xl);
    font-size: var(--text-base);
    min-height: 48px;
}

.btn--block {
    width: 100%;
}

/* ===== Progress Bar ===== */
.progress {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width var(--transition-normal);
    background: var(--accent);
}

.progress-fill--success { background: var(--success); }
.progress-fill--warning { background: var(--warning); }
.progress-fill--danger { background: var(--error); }

/* ===== Checkbox Options (for multiple-choice waves) ===== */
.option-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.option {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 48px;
    user-select: none;
}

.option:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.option.selected {
    border-color: var(--accent);
    background: var(--accent-light);
}

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

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

.option.missed {
    border-color: var(--success);
    background: transparent;
    border-style: dashed;
}

.option.disabled {
    cursor: default;
    pointer-events: none;
}

.option input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.option-label {
    flex: 1;
    font-size: var(--text-base);
}

.option-icon {
    font-size: var(--text-lg);
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

/* ===== Grade Buttons ===== */
.grade-buttons {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.grade-buttons .btn {
    flex: 1;
}

.grade-label {
    display: block;
    font-size: var(--text-xs);
    opacity: 0.8;
    margin-top: 2px;
}

/* ===== Review View ===== */
.review-container {
    max-width: 640px;
    margin: 0 auto;
}

.review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.review-progress-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.review-timer {
    font-size: var(--text-sm);
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.problem-title {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.problem-title h2 {
    font-size: var(--text-xl);
    font-weight: 700;
}

.problem-link {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.problem-link:hover {
    color: var(--accent);
}

.problem-description {
    color: var(--text-secondary);
    font-size: var(--text-base);
    line-height: 1.7;
    margin-bottom: var(--space-lg);
    white-space: pre-line;
}

.wave-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin: var(--space-lg) 0;
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.wave-divider::before,
.wave-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.wave-question {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--space-md);
}

.wave-not-due {
    font-size: var(--text-xs);
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    margin-left: var(--space-sm);
}

.explanation {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    line-height: 1.6;
    border-left: 3px solid var(--accent);
}

.reveal-content {
    margin-top: var(--space-md);
    padding: var(--space-lg);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    line-height: 1.7;
}

.expected-points {
    list-style: none;
    margin-top: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.expected-points li {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    border-left: 3px solid var(--accent);
}

/* ===== Session Summary ===== */
.session-summary {
    text-align: center;
    padding: var(--space-2xl) 0;
}

.session-summary h2 {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-lg);
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

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

.summary-stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
}

.summary-stat-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ===== Dashboard ===== */
.dashboard-hero {
    text-align: center;
    padding: var(--space-xl) 0;
}

.due-count {
    font-size: var(--text-3xl);
    font-weight: 800;
    color: var(--accent);
}

.due-label {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.streak {
    font-size: var(--text-base);
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.streak-count {
    font-weight: 700;
    color: var(--warning);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-md);
    margin-top: var(--space-lg);
}

.category-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
}

.category-name {
    flex: 0 0 180px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-bar {
    flex: 1;
}

.category-pct {
    flex: 0 0 40px;
    text-align: right;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
}

.weak-area {
    padding: var(--space-sm) var(--space-md);
    background: var(--error-light);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    color: var(--error);
    margin-bottom: var(--space-sm);
}

/* ===== Browse ===== */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.filter-select {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--border-focus);
}

.problem-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.problem-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.problem-item:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.problem-item-title {
    flex: 1;
    font-weight: 500;
}

.problem-item-meta {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.problem-item-next {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.problem-detail {
    padding: var(--space-md);
    padding-top: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    margin-top: -1px;
}

.wave-detail {
    display: flex;
    justify-content: space-between;
    padding: var(--space-xs) 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.wave-detail-label {
    font-weight: 500;
}

.wave-detail-meta {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
}

.category-header {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: var(--space-md) 0 var(--space-sm);
    margin-top: var(--space-md);
}

.category-header:first-child {
    margin-top: 0;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    animation: toast-in 0.3s ease;
}

.toast--success { border-left: 3px solid var(--success); }
.toast--error { border-left: 3px solid var(--error); }

@keyframes toast-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-sm);
    color: var(--text-secondary);
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.gap-sm { gap: var(--space-sm); }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .nav {
        padding: var(--space-sm);
    }

    .nav-brand {
        font-size: var(--text-base);
    }

    .main {
        padding: var(--space-md) var(--space-sm);
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .category-name {
        flex: 0 0 120px;
    }

    .grade-buttons {
        flex-wrap: wrap;
    }

    .grade-buttons .btn {
        min-width: calc(50% - var(--space-xs));
    }

    .filters {
        flex-direction: column;
    }

    .filter-select {
        width: 100%;
    }

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