/* Dotted Page. One world for every page: a white sheet printed in black, lying on a
 * sheet of colored construction paper. Ballpoint blue is the pen (every button,
 * link and trace); the grader's red is for scores only. The front page's scroll
 * story has its own stylesheet, src/styles/home.css. DESIGN.md has the system. */

@font-face {
  font-family: "Atkinson Hyperlegible Next"; font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/fonts/atkinson-hyperlegible-next-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Edu SA Beginner"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/fonts/edu-sa-beginner-latin.woff2") format("woff2");
}

/* ---------------------------------------------------------------- tokens */
:root {
  /* the pad of construction paper: the ground a page lies on */
  --paper-sun: oklch(88.5% 0.165 93);
  --paper-moon: oklch(81% 0.09 278);
  --paper-fern: oklch(83% 0.15 140);
  --paper-lava: oklch(79% 0.14 45);
  --paper-pink: oklch(82% 0.11 355);
  --ground: var(--paper-sun);
  /* the sheet and its print */
  --sheet: oklch(100% 0 0);
  --print: oklch(19% 0.02 272);
  --print-soft: oklch(19% 0.02 272 / 0.76);   /* second voice: takes its tint from whatever is under it */
  --print-faint: oklch(19% 0.02 272 / 0.58);  /* placeholders and hints, on white */
  --rule: oklch(19% 0.02 272 / 0.16);
  --rule-strong: oklch(19% 0.02 272 / 0.5);
  /* the pen */
  --ink: oklch(42% 0.21 268);
  --ink-deep: oklch(34% 0.19 268);
  --ink-wash: oklch(95.5% 0.028 268);
  --on-ink: oklch(100% 0 0);
  /* the grader */
  --mark: oklch(55% 0.21 28);
  --mark-wash: oklch(95.5% 0.028 28);
  --note: oklch(40% 0.1 80); --note-wash: oklch(96% 0.05 93);
  /* the back of the pad: the footer */
  --board: oklch(21% 0.03 272);
  --on-board: oklch(97% 0.01 272);
  --on-board-soft: oklch(97% 0.01 272 / 0.72);
  /* the grader's overlay pens (src/grader/overlay.ts) and the printed page (the PDF) */
  --legend-ink: #1e5ae6; --legend-ok: #00a03c; --legend-miss: #e11e1e; --legend-off: #ff8c00;
  --sheet-white: #ffffff; --sheet-black: #000000;

  --shade: oklch(24% 0.06 93 / 0.42);
  --shadow-paper: 0 1px 1px oklch(19% 0.02 272 / 0.06), 0 24px 48px -24px var(--shade);
  --shadow-lift: 0 2px 3px oklch(19% 0.02 272 / 0.08), 0 12px 24px -12px var(--shade);

  --font: "Atkinson Hyperlegible Next", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-hand: "Edu SA Beginner", "Segoe Print", "Bradley Hand", cursive;   /* the grader's hand: scores and remarks, nowhere else */
  --font-sheet: Helvetica, Arial, sans-serif;                                /* the worksheet's own printed header */

  --text-xs: 0.8125rem; --text-sm: 0.9375rem; --text-md: 1.0625rem; --text-lg: 1.25rem; --text-xl: 1.5rem; --text-2xl: 1.875rem;
  --text-lead: clamp(1.125rem, 0.45vw + 1rem, 1.375rem);
  --text-title: clamp(1.875rem, 1.6vw + 1.25rem, 2.75rem);
  --text-step: clamp(2rem, 2.7vw + 1rem, 3.75rem);
  --text-hero: clamp(2.375rem, 4.2vw + 1rem, 5rem);

  --space-3xs: 2px; --space-2xs: 4px; --space-xs: 8px; --space-sm: 12px; --space-md: 16px; --space-lg: 24px; --space-xl: 40px; --space-2xl: 64px; --space-3xl: 96px; --space-4xl: 144px;
  --container: 1440px; --gutter: 56px; --gap: 32px;
  --nav-h: 76px; --control-h: 52px;
  --r-sheet: 5px; --r-control: 12px; --r-pill: 999px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1); --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-settle: linear(0, 0.36 9%, 0.72 20%, 0.95 31%, 1.04 41%, 1.05 49%, 1.02 62%, 1 78%, 1);   /* paper landing */
  --dur-micro: 120ms; --dur-short: 220ms; --dur-long: 480ms;
}
@supports (color: color-mix(in oklch, red, blue)) {
  :root { --shade: color-mix(in oklch, var(--ground) 30%, oklch(16% 0.04 272 / 0.62)); }
}
[data-paper="moon"] { --ground: var(--paper-moon); }
[data-paper="fern"] { --ground: var(--paper-fern); }
[data-paper="lava"] { --ground: var(--paper-lava); }
[data-paper="pink"] { --ground: var(--paper-pink); }
@media (max-width: 60rem) { :root { --gutter: 24px; --nav-h: 64px; --gap: 24px; } }
@media (max-width: 40rem) { :root { --gutter: 16px; --nav-h: 60px; } }

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--print) var(--ground); scroll-padding-top: var(--space-lg); background: var(--ground); }
html, body { overflow-x: clip; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--ground); color: var(--print); caret-color: var(--ink); accent-color: var(--ink);
  font: 400 var(--text-md)/1.6 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color var(--dur-long) var(--ease-out);
}
main { flex: 1; }
::selection { background: var(--ink); color: var(--on-ink); }
:focus-visible { outline: 3px solid var(--print); outline-offset: 3px; border-radius: 4px; }
[hidden] { display: none !important; }
a { color: var(--ink); text-decoration-thickness: 1.5px; text-underline-offset: 0.2em; }
a:hover { color: var(--ink-deep); text-decoration-thickness: 2.5px; }
h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.02em; line-height: 1.08; text-wrap: balance; overflow-wrap: break-word; min-width: 0; }
h1 { font-size: var(--text-title); }
h2 { font-size: var(--text-2xl); line-height: 1.15; letter-spacing: -0.015em; }
h3 { font-size: var(--text-lg); line-height: 1.25; letter-spacing: -0.005em; }
p { margin: 0; text-wrap: pretty; }
ul, ol { margin: 0; padding-left: 1.3em; }
img, video { max-width: 100%; height: auto; display: block; }
svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--gutter); }
.lead { font-size: var(--text-lead); line-height: 1.5; max-width: 44ch; color: var(--print-soft); }
.muted { color: var(--print-soft); font-size: var(--text-sm); }
.num, td.num { font-variant-numeric: tabular-nums; }
.m0 { margin: 0; }

