:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #1d2733;
  --muted: #5d6875;
  --line: #e2dccf;
  --brand: #173f5f;
  --brand-ink: #ffffff;
  --accent: #b7791f;
  --accent-soft: #f4e6c8;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --no: #b3261e;
  --no-soft: #fbe9e7;
  --mid: #b7791f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 39, 51, .06), 0 4px 16px rgba(29, 39, 51, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171d;
    --surface: #1b222b;
    --ink: #e7eaee;
    --muted: #9aa5b1;
    --line: #2c3540;
    --brand: #7fb2d9;
    --brand-ink: #0e1620;
    --accent: #e0b25c;
    --accent-soft: #3a3020;
    --ok: #5cc48d;
    --ok-soft: #173328;
    --no: #f08a80;
    --no-soft: #3a1f1d;
    --mid: #e0b25c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.75rem; margin: 0 0 .4rem; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; }
button, input { font: inherit; color: inherit; }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.lead { color: var(--muted); margin: 0; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.err { color: var(--no); min-height: 1.2em; margin: .6rem 0 0; }
.loading { padding: 3rem 0; text-align: center; color: var(--muted); }

/* header */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; min-height: 60px; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; font-weight: 600; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: var(--accent-soft); display: grid; place-items: center; font-family: Georgia, serif; font-size: 1.15rem; }
nav { display: flex; gap: .25rem; }
.navlink { background: none; border: 0; padding: .45rem .7rem; border-radius: 8px; cursor: pointer; color: var(--muted); }
.navlink:hover { background: var(--bg); color: var(--ink); }
.navlink.active { color: var(--ink); background: var(--bg); font-weight: 600; }

main { padding: 1.5rem 16px 2rem; }
.intro { margin: .5rem 0 1.25rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow); }

