/* Time series practice: graph paper. Pale blue-grey ground, navy ink and one steel-blue accent for the plotted line.
   The page's one motif is a small seasonal zigzag rising under the heading. */
:root {
  --bg: #f3f5f8; --paper: #ffffff; --ink: #15233b; --muted: #46536a; --line: #cfd7e3; --line2: #8794a8;
  --accent: #1d5fa6; --accent-ink: #ffffff; --accent-soft: #e2ecf7;
  --ok: #1b6a3a; --ok-soft: #e0f1e5; --bad: #a3261b; --bad-soft: #fbe4e1; --warn: #7a5200; --warn-soft: #faefd4;
  --head: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 4px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1520; --paper: #162031; --ink: #e4eaf3; --muted: #a9b6c9; --line: #2b3a52; --line2: #55667f;
    --accent: #8cbcf5; --accent-ink: #0b1a2c; --accent-soft: #1d3150;
    --ok: #7fd49d; --ok-soft: #1a3324; --bad: #ff9b8f; --bad-soft: #3d1f1b; --warn: #efc46a; --warn-soft: #382e15;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 9; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, h4 { font-family: var(--head); line-height: 1.2; letter-spacing: -0.01em; }

/* hero: the rising seasonal zigzag (an inline SVG in index.html) */
.hero { padding: 22px 0 4px; }
.hero h1 { font-size: clamp(1.65rem, 5vw, 2.4rem); margin: 0 0 6px; }
.zig { display: block; width: min(240px, 60%); height: auto; margin: 0 0 6px; }
.zig .zl { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.zig .zt { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; }
.lede { margin: 4px 0 0; max-width: 62ch; color: var(--muted); }

/* setup */
.setup { margin: 12px 0 10px; display: grid; gap: 10px; }
.setup fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.setup legend { font-weight: 700; margin-bottom: 4px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span { display: flex; align-items: center; min-height: 44px; padding: 6px 14px; border: 1px solid var(--line2); background: var(--paper); border-radius: var(--r); white-space: nowrap; }
.chip input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); box-shadow: inset 0 -3px 0 var(--accent); }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.setrow { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.inline { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; }
select, input { font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line2); border-radius: var(--r); }
select { min-height: 44px; padding: 6px 10px; max-width: 100%; }
.btn { font: inherit; min-height: 44px; padding: 8px 16px; border-radius: var(--r); border: 1px solid var(--ink); background: var(--paper); color: var(--ink); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 6px 14px; }
.btn:hover { filter: brightness(0.96); }
.link { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 10px 4px; min-height: 44px; }
.note { margin: 8px 0; padding: 10px 12px; background: var(--warn-soft); border-radius: var(--r); }
#store-note { overflow-wrap: anywhere; }
.note.info { background: var(--paper); border: 1px solid var(--line); }
@media (max-width: 600px) {
  .hero { padding-top: 12px; }
  .lede { display: none; }
  .setup { gap: 6px; margin-top: 8px; }
  .chips { gap: 4px; }
  #levels { display: grid; grid-template-columns: 1fr 1fr; }
  .chip span { padding: 6px 8px; }
  #levels .chip span { white-space: normal; line-height: 1.2; }
  .sheet { padding: 12px 12px 14px; }
}

/* the sheet */
.sheet { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 16px; margin: 10px 0 18px; }
.sheet:focus { outline: none; }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.code { font-family: var(--mono); letter-spacing: 0.08em; color: var(--accent); }
.lvname { font-family: var(--sans); font-size: 1rem; font-weight: 400; color: var(--muted); }
.score { margin: 0; color: var(--muted); }
.rules { margin: 6px 0 2px; }
.rules summary, .work summary, .recent summary, .faq summary, .pdata summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 8px; font-weight: 600; list-style: none; }
.rules summary::-webkit-details-marker, .pdata summary::-webkit-details-marker, .work summary::-webkit-details-marker, .recent summary::-webkit-details-marker, .faq summary::-webkit-details-marker { display: none; }
.rules summary::before, .pdata summary::before, .work summary::before, .recent summary::before, .faq summary::before { content: ""; flex: none; width: 0; height: 0; border-style: solid; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent currentColor; }
.rules[open] > summary::before, .pdata[open] > summary::before, .work[open] > summary::before, .recent[open] > summary::before, .faq[open] > summary::before { transform: rotate(90deg); }
.rules ul { margin: 4px 0 8px; padding-left: 20px; max-width: 80ch; }
.rules li { margin: 0 0 4px; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 14px 0 6px; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; }
.qhead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 16px; margin: 4px 0 6px; }
.qhead .see { font-weight: 600; }
.q h3 { margin: 0; font-size: 1.2rem; display: flex; gap: 10px; align-items: baseline; }
.qn { font-family: var(--mono); color: var(--accent-ink); background: var(--accent); border-radius: 3px; padding: 0 7px; font-size: 1rem; }
.q h3 { font-size: 1.15rem; }
.sec + .sec { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); }
.slab { margin: 0 0 4px; font-size: 1.1rem; }
.scen, .task, .rec { margin: 0 0 10px; max-width: 75ch; }
.task { font-weight: 600; }
.rec { font-family: var(--mono); font-size: 1.05rem; padding: 6px 10px; background: var(--bg); border-radius: var(--r); display: inline-block; overflow-wrap: anywhere; }
sub, sup { font-size: 0.75em; line-height: 0; }

