:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #e3e8ef;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --primary-soft: #eaf1ff;
  --success: #16a36a;
  --success-soft: #e9f9f1;
  --danger: #e5484d;
  --danger-soft: #fff0f0;
  --warning: #f59e0b;
  --shadow: 0 10px 30px rgba(30, 50, 90, .08);
  --radius: 16px;
  --sidebar: 254px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #151f34;
  --surface-2: #111a2d;
  --text: #edf2ff;
  --muted: #9aa7bd;
  --border: #29364d;
  --primary: #5b8cff;
  --primary-2: #7aa2ff;
  --primary-soft: #1c2d53;
  --success-soft: #13382d;
  --danger-soft: #422126;
  --shadow: 0 12px 38px rgba(0,0,0,.26);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 30;
  display: flex; flex-direction: column; padding: 22px 14px 18px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 12px 22px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px;
  color: white; background: linear-gradient(145deg, #4192ff, #2563eb); font-size: 24px;
  box-shadow: 0 8px 20px rgba(37,99,235,.26);
}
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
.nav-list { display: grid; gap: 5px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 0 13px;
  border: 0; border-radius: 11px; color: var(--muted); background: transparent; text-align: left;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--primary); background: var(--primary-soft); font-weight: 650; }
.nav-icon { width: 22px; text-align: center; }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }
.source-link { text-align: center; color: var(--muted); font-size: 12px; text-decoration: none; }
.source-link:hover { color: var(--primary); }

.main { min-height: 100vh; margin-left: var(--sidebar); }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 66px; padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--surface) 93%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 18px; font-weight: 750; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content { max-width: 1180px; margin: 0 auto; padding: 28px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 22px; }
.section-title { margin: 0 0 16px; font-size: 18px; }
.section-subtitle { margin: -9px 0 18px; color: var(--muted); font-size: 13px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { display: flex; gap: 14px; align-items: center; padding: 18px; }
.stat-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 13px; background: var(--primary-soft); color: var(--primary); font-size: 21px; }
.stat-value { font-size: 24px; font-weight: 800; line-height: 1.15; }
.stat-label { color: var(--muted); font-size: 13px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.field { display: grid; gap: 7px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
select, input[type="text"], input[type="search"], input[type="number"], textarea {
  width: 100%; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb,var(--primary) 18%, transparent); }
textarea { min-height: 110px; resize: vertical; }
.radio-row { display: flex; gap: 14px; flex-wrap: wrap; }
.radio-chip { display: flex; align-items: center; gap: 6px; color: var(--text); }
.primary-btn, .secondary-btn, .ghost-btn, .danger-btn, .icon-btn {
  border: 1px solid transparent; border-radius: 10px; transition: .18s ease;
}
.primary-btn { padding: 11px 18px; color: white; background: var(--primary); font-weight: 700; }
.primary-btn:hover { background: var(--primary-2); transform: translateY(-1px); }
.secondary-btn { padding: 10px 16px; color: var(--primary); background: var(--primary-soft); font-weight: 650; }
.ghost-btn { padding: 9px 12px; color: var(--text); background: transparent; border-color: var(--border); }
.ghost-btn:hover { background: var(--surface-2); }
.danger-btn { padding: 10px 16px; color: white; background: var(--danger); }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; background: transparent; color: var(--text); font-size: 18px; }
.icon-btn:hover { background: var(--surface-2); }
.full { width: 100%; }
.actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions-row.end { justify-content: flex-end; }
.start-btn { width: 100%; margin-top: 16px; }

