:root {
  --bg: #f4f2ec;
  --card: #fffefb;
  --ink: #1c2321;
  --muted: #5f6b68;
  --line: #ddd8cc;
  --accent: #0f6e64;
  --accent-ink: #fff;
  --accent-soft: #e0efeb;
  --good: #1e7a3c;
  --good-soft: #e3f3e6;
  --bad: #b0362b;
  --bad-soft: #fbe9e6;
  --warn: #8a5a00;
  --warn-soft: #f8edd2;
  --shadow: 0 1px 2px rgb(40 35 20 / .06), 0 6px 20px rgb(40 35 20 / .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --card: #1a201f;
    --ink: #e6ebe9;
    --muted: #9aa7a3;
    --line: #2f3836;
    --accent: #4fc2b0;
    --accent-ink: #06201c;
    --accent-soft: #17332f;
    --good: #72d08c;
    --good-soft: #16301f;
    --bad: #f08a7e;
    --bad-soft: #371c19;
    --warn: #e5b95c;
    --warn-soft: #332a14;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-wrap: break-word;
}
[hidden] { display: none !important; }
h1, h2 { line-height: 1.3; margin: 0; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* 禁止选中复制；输入框除外 */
body.quiz { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.quiz input { -webkit-user-select: text; user-select: text; }

.wrap { width: 100%; max-width: 780px; margin: 0 auto; padding-inline: 16px; }
.loading { text-align: center; color: var(--muted); padding: 40px 16px; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 18px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
  text-decoration: none; text-align: center; line-height: 1.35;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); text-decoration: underline; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); margin-top: 24px; }
.panel p:first-child { margin-top: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 0; }

/* 登录 */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: 100%; max-width: 420px; margin: 0; }
.login h1 { margin-bottom: 12px; }
.login p { color: var(--muted); }
.login label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="password"], input[type="number"], input:not([type]) {
  width: 100%; min-height: 46px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.login input { font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; }
.error { color: var(--bad) !important; margin: 8px 0; min-height: 1.65em; }

/* 顶栏 */
.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.top nav { display: flex; gap: 4px; }
.top nav a, .top nav button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border: 0; border-radius: 8px; background: none; color: var(--muted); text-decoration: none; white-space: nowrap;
}
.top nav [aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.top nav b { font-size: 12px; line-height: 1; padding: 4px 7px; border-radius: 99px; background: var(--bad-soft); color: var(--bad); }

main.wrap { padding-bottom: 48px; }

/* 题库首页 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; justify-content: space-between; }
.stats dt { font-size: 13px; color: var(--muted); line-height: 1.4; }
.stats dd { margin: 4px 0 0; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stats small { font-size: 13px; font-weight: 400; color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: thin; }
.chips > * {
  flex: none; min-height: 40px; display: inline-flex; align-items: center; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink); text-decoration: none;
}
.chips > [aria-selected="true"], .chips > [aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chips > :focus-visible { outline-offset: -3px; }

.intro { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 4px; }
.intro p { margin: 0; color: var(--muted); flex: 1 1 260px; }
section h2 { font-size: 18px; margin: 26px 0 10px; display: flex; align-items: baseline; gap: 10px; }
section h2 small { font-size: 13px; font-weight: 400; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  color: var(--ink); text-decoration: none; line-height: 1.5;
}
.tile span { font-size: 13px; color: var(--muted); }
.tile em { font-size: 13px; font-style: normal; margin-top: 6px; color: var(--muted); }
.tile.part { border-color: var(--accent); }
.tile.part em { color: var(--accent); }
.tile.full { background: var(--good-soft); border-color: var(--good); }
.tile.full em { color: var(--good); }
.tile.miss { background: var(--warn-soft); border-color: var(--warn); }
.tile.miss em { color: var(--warn); }
@media (hover: hover) {
  .tile:hover { border-color: var(--accent); }
}

/* 题目卡片 */
.heading { margin: 18px 0 14px; }
.heading a { display: inline-block; margin-bottom: 8px; }
.heading h1 { font-size: 22px; }
.heading p { margin: 6px 0 0; color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px; margin-top: 14px; box-shadow: var(--shadow); scroll-margin-top: 70px;
}
.card.right { border-color: var(--good); }
.card.wrong { border-color: var(--bad); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.num { font-weight: 700; color: var(--accent); }
.qid { font-family: ui-monospace, Consolas, monospace; }
.tag { display: inline-block; font-size: 12px; line-height: 1.5; padding: 1px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); margin-right: 8px; font-weight: 600; }
.stem { margin: 10px 0 14px; font-size: 17px; white-space: pre-line; }
.note { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }
.options { display: grid; gap: 8px; }
.options button {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left;
  min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: transparent; line-height: 1.55;
}
.options i {
  flex: none; width: 24px; height: 24px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%; font-style: normal; font-size: 13px; font-weight: 600; line-height: 1;
}
.options span { flex: 1; min-width: 0; padding-top: 0; }
.options .skip { border-style: dashed; color: var(--muted); }
.options button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.options button[aria-checked="true"] i { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.options button.is-answer { border: 1px solid var(--good); background: var(--good-soft); color: var(--ink); }
.options button.is-answer i { background: var(--good); border-color: var(--good); color: var(--card); }
.options button.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.options button.is-wrong i { background: var(--bad); border-color: var(--bad); color: var(--card); }
.card.done .skip:not([aria-checked="true"]) { display: none; }
@media (hover: hover) {
  .options button:not(:disabled):hover { border-color: var(--accent); }
}

.reveal { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.reveal p { margin: 6px 0 0; }
.verdict { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 0 !important; }
.right .verdict strong { color: var(--good); }
.wrong .verdict strong { color: var(--bad); }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 14px; color: var(--muted); }

.bar {
  position: sticky; bottom: 0; z-index: 5; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}
.bar .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.bar .count { margin-right: auto; }
main.wrap:has(+ .bar) { padding-bottom: 20px; }
.empty { text-align: center; }

/* 水印和遮挡 */
#watermark { position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: .17; }
#shield { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 24px; }
#shield button { display: flex; flex-direction: column; gap: 8px; max-width: 360px; padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); text-align: center; }
#shield strong { font-size: 18px; }
#shield span { color: var(--muted); }
html.shielded #app { visibility: hidden; }
@media print {
  body.quiz { display: none !important; }
}

/* 管理页 */
.admin .wrap { max-width: 900px; }
.admin h1 { font-size: 22px; }
.admin h2 { font-size: 17px; margin: 24px 0 10px; }
.admin .panel h2 { margin-top: 0; }
.admin .panel .error { min-height: 0; margin: 6px 0 0; }
.admin .panel .error:empty { display: none; }
.admin .panel .row { margin-top: 10px; }
.admin .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; }
.form { display: grid; grid-template-columns: 1fr 110px auto; gap: 10px; align-items: end; }
.form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
.form input { color: var(--ink); font-size: 16px; }
.fresh textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: 14px/1.7 ui-monospace, Consolas, monospace; resize: vertical; }
.keys { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.keys li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.keys .title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.keys dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 6px 14px; margin: 8px 0; }
.keys dt { font-size: 12px; color: var(--muted); }
.keys dd { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.keys .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.keys .actions .btn { min-height: 38px; padding: 4px 14px; font-size: 14px; }
.btn.danger { color: var(--bad); }
.tag.good { background: var(--good-soft); color: var(--good); }
.blocked { margin: 0 0 8px; font-size: 14px; color: var(--warn); }

@media (max-width: 560px) {
  body { font-size: 15px; }
  .card { padding: 14px; }
  .stem { font-size: 16px; }
  .stats dd { font-size: 22px; }
  .stats div { padding: 10px; }
  .top .brand { font-size: 15px; }
  .top nav a, .top nav button { padding: 0 8px; }
  .intro .btn { width: 100%; }
  .chips { scrollbar-width: none; }
  .bar .btn.primary { flex: 1 0 auto; }
  .bar .count { width: 100%; }
  .form { grid-template-columns: 1fr 90px; }
  .form .btn { grid-column: 1 / -1; }
}
