/* Quiz Night Pack - an editorial, paper-first stylesheet. The pages on screen are the pages that print: the screen
 * rules dress them as sheets on a desk, the print rules strip everything else away. System font stacks only (the
 * CSP allows no font CDN): a book serif for display and the sheets, a humanist sans for the controls. */

:root {
  --paper: #f3ede1;
  --paper-2: #ebe3d3;
  --sheet: #fffdf8;
  --ink: #221f1a;
  --ink-2: #4a443b;
  --muted: #776e61;
  --rule: #d8cdb8;
  --rule-strong: #b9ab92;
  --accent: #a8391c;
  --accent-ink: #ffffff;
  --green: #1f5e48;
  --hl: #f6e3a1;
  --warn: #8a5a00;
  --bad: #a8391c;
  --shadow: 0 1px 2px rgba(60, 45, 20, .10), 0 12px 32px rgba(60, 45, 20, .14);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: "Gill Sans", "Gill Sans MT", Seravek, "Optima", Candara, "Segoe UI", "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #1c1a16;
  --paper-2: #24211c;
  --sheet: #2b2822;
  --ink: #efe8da;
  --ink-2: #d6cdbc;
  --muted: #a99f8e;
  --rule: #463f34;
  --rule-strong: #5d5446;
  --accent: #e0714f;
  --accent-ink: #1c1a16;
  --green: #7cc9a6;
  --hl: #5a4a1c;
  --warn: #e4b45a;
  --bad: #f08a6a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.5; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .8rem; }
.warn { color: var(--warn); }

/* --- Strip and masthead ------------------------------------------------------------------------------------------- */
.strip, .topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 28px; font-size: .85rem; border-bottom: 1px solid var(--rule); }
.backlink { text-decoration: none; color: var(--ink-2); }
.topactions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.credits { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.topup { color: var(--accent); text-decoration: none; font-weight: 600; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; }
button.link:hover { text-decoration: underline; }

.masthead { max-width: 1240px; margin: 0 auto; padding: 36px 28px 26px; text-align: center; border-bottom: 3px double var(--ink); }
.dateline { margin: 0; text-transform: uppercase; letter-spacing: .22em; font-size: .72rem; color: var(--muted); }
.masthead h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(2.6rem, 7vw, 5rem); line-height: 1; margin: 10px 0 12px; letter-spacing: -.01em; }
.dek { font-family: var(--serif); font-style: italic; font-size: 1.2rem; color: var(--ink-2); margin: 0 auto 20px; max-width: 40em; }
.samples { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.samples-lbl { font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.sample { background: var(--sheet); border: 1px solid var(--rule-strong); border-radius: 2px; padding: 8px 14px; cursor: pointer; text-align: left; box-shadow: 0 1px 0 var(--rule); }
.sample small { display: block; color: var(--muted); font-size: .75rem; }
.sample:hover { border-color: var(--ink); }

/* --- Layout: the slip beside the proofs ----------------------------------------------------------------------------- */
.layout { max-width: 1240px; margin: 0 auto; padding: 28px; display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 36px; align-items: start; }
.slip { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--sheet); border: 1px solid var(--rule-strong);
  box-shadow: var(--shadow); padding: 0 20px 20px; border-top: 6px solid var(--accent); }
.slip::before { content: ""; display: block; height: 0; }
.slip-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 0 10px; margin-bottom: 4px; border-bottom: 1px dashed var(--rule-strong);
  font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }
fieldset { border: 0; border-bottom: 1px dashed var(--rule); margin: 0; padding: 12px 0 14px; min-width: 0; }
legend { float: left; width: 100%; padding: 0; margin-bottom: 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .16em; color: var(--accent); font-weight: 700; }
legend + * { clear: both; }
label { display: block; font-size: .82rem; color: var(--ink-2); margin: 8px 0 3px; }
input[type="text"], input[type="number"], select { width: 100%; background: transparent; border: 0; border-bottom: 1.5px solid var(--rule-strong); border-radius: 0; padding: 5px 2px; }
input[type="text"]:focus, input[type="number"]:focus, select:focus { outline: none; border-bottom-color: var(--accent); background: var(--paper); }
select { padding-right: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
label.check { display: flex; gap: 8px; align-items: center; margin: 10px 0 2px; font-size: .9rem; color: var(--ink); }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; clear: both; }
.chip { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 4px 10px; border: 1px solid var(--rule-strong); border-radius: 999px; font-size: .82rem; cursor: pointer; color: var(--ink); background: var(--sheet); }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.rounds-ed { margin-top: 12px; }
.rounds-ed summary { cursor: pointer; font-size: .88rem; font-weight: 600; }
.redit { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .78rem; table-layout: fixed; }
.redit th { text-align: left; font-weight: 600; color: var(--muted); padding: 2px; }
.redit th:nth-child(1) { width: 26px; } .redit th:nth-child(4) { width: 44px; }
.redit td { padding: 2px; }
.redit select { font-size: .78rem; padding: 3px 0; }
.rid { font-family: var(--serif); font-weight: 600; }
.plansum { font-family: var(--serif); font-size: 1.02rem; margin: 14px 0 6px; padding: 8px 10px; background: var(--hl); color: var(--ink); }
:root[data-theme="dark"] .plansum { color: var(--ink); }
.plannotes { margin: 4px 0; padding-left: 18px; font-size: .82rem; }
.plannotes .bad { color: var(--bad); } .plannotes .warn { color: var(--warn); }

