/* Sankey practice: an engineer's pad. Cream paper with a pale cyan grid, deep teal ink, the useful arrow in amber
   (the one colour that means "useful"), wasted arrows in slate. Book-face headings, flat rules, one radius. */
:root {
  --bg: #f4f2ea; --paper: #fffdf7; --ink: #182a2b; --muted: #485556; --line: #d4d6cc; --line2: #7d8a88;
  --accent: #0d5c5a; --accent-ink: #ffffff; --accent-soft: #dcecea;
  --g1: #bfdfe0; --g5: #7fbcc0; --useful: #f0b43c; --useful-o: #8a5a00; --waste: #9fb0c2; --waste-o: #3d4f62; --input: #d9cfb2;
  --ok: #1c6a3a; --ok-soft: #e0f0e5; --bad: #a3261b; --bad-soft: #fbe4e1; --warn: #6b4d00; --warn-soft: #f5ebcd;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --head: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 3px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111818; --paper: #172021; --ink: #e4ecea; --muted: #b3c0be; --line: #2c3a3b; --line2: #6f7f7d;
    --accent: #7fd0c9; --accent-ink: #0b1f1e; --accent-soft: #1c3332;
    --g1: #253a3c; --g5: #3e6266; --useful: #c98f1a; --useful-o: #f7c96b; --waste: #4b5d70; --waste-o: #b9c9da; --input: #5c5440;
    --ok: #84d3a0; --ok-soft: #163020; --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: 17px/1.55 var(--sans); font-variant-numeric: tabular-nums; }
.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(--useful-o); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--head); line-height: 1.15; font-weight: 700; letter-spacing: 0; }

/* hero */
.hero { padding: 22px 0 2px; }
.hero h1 { font-size: clamp(1.8rem, 5.2vw, 2.6rem); margin: 0 0 6px; }
.lede { margin: 4px 0 0; max-width: 66ch; }
.crumbs { margin: 2px 0 0; }
.crumbs a { font-weight: 600; display: inline-flex; align-items: center; min-height: 44px; }

/* setup */
.setup { margin: 8px 0 8px; }
.setrow { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.inline { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; max-width: 100%; flex-wrap: wrap; }
@media (max-width: 560px) {
  .setrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: end; }
  .setrow .inline { display: grid; gap: 2px; }
  .setrow select { width: 100%; }
}
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%; min-width: 0; }
.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 16px; }
.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); overflow-wrap: anywhere; }
.note.info { background: var(--accent-soft); }