.quick-list { display: grid; gap: 10px; }
.quick-item {
  display: flex; justify-content: space-between; align-items: center; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.quick-item:last-child { border-bottom: 0; }
.quick-item strong { font-size: 14px; }
.quick-item span { font-size: 12px; color: var(--muted); }
.progress { height: 7px; overflow: hidden; background: var(--border); border-radius: 999px; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

.practice-layout { display: grid; grid-template-columns: minmax(0,1fr) 250px; gap: 18px; }
.quiz-card { padding: 24px; }
.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.badge { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 12px; font-weight: 700; }
.quiz-counter { color: var(--muted); font-size: 13px; }
.question-text { font-size: 19px; font-weight: 690; line-height: 1.75; margin: 0 0 18px; white-space: pre-wrap; }
.options { display: grid; gap: 10px; }
.option {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; padding: 13px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer;
}
.option:hover { border-color: color-mix(in srgb,var(--primary) 55%, var(--border)); }
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.correct { border-color: var(--success); background: var(--success-soft); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.option-key { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); font-weight: 750; }
.answer-panel { margin-top: 18px; padding: 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.answer-panel.good { border-color: color-mix(in srgb,var(--success) 50%, var(--border)); background: var(--success-soft); }
.answer-panel.bad { border-color: color-mix(in srgb,var(--danger) 50%, var(--border)); background: var(--danger-soft); }
.answer-title { font-weight: 800; margin-bottom: 7px; }
.answer-line { color: var(--muted); }
.answer-line b { color: var(--success); }
.quiz-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }
.quiz-actions > div { display: flex; gap: 8px; }
.side-card { padding: 18px; height: fit-content; position: sticky; top: 88px; }
.question-map { display: grid; grid-template-columns: repeat(5,1fr); gap: 7px; }
.q-dot { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.q-dot.current { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.q-dot.correct { color: white; background: var(--success); border-color: var(--success); }
.q-dot.wrong { color: white; background: var(--danger); border-color: var(--danger); }
.side-legend { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; color: var(--muted); font-size: 11px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.toolbar-left, .toolbar-right { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.list { display: grid; gap: 10px; }
.list-item { padding: 16px 18px; }
.list-item-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.list-item-title { font-weight: 670; line-height: 1.65; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 9px; }
.pill { padding: 2px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.empty { text-align: center; padding: 54px 18px; color: var(--muted); }
.empty-icon { font-size: 44px; margin-bottom: 8px; }

.chart-row { display: grid; grid-template-columns: 72px 1fr 56px; gap: 12px; align-items: center; margin: 12px 0; }
.chart-row .progress { height: 10px; }
.data-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.data-tile { padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.data-tile h3 { margin: 0 0 7px; font-size: 15px; }
.data-tile p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.modal { width: min(720px, calc(100vw - 28px)); max-height: 88vh; padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(8,15,30,.55); backdrop-filter: blur(3px); }
.modal-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; overflow: auto; }
.page-image { display: block; max-width: 100%; margin: auto; border-radius: 10px; border: 1px solid var(--border); }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 28px; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; padding: 10px 15px; color: white; background: #172033; border-radius: 10px; box-shadow: var(--shadow); transition: .22s; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.overlay { position: fixed; inset: 0; z-index: 25; background: rgba(10,18,35,.48); }
.mobile-only, .bottom-nav { display: none; }

@media (max-width: 980px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .dashboard-grid, .practice-layout { grid-template-columns: 1fr; }
  .side-card { position: static; }
  .question-map { grid-template-columns: repeat(10,1fr); }
}

@media (max-width: 760px) {
  :root { --radius: 14px; }
  .sidebar { transform: translateX(-105%); transition: transform .22s ease; width: min(82vw, 300px); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding-bottom: 70px; }
  .mobile-only { display: grid; }
  .topbar { height: 58px; padding: 0 12px; }
  .topbar-title { font-size: 16px; }
  .topbar-actions .ghost-btn { display: none; }
  .content { padding: 14px 12px 22px; }
  .stats-grid { gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-icon { width: 38px; height: 38px; }
  .stat-value { font-size: 20px; }
  .form-grid, .data-grid { grid-template-columns: 1fr; }
  .quiz-card { padding: 17px; }
  .question-text { font-size: 17px; }
  .quiz-actions { position: sticky; bottom: 68px; z-index: 8; padding: 10px 0 0; background: linear-gradient(transparent, var(--surface) 22%); }
  .quiz-actions .ghost-btn { padding-inline: 10px; }
  .question-map { grid-template-columns: repeat(8,1fr); }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar input, .toolbar select { flex: 1; min-width: 0; }
  .bottom-nav {
    position: fixed; z-index: 24; inset: auto 0 0; height: 62px; padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(4,1fr); background: color-mix(in srgb,var(--surface) 95%, transparent);
    border-top: 1px solid var(--border); backdrop-filter: blur(14px);
  }
  .bottom-nav .nav-item { display: grid; place-items: center; gap: 0; padding: 5px; min-height: 56px; border-radius: 0; font-size: 11px; }
  .bottom-nav .nav-icon { font-size: 18px; }
  .list-item-head { flex-direction: column; }
}

@media (max-width: 440px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { gap: 9px; }
  .stat-label { font-size: 11px; }
  .question-map { grid-template-columns: repeat(6,1fr); }
  .quiz-actions > div:first-child .ghost-btn:nth-child(2) { display: none; }
}