/* tables */
.twrap { overflow-x: auto; max-width: 100%; margin: 0 0 10px; }
table.dt { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.dt caption { text-align: left; font-weight: 700; padding: 0 0 4px; }
.dt th, .dt td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; font-weight: 400; }
.dt thead th { font-weight: 700; color: var(--muted); border-bottom: 2px solid var(--ink); vertical-align: bottom; }
.dt .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.dt thead th.num { font-family: var(--sans); white-space: normal; }
.dt tbody th[scope="row"] { color: var(--muted); font-weight: 600; }
.dt td.in { padding: 3px 6px; }

input.cell { min-height: 44px; padding: 6px 8px; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; max-width: 100%; }
input.cell { width: calc(var(--w, 10) * 1ch + 22px); }
select.cell { max-width: min(100%, 30em); }
.cell.is-right { border-color: var(--ok); background: var(--ok-soft); box-shadow: inset 0 0 0 1px var(--ok); }
.cell.is-wrong, .cell.is-unread { border-color: var(--bad); background: var(--bad-soft); box-shadow: inset 0 0 0 1px var(--bad); }
.cell.is-close { border-color: var(--warn); background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn); }

/* the strip of values: one labelled cell a period */
/* on screen a rule under each row of cells, no box in the card's box; paper draws the grid (print block) */
.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.6em, 1fr)); gap: 0; margin: 0 0 12px; max-width: 760px; }
.strip div { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); }
.strip dt { color: var(--muted); }
.strip dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 600; }

/* the time series plot: wide drawing above 560px, narrow below (both in the page, one shown) */
.plot { margin: 0 0 12px; max-width: 700px; }
.plot .yt { margin: 0 0 2px; color: var(--muted); }
.plot svg { display: block; width: 100%; height: auto; }
.plot .pn { display: none; }
@media (max-width: 767px) { .plot .pw { display: none; } .plot .pn { display: block; max-width: 420px; } }
.plot .gl { stroke: var(--line); stroke-width: 1; }
.plot .cy { stroke: var(--line2); stroke-width: 1; stroke-dasharray: 3 4; }
.plot .ax, .plot .tm { stroke: var(--ink); stroke-width: 1.2; }
.plot .tk { fill: var(--muted); }
.plot .tt { fill: var(--ink); font-weight: 600; }
.plot .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.plot circle { fill: var(--accent); }
.pdata { margin: 4px 0 0; }
.pdata summary { color: var(--accent); }