/* ---------------------------------------------------------------- chrome */
header.site { position: relative; z-index: 20; }
header.site .bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm) var(--space-lg); min-height: var(--nav-h); }
.logo { display: inline-flex; align-items: center; gap: var(--space-xs); font: 800 var(--text-lg)/1 var(--font); letter-spacing: -0.02em; color: var(--print); text-decoration: none; white-space: nowrap; }
.logo:hover { color: var(--print); }
/* the mark: a dotted d which, turned upside down, is a traced p (public/logo.svg) */
.logo svg { height: 34px; width: auto; flex: none; transition: rotate var(--dur-long) var(--ease-settle); }
.logo:hover svg { rotate: 180deg; }
.logo .mark-dots { fill: var(--print); }
.logo .mark-ink { stroke: var(--ink); }
nav.main { display: flex; gap: var(--space-2xs); }
nav.main a { position: relative; display: inline-flex; align-items: center; min-height: 44px; padding-inline: var(--space-sm); color: var(--print); font-size: var(--text-md); font-weight: 600; text-decoration: none; white-space: nowrap; }
/* the link under the pointer, and the page you are on, get a pen stroke under them */
nav.main a::after { content: ""; position: absolute; left: var(--space-sm); right: var(--space-sm); bottom: 9px; height: 3px; border-radius: 2px; background: var(--ink); transform: scaleX(0); transform-origin: left; transition: transform var(--dur-short) var(--ease-out); }
nav.main a:hover::after, nav.main a[aria-current="page"]::after { transform: scaleX(1); }
nav.main a:active { color: var(--ink-deep); }

footer.site { margin-top: auto; background: var(--board); color: var(--on-board); }
.colophon { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--space-xl) var(--gap); align-items: end; padding-block: var(--space-2xl) var(--space-xl); }
.colophon .wordmark { width: min(100%, 34rem); height: auto; overflow: visible; }
.colophon .wordmark path { fill: none; stroke: var(--on-board); stroke-width: 1.9; stroke-linecap: round; }
.colophon .wordmark .traced { stroke: var(--paper-sun); stroke-width: 2.3; stroke-linejoin: round; }
.colophon .legal-line { margin-top: var(--space-lg); color: var(--on-board-soft); font-size: var(--text-sm); max-width: 48ch; }
.colophon .links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2xs) var(--space-lg); font-size: var(--text-md); }
.colophon .links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--on-board); font-weight: 600; text-decoration-color: transparent; white-space: nowrap; }
.colophon .links a:hover { text-decoration-color: var(--paper-sun); }
footer.site :focus-visible { outline-color: var(--on-board); }

