/* Hydrograph practice: a stream-gauging field sheet. Cool grey-green paper, deep river-teal ink, a staff-gauge tick
   rule under the title, ruled tables with figures in a tabular face, slate-blue rain bars and one rust accent for
   the set code, focus and links. */
:root {
  --bg: #eef2f1; --paper: #fbfcfb; --ink: #13252c; --muted: #44555c; --line: #c4d0cf; --line2: #7d9196;
  --teal: #0d5b70; --accent: #a34417; --accent-ink: #ffffff;
  --rain: #7f9cbc; --s1: #0d5b70; --s2: #a34417; --base: #6a7a80;
  --ok: #1b6431; --ok-soft: #dbeee0; --bad: #a3261b; --bad-soft: #fae3df; --warn: #6c4c00; --warn-soft: #f3e7c6;
  --head: Rockwell, "Roboto Slab", "Zilla Slab", Georgia, "Times New Roman", 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: 2px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a1e; --paper: #172328; --ink: #e2ebea; --muted: #a9bbbe; --line: #2f4148; --line2: #6f8790;
    --teal: #7fc4d6; --accent: #f29a6b; --accent-ink: #22100a;
    --rain: #5f7fa3; --s1: #7fc4d6; --s2: #f29a6b; --base: #93a5ab;
    --ok: #86d29e; --ok-soft: #163020; --bad: #ff9d90; --bad-soft: #3e201c; --warn: #ecc86e; --warn-soft: #362c14;
  }
}
* { 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); }
.wrap { max-width: 1100px; 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; font-weight: 700; color: var(--teal); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* heading, with a staff-gauge rule: ticks every 4 px, a longer one every 20 */
.hero { padding: 20px 0 14px; position: relative; }
.hero::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 10px;
  background: repeating-linear-gradient(90deg, var(--teal) 0 2px, transparent 2px 20px) bottom / 100% 10px no-repeat,
    repeating-linear-gradient(90deg, var(--line2) 0 1px, transparent 1px 4px) bottom / 100% 5px no-repeat; }
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.35rem); margin: 0 0 6px; }
.lede { margin: 0; max-width: 68ch; }
.safety { margin: 6px 0 4px; color: var(--muted); }
.crumbs { margin: 0 0 4px; }
.topics { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 12px 0 0; }
.topics a { display: inline-flex; align-items: center; min-height: 44px; padding: 4px 12px; color: var(--ink); text-decoration: none; border-bottom: 3px solid transparent; }
.topics a:hover { border-bottom-color: var(--line2); }
.topics a[aria-current] { border-bottom-color: var(--teal); font-weight: 700; color: var(--teal); }

/* setup */
.setup { margin: 12px 0 10px; display: grid; gap: 10px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: 700; margin-bottom: 6px; 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: inline-flex; align-items: center; min-height: 44px; padding: 6px 14px; border: 1px solid var(--line2); border-radius: var(--r); background: var(--paper); cursor: pointer; }
.chip input:checked + span { background: var(--teal); color: var(--paper); border-color: var(--teal); font-weight: 700; }
.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; }
label.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 8px; max-width: 100%; }
.btn { font: inherit; font-weight: 600; min-height: 44px; padding: 8px 16px; border: 1px solid var(--ink); border-radius: var(--r); background: var(--paper); color: var(--ink); cursor: pointer; }
.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; padding: 10px 4px; min-height: 44px; color: var(--accent); text-decoration: underline; cursor: pointer; }
.note { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--bad); background: var(--bad-soft); border-radius: var(--r); max-width: 78ch; overflow-wrap: anywhere; }
.note.info { border-color: var(--line2); background: var(--paper); }