.lanes { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 14px 0 10px; border: 1px solid var(--ink); }
.lane { background: transparent; border: 0; padding: 8px 10px; text-align: left; cursor: pointer; color: var(--ink); }
.lane + .lane { border-left: 1px solid var(--ink); }
.lane strong { display: block; font-size: .9rem; }
.lane span { display: block; font-size: .72rem; color: var(--muted); line-height: 1.3; }
.lane.active { background: var(--ink); color: var(--paper); }
.lane.active span { color: var(--paper-2); }
.meter { font-size: .8rem; color: var(--ink-2); margin: 8px 0; }
.gate { font-size: .85rem; background: var(--paper); border-left: 3px solid var(--accent); padding: 8px 10px; margin: 8px 0; }
.gate a { font-weight: 700; }
.runbtn { width: 100%; padding: 12px; background: var(--accent); color: var(--accent-ink); border: 0; font-family: var(--serif); font-size: 1.15rem; font-weight: 600; letter-spacing: .02em; cursor: pointer; }
.runbtn:disabled { opacity: .45; cursor: not-allowed; }
.progress { margin-top: 12px; border: 1px solid var(--rule-strong); padding: 10px 12px; background: var(--paper); }
.ptitle { margin: 0 0 6px; font-family: var(--serif); font-weight: 600; }
.steps { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.step { color: var(--muted); padding: 1px 0; }
.step.done { color: var(--green); } .step.live { color: var(--ink); font-weight: 600; }
.step-ic { display: inline-block; width: 1.2em; }

/* --- Proofs: toolbar and the pages ------------------------------------------------------------------------------------ */
.proofs { min-width: 0; }
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.tabs { display: flex; flex-wrap: wrap; gap: 0; border-bottom: 1px solid var(--ink); }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: 6px 12px; cursor: pointer; color: var(--ink-2); font-size: .9rem; margin-bottom: -1px; }
.tab.active { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.primary { background: var(--ink); color: var(--paper); border: 0; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.mini { background: var(--sheet); border: 1px solid var(--rule-strong); padding: 5px 10px; font-size: .8rem; cursor: pointer; color: var(--ink); }
.mini:hover, .primary:hover { border-color: var(--ink); }
.mini:disabled { opacity: .5; cursor: not-allowed; }
.stateline { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 14px; font-family: var(--serif); font-size: 1.02rem; margin: 6px 0 12px; }
.stale, .partial, .swapbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 8px 12px; margin: 8px 0; font-size: .88rem; border-left: 3px solid var(--warn); background: var(--paper-2); }
.partial { border-left-color: var(--bad); }
.swapbar { border-left-color: var(--green); position: sticky; top: 8px; z-index: 5; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.recon { margin: 10px 0 16px; border: 1px solid var(--rule-strong); background: var(--sheet); padding: 8px 14px; }
.recon summary { cursor: pointer; font-weight: 600; color: var(--green); }
.recon.has-bad summary { color: var(--bad); }
.recon ul { list-style: none; margin: 8px 0 2px; padding: 0; font-size: .86rem; }
.recon li { padding: 3px 0; border-top: 1px dotted var(--rule); }
.recon .ic { display: inline-block; width: 1.2em; font-weight: 700; }
.recon-ok .ic { color: var(--green); } .recon-warn .ic { color: var(--warn); } .recon-bad { color: var(--bad); }
.raw pre { white-space: pre-wrap; word-break: break-word; background: var(--sheet); padding: 12px; border: 1px solid var(--rule); max-height: 360px; overflow: auto; font-size: .8rem; }

.pages { display: flex; flex-direction: column; align-items: center; gap: 28px; }
.pages[data-sheet="cover"] .page:not(.cover), .pages[data-sheet="host"] .page:not(.host), .pages[data-sheet="handout"] .page:not(.handout),
.pages[data-sheet="answers"] .page:not(.answers), .pages[data-sheet="score"] .page:not(.score) { display: none; }

/* A sheet on the desk: paper proportions, always printed colours, whatever the theme. */
.page { position: relative; width: 100%; max-width: 760px; min-height: calc(min(760px, 100%) * 1.414); background: #fffdf8; color: #1d1a16; box-shadow: var(--shadow);
  padding: 52px 58px 64px; font-family: var(--serif); font-size: 15px; line-height: 1.45; }
:root[data-paper="letter"] .page { min-height: calc(min(760px, 100%) * 1.294); }
.page .kicker { font-family: var(--sans); text-transform: uppercase; letter-spacing: .14em; font-size: .68rem; color: #8a3a20; border-bottom: 1.5px solid #1d1a16; padding-bottom: 5px; }
.page .pageh { font-size: 1.85rem; font-weight: 600; line-height: 1.15; margin: 14px 0 16px; }
.page.cover .pageh { font-size: clamp(2rem, 5vw, 3.1rem); margin: 34px 0 18px; text-align: center; }
.page.cover .kicker { text-align: center; }
.page .intro { font-style: italic; text-align: center; font-size: 1.1rem; max-width: 30em; margin: 0 auto 26px; color: #3c372f; }
.page .fields { display: flex; gap: 18px; margin: 18px 0 24px; }
.page .fields span { flex: 1; border-bottom: 1px solid #1d1a16; padding-top: 22px; font-family: var(--sans); font-size: .72rem; color: #6b645a; text-transform: uppercase; letter-spacing: .08em; }
.page .team { margin-top: 8px; }
.page table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: .85rem; }
.page th, .page td { border: 1px solid #1d1a16; padding: 6px 8px; text-align: left; }
.page th { background: #f1ece2; font-weight: 600; }
.page .order { margin: 6px 0 20px; } .page .order .at, .page .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.page .order .foot td { font-weight: 600; border-top: 2px solid #1d1a16; }
.page .rules { font-family: var(--sans); font-size: .88rem; padding-left: 18px; }
.page .rules li { margin: 4px 0; }
.page ol.qs { list-style: none; margin: 0; padding: 0; }
.page .q { padding: 9px 0 10px; border-bottom: 1px solid #ddd3c1; break-inside: avoid; }
.page .qline { display: flex; gap: 8px; }
.page .n { flex: 0 0 2em; font-weight: 700; }
.page .qt { flex: 1; }
.page .ph .qt { color: #9b9284; font-style: italic; }
.page .opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 16px; margin: 5px 0 0 2.5em; font-family: var(--sans); font-size: .88rem; }
.page .opt b { display: inline-block; width: 1.3em; height: 1.3em; line-height: 1.3em; text-align: center; border: 1px solid #1d1a16; border-radius: 50%; font-size: .72rem; margin-right: 4px; }
.page .opt.key b { background: #1f5e48; color: #fff; border-color: #1f5e48; }
.page .opt .rule { display: inline-block; width: 70%; border-bottom: 1px solid #c9bfab; height: .9em; vertical-align: middle; }
.page .ans { margin: 5px 0 0 2.5em; font-family: var(--sans); font-weight: 700; color: #1f5e48; font-size: .92rem; }
.page .lbl { font-weight: 400; text-transform: uppercase; letter-spacing: .1em; font-size: .66rem; color: #6b645a; margin-right: 4px; }
.page .flag { display: inline-block; margin-left: 8px; padding: 0 6px; font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; background: #f6e3a1; color: #6b4a00; font-weight: 700; }
.page .flag.new { background: #d7ebe2; color: #1f5e48; }
.page .why { margin: 3px 0 0 2.5em; font-size: .86rem; color: #555048; font-style: italic; }
.page .issue { margin: 4px 0 0 2.5em; font-family: var(--sans); font-size: .78rem; color: #a8391c; }
.page .swapped .qt { background: linear-gradient(transparent 60%, #d7ebe2 60%); }
.page .mark { display: flex; gap: 10px; align-items: center; margin: 6px 0 0 2.5em; font-family: var(--sans); font-size: .78rem; }
.page .mark select { width: auto; max-width: 60%; border: 1px solid #c9bfab; padding: 2px 4px; color: #1d1a16; background: #fffdf8; font-size: .78rem; }
.page .mark .meta { color: #8a8175; }
.page .tb { margin-top: 22px; padding: 12px 14px; border: 1.5px dashed #1d1a16; font-family: var(--sans); }
.page .tb .ans, .page .tb .why { margin-left: 0; }
.page .plist h3 { font-size: 1.05rem; margin: 18px 0 6px; }
.page .plist ul { padding-left: 20px; font-family: var(--sans); font-size: .9rem; }
.page .muted { color: #8a8175; }
.page .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 10px; }
.page .acol h3 { font-size: 1.05rem; margin: 6px 0 4px; }
.page .ln { display: flex; gap: 10px; align-items: flex-end; height: 32px; border-bottom: 1px solid #a99f8c; font-family: var(--sans); }
.page .ln b { min-width: 2em; }
.page .ln .choices { margin-left: auto; letter-spacing: .3em; color: #6b645a; font-size: .85rem; white-space: pre; }
.page .ln.tot { border-bottom: 2px solid #1d1a16; }
.page .grid td { height: 34px; }
.page .folio { position: absolute; left: 58px; right: 58px; bottom: 22px; border-top: 1px solid #ddd3c1; padding-top: 5px; font-family: var(--sans); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: #8a8175; }
.pagetools { position: absolute; top: 14px; right: 18px; }
.pagetools .mini { background: #fffdf8; color: #1d1a16; border-color: #c9bfab; font-size: .72rem; }

/* --- History, how, footer, toasts ------------------------------------------------------------------------------------- */
.history, .how { max-width: 1240px; margin: 0 auto; padding: 8px 28px 24px; }
.histhead { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; border-top: 3px double var(--ink); padding-top: 18px; }
.histhead h2, .how h2 { font-family: var(--serif); font-weight: 600; font-size: 1.6rem; margin: 0; }
.histhead select { width: auto; }
.hlist { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.hbtn { width: 100%; text-align: left; background: var(--sheet); border: 1px solid var(--rule-strong); padding: 10px 12px; cursor: pointer; }
.hbtn:hover { border-color: var(--ink); }
.htitle { display: block; font-family: var(--serif); font-weight: 600; }
.hmeta { display: block; font-size: .78rem; color: var(--muted); }
.how { border-top: 1px solid var(--rule); padding-top: 22px; }
.howgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px 28px; }
.howgrid p { margin: 8px 0; font-size: .92rem; color: var(--ink-2); }
.howgrid strong { display: block; font-family: var(--serif); font-size: 1.05rem; color: var(--ink); }
.foot { max-width: 1240px; margin: 0 auto; padding: 18px 28px 40px; border-top: 1px solid var(--rule); font-size: .82rem; color: var(--muted); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--paper); padding: 10px 14px; font-size: .88rem; box-shadow: var(--shadow); transition: opacity .5s; }
.toast.err { border-left: 4px solid var(--accent); }
.toast.ok { border-left: 4px solid #7cc9a6; }
.toast a { color: var(--hl); }
.toast.gone { opacity: 0; }

/* --- Docs pages (api.html, tokens.html) ------------------------------------------------------------------------------- */
.doc { max-width: 900px; margin: 0 auto; padding: 24px 28px 40px; }
.doc h1, .doc h2, .doc h3 { font-family: var(--serif); font-weight: 600; }
.doc pre { background: var(--sheet); border: 1px solid var(--rule); padding: 12px; overflow-x: auto; font-size: .8rem; max-width: 100%; }
.doc code { font-family: var(--mono); font-size: .85em; }
.doc table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.doc td, .doc th { border: 1px solid var(--rule); padding: 6px 8px; text-align: left; font-size: .88rem; vertical-align: top; }
.codegroup { margin: 10px 0 18px; }
.codegroup .tabs { border-bottom: 1px solid var(--rule-strong); }
.statebox { background: var(--sheet); border: 1px solid var(--rule); padding: 10px 14px; margin: 12px 0; }
.tokenrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.tokenbox { font-family: var(--mono); font-size: .82rem; background: var(--sheet); border: 1px solid var(--rule); padding: 8px 10px; word-break: break-all; width: 100%; }

/* --- Narrow screens -------------------------------------------------------------------------------------------------------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 16px; }
  .slip { position: static; max-height: none; }
  .masthead, .history, .how, .foot { padding-left: 16px; padding-right: 16px; }
  .strip { padding: 8px 16px; }
}
@media (max-width: 600px) {
  .page { padding: 30px 20px 50px; font-size: 14px; min-height: 0 !important; }
  .page .folio { left: 20px; right: 20px; }
  .page .opts { grid-template-columns: minmax(0, 1fr); margin-left: 2em; }
  .page .cols { grid-template-columns: minmax(0, 1fr); }
  .page .fields { flex-wrap: wrap; }
  .page .grid { display: block; overflow-x: auto; }
  .page .pageh { font-size: 1.45rem; }
  .pagetools { position: static; margin-bottom: 8px; }
  .three { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .dek { font-size: 1.05rem; }
}

/* --- Print: only the selected sheets, one per page ----------------------------------------------------------------------- */
@page a4sheet { size: A4; margin: 12mm; }
@page lettersheet { size: letter; margin: 0.5in; }
@media print {
  :root, :root[data-theme="dark"] { --paper: #fff; --ink: #1d1a16; color-scheme: light; }
  body { background: #fff; }
  .noprint, .strip, .masthead, .slip, .toolbar, .history, .how, .foot, .toasts { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .pages { display: block; gap: 0; }
  .page { box-shadow: none; max-width: none; width: auto; min-height: 0 !important; padding: 0 0 12mm; break-after: page; page-break-after: always; }
  .page:last-child { break-after: auto; page-break-after: auto; }
  :root[data-paper="a4"] .page { page: a4sheet; }
  :root[data-paper="letter"] .page { page: lettersheet; }
  .page .folio { position: static; margin-top: 10mm; }
  .page .q { break-inside: avoid; }
}
.topbar .brand { display: flex; gap: 8px; align-items: center; }
.topbar .sep { color: var(--muted); }
