/* ===== 全局重置与变量 ===== */
:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #4338ca;
    --primary-bg: #eef2ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
    --radius: 14px;
    --radius-sm: 10px;
    --header-h: 52px;
    --nav-h: 58px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 学科主题色 */
.theme-network { --theme: #3b82f6; --theme-bg: #eff6ff; }
.theme-org { --theme: #f59e0b; --theme-bg: #fffbeb; }
.theme-os { --theme: #10b981; --theme-bg: #ecfdf5; }
.theme-ds { --theme: #8b5cf6; --theme-bg: #f5f3ff; }
.theme-politics { --theme: #ef4444; --theme-bg: #fef2f2; }
.theme-math { --theme: #06b6d4; --theme-bg: #ecfeff; }
.theme-prob { --theme: #ec4899; --theme-bg: #fdf2f8; }
.theme-linalg { --theme: #14b8a6; --theme-bg: #f0fdfa; }

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* ===== 顶部导航 ===== */
.app-header {
    height: calc(var(--header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    display: flex;
    align-items: center;
    padding-left: 8px;
    padding-right: 8px;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-title {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: .5px;
}

.header-left, .header-right {
    min-width: 40px;
    display: flex;
    align-items: center;
}

.header-right { justify-content: flex-end; }

.icon-btn {
    background: none;
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background .2s;
}
.icon-btn:active { background: rgba(255,255,255,.2); }

/* ===== 主内容区 ===== */
.app-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 10px);
}

.page { padding: 14px 14px 20px; animation: fadeIn .25s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== 底部导航 ===== */
.bottom-nav {
    height: calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-light);
    text-decoration: none;
    font-size: 11px;
    transition: color .2s;
    cursor: pointer;
}

.nav-item.active { color: var(--primary); }
.nav-item svg { transition: transform .2s; }
.nav-item.active svg { transform: scale(1.1); }

/* ===== 通用组件 ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
}

.section-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.section-title::before {
    content: '';
    width: 4px;
    height: 18px;
    background: var(--primary);
    border-radius: 2px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .2s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-ghost { background: var(--bg-page); color: var(--text-secondary); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-success { background: #d1fae5; color: var(--success); }
.badge-warning { background: #fef3c7; color: var(--warning); }
.badge-danger { background: #fee2e2; color: var(--danger); }

/* ===== 首页 ===== */
.hero-banner {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: var(--radius);
    padding: 22px 18px;
    color: #fff;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
}
.hero-banner::after {
    content: '';
    position: absolute;
    top: -30px; right: -30px;
    width: 120px; height: 120px;
    background: rgba(255,255,255,.1);
    border-radius: 50%;
}
.hero-banner::before {
    content: '';
    position: absolute;
    bottom: -40px; right: 30px;
    width: 80px; height: 80px;
    background: rgba(255,255,255,.08);
    border-radius: 50%;
}
.hero-banner h2 { font-size: 20px; margin-bottom: 6px; position: relative; z-index: 1; }
.hero-banner p { font-size: 13px; opacity: .9; position: relative; z-index: 1; }
.hero-stats { display: flex; gap: 16px; margin-top: 14px; position: relative; z-index: 1; }
.hero-stat { flex: 1; }
.hero-stat .num { font-size: 22px; font-weight: 800; }
.hero-stat .label { font-size: 11px; opacity: .85; }

.progress-ring-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
}
.progress-ring { width: 64px; height: 64px; position: relative; flex-shrink: 0; }
.progress-ring svg { transform: rotate(-90deg); }
.progress-ring .pct {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.quick-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 6px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform .15s;
}
.quick-item:active { transform: scale(.95); }
.quick-item .qi-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 6px;
    font-size: 20px;
}
.quick-item span { font-size: 11px; color: var(--text-secondary); }

.today-task {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.today-task:last-child { border-bottom: none; }
.today-task-info { flex: 1; }
.today-task-info .tt-title { font-size: 14px; font-weight: 600; }
.today-task-info .tt-sub { font-size: 12px; color: var(--text-light); }
.task-check {
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.task-check.done {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

/* ===== 课程页 ===== */
.subject-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.subject-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px 14px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform .15s;
    border-left: 4px solid var(--theme);
    position: relative;
    overflow: hidden;
}
.subject-card:active { transform: scale(.97); }
.subject-card .sc-icon {
    font-size: 28px;
    margin-bottom: 8px;
}
.subject-card .sc-name { font-size: 14px; font-weight: 700; }
.subject-card .sc-count { font-size: 11px; color: var(--text-light); margin-top: 4px; }
.subject-card .sc-progress {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}
.subject-card .sc-progress-bar {
    height: 100%;
    background: var(--theme);
    border-radius: 2px;
    transition: width .4s;
}

.chapter-list { margin-bottom: 12px; }
.chapter-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}
.chapter-item:active { background: var(--bg-page); }
.chapter-num {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--theme-bg);
    color: var(--theme);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.chapter-info { flex: 1; min-width: 0; }
.chapter-info .ci-title { font-size: 14px; font-weight: 600; }
.chapter-info .ci-meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }

/* 知识点详情 */
.kp-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}
.kp-item .kp-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}
.kp-item .kp-tag {
    background: var(--theme-bg);
    color: var(--theme);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}
.kp-item .kp-title { font-size: 15px; font-weight: 700; flex: 1; }
.kp-content {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.75;
    white-space: pre-wrap;
}
.kp-content code {
    background: var(--bg-page);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--danger);
}
/* 知识点操作按钮组：三按钮等宽等高 */
.kp-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.kp-actions .kp-act-btn {
    flex: 1;
    box-sizing: border-box;
    height: 34px;
    padding: 0 8px;
    font-size: 13px;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kp-video {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--theme-bg);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--theme);
}
.kp-video svg { flex-shrink: 0; }

/* ===== 题库页 ===== */
.quiz-filter {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.quiz-filter::-webkit-scrollbar { display: none; }
.filter-chip {
    padding: 6px 14px;
    border-radius: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    transition: all .2s;
    flex-shrink: 0;
}
.filter-chip.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.quiz-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform .15s;
}
.quiz-card:active { transform: scale(.98); }
.quiz-card .qc-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.quiz-card .qc-type {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
}
.qc-type.single { background: #dbeafe; color: #2563eb; }
.qc-type.multi { background: #fef3c7; color: #d97706; }
.qc-type.judge { background: #d1fae5; color: #059669; }
.qc-type.synthesis { background: #f3e8ff; color: #7c3aed; }
.quiz-card .qc-year { font-size: 12px; color: var(--text-light); }
.quiz-card .qc-stem {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 答题界面 */
.quiz-player .qp-progress {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}
.qp-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 18px;
    overflow: hidden;
}
.qp-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width .3s;
}
.qp-question { font-size: 16px; font-weight: 600; line-height: 1.7; margin-bottom: 16px; }
.qp-options { margin-bottom: 20px; }
.qp-option {
    padding: 14px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    transition: all .2s;
}
.qp-option:active { background: var(--bg-page); }
.qp-option.selected { border-color: var(--primary); background: var(--primary-bg); }
.qp-option.correct { border-color: var(--success); background: #d1fae5; }
.qp-option.wrong { border-color: var(--danger); background: #fee2e2; }
.qp-option .opt-label {
    width: 24px; height: 24px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}
.qp-option.selected .opt-label { border-color: var(--primary); background: var(--primary); color: #fff; }
.qp-option.correct .opt-label { border-color: var(--success); background: var(--success); color: #fff; }
.qp-option.wrong .opt-label { border-color: var(--danger); background: var(--danger); color: #fff; }
.qp-option .opt-text { flex: 1; font-size: 14px; line-height: 1.6; }

.qp-explain {
    background: var(--bg-page);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
}
.qp-explain .qe-label { font-weight: 700; color: var(--text-main); display: block; margin-bottom: 4px; }
.qp-explain .qe-answer { color: var(--success); font-weight: 700; margin-bottom: 6px; }
.qp-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ===== 错题本 ===== */
.wrong-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    border-left: 3px solid var(--danger);
}
.wrong-card .wc-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.wrong-card .wc-stem {
    font-size: 14px;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
}
.wrong-card .wc-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wrong-card .wc-meta { font-size: 12px; color: var(--text-light); }
.wrong-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.wrong-empty .we-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== 打卡页 ===== */
.checkin-hero {
    background: linear-gradient(135deg, var(--success), #059669);
    border-radius: var(--radius);
    padding: 20px;
    color: #fff;
    text-align: center;
    margin-bottom: 16px;
}
.checkin-hero .ch-day { font-size: 36px; font-weight: 800; }
.checkin-hero .ch-label { font-size: 13px; opacity: .9; margin-top: 4px; }
.checkin-hero .ch-btn {
    margin-top: 14px;
    padding: 10px 32px;
    background: rgba(255,255,255,.25);
    backdrop-filter: blur(4px);
    border: 1.5px solid rgba(255,255,255,.4);
    color: #fff;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.checkin-hero .ch-btn:active { transform: scale(.97); }
.checkin-hero .ch-btn.checked {
    background: rgba(255,255,255,.15);
}

.calendar {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}
.cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.cal-nav-btn {
    background: var(--bg-page);
    border: none;
    width: 32px; height: 32px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
}
.cal-title { font-size: 15px; font-weight: 700; }
.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    margin-bottom: 6px;
}
.cal-weekdays span { font-size: 12px; color: var(--text-light); }
.cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.cal-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    position: relative;
}
.cal-day.other { color: var(--text-light); opacity: .4; }
.cal-day.checked {
    background: var(--success);
    color: #fff;
    font-weight: 700;
}
.cal-day.today {
    border: 2px solid var(--primary);
    font-weight: 700;
}
.cal-day .dot {
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--success);
    margin-top: 2px;
}

.streak-stat {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}
.streak-item {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.streak-item .si-num { font-size: 24px; font-weight: 800; color: var(--primary); }
.streak-item .si-label { font-size: 11px; color: var(--text-light); margin-top: 2px; }

/* ===== 模态框 ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    display: none;
    align-items: flex-end;
    justify-content: center;
}
.modal-overlay.show { display: flex; animation: fadeIn .2s; }
.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 500px;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    animation: slideUp .3s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-header .icon-btn { color: var(--text-secondary); }
.modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 18px 30px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    background: rgba(0,0,0,.8);
    color: #fff;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s;
}
.toast.show { opacity: 1; }

/* ===== 空状态 ===== */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-light);
}
.empty-state .es-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== 编辑表单 ===== */
.edit-form .form-group { margin-bottom: 14px; }
.edit-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.edit-form input, .edit-form textarea, .edit-form select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-page);
    transition: border .2s;
}
.edit-form input:focus, .edit-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}
.edit-form textarea { min-height: 100px; resize: vertical; }

/* 响应式 - 大屏居中 */
@media (min-width: 600px) {
    #app { max-width: 480px; margin: 0 auto; box-shadow: var(--shadow-lg); }
    .modal-overlay { align-items: center; }
    .modal-content { border-radius: 20px; max-height: 80vh; }
}