/* answers under the problem */
.answers { display: grid; gap: 4px; max-width: 720px; }
.arow { display: grid; grid-template-columns: minmax(0, 20em) auto; align-items: center; justify-content: start; gap: 4px 16px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.alab { font-weight: 600; }
.aval { display: inline-flex; align-items: center; gap: 6px; justify-self: start; min-width: 0; max-width: 100%; }
.arow.asel { grid-template-columns: minmax(0, 1fr); }
.arow.asel .aval { justify-self: start; }
@media (max-width: 560px) { .arow { grid-template-columns: minmax(0, 1fr); } .aval { justify-self: start; } }
.u { color: var(--muted); }
.kv { font-family: var(--mono); font-weight: 700; }

/* tables that do not fit (fit.js measures them; screen only): each row becomes a block, each value labelled with its column */
@media screen {
  .twrap.rows { overflow-x: visible; }
  .twrap.rows table, .twrap.rows tbody { display: block; width: 100%; }
  .twrap.rows caption { display: block; }
  .twrap.rows thead { display: none; }
  .twrap.rows tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5em, 1fr)); gap: 4px 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .twrap.rows tbody th[scope="row"] { grid-column: 1 / -1; }
  .twrap.rows th, .twrap.rows td { border: 0; padding: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; min-width: 0; }
  .twrap.rows th { justify-content: flex-start; font-weight: 700; color: var(--ink); }
  .twrap.rows td::before { content: attr(data-l); font: 600 1rem var(--sans); color: var(--muted); }
  .twrap.rows td.in { flex-wrap: wrap; }
  .twrap.rows td.in .cw { margin-left: auto; }
}