/* the sheet: a ruled pad, a heavy rule at the top */
.sheet { background: var(--paper); border-top: 4px solid var(--ink); padding: 12px 18px 16px; margin: 8px 0 18px; box-shadow: 0 1px 0 var(--line); }
@media (max-width: 480px) { .sheet { padding: 10px 12px 14px; margin-left: -8px; margin-right: -8px; } }
.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.35rem; }
.code { font-family: var(--mono); letter-spacing: 0.06em; }
.lvname { font-family: var(--sans); font-weight: 500; color: var(--muted); font-size: 1rem; }
.score { margin: 0; color: var(--muted); }
details.rules { margin: 6px 0 2px; }
details.rules summary, details.work summary, details.recent summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; color: var(--accent); }
details.rules ul { margin: 4px 0 10px; padding-left: 20px; max-width: 80ch; }
details.rules li { margin: 0 0 4px; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { padding: 16px 0 16px; border-top: 1px solid var(--line2); }
.q:first-child { border-top: 0; }
.qhead { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 14px; flex-wrap: wrap; }
.qhead h3 { margin: 0 0 4px; font-size: 1.3rem; display: flex; gap: 10px; align-items: baseline; }
.qn { font-family: var(--mono); font-size: 1rem; color: var(--accent); font-weight: 800; }
.qn::after { content: "."; }
.see { font-weight: 600; padding: 10px 0; }
@media (max-width: 600px) { .see { display: none; } }
.qtext { margin: 2px 0 10px; max-width: 76ch; }

/* a problem: the diagram (or table), then the answer rows; side by side when there is room */
.qbody { display: grid; gap: 8px 26px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.qfig { min-width: 0; }
@media (min-width: 900px) {
  .q-read .qbody, .q-draw .qbody { grid-template-columns: minmax(0, 500px) minmax(0, 1fr); }
  .q-read .answers, .q-draw .answers { grid-template-columns: minmax(0, 1fr); }
}
.fig { margin: 0; padding: 0; min-width: 0; }
.fig figcaption { color: var(--muted); padding: 4px 0 0; }
.fig figcaption.pv { color: var(--ink); }
svg.sk { display: block; max-width: 100%; height: auto; }
.g1 { stroke: var(--g1); stroke-width: 1; fill: none; shape-rendering: crispEdges; }
.g5 { stroke: var(--g5); stroke-width: 1; fill: none; shape-rendering: crispEdges; }
.ar { stroke: none; }
.ar.in { fill: var(--input); }
.ar.use { fill: var(--useful); }
.ar.waste { fill: var(--waste); }
.fill { opacity: 0.85; }
.ol { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.dim { fill: none; stroke: var(--ink); stroke-width: 1.2; }
svg.sk .lt { font-family: var(--sans); font-weight: 800; fill: var(--ink); }
.legend { list-style: none; margin: 6px 0 0; padding: 0; max-width: 60ch; }
.legend li { display: grid; grid-template-columns: 1.2em minmax(0, 1fr); gap: 10px; padding: 2px 0; }
.legend .lt { font-family: var(--mono); min-width: 1.2em; }
.legend .kv { color: var(--muted); white-space: nowrap; }
table.dt { border-collapse: collapse; margin: 0 0 10px; width: 100%; max-width: 40em; }
.dt th, .dt td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.dt thead th { border-bottom: 2px solid var(--ink); }
.dt .n { text-align: right; white-space: nowrap; font-family: var(--mono); }
.dt thead .n { font-family: var(--sans); white-space: normal; }
.dt tbody th { font-family: var(--mono); }

/* answer rows */
.answers { display: grid; gap: 0 22px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 25em), 1fr)); align-content: start; }
.arow { display: flex; align-items: center; justify-content: space-between; gap: 4px 10px; min-height: 52px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.alab { font-weight: 600; flex: 1 1 9em; }
.aval { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.un { color: var(--muted); min-width: 4.6em; padding-left: 6px; }
.un.typed { visibility: hidden; }
.cw { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; min-width: 0; }
input.cell { width: 9.5em; max-width: 100%; min-height: 44px; padding: 6px 8px; text-align: right; font-family: var(--mono); font-size: 16px; }
input.cell.wide { text-align: left; width: 13em; }
input.cell.wide + .un { min-width: 0; padding: 0; }
input.cell.is-right { border-color: var(--ok); background: var(--ok-soft); }
input.cell.is-close { border-color: var(--warn); background: var(--warn-soft); }
input.cell.is-wrong, input.cell.is-unread { border-color: var(--bad); background: var(--bad-soft); }
input.cell.is-own { border-color: var(--warn); border-style: dashed; }
.mk { display: inline-flex; align-items: baseline; width: 2.3em; flex: none; font-weight: 800; padding-left: 3px; white-space: nowrap; }
.mk-right { color: var(--ok); } .mk-close, .mk-own { color: var(--warn); } .mk-wrong, .mk-unread { color: var(--bad); }
.mn { font-size: 0.8em; font-weight: 700; margin-left: 1px; }

/* feedback */
.fbwrap { margin: 6px 0; }
.fbl { margin: 4px 0; padding: 0 0 0 2.2em; max-width: 80ch; }
.fb { margin: 4px 0; padding: 6px 10px; border-radius: var(--r); background: var(--bad-soft); max-width: 80ch; }
.fbl .fb::marker { font-weight: 700; }
.fb.right { background: var(--ok-soft); }
.fb.close { background: var(--warn-soft); }
.fb.own { background: var(--paper); border: 1px dashed var(--warn); }
.fb.empty { background: var(--paper); border: 1px solid var(--line); }
.qfoot { margin-top: 6px; }
details.work { margin-top: 6px; }
.keyfig { padding: 4px 0 6px; }
.keyfig .fig { margin: 0 0 4px; }
.kans { margin: 8px 0 6px; padding-left: 0; list-style: none; }
.kans li { margin: 0 0 2px; }
.steps { margin: 0; padding-left: 1.4em; }
.steps li { margin: 0 0 6px; max-width: 86ch; overflow-wrap: anywhere; }
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line2); }
.confirm { margin: 0; flex-basis: 100%; padding: 10px; background: var(--warn-soft); border-radius: var(--r); }
.save-hint { margin: 0; color: var(--muted); flex-basis: 100%; }

/* print and share */
.share { margin: 0 0 22px; }
.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; max-width: 100%; }
.share-out label { display: grid; gap: 4px; font-weight: 600; }
.share-out input { min-height: 44px; padding: 6px 10px; width: 100%; }
.recent ul { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 2px 0; }
.when { display: block; color: var(--muted); }
.hint { color: var(--muted); margin: 6px 0; }