/* ---------------------------------------------------------------- controls */
label { display: block; font-weight: 700; margin: var(--space-lg) 0 var(--space-xs); }
label.check { display: flex; gap: var(--space-sm); align-items: flex-start; font-weight: 400; margin-top: 0; max-width: 60ch; }
label.check a { white-space: nowrap; }
label.check input { width: 24px; height: 24px; margin: var(--space-3xs) 0 0; flex: none; }
input[type="text"], select, textarea {
  width: 100%; min-height: var(--control-h); padding: var(--space-sm) var(--space-md);
  border: 1.5px solid var(--rule-strong); border-radius: var(--r-control); background: var(--sheet);
  outline: 3px solid transparent; outline-offset: 2px;
  transition: border-color var(--dur-micro) var(--ease-out), box-shadow var(--dur-short) var(--ease-out);
}
/* The native arrow ignores padding and hugs the border, so draw our own chevron with room on its right. */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  padding-right: calc(var(--space-md) + 14px + var(--space-sm));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%2316181f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--space-md) center; background-size: 14px 8px;
}
input[type="text"]:hover, select:hover, textarea:hover { border-color: var(--print); }
input[type="text"]:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--ink); outline-color: var(--ink); border-radius: var(--r-control); }
input:disabled, select:disabled, textarea:disabled { opacity: 0.55; cursor: not-allowed; }
::placeholder { color: var(--print-faint); opacity: 1; }
textarea { min-height: 13.75rem; resize: vertical; line-height: 1.55; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-md); }

.button, button.primary, button.secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs); min-height: var(--control-h); padding: 0 var(--space-lg);
  font: 700 var(--text-md)/1.2 var(--font); white-space: nowrap; text-decoration: none; cursor: pointer;
  border-radius: var(--r-control); border: 1.5px solid var(--ink); background: var(--ink); color: var(--on-ink);
  box-shadow: var(--shadow-lift);
  transition: background-color var(--dur-short) var(--ease-out), border-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out), translate var(--dur-micro) var(--ease-out), box-shadow var(--dur-short) var(--ease-out);
}
.button:hover, button.primary:hover { background: var(--ink-deep); border-color: var(--ink-deep); color: var(--on-ink); translate: 0 -1px; }
.button:active, button.primary:active, button.secondary:active { translate: 0 1px; box-shadow: none; }
.button.secondary, button.secondary { background: var(--sheet); color: var(--print); border-color: var(--rule-strong); box-shadow: none; }
.button.secondary:hover, button.secondary:hover { background: var(--ink-wash); color: var(--ink-deep); border-color: var(--ink); translate: none; }
button:disabled, button[aria-busy="true"] { opacity: 0.55; cursor: not-allowed; translate: none; box-shadow: none; }
button.link { background: none; border: 0; padding: var(--space-xs) 0; margin-block: calc(-1 * var(--space-xs)); font: inherit; color: var(--ink); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 0.2em; cursor: pointer; }
button.link:hover { color: var(--ink-deep); text-decoration-thickness: 2.5px; }
button.link:active { color: var(--print); }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-top: var(--space-lg); }
.file-button { position: relative; margin: 0; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
label.button:focus-within { outline: 3px solid var(--print); outline-offset: 3px; }

.error { background: var(--mark-wash); color: oklch(38% 0.15 28); border: 1.5px solid oklch(55% 0.21 28 / 0.45); border-radius: var(--r-control); padding: var(--space-sm) var(--space-md); margin: var(--space-lg) 0; max-width: 60ch; }
.note { background: var(--note-wash); color: var(--note); border-radius: var(--r-control); padding: var(--space-sm) var(--space-md); margin: var(--space-lg) 0; max-width: 60ch; }
#fit { min-height: 1lh; margin-top: var(--space-xs); }
#fit.warn { color: oklch(42% 0.17 28); font-weight: 700; }
#turnstile:not(:empty) { margin-top: var(--space-lg); }
/* a worksheet, wherever it is shown as printed */
.paper { background: var(--sheet-white); box-shadow: var(--shadow-paper); border-radius: var(--r-sheet); overflow: hidden; }
canvas { display: block; width: 100%; height: auto; }

/* ---------------------------------------------------------------- the white sheet a page's words are printed on */
.slab { background: var(--sheet); border-radius: var(--r-sheet); box-shadow: var(--shadow-paper); padding: clamp(var(--space-lg), 4vw, var(--space-2xl)); }
/* a piece of the colored paper inside a white sheet: where a worksheet is shown */
.mat { background: var(--ground); border-radius: var(--r-control); padding: var(--space-xl); }
main.app { padding-block: var(--space-md) var(--space-3xl); }
.app h1 { margin-bottom: var(--space-xs); }
.app h2 { font-size: var(--text-xl); line-height: 1.2; }
.app-head { margin-bottom: var(--space-xl); }

/* ---------------------------------------------------------------- make */
.workspace { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: var(--gap); align-items: start; }
.panel h1 { margin-bottom: var(--space-xl); }
.group + .group { margin-top: var(--space-xl); padding-top: var(--space-xl); border-top: 2px dotted var(--rule-strong); }
.group > label:first-child { margin-top: 0; }
.group .muted { margin-top: var(--space-sm); }
.stage-col { display: flex; flex-direction: column; gap: var(--space-sm); position: sticky; top: var(--space-md); }
.stage { position: relative; height: calc(100dvh - var(--space-3xl)); max-height: 900px; min-height: 420px; container-type: size; display: grid; place-items: center; }
.stage > * { --h: min(96cqh, 124cqw); grid-area: 1 / 1; }
.sheet { position: relative; height: var(--h); aspect-ratio: 612 / 792; background: var(--sheet-white); box-shadow: var(--shadow-paper); border-radius: 2px; rotate: 1.2deg; view-transition-name: sheet; }
.page { display: block; width: 100%; height: 100%; }
.page text { font-family: var(--font-sheet); fill: var(--sheet-black); }
.page .ink path { display: none; }
.stage.intro .r { animation: rise 0.7s var(--ease-out) both; animation-delay: calc(0.15s + var(--r) * 0.12s); }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } }
.stage-note { margin: 0; text-align: center; color: var(--print-soft); font-size: var(--text-sm); font-weight: 600; }
#saved-section { margin-top: var(--space-2xl); }
#saved-section h2 { margin-bottom: var(--space-xs); }
.saved { list-style: none; padding: 0; margin: var(--space-lg) 0 0; border-top: 2px solid var(--print); }
.saved li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2xs) var(--space-lg); align-items: baseline; padding: var(--space-md) 0; margin: 0; border-bottom: 1px solid var(--rule); }
.saved a { font-weight: 700; }
.saved .last-score { font: 700 var(--text-lg)/1 var(--font-hand); color: var(--mark); }

