:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #5b6779;
  --line: #dde3ec;
  --accent: #0d5bd7;
  --accent-soft: #e3edff;
  --good: #178a4c;
  --good-soft: #e2f5e9;
  --bad: #c62838;
  --bad-soft: #fde7e9;
  --warn: #b26a00;
  --warn-soft: #fff3dd;
  --chip: #eef1f6;
  --code-bg: #10192b;
  --code-fg: #d6e2f5;
  --shadow: 0 1px 3px rgba(16, 30, 60, .08), 0 4px 14px rgba(16, 30, 60, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1522;
    --card: #1a2233;
    --text: #e8edf6;
    --muted: #9aa7bd;
    --line: #2c3750;
    --accent: #5c93f5;
    --accent-soft: #1d3054;
    --good: #4cc482;
    --good-soft: #16342a;
    --bad: #f07a86;
    --bad-soft: #45222a;
    --warn: #e6b566;
    --warn-soft: #3d3421;
    --chip: #242f47;
    --code-bg: #0a1120;
    --code-fg: #c9d7ef;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 17px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { max-width: 680px; margin: 0 auto; padding: 12px 14px 90px; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
img { max-width: 100%; }
.hidden { display: none !important; }

/* ---------- generic ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.title { font-size: 1.5rem; font-weight: 800; margin: 18px 4px 2px; }
.subtitle { color: var(--muted); margin: 0 4px 10px; font-size: .95rem; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 13px 18px;
  border-radius: 12px;
  font-size: 1.02rem;
  font-weight: 700;
  text-align: center;
  background: var(--accent);
  color: #fff;
  margin: 10px 0;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--chip); color: var(--text); }
.btn.ghost { background: none; border: 1.5px solid var(--line); color: var(--muted); min-height: 46px; }
.btn.danger { background: var(--bad); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.chip {
  display: inline-block;
  background: var(--chip);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- home ---------- */
.mode-card { cursor: pointer; transition: transform .06s; }
.mode-card:active { transform: scale(.985); }
.mode-card .emoji { font-size: 1.9rem; }
.mode-card h2 { margin: 6px 0 4px; font-size: 1.2rem; }
.mode-card p { margin: 0; color: var(--muted); font-size: .95rem; }
.stat-line { display: flex; justify-content: space-between; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: .93rem; }
.stat-line:last-child { border-bottom: none; }
.stat-line .score { font-weight: 700; }

/* ---------- setup ---------- */
.opt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  margin: 8px 0;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  text-align: left;
  font-size: .98rem;
}
.opt-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.opt-row .box {
  flex: 0 0 24px;
  height: 24px;
  border: 2px solid var(--muted);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  color: #fff;
}
.opt-row.selected .box { background: var(--accent); border-color: var(--accent); }
.opt-row .grow { flex: 1; }
.opt-row .meta { color: var(--muted); font-size: .82rem; }
.seg { display: flex; gap: 8px; margin: 8px 0 14px; }
.seg button {
  flex: 1;
  min-height: 48px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-weight: 600;
  font-size: .92rem;
}
.seg button.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; min-height: 50px; }
.switch { position: relative; width: 52px; height: 30px; border-radius: 999px; background: var(--chip); transition: background .15s; flex: 0 0 auto; }
.switch.on { background: var(--accent); }
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: left .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch.on::after { left: 25px; }

/* ---------- quiz header ---------- */
.quiz-top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 2px 8px;
}
.quiz-top .bar-row { display: flex; align-items: center; gap: 10px; }
.progress-label { font-size: .88rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: .95rem; }
.timer.low { color: var(--bad); }
.pbar { flex: 1; height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.pbar > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .2s; }
.quit-btn { color: var(--muted); font-size: 1.3rem; padding: 4px 8px; }

/* ---------- question ---------- */
.stem { font-size: 1.05rem; font-weight: 600; margin: 10px 2px; }
.exhibit-img {
  display: block;
  margin: 10px auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: zoom-in;
  max-height: 340px;
  object-fit: contain;
}
.exhibit-note { color: var(--muted); font-style: italic; font-size: .86rem; margin: 6px 2px; }
pre.codeblock {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 12px;
  padding: 14px;
  overflow-x: auto;
  font-size: .86rem;
  line-height: 1.55;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}