/* the text below */
.content { max-width: 74ch; padding-bottom: 24px; }
.content h2 { font-size: 1.6rem; margin: 28px 0 8px; }
.content li { margin-bottom: 4px; }
.content .fig { margin: 8px 0; max-width: 520px; }
.faq details { border-top: 1px solid var(--line); }
.faq details:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; padding: 6px 0; }
.faq p { margin: 0 0 12px; }
.sources { color: var(--muted); overflow-wrap: anywhere; }
footer { border-top: 1px solid var(--line); padding: 16px 0 28px; color: var(--muted); }
footer p { margin: 6px 0; }
.sb-more a { white-space: nowrap; }
.toast { position: fixed; left: 16px; right: 16px; bottom: 16px; margin: 0 auto; width: fit-content; max-width: 560px; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 20; }
.toast.on { opacity: 1; }
.toast.top { bottom: auto; top: 16px; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
.print-root { display: none; }

/* ---------- print: squares are 5 mm, never scaled ---------- */
@page { margin: 12mm; }
@media print {
  body { background: #fff; color: #000; font-size: 10.5pt; }
  main, footer, .toast, .skip { 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: 9.5pt; color: #222; padding-bottom: 4pt; border-bottom: 0.5pt solid #888; }
  .pt > tbody > tr > td { padding: 0; }
  .prun > span:first-child { display: block; }
  .pbar { display: flex; align-items: center; gap: 8pt; margin-top: 2pt; font-size: 9pt; }
  .pbar svg { flex: none; }
  .b10 { fill: #fff; stroke: #000; stroke-width: 0.3; }
  .t10 { stroke: #000; stroke-width: 0.3; }
  .ph { display: flex; justify-content: space-between; align-items: baseline; gap: 6pt 12pt; flex-wrap: wrap; margin: 4pt 0; }
  .ph h2 { font-size: 14pt; margin: 0; }
  .pmeta { margin: 0; display: flex; gap: 10pt; flex-wrap: wrap; font-size: 10pt; }
  .prules { margin: 0 0 4pt; padding-left: 14pt; font-size: 9.5pt; line-height: 1.22; }
  .prules li { margin: 0 0 1pt; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li, .pk > li { margin: 0 0 6pt; padding-top: 4pt; border-top: 1pt solid #000; break-inside: avoid; }
  .pq > li:first-child, .pk > li:first-child { break-inside: auto; }
  .pc, .pk > li > h3 + div { break-inside: avoid; }
  .pq > li:last-child, .pk > li:last-child { margin-bottom: 0; }
  .pq h3, .pk h3 { font-size: 12pt; margin: 0 0 2pt; break-after: avoid; }
  .qtext { margin: 0 0 4pt; max-width: none; line-height: 1.35; }
  .pfig { margin: 2pt 0; }
  .pfig svg.sk { display: block; max-width: none; }
  .pfig figcaption { font-size: 9.5pt; color: #222; }
  .legend { font-size: 10pt; margin: 2pt 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1pt 16pt; max-width: none; }
  .legend li { break-inside: avoid; padding: 0; gap: 5pt; }
  .pkb { display: grid; grid-template-columns: min-content minmax(0, 1fr); gap: 4pt 14pt; align-items: start; }
  .pkb.stack { grid-template-columns: minmax(0, 1fr); }
  .pkb figcaption { min-width: 40mm; }
  .pkb .kans { grid-template-columns: 1fr; }
  .prd { display: grid; grid-template-columns: min-content minmax(0, 1fr); gap: 4pt 14pt; align-items: start; }
  .prd.stack { grid-template-columns: minmax(0, 1fr); }
  .prd:not(.stack) .legend, .prd:not(.stack) .plines { grid-template-columns: 1fr; }
  .pwork { margin: 2pt 0 0; }
  .pwork span { display: block; height: 8mm; border-bottom: 0.5pt solid #555; }
  .legend .kv { color: #222; white-space: nowrap; }
  table.dt { max-width: 150mm; font-size: 10pt; line-height: 1.25; margin: 2pt 0 4pt; }
  .dt th, .dt td { padding: 2pt 4pt; border-bottom: 0.5pt solid #777; }
  .dt thead th { border-bottom: 1pt solid #000; }
  .pdt { display: grid; grid-template-columns: minmax(0, 1fr) 76mm; gap: 0 10pt; align-items: start; }
  .pdt table.dt { margin: 2pt 0; }
  .pdt .dt th, .pdt .dt td { padding: 1.5pt 4pt; }
  .pdt .plines { grid-template-columns: 1fr; }
  .pdt .plines li { padding-top: 3pt; line-height: 1.25; }
  .pdt .plines .pl { min-width: 15mm; }
  .pcap { margin: 4pt 0 0; font-size: 9.5pt; color: #222; max-width: none; }
  .plines { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; column-gap: 18pt; }
  .plines li { display: flex; align-items: flex-end; gap: 6pt; padding: 5pt 0 1pt; }
  .plines .pl { flex: 1 1 auto; border-bottom: 0.75pt solid #000; min-width: 0.8in; height: 11pt; }
  .kans { font-size: 10pt; display: grid; grid-template-columns: 1fr 1fr; gap: 0 18pt; margin: 2pt 0; }
  .kans li { break-inside: avoid; }
  .steps { font-size: 10pt; }
  .steps li { margin: 0.5pt 0; max-width: none; break-inside: avoid; }
  .g1 { stroke: #78a9ae; stroke-width: 0.2; }
  .g5 { stroke: #4f9499; stroke-width: 0.3; }
  .ar.in { fill: #e6dcc0; } .ar.use { fill: #f6c869; } .ar.waste { fill: #c3ced9; }
  .fill { opacity: 1; }
  .ol { stroke: #000; stroke-width: 0.35; }
  .dim { stroke: #000; stroke-width: 0.25; }
  svg.sk .lt { fill: #000; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