/* the sheet */
.sheet { margin: 14px 0 18px; }
.sheet:focus { outline: none; }
.sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 16px; border-bottom: 2px solid var(--teal); padding-bottom: 6px; }
.sheet-head h2 { font-size: 1.3rem; margin: 0; }
.code { font-family: var(--mono); color: var(--accent); letter-spacing: 0.06em; }
.lvname { font-family: var(--sans); font-weight: 400; color: var(--muted); font-size: 1rem; }
.score { margin: 0; font-weight: 600; }
.rules { margin: 10px 0; }
.rules summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.rules ul { margin: 4px 0 8px; padding-left: 1.3em; max-width: 82ch; }
.rules li { margin: 4px 0; }
.qs { list-style: none; margin: 0; padding: 0; }
.q { background: var(--paper); border: 1px solid var(--line); padding: 12px 14px 14px; margin: 16px 0; }
.qhead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; }
.qhead h3 { margin: 0; font-size: 1.2rem; }
.qn { display: inline-block; min-width: 1.6em; margin-right: 6px; color: var(--accent); }
.see { white-space: nowrap; padding: 10px 0; }
.scen { margin: 6px 0 10px; max-width: 74ch; }

/* data and chart side by side when there is room */
.qtop { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px 24px; align-items: start; }
.qtop > * { min-width: 0; }
@media (min-width: 760px) { .qtop.has-fig { grid-template-columns: minmax(0, 1fr) minmax(280px, 420px); } }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16em), 1fr)); gap: 2px 20px; margin: 0 0 10px; }
.facts div { display: flex; flex-wrap: wrap; gap: 0 6px; border-bottom: 1px dotted var(--line); padding: 2px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.ylab { margin: 0 0 2px; color: var(--muted); }
.years { margin: 0 0 10px; }
.example { margin: 8px 0; }
.ytab { border-collapse: collapse; font-variant-numeric: tabular-nums; display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5em, 1fr)); gap: 0 18px; }
.ytab thead { display: none; }
.ytab tbody { display: contents; }
.ytab tr { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted var(--line); padding: 2px 0; }
.ytab th { font-weight: 400; color: var(--muted); text-align: left; }
.ytab td { font-family: var(--mono); }

/* tables */
.twrap { max-width: 100%; margin: 6px 0 10px; }
table.dtab { border-collapse: collapse; font-variant-numeric: tabular-nums; width: auto; min-width: min(100%, 26em); }
table.dtab th, table.dtab td { min-width: 4.5em; }
table.dtab th, table.dtab td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
table.dtab thead th { font-family: var(--sans); font-size: 1rem; font-weight: 700; color: var(--teal); border-bottom: 2px solid var(--teal); white-space: normal; vertical-align: bottom; line-height: 1.25; }
table.dtab tbody th { font-weight: 600; font-family: var(--mono); }
table.dtab td { font-family: var(--mono); }
table.dtab td.e { color: var(--muted); }
table.dtab tfoot th, table.dtab tfoot td { border-bottom: 0; border-top: 1.5px solid var(--ink); }
.kv { font-family: var(--mono); }
/* tables that do not fit their box: each row becomes a block with every value labelled (fit.js) */
@media screen {
  .twrap.rows table, .twrap.rows tbody, .twrap.rows tfoot { display: block; width: 100%; min-width: 0; }
  .twrap.rows thead { display: none; }
  .twrap.rows tr { display: block; padding: 6px 0; border-bottom: 1.5px solid var(--line2); }
  .twrap.rows th, .twrap.rows td { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 0; padding: 2px 0; white-space: normal; }
  .twrap.rows th[data-l]::before, .twrap.rows td[data-l]::before { content: attr(data-l); font-family: var(--sans); color: var(--muted); text-align: left; }
  .twrap.rows th { color: var(--teal); }
  .twrap.rows td.e { display: none; }
  /* tight: short column names and narrow boxes, so a phone keeps the table (fit.js tries this first) */
  .twrap.tight .tleg { display: block; }
  .twrap.tight .hs { display: inline; }
  .twrap.tight .hl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .twrap.tight table.dtab { min-width: 0; }
  .twrap.tight table.dtab th, .twrap.tight table.dtab td { min-width: 0; padding: 4px 2px; }
  .twrap.tight input.cell { width: calc((var(--w, 8) - 2) * 1ch + 12px); padding: 6px 4px; }
  .twrap.tight .mk { min-width: 0.9em; }
}
.hs, .tleg { display: none; }
.tleg { margin: 0 0 4px; color: var(--muted); }