/* buttons */
.btn { background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand); padding: .6rem 1.1rem; border-radius: 10px; cursor: pointer; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.big { padding: .8rem 1.6rem; font-size: 1.05rem; }
.btn.danger { color: var(--no); }
.linkbtn { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* setup */
.resume { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; border-color: var(--accent); background: var(--accent-soft); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: -.2rem 0 .8rem; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: .5rem .9rem; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.chapter { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 0; }
.chapter:first-child { border-top: 0; }
.chapter legend { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: .55rem 0; float: left; }
.chapter legend label { display: flex; gap: .6rem; align-items: center; cursor: pointer; font-weight: 600; }
.chapter .subs { clear: both; padding: 0 0 .6rem 1.7rem; }
.toggle { background: none; border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 30px; cursor: pointer; color: var(--muted); flex: none; }
.toggle span { display: inline-block; transition: transform .15s; }
.toggle.open span { transform: rotate(180deg); }
.sub { display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .6rem; align-items: baseline; padding: .3rem 0; cursor: pointer; }
.sub input { transform: translateY(2px); }
.sub-meta { color: var(--muted); font-size: .85rem; white-space: nowrap; }
@media (max-width: 560px) { .sub-meta { grid-column: 2; } }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 1.05rem; height: 1.05rem; flex: none; }
.acc { font-weight: 600; margin-left: .3rem; padding: 0 .35rem; border-radius: 6px; }
.acc.good { color: var(--ok); background: var(--ok-soft); }
.acc.mid { color: var(--mid); background: var(--accent-soft); }
.acc.low { color: var(--no); background: var(--no-soft); }
.sel-actions { justify-content: space-between; border-top: 1px solid var(--line); padding-top: .7rem; margin-top: .3rem; }

.options .opt { display: grid; grid-template-columns: 150px 1fr; gap: .4rem 1rem; align-items: center; padding: .55rem 0; }
.options .opt[hidden] { display: none; }
.opt-label { font-weight: 600; }
.opt .check { grid-column: 1 / -1; display: flex; gap: .55rem; align-items: center; }
.seg { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: inline-block; padding: .35rem .8rem; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.seg input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.seg.count input[type=number] { position: static; opacity: 1; width: 5.5rem; padding: .35rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
#ptitle { width: 100%; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
@media (max-width: 560px) {
  .options .opt { grid-template-columns: 1fr; }
  h1 { font-size: 1.45rem; }
}

/* quiz */
.quiz-head { margin-bottom: .8rem; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: .45rem; }
.bar span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.tier { font-weight: 600; }
.tier-R { color: var(--ok); }
.tier-S { color: var(--mid); }
.tier-T { color: var(--no); }
.qnum { margin: 0 0 .3rem; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.stem { font-size: 1.1rem; margin: 0 0 .8rem; font-weight: 500; }
.roman { list-style: none; padding: 0; margin: 0 0 1rem; }
.roman li { display: flex; gap: .7rem; padding: .2rem 0; }
.rn { flex: none; width: 2.2rem; font-weight: 600; color: var(--muted); font-family: Georgia, serif; }
.choices { display: grid; gap: .5rem; }
.choice { display: flex; gap: .8rem; align-items: flex-start; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; cursor: pointer; }
.choice:hover:not(:disabled) { border-color: var(--brand); background: var(--bg); }
.choice:disabled { cursor: default; }
.key { flex: none; display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; border: 1px solid var(--line); font-weight: 700; font-size: .85rem; margin-right: .2rem; }
.choice.right, .opts-static .right { border-color: var(--ok); background: var(--ok-soft); }
.choice.right .key, .opts-static .right .key { background: var(--ok); color: #fff; border-color: var(--ok); }
.choice.wrong, .opts-static .wrong { border-color: var(--no); background: var(--no-soft); }
.choice.wrong .key, .opts-static .wrong .key { background: var(--no); color: #fff; border-color: var(--no); }
.feedback { margin-top: 1rem; padding: .8rem 1rem; border-radius: 10px; border-left: 4px solid; }
.feedback p { margin: .2rem 0; }
.feedback.ok { border-color: var(--ok); background: var(--ok-soft); }
.feedback.no { border-color: var(--no); background: var(--no-soft); }
.verdict { font-weight: 700; }
.ref { color: var(--muted); font-size: .875rem; }
.hint { text-align: center; margin-top: 1rem; }
@media (hover: none) { .hint { display: none; } }

/* results */
.result { text-align: center; padding: 2rem 1.2rem; }
.score { font-family: Georgia, serif; font-size: 1.6rem; margin: .5rem 0; color: var(--muted); }
.score span { font-size: 3.2rem; color: var(--ink); font-weight: 700; }
.result .row { margin-top: 1.2rem; }
.review { margin-top: 1.5rem; }
.opts-static { list-style: none; padding: 0; margin: 0 0 .8rem; display: grid; gap: .35rem; }
.opts-static li { display: flex; gap: .6rem; align-items: center; padding: .4rem .6rem; border: 1px solid transparent; border-radius: 8px; }

/* progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.stat { text-align: center; display: flex; flex-direction: column; }
.stat .big { font-size: 1.9rem; font-weight: 700; font-family: Georgia, serif; }
.ptable { width: 100%; border-collapse: collapse; font-size: .95rem; }
.ptable th, .ptable td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ptable .num { text-align: right; white-space: nowrap; }
.ptable .chrow th { background: var(--bg); font-weight: 600; }
.meter { display: inline-block; width: 90px; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: .4rem; }
.meter span { display: block; height: 100%; }
.meter .good { background: var(--ok); }
.meter .mid { background: var(--mid); }
.meter .low { background: var(--no); }
.sessions { list-style: none; margin: 0; padding: 0; }
.sessions li { display: flex; gap: 1rem; flex-wrap: wrap; padding: .45rem 0; border-bottom: 1px solid var(--line); }
@media (max-width: 560px) {
  .stats { gap: .5rem; }
  .meter { width: 50px; }
}

/* print paper (screen preview) */
.print-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.paper { background: #fff; color: #111; border: 1px solid var(--line); border-radius: 4px; padding: 2rem 2.2rem; margin-bottom: 1.5rem; font-family: Georgia, "Times New Roman", serif; }
.paper-head { border-bottom: 2px solid #111; margin-bottom: 1.2rem; padding-bottom: .8rem; }
.paper-head h1 { margin: 0 0 .3rem; font-size: 1.5rem; }
.paper-head p { margin: .15rem 0; }
.fields { display: flex; flex-wrap: wrap; gap: .6rem 1.6rem; margin-top: .8rem; }
.fields i { display: inline-block; width: 11rem; border-bottom: 1px solid #111; height: 1em; }
.fields i.short { width: 2.5rem; }
.pq { list-style: none; padding: 0; margin: 0; }
.pitem { padding: .5rem 0 .7rem; break-inside: avoid; page-break-inside: avoid; }
.pitem .stem { font-size: 1rem; font-weight: 400; margin: 0 0 .35rem; display: flex; gap: .6rem; }
.pn { flex: none; min-width: 1.6rem; font-weight: 700; }
.pitem .roman { margin: 0 0 .35rem 2.2rem; }
.popts { list-style: none; padding: 0; margin: 0 0 0 2.2rem; display: grid; gap: .15rem; }
.popts li { display: flex; gap: .5rem; }
.popts .key, .keygrid .key { border: 0; width: auto; height: auto; font-weight: 700; display: inline; }
.keygrid { list-style: none; padding: 0; margin: 0 0 1.2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: .3rem .8rem; }
.keygrid span { display: inline-block; min-width: 1.8rem; text-align: right; }
.keyexp { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.keyexp li { padding: .3rem 0; border-top: 1px solid #ddd; break-inside: avoid; }
.keyexp .ref { color: #555; font-size: .85rem; }
@media (max-width: 560px) { .paper { padding: 1.2rem 1rem; } }

.site-footer { color: var(--muted); font-size: .85rem; padding-bottom: 2rem; }

@media print {
  @page { margin: 16mm 14mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .print-bar { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { border: 0; padding: 0; margin: 0; border-radius: 0; }
  .paper.answers { break-before: page; page-break-before: always; }
}