/* ---------------------------------------------------------------- grade */
.grade-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--space-2xl) var(--gap); align-items: start; }
.grade-grid .lead { margin-bottom: var(--space-lg); }
.grade-grid h2 { margin: var(--space-2xl) 0 var(--space-sm); }
.ticks { list-style: none; padding: 0; max-width: 40em; border-top: 1px solid var(--rule); }
.ticks li { position: relative; padding: var(--space-md) 0 var(--space-md) var(--space-xl); margin: 0; border-bottom: 1px solid var(--rule); }
.ticks li::before { content: ""; position: absolute; left: var(--space-xs); top: 1.15rem; width: 9px; height: 17px; border: solid var(--ink); border-width: 0 3px 3px 0; rotate: 42deg; border-radius: 1px; }
.shot { margin: 0; }
.shot .mat { display: grid; place-items: center; }
.shot .diagram { max-width: 280px; }
.shot figcaption { margin-top: var(--space-sm); text-align: center; text-wrap: balance; }
.diagram { display: block; width: 100%; height: auto; filter: drop-shadow(0 14px 16px var(--shade)); rotate: -2deg; }
.diagram .pg { fill: var(--sheet-white); }
.diagram .ln { stroke: var(--rule-strong); stroke-width: 1; fill: none; }
.diagram .qr { fill: var(--print); stroke: var(--mark); stroke-width: 3; paint-order: stroke; }
.diagram .t { fill: var(--sheet-white); stroke: var(--mark); stroke-width: 2.6; }
.diagram .td { fill: var(--print); }
.diagram .ink { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; }
.working { display: flex; flex-direction: column; align-items: center; gap: var(--space-xl); padding-block: var(--space-xl) var(--space-2xl); font-size: var(--text-xl); font-weight: 800; letter-spacing: -0.01em; }
.scan { position: relative; width: 190px; }
.scan .diagram { rotate: none; }
/* the scan line travels the page's height: 190px wide at 160:207 is about 246px tall */
.scan i { position: absolute; left: calc(-1 * var(--space-sm)); right: calc(-1 * var(--space-sm)); top: 4%; height: 3px; border-radius: 2px; background: var(--mark); animation: scan 1.5s var(--ease-in-out) infinite alternate; }
@keyframes scan { to { transform: translateY(224px); } }