.answer-opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  min-height: 56px;
  padding: 13px 14px;
  margin: 9px 0;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: var(--card);
  text-align: left;
  font-size: .98rem;
  line-height: 1.45;
}
.answer-opt .letter {
  flex: 0 0 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--chip);
  color: var(--muted);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  margin-top: 1px;
}
.answer-opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.answer-opt.picked .letter { background: var(--accent); color: #fff; }
.answer-opt.correct { border-color: var(--good); background: var(--good-soft); }
.answer-opt.correct .letter { background: var(--good); color: #fff; }
.answer-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer-opt.wrong .letter { background: var(--bad); color: #fff; }
.answer-opt:disabled { cursor: default; opacity: 1; }

.feedback { border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-weight: 700; }
.feedback.good { background: var(--good-soft); color: var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback .expl { font-weight: 400; color: var(--text); margin-top: 8px; font-size: .93rem; }

/* ---------- drag & drop (tap to place) ---------- */
.dd-hint { color: var(--muted); font-size: .88rem; margin: 8px 2px; }
.dd-group { border: 1.5px solid var(--line); border-radius: 13px; padding: 12px; margin: 10px 0; background: var(--card); }
.dd-group .glabel { font-weight: 800; font-size: .92rem; margin-bottom: 8px; }
.dd-slot {
  display: block;
  width: 100%;
  min-height: 50px;
  border: 2px dashed var(--line);
  border-radius: 11px;
  margin: 8px 0;
  padding: 11px 12px;
  color: var(--muted);
  font-size: .93rem;
  text-align: left;
  background: var(--bg);
}
.dd-slot.filled { border-style: solid; border-color: var(--accent); color: var(--text); background: var(--accent-soft); font-weight: 600; }
.dd-slot.target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dd-slot.correct { border-color: var(--good); background: var(--good-soft); }
.dd-slot.wrong { border-color: var(--bad); background: var(--bad-soft); }
.dd-slot .fix { display: block; font-size: .82rem; font-weight: 600; color: var(--good); margin-top: 5px; }
.dd-pool { display: flex; flex-wrap: wrap; gap: 9px; margin: 12px 0; }
.dd-item {
  border: 1.5px solid var(--line);
  background: var(--card);
  border-radius: 11px;
  padding: 11px 14px;
  min-height: 48px;
  font-size: .93rem;
  text-align: left;
  box-shadow: var(--shadow);
}
.dd-item.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.dd-item.used { opacity: .35; }
pre.codeblock .blank {
  display: inline-block;
  min-width: 110px;
  border: 1.5px dashed #6b7d9e;
  border-radius: 7px;
  background: rgba(255,255,255,.07);
  color: #9db4d8;
  padding: 2px 10px;
  margin: 1px 0;
  font: inherit;
  font-size: .86rem;
  vertical-align: baseline;
}
pre.codeblock .blank.filled { border-style: solid; border-color: var(--accent); color: #fff; background: rgba(92,147,245,.25); }
pre.codeblock .blank.target { border-color: #fff; box-shadow: 0 0 0 2px rgba(92,147,245,.6); }
pre.codeblock .blank.correct { border-color: #4cc482; background: rgba(76,196,130,.25); color: #d7f5e5; }
pre.codeblock .blank.wrong { border-color: #f07a86; background: rgba(240,122,134,.22); color: #ffd9dd; text-decoration: line-through; }
pre.codeblock .fixinline { color: #4cc482; font-weight: 700; }

/* ---------- bottom action bar ---------- */
.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  z-index: 6;
}
.action-bar .inner { max-width: 680px; margin: 0 auto; display: flex; gap: 10px; }
.action-bar .btn { margin: 0; }
.action-bar .nav { flex: 0 0 88px; }

/* ---------- results ---------- */
.score-hero { text-align: center; padding: 26px 16px; }
.score-hero .big { font-size: 3rem; font-weight: 900; line-height: 1.1; }
.score-hero .big.pass { color: var(--good); }
.score-hero .big.fail { color: var(--bad); }
.score-hero .sub { color: var(--muted); }
.dom-row { margin: 12px 0; }
.dom-row .head { display: flex; justify-content: space-between; font-size: .92rem; margin-bottom: 5px; }
.dom-row .head .pct { font-weight: 800; }
.dom-bar { height: 10px; border-radius: 99px; background: var(--chip); overflow: hidden; }
.dom-bar > div { height: 100%; border-radius: 99px; }
.review-q { border-top: 1px solid var(--line); padding: 12px 2px; }
.review-q .rq-head { display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left; }
.review-q .mark { font-weight: 900; flex: 0 0 20px; }
.review-q .mark.ok { color: var(--good); }
.review-q .mark.ko { color: var(--bad); }
.review-q .rq-stem { flex: 1; font-size: .92rem; }
.review-q .rq-body { margin-top: 10px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, .93);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  overflow: auto;
  padding: 12px;
}
.lightbox img { max-width: 100%; max-height: 95vh; object-fit: contain; border-radius: 8px; background: #fff; }

@media (min-width: 700px) {
  html { font-size: 18px; }
  .exhibit-img { max-height: 420px; }
}