/* answer lines */
.aline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 8px 0; }
.alab { font-weight: 600; min-width: 13em; }
.abox { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.unit { color: var(--muted); }
/* the unit sits right after its box; the mark goes after the unit */
.abox > .cw { display: contents; }
.abox .unit { order: 1; }
.abox .mk { order: 2; }

/* charts */
.chart, .map { display: block; width: 100%; max-width: 420px; height: auto; }
.map { max-width: 320px; }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart .axl { stroke: var(--ink); stroke-width: 1.2; }
.chart .tk, .chart .ax { fill: var(--muted); font: 14px var(--sans); }
.chart .bar { fill: var(--rain); }
.chart .ln { fill: none; stroke-width: 2.4; stroke-linejoin: round; }
.chart .s1 { stroke: var(--s1); }
.chart .s2 { stroke: var(--s2); }
.chart .base { stroke: var(--base); stroke-dasharray: 5 4; }
.chart .lvl { stroke-width: 2; stroke-dasharray: 6 3; }
.map .cell { fill: none; stroke: var(--line2); stroke-width: 1; stroke-dasharray: 4 3; }
.map .basin { fill: none; stroke: var(--teal); stroke-width: 2.4; }
.map .gauge { fill: var(--accent); }
.map .gl2 { fill: var(--ink); font: 700 15px var(--sans); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
.kchart { margin: 6px 0; }

/* boxes and marks */
input.cell { min-height: 44px; padding: 6px 8px; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; max-width: 100%; width: calc(var(--w, 8) * 1ch + 20px); }
.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); }
.cell.is-own { border-color: var(--warn); border-style: dashed; box-shadow: inset 0 0 0 1px var(--warn); }
.cw { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; min-width: 0; }
.cw > .cell { flex: 0 1 auto; min-width: 5ch; }
.mk { flex: none; min-width: 1.6em; font-weight: 700; font-size: 1.1rem; line-height: 1; white-space: nowrap; text-align: left; }
.mn { font-size: 0.8rem; vertical-align: super; margin-left: 1px; }
.mk-right { color: var(--ok); }
.mk-close, .mk-own { color: var(--warn); }
.mk-wrong, .mk-unread { color: var(--bad); }
.fbwrap { margin: 8px 0; }
.fbl { margin: 4px 0; padding: 0 0 0 2.2em; max-width: 82ch; }
.fb { margin: 4px 0; padding: 6px 10px; border-radius: var(--r); background: var(--bad-soft); max-width: 82ch; }
.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: 8px 0 4px; }
.work { margin-top: 8px; border-top: 1px solid var(--line); }
.work summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.keyfig { padding: 4px 0 6px; }
.steps { margin: 10px 0 0; padding-left: 1.4em; }
.steps li { margin: 4px 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.sheet-foot { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 8px; }
.confirm { flex-basis: 100%; margin: 0; padding: 8px 10px; background: var(--warn-soft); border-radius: var(--r); }
.save-hint { margin: 0; color: var(--muted); }

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

/* text below the tool */
.content { max-width: 75ch; padding-bottom: 24px; }
.content h2 { font-size: 1.35rem; margin: 28px 0 8px; }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; font-weight: 600; padding: 10px 0; min-height: 44px; }
.faq p { margin: 0 0 12px; }
.sources { color: var(--muted); }
.sources a { overflow-wrap: anywhere; }