.done-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-template-rows: auto 1fr; grid-template-areas: "result viewer" "rest viewer"; gap: 0 var(--space-2xl); align-items: start; }
.done-grid > .result { grid-area: result; }
.done-grid > .viewer { grid-area: viewer; position: sticky; top: var(--space-md); }
.done-grid > .rest { grid-area: rest; }
.result { display: flex; align-items: center; gap: var(--space-lg); margin-bottom: var(--space-xl); }
/* the grade, as a teacher circles it */
.score-badge {
  flex: none; width: 148px; height: 142px; display: grid; place-items: center; background: var(--sheet-white); color: var(--mark);
  border: 5px solid var(--mark); border-radius: 54% 46% 52% 48% / 48% 54% 46% 52%; rotate: -6deg;
  font: 700 4rem/1 var(--font-hand); font-variant-numeric: tabular-nums;
}
.comment { font: 700 var(--text-title)/1.1 var(--font-hand); color: var(--mark); margin: 0 0 var(--space-2xs); }
.notes { max-width: 44em; margin: 0 0 var(--space-lg); padding-left: 1.2em; }
.notes li { margin-bottom: var(--space-xs); }
.rest > .muted { max-width: 60ch; }
.rest h2 { margin: var(--space-2xl) 0 var(--space-sm); }
.viewer .paper { margin: var(--space-md) 0 0; }
.toggle { display: inline-flex; border: 1.5px solid var(--print); border-radius: var(--r-control); overflow: hidden; background: var(--sheet); }
.toggle button { font: 700 var(--text-sm)/1.2 var(--font); padding: 0 var(--space-md); min-height: 44px; border: 0; background: var(--sheet); color: var(--print); cursor: pointer; transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out); }
.toggle button:hover { background: var(--ink-wash); color: var(--ink-deep); }
.toggle button:active { background: var(--ink-wash); }
.toggle button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.toggle button:focus-visible { outline-offset: -5px; outline-color: var(--print); }
.toggle button[aria-pressed="true"]:focus-visible { outline-color: var(--on-ink); }
.legend { margin: var(--space-md) 0 0; color: var(--print); }
.legend span { display: inline-flex; align-items: center; gap: var(--space-xs); margin-right: var(--space-md); white-space: nowrap; }
/* the overlay's pens, drawn as a pen stroke */
.legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }
.k-ink { background: var(--legend-ink); }
.k-ok { background: var(--legend-ok); }
.k-miss { background: var(--legend-miss); }
.k-off { background: var(--legend-off); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: var(--space-md) var(--space-sm) var(--space-md) 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { border-bottom: 2px solid var(--print); font-size: var(--text-sm); white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; padding-right: 0; }
td.num { font-weight: 700; }

/* ---------------------------------------------------------------- one worksheet */
.sheet-grid { display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 6fr); gap: var(--gap); align-items: start; }
.page-head { margin-bottom: var(--space-xl); }
.page-head h1 { margin-bottom: var(--space-xs); }
.preview { position: sticky; top: var(--space-md); padding: var(--space-md) var(--space-xl) var(--space-xl); }
.preview .paper { rotate: 1.2deg; max-width: 560px; margin-inline: auto; border-radius: 2px; }
.todo { list-style: none; padding: 0; margin: 0 0 var(--space-2xl); counter-reset: todo; max-width: 40em; }
.todo li { counter-increment: todo; position: relative; padding: var(--space-lg) 0 var(--space-lg) var(--space-3xl); margin: 0; border-top: 2px dotted var(--rule-strong); }
.todo li::before { content: counter(todo); position: absolute; left: 0; top: var(--space-md); font: 800 var(--text-title)/1 var(--font); color: var(--ink); font-variant-numeric: tabular-nums; }
.todo h2 { margin-bottom: var(--space-xs); }
.todo p + p { margin-top: var(--space-sm); }
.todo .actions { margin: var(--space-md) 0 0; }
.sheet-grid h3 { margin: 0 0 var(--space-sm); }
.sheet-text { white-space: pre-wrap; background: var(--ink-wash); border-radius: var(--r-control); padding: var(--space-md) var(--space-lg); max-width: 40em; margin-bottom: var(--space-md); }

