/* ============================================
   马原题库练习系统 - 样式表
   支持：亮色/暗色手动切换 + 系统自动、响应式布局
   ============================================ */

/* === CSS 变量（亮色主题 — 默认） === */
:root,
body.light {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e9ecef;
    --bg-hover: #dee2e6;
    --bg-correct: #d4edda;
    --bg-wrong: #f8d7da;
    --bg-selected: #cce5ff;
    --bg-card: #ffffff;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --text-inverse: #ffffff;
    --border-color: #dee2e6;
    --border-light: #e9ecef;
    --accent: #1a5276;
    --accent-light: #2980b9;
    --accent-bg: #d4e6f1;
    --success: #27ae60;
    --success-bg: #d5f5e3;
    --danger: #e74c3c;
    --danger-bg: #fadbd8;
    --warning: #f39c12;
    --warning-bg: #fdebd0;
    --progress-bg: #e9ecef;
    --progress-fill: #27ae60;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --font-sans: "KaiTi", "STKaiti", "AR PL UKai CN", "Noto Serif SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-ui: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
    --transition: 0.2s ease;
    --theme-transition: 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* === 暗色主题（系统偏好） === */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a2e;
        --bg-secondary: #16213e;
        --bg-tertiary: #0f3460;
        --bg-hover: #1a3a6b;
        --bg-correct: #1b3a1b;
        --bg-wrong: #3a1b1b;
        --bg-selected: #1a3a5c;
        --bg-card: #1e2a3a;
        --text-primary: #e4e6eb;
        --text-secondary: #b0b3b8;
        --text-muted: #8a8d91;
        --text-inverse: #ffffff;
        --border-color: #3a3a5c;
        --border-light: #2a2a4a;
        --accent: #5dade2;
        --accent-light: #85c1e9;
        --accent-bg: #1a3048;
        --success: #2ecc71;
        --success-bg: #1a3020;
        --danger: #e74c3c;
        --danger-bg: #301a1a;
        --warning: #f1c40f;
        --warning-bg: #302a15;
        --progress-bg: #2a2a4a;
        --progress-fill: #2ecc71;
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    }
}

/* === 暗色主题（JS 手动切换 — 优先级高于 @media） === */
body.dark {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-hover: #1a3a6b;
    --bg-correct: #1b3a1b;
    --bg-wrong: #3a1b1b;
    --bg-selected: #1a3a5c;
    --bg-card: #1e2a3a;
    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --text-muted: #8a8d91;
    --text-inverse: #ffffff;
    --border-color: #3a3a5c;
    --border-light: #2a2a4a;
    --accent: #5dade2;
    --accent-light: #85c1e9;
    --accent-bg: #1a3048;
    --success: #2ecc71;
    --success-bg: #1a3020;
    --danger: #e74c3c;
    --danger-bg: #301a1a;
    --warning: #f1c40f;
    --warning-bg: #302a15;
    --progress-bg: #2a2a4a;
    --progress-fill: #2ecc71;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* === 全局重置 === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

body.theme-switching,
body.theme-switching * {
    transition:
        background-color var(--theme-transition),
        color var(--theme-transition),
        border-color var(--theme-transition),
        box-shadow var(--theme-transition),
        fill var(--theme-transition) !important;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 320ms;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* === 排版 === */
h1,
h2,
h3,
h4 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1 {
    font-size: 1.75rem;
}

h2 {
    font-size: 1.4rem;
}

h3 {
    font-size: 1.15rem;
}

h4 {
    font-size: 1rem;
}

a {
    color: var(--accent-light);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    text-decoration: underline;
}

/* === 布局容器 === */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
}

/* === 顶部导航栏 === */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition);
}

.navbar-inner {
    max-width: 1140px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    gap: 14px;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
    letter-spacing: -0.02em;
}

.navbar-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex-shrink: 0;
}

/* 导航按钮（章节/错题/设置） */
.navbar-links {
    display: flex;
    gap: 2px;
    align-items: center;
}

.navbar-links .nav-btn {
    padding: 7px 16px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font-ui);
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.navbar-links .nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.navbar-links .nav-btn.active {
    background: var(--accent);
    color: var(--text-inverse);
}