/* footer */
footer { border-top: 2px solid var(--teal); padding: 18px 0 28px; background: var(--bg); }
.indep { margin: 0 0 10px; color: var(--muted); max-width: 80ch; }
.sb-footer p { margin: 6px 0; }
.sb-more { line-height: 1.8; }
.sb-privacy, .sb-credit { color: var(--muted); }

.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: 520px) {
  .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; }
  .q { padding: 10px 10px 12px; margin: 12px -6px; }
  .alab { min-width: 0; flex-basis: 100%; }
  .topics a { padding: 4px 8px; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

.print-root { display: none; }

/* ---------- print ---------- */
@page { margin: 12mm; }
@media print {
  :root { --paper: #fff; --ink: #000; --muted: #333; --line: #999; --line2: #555; --teal: #000; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  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: 9.5pt; color: #333; padding-bottom: 4pt; border-bottom: 0.5pt solid #888; text-align: left; font-weight: 400; }
  .psafe { display: block; font-weight: 700; color: #000; }
  .pt > tbody > tr > td { padding: 0; }
  .ph { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4pt 16pt; border-bottom: 1.5pt solid #000; margin: 6pt 0; }
  .ph h2 { font-size: 15pt; margin: 0 0 3pt; }
  .pmeta { display: flex; gap: 16pt; margin: 0; }
  .prules { margin: 4pt 0 6pt; padding-left: 14pt; font-size: 10pt; }
  .prules li { margin: 1pt 0; }
  .pq, .pk { list-style: none; margin: 0; padding: 0; }
  .pq > li, .pk > li { break-inside: avoid; border-top: 1pt solid #000; padding: 3pt 0 4pt; margin-top: 3pt; }
  .pq h3, .pk h3 { font-size: 11.5pt; margin: 0 0 2pt; color: #000; }
  .scen { margin: 2pt 0 4pt; }
  .qtop.has-fig { display: grid; grid-template-columns: minmax(0, 1fr) 52mm; gap: 8pt; }
  .pmap { width: 52mm; }
  .map .cell { stroke: #555; } .map .basin { stroke: #000; } .map .gauge { fill: #000; } .map .gl2 { fill: #000; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12pt; margin: 0 0 3pt; font-size: 10pt; }
  .facts div { border-bottom: 0; padding: 0; }
  .ytab { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0 10pt; font-size: 10pt; }
  .ytab tr { border-bottom: 0.5pt dotted #999; padding: 0; }
  .twrap { margin: 2pt 0 4pt; }
  table.dtab, table.dtab.narrow { width: auto; min-width: 0; margin-left: 0.5pt; }
  table.dtab th, table.dtab td { line-height: 1.2; padding: 1.5pt 6pt; border-bottom: 0.5pt solid #999; font-size: 10pt; }
  table.dtab thead th { font-size: 9.5pt; border-bottom: 1pt solid #000; color: #000; max-width: 30mm; }
  table.dtab tfoot th, table.dtab tfoot td { border-top: 1pt solid #000; }
  .pblank { display: inline-block; border-bottom: 0.75pt solid #000; height: 13pt; vertical-align: bottom; }
  .aline { margin: 2pt 0; gap: 2pt 8pt; }
  .alab { min-width: 50mm; }
  .unit { font-size: 10pt; white-space: nowrap; }
  .keyfig { padding: 0; }
  .steps { margin: 4pt 0 0; font-size: 10pt; }
  .steps li { margin: 1pt 0; }
  /* Muskingum: the routing table beside the data and coefficients, so two reaches share a page */
  .pq > li.t-route .qdata, .pk > li.t-route .keyfig { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 14mm; align-items: start; }
  .pq > li.t-route .qdata > *, .pk > li.t-route .keyfig > * { grid-column: 1; }
  .pq > li.t-route .qdata > .twrap, .pk > li.t-route .keyfig > .twrap { grid-column: 2; grid-row: 1 / span 6; margin-top: 0; }
  .pk > li.t-route .keyfig > .steps { grid-column: 1 / -1; }
}