/* feedback */
.fbwrap { margin: 6px 0; }
.fbl { margin: 4px 0; padding: 0 0 0 2.2em; max-width: 78ch; }
.fb { margin: 4px 0; padding: 6px 10px; border-radius: var(--r); background: var(--bad-soft); max-width: 78ch; }
.fbl .fb::marker { font-weight: 700; }
.fb.right { background: var(--ok-soft); }
.fb.close { background: var(--warn-soft); }
.fb.empty { background: var(--paper); border: 1px solid var(--line); }
.cw { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.cw > .cell { flex: none; }
.cw > select.cell { flex: 0 1 auto; min-width: 0; }
.dt td.in .cw { display: flex; justify-content: flex-end; }
.mk { flex: none; min-width: 1.9em; font-weight: 700; font-size: 1.1rem; line-height: 1; white-space: nowrap; }
.mn { font-size: 1rem; font-family: var(--mono); }
.mk-right { color: var(--ok); }
.mk-close { color: var(--warn); }
.mk-wrong, .mk-unread { color: var(--bad); }
.qfoot { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.work { margin: 4px 0 8px; }
.keyfig { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.kpart, .ksec, .sec { min-width: 0; }
.kpart + .kpart { border-top: 1px dashed var(--line); padding-top: 8px; }
.steps { margin: 8px 0; padding-left: 20px; font-family: var(--mono); max-width: 80ch; }
.steps li { margin: 3px 0; overflow-wrap: anywhere; }
.steps li.say { font-family: var(--sans); list-style: none; margin-left: -20px; }

.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.confirm { flex-basis: 100%; margin: 0; padding: 10px; background: var(--warn-soft); border-radius: var(--r); }
.save-hint { flex-basis: 100%; margin: 0; color: var(--muted); }

/* print and share */
.share { margin: 0 0 24px; }
.print-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.print-row label { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; flex-wrap: wrap; }
.share-out label { display: grid; gap: 4px; font-weight: 600; }
.share-out input { width: 100%; min-height: 44px; padding: 6px 10px; font-family: var(--mono); }
.recent { margin-top: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 12px; }
.recent ul { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding: 6px 0; }
.recent .when { display: block; color: var(--muted); }
.hint { color: var(--muted); }

/* content */
.content { max-width: 75ch; padding-bottom: 20px; }
.content h2 { font-size: 1.4rem; margin: 26px 0 8px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq details p { margin: 0 0 12px; }
.sources { color: var(--muted); }
footer { border-top: 2px solid var(--ink); padding: 18px 0 30px; color: var(--muted); }
.sb-footer p { margin: 6px 0; }
.sb-more a { color: var(--muted); }
.sb-credit a { color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r); max-width: min(92vw, 560px); z-index: 20; pointer-events: none; transition: transform 0.2s; }
.toast.on { transform: translate(-50%, 0); }
.toast.top { top: 16px; bottom: auto; transform: translate(-50%, -140%); }
.toast.top.on { transform: translate(-50%, 0); }
@media (max-width: 600px) {
  .toast { left: 8px; right: 8px; bottom: 8px; max-width: none; text-align: center; transform: translateY(140%); }
  .toast.top { top: 8px; bottom: auto; transform: translateY(-140%); }
  .toast.on, .toast.top.on { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
[hidden] { display: none !important; }
.print-root { display: none; }

/* ---------- print ---------- */
@page { margin: 12mm; }
@media print {
  :root { --ink: #000; --muted: #333; --line: #888; --line2: #444; --paper: #fff; --bg: #fff; --accent: #000; }
  body { background: #fff; color: #000; font: 10.5pt/1.35 var(--sans); }
  main, footer, .skip, .toast { display: none !important; }
  .print-root { display: block; }
  .psheet, .pkey { break-after: page; }
  .pkey:last-child, .psheet:last-child { break-after: auto; }
  table.pt { width: 100%; border-collapse: collapse; }
  .pt > thead .prun { font-size: 10pt; color: #333; padding-bottom: 4px; border-bottom: 0.5pt solid #888; }
  .ph { display: flex; justify-content: space-between; align-items: baseline; gap: 6pt 12pt; flex-wrap: wrap; margin-bottom: 4pt; }
  .ph h2 { margin: 4px 0 0; font-size: 15pt; border-bottom: 1.5pt solid #000; padding-bottom: 2px; }
  .zig { display: none; }
  .pmeta { display: flex; gap: 14pt; margin: 0; }
  .prules { margin: 4px 0 6px; padding-left: 14pt; font-size: 10pt; }
  .prules li { margin: 0 0 2px; break-inside: avoid; }
  /* exam style: the rules in two columns, so part (a) starts under them on the first page */
  .prules.two { columns: 2; column-gap: 18pt; }
  .prules.two li { break-inside: auto; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li { margin: 0 0 8pt; break-inside: avoid; }
  .pq > li.exam { break-inside: auto; }
  .pq > li.exam .sec { break-inside: avoid; }
  .pq > li.exam .sec + .sec { break-before: page; }
  .pk > li { margin: 0 0 9pt; break-inside: avoid; }
  /* a fixed number of problems to a page (app.js PER_PAGE), so every copy of a class set takes the same pages */
  .pq > li.pnew, .pk > li.pnew { break-before: page; }
  .pq h3, .pk h3 { font-size: 12pt; margin: 6px 0 2px; break-after: avoid; }
  .slab { font-size: 11pt; margin: 4pt 0 1pt; }
  .sec + .sec { margin-top: 6pt; padding-top: 4pt; border-top: 0.5pt dashed #888; break-inside: avoid; }
  .scen, .task, .rec { margin: 0 0 4pt; color: #000; }
  .rec { background: none; padding: 0; font-size: 10.5pt; }
  .twrap { overflow: visible; break-inside: avoid; margin: 0 0 4pt; }
  table.dt { font-size: 10pt; }
  .dt caption { font-size: 10pt; padding-bottom: 2pt; }
  .dt th, .dt td { padding: 1pt 6pt; border-bottom: 0.5pt solid #777; }
  .dt thead th { border-bottom: 1pt solid #000; color: #000; }
  .dt td.in { min-width: 7em; height: 21pt; border: 0.5pt solid #777; }
  .pblank { display: inline-block; border-bottom: 0.75pt solid #000; height: 21pt; vertical-align: bottom; }
  .dt td.in .pblank { border: 0; }
  .answers { max-width: 150mm; gap: 0; grid-template-columns: 1fr; }
  .arow { display: flex; border-bottom: 0; padding: 0; min-height: 22pt; align-items: flex-end; gap: 6pt; grid-template-columns: none; }
  .alab { flex: 0 1 auto; }
  .aval { justify-self: auto; margin-left: auto; flex: none; }
  .arow.asel { grid-column: 1 / -1; display: block; padding-top: 3pt; }
  .arow.asel .alab { display: block; }
  .arow.asel .aval { display: block; margin-left: 0; }
  .pchoice { display: block; line-height: 1.6; }
  .pchoice .opt { white-space: nowrap; }
  .plot { max-width: 160mm; margin: 0 0 4pt; break-inside: avoid; }
  .plot .yt { font-size: 10pt; color: #000; margin: 0; }
  .plot .pw { display: block; }
  .plot .tk { fill: #000; }
  .plot .gl { stroke: #bbb; }
  .plot .cy { stroke: #777; }
  .plot .ln { stroke: #000; stroke-width: 1.4; }
  .plot circle { fill: #000; }
  .strip { grid-template-columns: repeat(8, 1fr); max-width: none; margin: 0 0 4pt; border-top: 0.75pt solid #777; border-left: 0.75pt solid #777; break-inside: avoid; }
  .strip div { padding: 1pt 4pt; border-right: 0.75pt solid #777; border-bottom: 0.75pt solid #777; font-size: 10pt; }
  .strip dt { color: #333; }
  .pchoice::after { content: " (circle one)"; color: #333; font-size: 10pt; }
  sub, sup { font-size: 10pt; }
  /* working: real ruled lines 21pt apart (app.js WORK_LINES sets how many) */
  .pwork { border: 0.5pt solid #999; margin-top: 4pt; padding: 0 6pt; }
  .pwl { display: block; font-size: 10pt; color: #333; padding-top: 1pt; }
  .pl { display: block; height: 21pt; border-bottom: 0.5pt solid #999; }
  .pl:last-child { border-bottom: 0; }
  .pend { break-inside: avoid; }
  .keyfig { display: block; }
  .kpart { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); column-gap: 14pt; align-items: start; break-inside: avoid; }
  .kpart + .kpart { border-top: 0.5pt dashed #888; padding-top: 4pt; margin-top: 4pt; }
  .kpart .ksec { grid-column: 1; }
  .kpart .steps { grid-column: 2; }
  .kpart:has(.twrap) { display: block; }
  .kpart:has(.twrap) .ksec .answers { margin: 2pt 0 4pt; grid-template-columns: 1fr 1fr; }
  .kpart .ksec .answers { grid-template-columns: 1fr; }
  /* exam style and trend: the working runs the full width under the answers, so the keys fit their pages (PER_PAGE) */
  .pk.wide .kpart { display: block; }
  .pk.wide .kpart .ksec .answers { margin: 1pt 0 3pt; grid-template-columns: 1fr 1fr; column-gap: 14pt; }
  .pk.wide .kpart + .kpart { padding-top: 2pt; margin-top: 3pt; }
  .pk.wide .steps li { margin: 0; }
  .pk.wide h3 { margin-top: 0; }
  .kpart .arow { min-height: 0; display: block; }
  .kpart .alab::after { content: ":\00a0"; }
  .kpart .aval { display: inline; }
  .kpart .kv { overflow-wrap: anywhere; }
  .kpart .aval { margin-left: 0; }
  .steps { font-size: 10pt; margin: 0; padding-left: 12pt; }
  .steps li { margin: 1pt 0; }
  .steps li.say { margin-left: -12pt; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