/* 右侧工具区 */
.navbar-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* 主题切换 — 紧凑 pill */
.theme-toggle-group {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    overflow: hidden;
    flex-shrink: 0;
    margin-right: 6px;
}

.theme-btn {
    padding: 6px 11px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    font-family: var(--font-ui);
    transition: all 0.2s ease;
    white-space: nowrap;
    border-right: 1px solid var(--border-color);
}

.theme-btn:last-child {
    border-right: none;
}

.theme-btn:hover {
    background: var(--bg-hover);
}

.theme-btn.active {
    background: var(--accent);
    color: var(--text-inverse);
}

/* 外部图标链接 */
.nav-icon-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-ui);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-icon-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-icon-link svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

.nav-custom-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    object-fit: cover;
}

/* 汉堡菜单（移动端） */
.hamburger-btn {
    display: none;
    padding: 6px 10px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.3rem;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.hamburger-btn:hover {
    background: var(--bg-hover);
}

/* 移动端导航弹出层 */
.nav-mobile-dropdown {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 200;
    padding: 16px;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

.nav-mobile-dropdown.open {
    display: flex;
}

.nav-mobile-dropdown .nav-btn,
.nav-mobile-dropdown .nav-icon-link {
    width: 100%;
    justify-content: flex-start;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
}

.nav-mobile-dropdown .nav-btn.active {
    border-color: var(--accent);
}

/* === 进度条 === */
.progress-bar-container {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    position: sticky;
    top: 56px;
    z-index: 99;
}

.progress-bar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-label {
    font-size: 0.8rem;
    font-family: var(--font-ui);
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 60px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--progress-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 4px;
    transition: width 0.4s ease;
    min-width: 0;
}

.progress-text {
    font-size: 0.8rem;
    font-family: var(--font-ui);
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 80px;
    text-align: right;
}

/* === 主内容区 === */
.main-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 24px 72px;
}

/* === 章节列表 === */
.chapter-list-header {
    text-align: center;
    margin-bottom: 32px;
}

.hero-logo {
    width: 100px;
    height: 100px;
    margin-bottom: 16px;
    border-radius: 20px;
    box-shadow: var(--shadow-md);
}

.chapter-list-header h1 {
    margin-bottom: 8px;
}

.chapter-list-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.chapter-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.chapter-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-light);
}

.chapter-card-info {
    flex: 1;
    min-width: 0;
}

.chapter-card-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.chapter-card-meta {
    font-size: 0.8rem;
    font-family: var(--font-ui);
    color: var(--text-muted);
}

.chapter-card-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.chapter-mini-bar {
    width: 80px;
    height: 6px;
    background: var(--progress-bg);
    border-radius: 3px;
    overflow: hidden;
}

.chapter-mini-fill {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 3px;
    transition: width 0.4s ease;
}

.chapter-card-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* === 题目区域 === */
.question-section {
    margin-bottom: 40px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--accent);
}

.section-header h2 {
    font-size: 1.2rem;
    color: var(--accent);
}

.section-badge {
    background: var(--accent-bg);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-family: var(--font-ui);
    font-weight: 600;
}

.question-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    margin-bottom: 12px;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.question-card.correct {
    border-left: 4px solid var(--success);
    background: var(--bg-correct);
}

.question-card.wrong {
    border-left: 4px solid var(--danger);
    background: var(--bg-wrong);
}

.question-number {
    font-weight: 700;
    font-family: var(--font-ui);
    color: var(--accent);
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.question-content {
    font-size: 1rem;
    line-height: 1.8;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* === 选项 === */
.options-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
}

.option-item:hover {
    background: var(--bg-hover);
}

.option-item.selected {
    background: var(--bg-selected);
    border-color: var(--accent-light);
}

.option-item.correct-answer {
    background: var(--success-bg);
    border-color: var(--success);
}

.option-item.wrong-answer {
    background: var(--danger-bg);
    border-color: var(--danger);
}

.option-label {
    font-weight: 700;
    color: var(--accent);
    min-width: 24px;
    flex-shrink: 0;
}

.option-text {
    flex: 1;
}

/* === 判断题按钮 === */
.judge-buttons {
    display: flex;
    gap: 12px;
}

.judge-btn {
    flex: 1;
    padding: 12px 24px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
    font-family: var(--font-ui);
    font-weight: 600;
    transition: all var(--transition);
    text-align: center;
}

.judge-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-light);
}

