:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #616e7c;
  --line: #e1e6ed;
  --accent: #3b63d8;
  --accent-soft: #edf2ff;
  --warn: #c77c1c;
  --danger: #d0453b;
  --ok: #1f8a5b;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 12px; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h2 small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 6px; }
h3 { font-size: 15px; color: var(--muted); margin-top: 20px; }
p { margin: 0 0 12px; }
code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #2f54c0; }
.btn.primary:disabled { background: #9aaee6; cursor: default; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.large { padding: 12px 40px; font-size: 17px; }

/* ---------- start / done ---------- */
#screen-start, #screen-done { padding: 48px 16px; }
.intro { max-width: 560px; margin: 0 auto; }
.lead { font-size: 17px; }
.facts { list-style: none; padding: 0; margin: 16px 0; border-top: 1px solid var(--line); }
.facts li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.facts li span:last-child { color: var(--muted); }
.note { color: var(--muted); font-size: 14px; }
.start-form { display: grid; gap: 14px; margin-top: 20px; }
.start-form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.done { text-align: center; }
.check {
  width: 64px; height: 64px; margin: 0 auto 16px;
  border-radius: 50%; background: #e6f4ed; color: var(--ok);
  font-size: 34px; line-height: 64px;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 600; margin-right: auto; }
.rules-toggle { display: none; padding: 6px 12px; font-size: 14px; }
.timer {
  font: 600 20px "SF Mono", Menlo, Consolas, monospace;
  padding: 4px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent);
}
.timer.warn { background: #fdf3e4; color: var(--warn); }
.timer.danger { background: #fdecea; color: var(--danger); }

/* ---------- layout ---------- */
.layout {
  max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px;
  display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; align-items: start;
}
.rules {
  position: sticky; top: 76px;
  max-height: calc(100vh - 96px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; font-size: 14px;
}
.classes { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.classes dt { font-weight: 600; white-space: nowrap; }
.classes dd { margin: 0; color: #3e4c59; }
.rule-list { padding-left: 20px; margin: 0; }
.rule-list li { margin-bottom: 8px; }

/* ---------- questions ---------- */
.question { border: 0; padding: 16px 0; margin: 0; border-top: 1px solid var(--line); }
.question:first-child { border-top: 0; padding-top: 4px; }
.question legend { padding: 0; margin-bottom: 10px; font-weight: 500; }
.qno {
  display: inline-block; min-width: 24px; height: 24px; margin-right: 8px;
  border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  text-align: center; font-size: 14px; line-height: 24px; font-weight: 600;
}
.options { display: grid; gap: 8px; }
.option {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.option:hover { border-color: #b8c4d6; }
.option input { width: auto; margin: 5px 0 0; accent-color: var(--accent); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt-key { font-weight: 600; color: var(--muted); }

.scenario { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; margin-bottom: 12px; }
.scenario h3 { margin-top: 0; }
.scenario ul { margin: 0; padding-left: 18px; }
.hint { font-size: 14px; color: var(--muted); }

.rows { display: grid; gap: 10px; }
.row { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.row.flagged { border-color: #e8b98a; background: #fffaf3; }
.row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.row-no { font-weight: 600; min-width: 52px; }
.row-val { flex: 1; min-width: 200px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; width: auto; }
.seg span { display: block; padding: 5px 14px; font-size: 14px; }
.seg label + label span { border-left: 1px solid var(--line); }
.seg input:checked + span { background: var(--accent); color: #fff; }
.seg input[value="err"]:checked + span { background: var(--warn); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.row-fix { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 10px; margin-top: 12px; }
.row-fix label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.row-fix input:disabled { background: #f1f3f5; color: #9aa5b1; }

blockquote { margin: 0 0 12px; padding: 12px 16px; border-left: 3px solid var(--accent); background: #f8fafc; border-radius: 0 8px 8px 0; }
textarea { resize: vertical; }
.counter { text-align: right; font-size: 13px; color: var(--muted); margin-top: 4px; }

.submit-bar { text-align: center; padding: 8px 0 20px; }
.error { color: var(--danger); }

/* ---------- narrow screens ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .rules-toggle { display: inline-block; }
  .rules { display: none; position: static; max-height: none; }
  body.rules-open .rules { display: block; }
  .card { padding: 18px; }
  .row-fix { grid-template-columns: 1fr 1fr; }
  .row-fix label:last-child { grid-column: 1 / -1; }
}

/* ---------- admin ---------- */
.muted { color: var(--muted); }
.btn.small { padding: 5px 12px; font-size: 14px; }
.btn.danger-text { color: var(--danger); }
.admin .topbar-inner { flex-wrap: wrap; }
.admin #summary { margin-right: 8px; font-size: 14px; }
.admin-main { max-width: 980px; margin: 0 auto; padding: 20px 16px 60px; }
.empty { text-align: center; color: var(--muted); }
.sub-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-bottom: 14px; }
.sub-who strong { font-size: 18px; margin-right: 10px; }
.sub-meta { font-size: 14px; }
.tag { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: 10px; background: #eef1f5; font-size: 12px; color: var(--muted); }
.tag.account { margin: 0 10px 0 0; background: var(--accent-soft); color: var(--accent); font-family: "SF Mono", Menlo, Consolas, monospace; }
.tag.warn { background: #fdf3e4; color: var(--warn); }
.scores { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 24px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.scores span { color: var(--muted); font-size: 13px; margin-right: 6px; }
.scores b { font-size: 20px; }
.scores .total b { color: var(--accent); }
.hint-cell { margin-left: auto; font-size: 14px; color: var(--muted); }
.comm { margin: 14px 0; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.comm p { margin: 0; padding: 10px 12px; background: #f8fafc; border-radius: 8px; white-space: pre-wrap; }
.grade { display: grid; grid-template-columns: 120px 140px 1fr auto; gap: 10px; align-items: end; }
.grade label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.grade .actions { display: flex; align-items: center; gap: 8px; }
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1.6fr; gap: 16px; margin: 12px 0; }
pre { margin: 0; padding: 10px 12px; background: #f8fafc; border-radius: 8px; font-family: inherit; font-size: 13px; line-height: 1.7; white-space: pre-wrap; }
@media (max-width: 760px) {
  .grade { grid-template-columns: 1fr 1fr; }
  .grade .wide, .grade .actions { grid-column: 1 / -1; }
  .detail-grid { grid-template-columns: 1fr; }
  .hint-cell { margin-left: 0; width: 100%; }
}