/* ---------------------------------------------------------------- reading pages: one white sheet, set for reading */
main.narrow { flex: none; width: calc(100% - 2 * var(--gutter)); max-width: 50rem; margin: var(--space-md) auto var(--space-3xl); padding: clamp(var(--space-lg), 6vw, var(--space-3xl)) clamp(var(--space-lg), 7vw, var(--space-3xl)); background: var(--sheet); border-radius: var(--r-sheet); box-shadow: var(--shadow-paper); }
main.narrow > * { max-width: 38rem; }
main.narrow > p, main.narrow > ul, main.narrow > ol { margin-bottom: var(--space-md); }
main.narrow li { margin-bottom: var(--space-xs); }
main.narrow h1 { margin-bottom: var(--space-lg); }
main.narrow h2 { margin: var(--space-2xl) 0 var(--space-sm); }
main.narrow h1 + h2, main.narrow h1 + p + h2 { margin-top: var(--space-xl); }
main.narrow.legal h2 { font-size: var(--text-lg); line-height: 1.3; letter-spacing: -0.005em; margin-top: var(--space-xl); }
main.narrow.legal h3 { font-size: var(--text-md); line-height: 1.3; letter-spacing: 0; margin: var(--space-lg) 0 var(--space-xs); }
.legal, .prose { line-height: 1.65; }
.legal .caps { text-transform: none; font-weight: 700; }
.factors { list-style: none; padding: 0; margin: var(--space-lg) 0 var(--space-xl); border-top: 1px solid var(--rule); }
.factors li { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: var(--space-lg); align-items: center; padding: var(--space-md) 0; margin: 0; border-bottom: 1px solid var(--rule); }
.mini { display: block; width: 100%; height: auto; background: var(--ground); border-radius: var(--r-control); }
.mini .d { fill: var(--print); }
.mini .skip { fill: none; stroke: var(--mark); stroke-width: 1.6; stroke-dasharray: 2.4 2; }
.mini .ink { fill: none; stroke: var(--ink); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.88; }
.lost .actions { margin-top: var(--space-xl); }

/* ---------------------------------------------------------------- under 60rem */
@media (max-width: 60rem) {
  .workspace, .grade-grid, .sheet-grid, .done-grid, .colophon { grid-template-columns: minmax(0, 1fr); }
  .done-grid { grid-template-rows: auto; grid-template-areas: "result" "viewer" "rest"; }
  .done-grid > .viewer { position: static; margin-bottom: var(--space-xl); }
  .stage-col { position: static; }
  .stage { height: min(64dvh, 118vw); min-height: 0; }
  .preview { position: static; padding: var(--space-xs) var(--space-md) var(--space-lg); }
  .preview .paper { max-width: 420px; }
  .colophon .links { justify-content: flex-start; }
}
@media (max-width: 40rem) {
  /* the name and three links in one row, down to the narrowest phones */
  header.site .bar { gap: var(--space-xs); }
  nav.main { gap: 0; margin-right: -6px; }
  nav.main a { padding-inline: 6px; font-size: var(--text-sm); }
  nav.main a::after { left: 6px; right: 6px; }
  .logo { font-size: var(--text-md); gap: 6px; }
  .logo svg { height: 28px; }
  .row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .actions .button, .actions button { width: 100%; }
  .result { align-items: flex-start; }
  .score-badge { width: 112px; height: 108px; font-size: 3rem; }
  .factors li { grid-template-columns: 96px minmax(0, 1fr); gap: var(--space-md); }
  .todo li { padding-left: var(--space-2xl); }
  .mat { padding: var(--space-lg); }
  .shot .diagram { max-width: 200px; }
  main.narrow { width: calc(100% - 2 * var(--space-xs)); }
  .slab { margin-inline: calc(var(--space-xs) - var(--gutter)); }
}

/* ---------------------------------------------------------------- from one page to the next */
@view-transition { navigation: auto; }
::view-transition-group(sheet) { animation-duration: 0.55s; animation-timing-function: var(--ease-out); }

/* ---------------------------------------------------------------- less motion: every animation ends at once */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
  .scan i { top: 50%; animation: none; }
  @view-transition { navigation: none; }
}
@media (max-width: 23.5rem) {
  nav.main a { padding-inline: 5px; font-size: var(--text-xs); }
  nav.main a::after { left: 5px; right: 5px; }
  .logo { font-size: var(--text-sm); }
}