.judge-btn.selected {
    background: var(--bg-selected);
    border-color: var(--accent-light);
    color: var(--accent);
}

.judge-btn.correct-answer {
    background: var(--success-bg);
    border-color: var(--success);
    color: var(--success);
}

.judge-btn.wrong-answer {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}

/* === 解析区域 === */
.explanation-toggle {
    margin-top: 12px;
    padding: 7px 18px;
    border: 1px solid var(--accent-light);
    border-radius: 20px;
    background: var(--bg-secondary);
    color: var(--accent-light);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-ui);
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.explanation-toggle:hover {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
    text-decoration: none;
}

.explanation-content {
    margin-top: 10px;
    padding: 14px 18px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    border-left: 3px solid var(--warning);
    display: none;
}

.explanation-content.visible {
    display: block;
}

/* === 结果标记 === */
.result-icon {
    display: inline-block;
    margin-left: 8px;
    font-size: 1rem;
}

.result-icon.correct {
    color: var(--success);
}

.result-icon.wrong {
    color: var(--danger);
}

/* === 按钮 === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-ui);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: var(--accent-light);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--danger);
    color: var(--text-inverse);
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

/* === 错题本 === */
.wrong-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.wrong-filter {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font-ui);
    transition: all var(--transition);
}

.filter-btn:hover,
.filter-btn.active {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state h3 {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

/* === 设置 === */
.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 20px;
}

.settings-section h3 {
    margin-bottom: 12px;
}

.settings-section p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.settings-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* === 回到顶部 === */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-inverse);
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: var(--shadow-md);
    transition: all var(--transition);
    display: none;
    z-index: 50;
}

.back-to-top.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-to-top:hover {
    background: var(--accent-light);
    transform: translateY(-2px);
}

/* === 页面切换动画 === */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== 响应式 ==================== */

/* 平板（≤768px） */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    .navbar {
        padding: 0 14px;
    }

    .navbar-inner {
        height: 48px;
        gap: 8px;
    }

    .navbar-brand {
        font-size: 1rem;
        gap: 8px;
    }

    .navbar-logo {
        width: 30px;
        height: 30px;
    }

    .hamburger-btn {
        display: block;
    }

    /* 隐藏桌面导航和外部链接文字，纯汉堡驱动 */
    .navbar-links.desktop-nav {
        display: none;
    }

    .navbar-tools {
        display: none;
    }

    .progress-bar-container {
        top: 48px;
        padding: 10px 12px;
    }

    .progress-label,
    .progress-text {
        font-size: 0.68rem;
        min-width: auto;
    }

    .progress-bar-inner {
        gap: 8px;
    }

    .main-content {
        padding: 16px 12px 60px;
    }

    .chapter-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .chapter-card {
        padding: 14px 16px;
        flex-wrap: wrap;
    }

    .chapter-card-progress {
        width: 100%;
    }

    .chapter-mini-bar {
        width: 100%;
        flex: 1;
    }

    .question-card {
        padding: 14px 14px;
    }

    .judge-buttons {
        flex-direction: column;
    }

    .wrong-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .settings-actions {
        flex-direction: column;
    }

    .settings-actions .btn {
        width: 100%;
    }

    .section-header {
        flex-wrap: wrap;
    }

    .nav-mobile-dropdown {
        top: 48px;
    }

    h1 {
        font-size: 1.3rem;
    }

    h2 {
        font-size: 1.1rem;
    }
}

/* 手机（≤480px） */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .navbar {
        padding: 0 10px;
    }

    .navbar-inner {
        height: 44px;
        gap: 4px;
    }

    .navbar-brand {
        font-size: 0.95rem;
        gap: 6px;
    }

    .navbar-logo {
        width: 26px;
        height: 26px;
    }

    .hero-logo {
        width: 72px;
        height: 72px;
    }

    .progress-bar-container {
        top: 44px;
    }

    .nav-mobile-dropdown {
        top: 44px;
    }

    .back-to-top {
        bottom: 16px;
        right: 16px;
        width: 38px;
        height: 38px;
    }
}

/* === 无障碍：减少动效 === */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .chapter-card:hover {
        transform: none;
    }

    .back-to-top:hover {
        transform: none;
    }
}
