:root {
  --bg: #faf6f4;
  --surface: #ffffff;
  --surface-2: #f4ece9;
  --text: #2d2326;
  --muted: #7b6c70;
  --line: #eadfdb;
  --accent: #c2547a;
  --accent-strong: #a63f63;
  --accent-soft: #f8e3ea;
  --ok: #2f8a5b;
  --ok-soft: #e1f3e8;
  --bad: #c7443a;
  --bad-soft: #fbe5e2;
  --warn: #a8700f;
  --warn-soft: #fbf0d9;
  --shadow: 0 1px 2px rgba(60, 30, 40, .06), 0 6px 20px rgba(60, 30, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1618;
    --surface: #251e21;
    --surface-2: #2e2629;
    --text: #f1e9eb;
    --muted: #b3a2a7;
    --line: #3a3034;
    --accent: #e57fa3;
    --accent-strong: #f19bb9;
    --accent-soft: #43222f;
    --ok: #5cc68e;
    --ok-soft: #1e3a2b;
    --bad: #f0786d;
    --bad-soft: #45231f;
    --warn: #e7b24f;
    --warn-soft: #3d3016;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* 有設 display 的元素也要能用 hidden 藏起來 */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .9em; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 2px 0; text-align: left; min-width: 0; }
.brand-logo { flex: none; width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-by { font-size: 12px; color: var(--muted); }
.topnav { flex: none; }
.topnav button { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; color: var(--muted); }
.topnav button:hover { border-color: var(--accent); color: var(--accent); }

main { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.loading { color: var(--muted); text-align: center; padding: 60px 0; }

.hero { display: flex; align-items: center; gap: 16px; padding: 12px 4px 20px; }
.hero-logo { flex: none; width: 76px; height: 76px; border-radius: 18px; box-shadow: var(--shadow); }
.hero h1 { font-size: clamp(22px, 5vw, 28px); margin: 0 0 4px; letter-spacing: .02em; }
.counters { margin: 8px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counters b { color: var(--accent); font-weight: 700; }
.sub { color: var(--muted); margin: 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel.quiet { box-shadow: none; background: transparent; }
.panel h2 { font-size: 17px; margin: 0 0 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.panel-head h2 { margin-bottom: 12px; }
.head-actions { display: flex; gap: 12px; }

.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 14px; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--muted); }

.group + .group { margin-top: 16px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.group-head h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0; letter-spacing: .04em; }
.sections { display: grid; gap: 8px; }
.sec {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.sec:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.sec input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.sec-title { font-weight: 600; }
.sec-code { color: var(--muted); font-size: 13px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.sec-bar { height: 4px; border-radius: 4px; background: var(--line); margin-top: 6px; overflow: hidden; }
.sec-bar > span { display: block; height: 100%; background: var(--accent); }
.sec-stat { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.mode { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.mode:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.mode input { margin-top: 5px; accent-color: var(--accent); }
.mode b { display: block; }
.mode small { color: var(--muted); font-size: 13px; line-height: 1.4; display: block; }
.options-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 14px; }
.field { display: flex; gap: 8px; align-items: center; }
.field select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.check { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.check input { accent-color: var(--accent); width: 17px; height: 17px; }
.start-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.start-row.center { justify-content: center; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

.primary, .ghost {
  border-radius: 10px; padding: 10px 22px; font-weight: 600; border: 1px solid transparent;
  transition: background .15s, border-color .15s, transform .05s;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-strong); }
.primary:disabled, .ghost:disabled { opacity: .45; cursor: not-allowed; }
.ghost:disabled:hover { border-color: var(--line); }
.ghost { background: var(--surface); border-color: var(--line); }
.ghost:hover { border-color: var(--accent); }
.primary:active, .ghost:active { transform: translateY(1px); }
.small { padding: 6px 12px; font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* quiz */
.quiz-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress { flex: 1; height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.counter { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.q-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.tag { font-size: 13px; color: var(--accent); background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; }
.star { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 13px; color: var(--muted); }
.star[aria-pressed="true"] { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.q-text { font-size: clamp(17px, 4.2vw, 20px); font-weight: 600; line-height: 1.6; margin: 0 0 14px; }
.q-figure { display: block; max-height: 220px; max-width: 100%; margin: 0 auto 14px; border-radius: 8px; background: #fff; padding: 6px; }

.opts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.opt {
  width: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: left;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
  line-height: 1.55; transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt .num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 14px; font-weight: 700; }
.opt img { max-height: 110px; max-width: 160px; border-radius: 6px; display: block; background: #fff; padding: 4px; }
.opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.opt.selected .num { background: var(--accent); color: #fff; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.correct .num { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .num { background: var(--bad); color: #fff; }
.opts.img-opts { grid-template-columns: repeat(2, 1fr); }
.opts.img-opts .opt { align-items: center; }

.feedback { margin-top: 14px; padding: 10px 14px; border-radius: 10px; font-weight: 600; display: flex; align-items: center; gap: 12px; }
.fb-face { flex: none; width: 64px; height: 64px; border-radius: 50%; animation: face-pop .28s ease-out; }
@keyframes face-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.empty-note { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 14px; }
.empty-note img { flex: none; border-radius: 50%; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.q-note { margin-top: 10px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 14px; border-left: 3px solid var(--accent); }

.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.nav-btns { display: flex; gap: 8px; margin-left: auto; }

.exam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; margin-top: 16px; }
.exam-grid button { padding: 6px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-variant-numeric: tabular-nums; }
.exam-grid button.done { background: var(--accent-soft); border-color: var(--accent); }
.exam-grid button.current { outline: 2px solid var(--accent); outline-offset: 1px; }

/* result */
.result { flex-direction: column; justify-content: center; text-align: center; gap: 4px; }
.res-face { width: 112px; height: 112px; border-radius: 50%; box-shadow: var(--shadow); animation: face-pop .35s ease-out; }
@media (prefers-reduced-motion: reduce) { .fb-face, .res-face { animation: none; } }
.score { font-size: 56px; font-weight: 800; margin: 4px 0; font-variant-numeric: tabular-nums; }
.score.pass { color: var(--ok); }
.score.fail { color: var(--bad); }
.res-sections { display: grid; gap: 8px; }
.res-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 15px; }
.res-row .sec-bar { grid-column: 1 / -1; margin-top: 0; }
.wrong-list { padding-left: 0; list-style: none; margin: 0; display: grid; gap: 10px; }
.wrong-list > li { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.wrong-list > li .tag { display: inline-block; margin-bottom: 6px; }
.wl-q { font-weight: 600; margin-bottom: 4px; }
.wl-a { font-size: 14px; color: var(--muted); }
.wl-a b { color: var(--ok); font-weight: 600; }
.wl-a s { color: var(--bad); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* about */
.prose p, .prose ul { margin: 0 0 10px; }
.prose p:last-child, .prose ul:last-child { margin-bottom: 0; }
.prose ul { padding-left: 22px; }
.prose li + li { margin-top: 4px; }
.prose a { color: var(--accent); }
.source + .source { margin-top: 14px; }
.maker-card { display: flex; align-items: center; gap: 22px; }
.maker-card img { flex: none; width: 168px; height: 168px; border-radius: 50%; box-shadow: var(--shadow); }
.maker-card h2 { margin-bottom: 4px; }
.maker-name { font-weight: 700; color: var(--accent); }
.source h3 { font-size: 15px; margin: 0 0 4px; }

/* footer */
.site-foot { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.7; }
.site-foot p { margin: 0 0 6px; }
.site-foot b { color: var(--text); }
.site-foot .takedown { color: var(--text); font-weight: 600; }
.site-foot a, .prose a { color: var(--accent); }
.site-foot .link { font-size: 13px; margin-left: 4px; }
.site-foot .maker { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.site-foot .maker img { border-radius: 50%; }

@media (max-width: 560px) {
  .modes { grid-template-columns: 1fr; }
  .hero { gap: 12px; }
  .hero-logo { width: 60px; height: 60px; }
  .maker-card { flex-direction: column; text-align: center; }
  .maker-card img { width: 140px; height: 140px; }
  .brand-title { font-size: 15px; }
  .card { padding: 16px; }
  .opts.img-opts { grid-template-columns: 1fr 1fr; }
  .sec { grid-template-columns: auto 1fr; }
  .sec-stat { grid-column: 2; text-align: left; }
}
