/* ============================================================
   数学竞赛刷题台 — 样式
   纸感浅色 / 墨色深色，衬线标题 + 系统正文
   ============================================================ */
:root {
  --bg: #f4f1e9;
  --bg-2: #ece7db;
  --surface: #fffdf8;
  --surface-2: #f8f5ed;
  --ink: #1d2433;
  --ink-2: #3b4356;
  --muted: #6f7685;
  --line: #e0d9c9;
  --line-strong: #cfc6b2;
  --brand: #3448c5;
  --brand-ink: #ffffff;
  --brand-soft: #e8eafd;
  --gold: #a97b22;
  --gold-soft: #f6ecd2;
  --ok: #1c7a4c;
  --ok-soft: #e4f3ea;
  --bad: #b23b3b;
  --bad-soft: #f9e6e4;
  --shadow: 0 1px 2px rgba(29, 36, 51, .05), 0 8px 24px -18px rgba(29, 36, 51, .35);
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #12141b;
  --bg-2: #171a23;
  --surface: #1b1e28;
  --surface-2: #20242f;
  --ink: #eae6dc;
  --ink-2: #c9c4b8;
  --muted: #8f93a3;
  --line: #2b2f3c;
  --line-strong: #3b4050;
  --brand: #7c8cff;
  --brand-ink: #10121a;
  --brand-soft: #232846;
  --gold: #d8b064;
  --gold-soft: #2e2a1d;
  --ok: #62c294;
  --ok-soft: #1a2c24;
  --bad: #e58181;
  --bad-soft: #31201f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -20px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(52, 72, 197, .10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(169, 123, 34, .10), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: min(1120px, 100% - 48px); margin: 0 auto; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 28px;
  height: 64px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; flex: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--ink); color: var(--bg);
  font-family: var(--serif); font-size: 21px; line-height: 1;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: var(--serif); font-size: 16px; letter-spacing: .04em; }
.brand-text small { color: var(--muted); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; }

.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  position: relative; flex: none;
  padding: 7px 13px; border-radius: 999px;
  color: var(--ink-2); font-size: 14px; text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--ink); color: var(--bg); }
.nav a em {
  font-style: normal; font-size: 11px; margin-left: 4px;
  padding: 1px 6px; border-radius: 999px;
  background: var(--bad-soft); color: var(--bad);
}
.nav a.active em { background: rgba(255,255,255,.2); color: inherit; }

.top-actions { display: flex; gap: 8px; flex: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-size: 15px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--line-strong); background: var(--surface-2); }

/* ---------------- page scaffolding ---------------- */
main { padding: 34px 0 60px; min-height: 62vh; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 24px; flex-wrap: wrap;
}
.page-head h1 {
  margin: 0 0 4px; font-family: var(--serif); font-size: 27px; font-weight: 700;
  letter-spacing: .01em;
}
.page-head p { margin: 0; color: var(--muted); font-size: 14px; max-width: 62ch; }
.page-head .head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------------- buttons & inputs ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn.gold { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 40%, var(--line)); color: var(--gold); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); background: var(--bad-soft); }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--muted); letter-spacing: .02em; }

input[type="text"], input[type="search"], select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
textarea { resize: vertical; min-height: 120px; line-height: 1.65; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

/* ---------------- filter bar ---------------- */
.filters {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px;
  padding: 16px; margin-bottom: 20px;
}
.filters .grow { grid-column: span 1; }
.bank-filters { grid-template-columns: 2fr 1fr 1fr; }
.filter-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -6px 0 18px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-2); border-radius: 999px; padding: 5px 12px;
  font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }

/* ---------------- question card ---------------- */
.qcard { padding: 26px 28px 22px; }
.qcard-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.qindex { font-family: var(--mono); font-size: 12.5px; color: var(--muted); letter-spacing: .06em; }
.tag {
  font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.tag.track { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.tag.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.stem {
  font-size: 16.5px; line-height: 1.95; color: var(--ink);
  margin: 0 0 22px;
}
.stem .math.display, .solution .math.display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.katex { font-size: 1.06em; }
.katex-display { margin: .5em 0; }

.options { display: grid; gap: 10px; margin-bottom: 20px; }
.option {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface);
  cursor: pointer; text-align: left; font: inherit; color: var(--ink);
  transition: border-color .15s, background .15s;
}
.option:hover { background: var(--surface-2); }
.option .letter {
  display: grid; place-items: center; flex: none;
  width: 24px; height: 24px; border-radius: 7px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
}
.option.sel { border-color: var(--brand); background: var(--brand-soft); }
.option.sel .letter { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.option.right { border-color: var(--ok); background: var(--ok-soft); }
.option.right .letter { background: var(--ok); color: #fff; border-color: var(--ok); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }

.answer-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.answer-row input { flex: 1; min-width: 220px; }
.answer-row .btn { flex: none; }
.hint { color: var(--muted); font-size: 12.5px; }

.feedback {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: 12px; margin: 18px 0;
  border: 1px solid transparent; font-size: 14px;
}
.feedback .fb-icon { font-size: 16px; line-height: 1.4; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.feedback.info { background: var(--brand-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 22%, transparent); }
.feedback strong { display: block; margin-bottom: 2px; }
.feedback .math { color: var(--ink); }

.solution {
  border-top: 1px dashed var(--line-strong);
  margin-top: 20px; padding-top: 18px;
  font-size: 15px; line-height: 1.95; color: var(--ink-2);
}
.solution h3 { margin: 0 0 8px; font-family: var(--serif); font-size: 15px; color: var(--ink); letter-spacing: .04em; }
.qcard-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.qcard-foot .left, .qcard-foot .right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------- progress ---------------- */
.progress { height: 4px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .25s ease; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin: 10px 0 8px; }

/* ---------------- exam ---------------- */
.exam-layout { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 20px; align-items: start; }
.exam-main { min-width: 0; }
.exam-side { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 14px; }
.exam-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; margin-bottom: 18px; flex-wrap: wrap;
}
.timer { display: flex; align-items: baseline; gap: 8px; }
.timer b { font-family: var(--mono); font-size: 22px; letter-spacing: .04em; }
.timer.low b { color: var(--bad); }
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.palette button {
  aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2); font-family: var(--mono); font-size: 13px;
  cursor: pointer;
}
.palette button:hover { border-color: var(--brand); }
.palette button.answered { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 40%, transparent); color: var(--brand); }
.palette button.current { outline: 2px solid var(--brand); outline-offset: 1px; }
.palette button.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.palette button.incorrect { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.side-card { padding: 16px; }
.side-card h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; padding: 3px 0; }
.kv span:first-child { color: var(--muted); }
.kv b { font-family: var(--mono); font-weight: 500; }

.paper-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.paper-card { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.paper-card h2 { margin: 0; font-family: var(--serif); font-size: 19px; }
.paper-card .paper-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.paper-card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.paper-card .paper-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------------- lists / tables ---------------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .qtitle { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 2.1; }
.row .qtitle .katex { font-size: 1em; }
.row .qtitle .math.display { display: inline; }
.row .qsub { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; flex-wrap: wrap; }
.row .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { padding: 18px 20px; }
.stat .num { font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.stat .num small { font-size: 14px; color: var(--muted); font-family: var(--sans); }
.stat .label { color: var(--muted); font-size: 12.5px; letter-spacing: .04em; margin-top: 4px; }

.bars { padding: 20px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 14px; align-items: center; padding: 7px 0; font-size: 13.5px; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.bar-row .val { text-align: right; font-family: var(--mono); font-size: 12.5px; color: var(--muted); }

/* ---------------- import ---------------- */
.import-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 20px; align-items: start; }
.import-grid .card { padding: 22px; }
.code {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px; overflow: auto; max-height: 420px;
  white-space: pre; color: var(--ink-2);
}
.import-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.hr { height: 1px; background: var(--line); margin: 22px 0; border: 0; }

/* ---------------- misc ---------------- */
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  z-index: 80; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.footer {
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 18px 0 30px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12.5px;
}

.center { text-align: center; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------------- 组卷 / 计划 ---------------- */
.build-filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.checkline {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0; font-size: 14px; color: var(--ink-2); cursor: pointer;
}
.checkline input { width: auto; accent-color: var(--brand); }

.cal-head { display: grid; grid-template-columns: repeat(7, 42px); gap: 6px; margin-bottom: 6px; }
.cal-head span { text-align: center; font-size: 11px; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 42px); gap: 6px; }
.cal-cell { position: relative; width: 42px; height: 34px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--line); }
.cal-cell::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--brand); opacity: 0; }
.cal-cell.lvl-1::after { opacity: .16; }
.cal-cell.lvl-2::after { opacity: .38; }
.cal-cell.lvl-3::after { opacity: .66; }
.cal-cell.future { opacity: .32; }
.cal-cell.today { box-shadow: 0 0 0 2px var(--ink); }

/* ---------------- 打印（错题 PDF） ---------------- */
#print-root { display: none; }

@media print {
  @page { size: A4; margin: 16mm 14mm; }
  html, body { background: #fff !important; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; color: #111; }
  .print-page { font-family: var(--serif); color: #111; }
  .print-page h1 { font-size: 22pt; margin: 0 0 6pt; }
  .print-meta { font-size: 9.5pt; color: #555; border-bottom: 1px solid #ccc; padding-bottom: 8pt; margin-bottom: 14pt; }
  .print-q { break-inside: avoid; page-break-inside: avoid; margin: 0 0 14pt; }
  .print-q-head { font-size: 9.5pt; color: #444; margin-bottom: 4pt; }
  .print-stem { font-size: 11pt; margin-bottom: 6pt; }
  .print-ans { font-size: 10pt; margin-bottom: 4pt; }
  .print-sol { font-size: 10pt; color: #333; }
  .print-q .katex { font-size: 1em; }
  .print-q .math.display { margin: 4pt 0; }
}

/* ---------------- responsive ---------------- */
@media (max-width: 960px) {
  .exam-layout { grid-template-columns: 1fr; }
  .exam-side { position: static; }
  .import-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .wrap { width: calc(100% - 32px); }
  .topbar-inner { height: auto; padding: 10px 0 8px; flex-wrap: wrap; gap: 8px; }
  .brand { order: 1; }
  .top-actions { order: 2; margin-left: auto; }
  .nav { order: 3; flex: 0 0 100%; width: 100%; flex-wrap: wrap; overflow: visible; padding-bottom: 2px; gap: 2px 4px; }
  .nav a { padding: 6px 9px; font-size: 13px; }
  .brand-text small { display: none; }
  main { padding-top: 22px; }
  .qcard { padding: 20px 18px; }
  .stem { font-size: 15.5px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .field:last-child { grid-column: 1 / -1; }
  .bank-filters { grid-template-columns: 1fr 1fr; }
  .bank-filters .field:first-child { grid-column: 1 / -1; }
  .build-filters { grid-template-columns: 1fr 1fr; }
  .cal-head, .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal-cell { width: auto; height: 32px; }
  .bar-row { grid-template-columns: 84px 1fr 58px; }
  .palette { grid-template-columns: repeat(8, 1fr); }
  .page-head h1 { font-size: 22px; }
}
