/* ============================================================================
   TALLY  (#tallyRoot, body.tally-mode). Loaded with the engine (core/app.js
   ENGINES row), so nothing here reaches another chart.
   A clerk's ledger. Each row is an item, each bar one count, drawn thin with a
   rounded end on a hairline baseline; the numbers sit in text ink beside them.
   Under each ledger runs the tape: the same counts in figures, added line by
   line to a double-ruled sum, then stamped against the total the text states.
   The tape printing and the stamp landing are the one memorable thing; both
   stop under reduced motion and in Lite mode.
   Series hues (up to three) and the rise/fall pair are the engine's own, with
   a light and a dark value each, checked for color-blind separation; nothing
   is told by hue alone (labels, arrows, signs and position carry it too).
   ============================================================================ */

@font-face { font-family: "Fraunces"; src: url("../fonts/fraunces.woff2") format("woff2");
             font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../fonts/source-serif-4.woff2") format("woff2");
             font-weight: 200 900; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("../fonts/source-serif-4-italic.woff2") format("woff2");
             font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("../fonts/ibm-plex-sans-400.woff2") format("woff2");
             font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("../fonts/ibm-plex-sans-600.woff2") format("woff2");
             font-weight: 600; font-display: swap; }

body.tally-mode #tallyRoot {
  /* Dark values (dark mode, every palette). */
  --ty-s0: #c4802c;   /* first count: ochre */
  --ty-s1: #4d8bd6;   /* second count: blue */
  --ty-s2: #c065b2;   /* third count: plum */
  --ty-up: #2fa08b;   /* a rise */
  --ty-down: #d0684e; /* a fall */
  --ty-ok: var(--good);
  --ty-no: var(--warn);
  --ty-paper: color-mix(in srgb, var(--bg-1) 88%, #fff 5%);
  --ty-tape: color-mix(in srgb, var(--bg-1) 80%, #fff 7%);
  --ty-rule: var(--hairline);
  --ty-mark: color-mix(in srgb, var(--accent) 34%, transparent);
  --ty-display: "Fraunces", var(--font-display);
  --ty-read: "Source Serif 4", Georgia, "Times New Roman", serif;
  --ty-ui: "IBM Plex Sans", var(--font);
  display: block; position: relative; min-height: 100vh; min-height: 100dvh;
  background: var(--bg-1); color: var(--text);
  font-family: var(--ty-read); font-size: 17px; line-height: 1.6;
  padding: 0 24px 72px; overflow-x: clip;
}
:root[data-mode="light"] body.tally-mode #tallyRoot {
  --ty-s0: #a0560f;
  --ty-s1: #2463b5;
  --ty-s2: #9c3f8f;
  --ty-up: #00866f;
  --ty-down: #b5462c;
  --ty-paper: color-mix(in srgb, var(--bg-1) 55%, #fff 45%);
  --ty-tape: color-mix(in srgb, var(--bg-1) 35%, #fff 65%);
  --ty-mark: color-mix(in srgb, var(--accent) 24%, transparent);
}
/* Parchment's dim text is deepened, as in Berean and Controversy, to clear 4.5:1 on the tape. */
:root[data-mode="light"][data-theme="parchment"] body.tally-mode #tallyRoot { --text-dim: #66584a; }

/* The pill scrolls away with the title rather than sit over the ledger. */
body.tally-mode #tallyRoot #tallyBack { position: absolute; }
body.tally-mode #tallyRoot #tallyCredit { margin-top: 56px; }
body.tally-mode #tallyRoot :focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 3px; }
body.tally-mode #tallyRoot a:not(.lib-link) { color: var(--ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
body.tally-mode #tallyRoot button { font: inherit; color: inherit; }

/* ---- Layout: one column; on wide screens the sheet stands beside it ------ */
body.tally-mode #tallyRoot #tallyMain { max-width: 1240px; margin: 0 auto; padding-top: 76px; }
body.tally-mode #tallyRoot .ty-layout { display: block; }
body.tally-mode #tallyRoot .ty-column { max-width: 800px; margin: 0 auto; min-width: 0; }

/* ---- Title, opening, key ------------------------------------------------ */
body.tally-mode #tallyRoot .ty-eyebrow,
body.tally-mode #tallyRoot .ty-label {
  margin: 0; font: 600 12px/1.3 var(--ty-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--accent-soft);
}
body.tally-mode #tallyRoot .ty-head h1 {
  margin: 8px 0 10px; font: 600 clamp(34px, 6vw, 54px)/1.05 var(--ty-display); color: var(--ink); text-wrap: balance;
}
body.tally-mode #tallyRoot .ty-subtitle { margin: 0; font-size: 20px; line-height: 1.45; color: var(--text-dim); text-wrap: pretty; }
body.tally-mode #tallyRoot .ty-intro { margin: 26px 0 0; }
body.tally-mode #tallyRoot .ty-intro p { margin: 0 0 14px; }
body.tally-mode #tallyRoot .ty-key {
  list-style: none; margin: 22px 0 0; padding: 14px 0; display: grid; gap: 10px;
  border-top: 1px solid var(--ty-rule); border-bottom: 1px solid var(--ty-rule);
  font: 400 15px/1.4 var(--ty-ui);
}
body.tally-mode #tallyRoot .ty-key li { display: grid; grid-template-columns: 28px auto 1fr; align-items: baseline; gap: 4px 10px; }
body.tally-mode #tallyRoot .ty-key-name { font-weight: 600; color: var(--ink); }
body.tally-mode #tallyRoot .ty-key-where { color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-sw {
  display: inline-block; width: 22px; height: 8px; border-radius: 0 4px 4px 0; vertical-align: middle;
  background: var(--ty-s0); flex: none;
}
body.tally-mode #tallyRoot .ty-sw[data-s="1"] { background: var(--ty-s1); }
body.tally-mode #tallyRoot .ty-sw[data-s="2"] { background: var(--ty-s2); }

/* ---- A table ------------------------------------------------------------ */
body.tally-mode #tallyRoot .ty-table { margin-top: 60px; }
body.tally-mode #tallyRoot .ty-table-head h2,
body.tally-mode #tallyRoot .ty-chart-readings h2,
body.tally-mode #tallyRoot .ty-sources h2 {
  margin: 0 0 8px; font: 600 clamp(26px, 4vw, 32px)/1.15 var(--ty-display); color: var(--ink);
}
body.tally-mode #tallyRoot .ty-lead { margin: 0 0 18px; color: var(--text-dim); }

body.tally-mode #tallyRoot .ty-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin: 0 0 12px;
  font: 400 14px/1.3 var(--ty-ui);
}
body.tally-mode #tallyRoot .ty-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; color: var(--text); flex: 1 1 280px; }
body.tally-mode #tallyRoot .ty-legend > span { display: inline-flex; align-items: center; gap: 7px; }
body.tally-mode #tallyRoot .ty-legend-chg { color: var(--text-dim); }
body.tally-mode #tallyRoot [data-dir="up"] > .ty-chg-arrow,
body.tally-mode #tallyRoot .ty-legend-chg [data-dir="up"] { color: var(--ty-up); }
body.tally-mode #tallyRoot [data-dir="down"] > .ty-chg-arrow,
body.tally-mode #tallyRoot .ty-legend-chg [data-dir="down"] { color: var(--ty-down); }
body.tally-mode #tallyRoot .ty-legend-chg [data-dir] { font-weight: 600; }
body.tally-mode #tallyRoot .ty-segs { display: inline-flex; border: 1px solid var(--card-border); border-radius: 999px; padding: 3px; background: var(--ctrl-bg); }
body.tally-mode #tallyRoot .ty-seg {
  min-height: 34px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; cursor: pointer;
  font: 600 14px/1 var(--ty-ui); color: var(--text);
}
body.tally-mode #tallyRoot .ty-seg[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
body.tally-mode #tallyRoot .ty-seg:not([aria-pressed="true"]):hover { background: var(--ctrl-bg-hover); }
body.tally-mode #tallyRoot .ty-order { display: inline-flex; align-items: center; gap: 8px; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-select {
  min-height: 40px; padding: 0 30px 0 12px; border-radius: 10px; border: 1px solid var(--card-border);
  background: var(--ctrl-bg); color: var(--text); font: 400 16px/1 var(--ty-ui); cursor: pointer;
}

/* ---- The ledger ----------------------------------------------------------- */
body.tally-mode #tallyRoot .ty-ledger { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
body.tally-mode #tallyRoot .ty-group {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 16px 0 4px;
  font: 600 12px/1.3 var(--ty-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim);
}
body.tally-mode #tallyRoot .ty-group-sub { font-weight: 400; letter-spacing: .02em; text-transform: none; font-size: 13px; }
body.tally-mode #tallyRoot .ty-ledger:not([data-order="text"]) .ty-group { display: none; }
body.tally-mode #tallyRoot .ty-row {
  display: grid; grid-template-columns: 150px minmax(0, 1fr) 150px; grid-template-areas: "name bars chg";
  align-items: center; column-gap: 14px; padding: 6px 0; border-bottom: 1px solid var(--ty-rule);
  transition: transform .4s cubic-bezier(.3, .7, .2, 1);
}
body.tally-mode #tallyRoot .ty-row-head { display: contents; }
body.tally-mode #tallyRoot .ty-name {
  grid-area: name; justify-self: start; display: inline-flex; align-items: center; gap: 8px; min-height: 36px;
  padding: 0 8px; margin-left: -8px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left;
  font: 600 18px/1.2 var(--ty-display); color: var(--ink);
}
body.tally-mode #tallyRoot .ty-name:hover, body.tally-mode #tallyRoot .ty-name.is-open { background: var(--soft-fill); }
body.tally-mode #tallyRoot .ty-note-chip {
  font: 600 11px/1 var(--ty-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-soft);
  border: 1px solid currentColor; border-radius: 999px; padding: 3px 6px;
}
body.tally-mode #tallyRoot .ty-chg {
  grid-area: chg; justify-self: end; text-align: right; font: 600 15px/1.2 var(--ty-ui); color: var(--text);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
body.tally-mode #tallyRoot .ty-chg-arrow { margin-right: 4px; font-size: 11px; }
body.tally-mode #tallyRoot .ty-chg-p { font-weight: 400; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-chg[data-dir="same"] > .ty-chg-arrow { color: var(--text-dim); }

body.tally-mode #tallyRoot .ty-bars { grid-area: bars; display: grid; gap: 2px; min-width: 0; }
body.tally-mode #tallyRoot .ty-bar {
  display: grid; grid-template-columns: 0 minmax(0, 1fr); align-items: center; min-height: 26px; width: 100%;
  padding: 0; border: 0; border-radius: 6px; background: transparent; cursor: pointer; text-align: left;
}
body.tally-mode #tallyRoot .ty-bar:disabled { cursor: default; }
body.tally-mode #tallyRoot .ty-bar:not(:disabled):hover, body.tally-mode #tallyRoot .ty-bar.is-open { background: var(--soft-fill); }
body.tally-mode #tallyRoot .ty-bar-s { visibility: hidden; overflow: hidden; }
body.tally-mode #tallyRoot .ty-bar-track {
  display: flex; align-items: center; gap: 8px; min-width: 0; height: 100%;
  border-left: 1px solid var(--line);
}
body.tally-mode #tallyRoot .ty-fill {
  display: block; flex: none; height: 12px; border-radius: 0 4px 4px 0; background: var(--ty-s0);
  width: calc((100% - 4.6em) * var(--w, 0) / 100);
}
body.tally-mode #tallyRoot .ty-bar[data-s="1"] .ty-fill { background: var(--ty-s1); }
body.tally-mode #tallyRoot .ty-bar[data-s="2"] .ty-fill { background: var(--ty-s2); }
body.tally-mode #tallyRoot .ty-bar-n { font: 400 14px/1 var(--ty-ui); font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
/* The first row names its bars, so the key is never far (direct labels). */
body.tally-mode #tallyRoot .ty-ledger[data-n="2"] .ty-bar,
body.tally-mode #tallyRoot .ty-ledger[data-n="3"] .ty-bar { grid-template-columns: 48px minmax(0, 1fr); }
body.tally-mode #tallyRoot .ty-ledger[data-n="2"] .ty-row--first .ty-bar-s,
body.tally-mode #tallyRoot .ty-ledger[data-n="3"] .ty-row--first .ty-bar-s {
  visibility: visible; font: 600 12px/1 var(--ty-ui); color: var(--text-dim); padding-right: 6px; text-align: right;
}

/* Change view: one diverging bar per row from a zero line placed where the
   data puts it (the biggest fall reaches the left edge, the biggest rise the
   right), with room at each end for the figure. */
body.tally-mode #tallyRoot .ty-delta {
  --span: calc(100% - 152px); --ax: calc(76px + var(--span) * var(--axis, 50) / 100); --len: calc(var(--span) * var(--w, 0) / 100);
  display: none; grid-area: bars; position: relative; height: 34px; min-width: 0;
}
body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-bars { display: none; }
body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-delta { display: block; }
body.tally-mode #tallyRoot .ty-delta-axis { position: absolute; left: var(--ax); top: 0; bottom: 0; border-left: 1px solid var(--line); }
body.tally-mode #tallyRoot .ty-delta-fill { position: absolute; top: 11px; height: 12px; width: var(--len); }
body.tally-mode #tallyRoot .ty-delta[data-dir="up"] .ty-delta-fill { left: var(--ax); background: var(--ty-up); border-radius: 0 4px 4px 0; }
body.tally-mode #tallyRoot .ty-delta[data-dir="down"] .ty-delta-fill { right: calc(100% - var(--ax)); background: var(--ty-down); border-radius: 4px 0 0 4px; }
body.tally-mode #tallyRoot .ty-delta-n {
  position: absolute; top: 8px; font: 600 14px/18px var(--ty-ui); font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap;
}
body.tally-mode #tallyRoot .ty-delta[data-dir="up"] .ty-delta-n,
body.tally-mode #tallyRoot .ty-delta[data-dir="same"] .ty-delta-n { left: calc(var(--ax) + var(--len) + 6px); }
body.tally-mode #tallyRoot .ty-delta[data-dir="down"] .ty-delta-n { right: calc(100% - var(--ax) + var(--len) + 6px); }
/* In the change view the head's figure would repeat the bar's: keep the percent only. */
body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-chg-v { display: none; }

/* ---- The tape ------------------------------------------------------------- */
body.tally-mode #tallyRoot .ty-tape {
  position: relative; margin: 26px 0 0; padding: 16px 20px 18px 30px; border-radius: 4px 4px 14px 14px;
  background: var(--ty-tape); border: 1px solid var(--card-border);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .12);
}
/* The margin rule of a ledger sheet. */
body.tally-mode #tallyRoot .ty-tape::before {
  content: ""; position: absolute; left: 16px; top: 0; bottom: 0; border-left: 1.5px solid color-mix(in srgb, var(--ty-down) 55%, transparent);
}
body.tally-mode #tallyRoot .ty-tape-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 8px; }
body.tally-mode #tallyRoot .ty-tape-head h3 { margin: 0; font: 600 13px/1.2 var(--ty-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-again {
  min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--accent-soft); background: transparent; cursor: pointer;
  font: 600 14px/1 var(--ty-ui); color: var(--accent-soft);
}
body.tally-mode #tallyRoot .ty-again:hover { background: var(--soft-fill); }
body.tally-mode #tallyRoot .ty-tape-scroll { overflow: visible; }
body.tally-mode #tallyRoot .ty-tape-table {
  width: 100%; border-collapse: collapse; font: 400 15px/1.35 var(--ty-ui); font-variant-numeric: tabular-nums;
}
body.tally-mode #tallyRoot .ty-tape-table caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
body.tally-mode #tallyRoot .ty-tape-table th, body.tally-mode #tallyRoot .ty-tape-table td { padding: 3px 0; vertical-align: baseline; }
body.tally-mode #tallyRoot .ty-tape-table th[scope="row"] { text-align: left; font-weight: 400; color: var(--text); padding-right: 12px; }
body.tally-mode #tallyRoot .ty-tape-table td { text-align: right; padding-left: 14px; white-space: nowrap; color: var(--ink); }
body.tally-mode #tallyRoot .ty-tape-table thead th {
  text-align: right; font: 600 12px/1.3 var(--ty-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim);
  padding-bottom: 6px; border-bottom: 1px solid var(--ty-rule);
}
body.tally-mode #tallyRoot .ty-tape-table thead .ty-sw { width: 14px; margin-right: 6px; }
body.tally-mode #tallyRoot .ty-line { transition: opacity .2s ease, background-color .2s ease; }
body.tally-mode #tallyRoot .ty-line.is-now { background: var(--ty-mark); }
body.tally-mode #tallyRoot .ty-tape:not([data-state="done"]) .ty-line:not(.is-on) { opacity: .28; }
body.tally-mode #tallyRoot .ty-subtotal th[scope="row"] { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); padding-top: 2px; }
body.tally-mode #tallyRoot .ty-subtotal td { border-top: 1px solid var(--ty-rule); color: var(--text); }
body.tally-mode #tallyRoot .ty-subtotal > * { padding-bottom: 6px; }
body.tally-mode #tallyRoot .ty-tape:not([data-state="done"]) .ty-subtotal:not(.is-on) { opacity: .28; }
body.tally-mode #tallyRoot .ty-sub-n { display: block; }
body.tally-mode #tallyRoot .ty-sub-check {
  display: inline-flex; align-items: center; min-height: 28px; margin-top: 2px; padding: 0 8px; border-radius: 999px; cursor: pointer;
  border: 1px solid currentColor; background: transparent; font: 600 12px/1 var(--ty-ui); color: var(--ty-ok);
}
body.tally-mode #tallyRoot .ty-sub-check[data-ok="false"] { color: var(--ty-no); }
/* The sum: under a double rule, as on any ledger. */
body.tally-mode #tallyRoot .ty-added > * { border-top: 3px double var(--text); padding-top: 8px; font-weight: 600; font-size: 18px; color: var(--ink); }
body.tally-mode #tallyRoot .ty-added th[scope="row"] { font-size: 15px; color: var(--ink); font-weight: 600; }
body.tally-mode #tallyRoot .ty-stated th[scope="row"] { color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-stated-btn {
  display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; padding: 4px 6px; margin-right: -6px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; font: 400 15px/1.2 var(--ty-ui); font-variant-numeric: tabular-nums; color: var(--ink);
}
body.tally-mode #tallyRoot .ty-stated-btn:hover, body.tally-mode #tallyRoot .ty-stated-btn.is-open { background: var(--soft-fill); }
body.tally-mode #tallyRoot .ty-stated-ref { font-size: 12px; color: var(--accent-soft); text-decoration: underline; text-underline-offset: 2px; }
body.tally-mode #tallyRoot .ty-nostated { font-size: 13px; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-verdict td { padding-top: 10px; }

/* The stamp. */
body.tally-mode #tallyRoot .ty-stamp {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 5px 10px 5px 8px; border-radius: 6px;
  border: 2px solid var(--ty-ok); color: var(--ty-ok); white-space: normal; text-align: left;
  font: 600 13px/1.15 var(--ty-ui); letter-spacing: .08em; text-transform: uppercase;
  transform: rotate(-3deg); transform-origin: 100% 50%;
  transition: opacity .25s ease, transform .35s cubic-bezier(.2, 1.4, .4, 1);
}
body.tally-mode #tallyRoot .ty-stamp[data-ok="false"] { border-color: var(--ty-no); color: var(--ty-no); }
body.tally-mode #tallyRoot .ty-stamp-mark { font-size: 17px; letter-spacing: 0; }
body.tally-mode #tallyRoot .ty-tape:not([data-state="done"]) .ty-verdict .ty-stamp { opacity: 0; transform: rotate(-3deg) scale(1.3); }
body.tally-mode #tallyRoot .ty-tape:not([data-state="done"]) .ty-sub-check { visibility: hidden; }
body.low-power.tally-mode #tallyRoot .ty-row,
body.low-power.tally-mode #tallyRoot .ty-line,
body.low-power.tally-mode #tallyRoot .ty-stamp { transition: none; }
@media (prefers-reduced-motion: reduce) {
  body.tally-mode #tallyRoot .ty-row, body.tally-mode #tallyRoot .ty-line, body.tally-mode #tallyRoot .ty-stamp { transition: none; }
}

/* ---- Readings and sources ----------------------------------------------- */
body.tally-mode #tallyRoot .ty-readings { display: grid; gap: 16px; margin-top: 22px; }
body.tally-mode #tallyRoot .ty-reading {
  padding: 18px 22px 16px; border-radius: 14px; background: var(--ty-paper); border: 1px solid var(--ty-rule);
}
body.tally-mode #tallyRoot .ty-reading h3 { margin: 0 0 8px; font: 600 21px/1.25 var(--ty-display); color: var(--ink); }
body.tally-mode #tallyRoot .ty-reading-body p { margin: 0 0 12px; }
body.tally-mode #tallyRoot .ty-reading-body strong { color: var(--ink); }
body.tally-mode #tallyRoot .ty-src { margin: 4px 0 0; font: 400 13px/1.5 var(--ty-ui); color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-chart-readings { margin-top: 64px; }
body.tally-mode #tallyRoot .ty-sources { margin-top: 56px; font: 400 14px/1.5 var(--ty-ui); }
body.tally-mode #tallyRoot .ty-sources ul { margin: 0; padding-left: 1.2em; }
body.tally-mode #tallyRoot .ty-sources li { margin: 0 0 6px; }
body.tally-mode #tallyRoot .ty-retrieved, body.tally-mode #tallyRoot .ty-asv { color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-asv { margin: 12px 0 0; }

/* ---- The sheet ------------------------------------------------------------ */
body.tally-mode #tallyRoot .ty-sheet { display: none; }
body.tally-mode #tallyRoot .ty-sheet.is-open {
  display: block; position: fixed; z-index: 40; right: 20px; bottom: 20px; width: min(420px, calc(100vw - 40px));
  max-height: 70vh; max-height: 70dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 0 22px 22px; border-radius: 16px;
  background: linear-gradient(var(--ty-paper), var(--ty-paper)), var(--bg-1);
  border: 1px solid var(--card-border); box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
body.tally-mode #tallyRoot .ty-sheet:focus { outline: none; }
body.tally-mode #tallyRoot .ty-sheet:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: -2px; }
body.tally-mode #tallyRoot .ty-sheet-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; margin: 0 -22px 0; padding: 8px 12px 8px 22px;
  background: linear-gradient(var(--ty-paper), var(--ty-paper)), var(--bg-1); border-bottom: 1px solid var(--ty-rule);
}
body.tally-mode #tallyRoot .ty-sheet-body { padding-top: 10px; }
body.tally-mode #tallyRoot .ty-sheet-close {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border-radius: 50%; border: 1px solid var(--card-border); background: var(--ctrl-bg); cursor: pointer;
  font: 400 24px/1 var(--ty-ui); color: var(--ink);
}
body.tally-mode #tallyRoot .ty-sheet-close:hover { background: var(--ctrl-bg-hover); }
body.tally-mode #tallyRoot .ty-sheet-title { margin: 4px 0 6px; font: 600 28px/1.15 var(--ty-display); color: var(--ink); }
body.tally-mode #tallyRoot .ty-sheet-sub { display: block; margin-top: 4px; font: 400 15px/1.35 var(--ty-ui); color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-sheet-lead { margin: 0; color: var(--text-dim); font-size: 16px; }
body.tally-mode #tallyRoot .ty-sheet-change { margin: 0 0 6px; font: 400 15px/1.4 var(--ty-ui); font-variant-numeric: tabular-nums; color: var(--text); }
body.tally-mode #tallyRoot .ty-sheet-change[data-dir="up"] strong { color: var(--ink); }
body.tally-mode #tallyRoot .ty-sheet-change strong { font-weight: 600; }
body.tally-mode #tallyRoot .ty-sblock { clear: both; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--ty-rule); }
body.tally-mode #tallyRoot .ty-sblock-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; margin: 0; font: 600 14px/1.35 var(--ty-ui); color: var(--ink); }
body.tally-mode #tallyRoot .ty-sblock-where { flex-basis: 100%; font-weight: 400; color: var(--text-dim); padding-left: 30px; }
body.tally-mode #tallyRoot .ty-big { margin: 6px 0 4px; font: 600 34px/1.1 var(--ty-ui); color: var(--ink); }
body.tally-mode #tallyRoot .ty-big-unit { font-size: 16px; font-weight: 400; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-none { margin: 8px 0 0; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-passage { margin: 8px 0 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent); }
body.tally-mode #tallyRoot .ty-verse { margin: 0; font-style: italic; font-size: 17px; }
body.tally-mode #tallyRoot .ty-verse mark { background: var(--ty-mark); color: inherit; font-style: normal; font-weight: 600; padding: 0 .12em; border-radius: 3px; }
body.tally-mode #tallyRoot .ty-passage cite { display: block; margin-top: 4px; font: normal 600 13px/1.3 var(--ty-ui); letter-spacing: .03em; color: var(--accent-soft); }
body.tally-mode #tallyRoot .ty-note { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--ty-rule); }
body.tally-mode #tallyRoot .ty-note p:last-child { margin: 6px 0 0; }
body.tally-mode #tallyRoot .ty-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
body.tally-mode #tallyRoot .ty-sum dt { font: 600 12px/1.3 var(--ty-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-sum dd { margin: 2px 0 0; font: 600 24px/1.2 var(--ty-ui); font-variant-numeric: tabular-nums; color: var(--ink); }
body.tally-mode #tallyRoot .ty-sum dd.ty-sum-none { padding-top: 6px; font: 400 15px/1.4 var(--ty-ui); color: var(--text-dim); }
body.tally-mode #tallyRoot .ty-sheet .ty-stamp { margin: 4px 0 6px; transform: rotate(-2deg); transform-origin: 0 50%; }

/* Wide screens: the sheet is a column of its own beside the ledger, always
   there (it says what to tap until something is). */
@media (min-width: 1180px) {
  body.tally-mode #tallyRoot .ty-layout { display: grid; grid-template-columns: minmax(0, 800px) 380px; justify-content: center; gap: 48px; align-items: start; }
  body.tally-mode #tallyRoot .ty-column { margin: 0; }
  body.tally-mode #tallyRoot .ty-sheet,
  body.tally-mode #tallyRoot .ty-sheet.is-open {
    display: block; position: sticky; top: 24px; right: auto; bottom: auto; width: auto; margin-top: 150px;
    max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow-y: auto;
    padding: 0 22px 22px; border-radius: 16px; background: var(--ty-paper); border: 1px solid var(--card-border);
    box-shadow: none;
  }
  body.tally-mode #tallyRoot .ty-sheet:not(.is-open) .ty-sheet-close { display: none; }
}

/* Touch: every control at least 40px. */
@media (pointer: coarse) {
  body.tally-mode #tallyRoot .ty-name { min-height: 44px; }
  body.tally-mode #tallyRoot .ty-bar { min-height: 40px; }
  body.tally-mode #tallyRoot .ty-seg { min-height: 40px; }
  body.tally-mode #tallyRoot .ty-again { min-height: 44px; }
  body.tally-mode #tallyRoot .ty-sub-check { min-height: 40px; }
  body.tally-mode #tallyRoot .ty-stated-btn { min-height: 44px; justify-content: center; }
  body.tally-mode #tallyRoot .ty-sheet-close { width: 44px; height: 44px; }
}

/* ---- Phone ---------------------------------------------------------------- */
@media (max-width: 640px) {
  body.tally-mode #tallyRoot { padding: 0 16px 56px; font-size: 17px; }
  body.tally-mode #tallyRoot #tallyMain { padding-top: 60px; }
  body.tally-mode #tallyRoot .ty-head h1 { font-size: 36px; }
  body.tally-mode #tallyRoot .ty-subtitle { font-size: 18px; }
  /* The ledger needs the first screen: the key's long form waits in the sheet,
     and the legend line above the ledger names the counts. */
  body.tally-mode #tallyRoot .ty-key { display: none; }
  body.tally-mode #tallyRoot .ty-intro { margin-top: 18px; }
  body.tally-mode #tallyRoot .ty-intro p { margin-bottom: 10px; }
  body.tally-mode #tallyRoot .ty-table { margin-top: 28px; }
  body.tally-mode #tallyRoot .ty-lead { margin-bottom: 12px; font-size: 16px; line-height: 1.5; }
  body.tally-mode #tallyRoot .ty-controls { gap: 10px 12px; }
  /* One row of controls: the switch and the order, the order's label spoken only. */
  body.tally-mode #tallyRoot .ty-legend > .ty-legend-chg { display: none; }
  body.tally-mode #tallyRoot .ty-order > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  body.tally-mode #tallyRoot .ty-order { flex: 1 1 120px; min-width: 0; }
  body.tally-mode #tallyRoot .ty-select { width: 100%; min-width: 0; }
  body.tally-mode #tallyRoot .ty-legend { flex-basis: 100%; }
  /* A row: the name and its change on one line, the bars full width below. */
  body.tally-mode #tallyRoot .ty-row { display: block; padding: 6px 0 8px; }
  body.tally-mode #tallyRoot .ty-row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  body.tally-mode #tallyRoot .ty-chg { font-size: 14px; }
  /* Change view: one line a row, the name beside its bar. */
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; padding: 2px 0; }
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-row-head { display: contents; }
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-name,
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-delta { grid-area: auto; }
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-chg { display: none; }
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-name { font-size: 16px; }
  body.tally-mode #tallyRoot .ty-ledger[data-view="change"] .ty-note-chip { display: none; }
  body.tally-mode #tallyRoot .ty-delta { height: 44px; --span: calc(100% - 116px); --ax: calc(58px + var(--span) * var(--axis, 50) / 100); }
  body.tally-mode #tallyRoot .ty-delta-fill { top: 16px; }
  body.tally-mode #tallyRoot .ty-delta-n { top: 13px; font-size: 13px; }
  body.tally-mode #tallyRoot .ty-sheet-bar { margin: 0 -16px; padding-left: 16px; }
  body.tally-mode #tallyRoot .ty-tape { margin-left: -4px; margin-right: -4px; padding: 14px 12px 16px 24px; }
  body.tally-mode #tallyRoot .ty-tape::before { left: 12px; }
  body.tally-mode #tallyRoot .ty-tape-table { font-size: 15px; }
  body.tally-mode #tallyRoot .ty-tape-table td { padding-left: 10px; }
  body.tally-mode #tallyRoot .ty-stamp { font-size: 12px; letter-spacing: .05em; padding: 4px 8px 4px 6px; }
  body.tally-mode #tallyRoot .ty-reading { padding: 16px 16px 14px; }
  /* The sheet rises from the bottom: full width, at most 70% of the screen. */
  body.tally-mode #tallyRoot .ty-sheet.is-open {
    left: 0; right: 0; bottom: 0; width: auto; border-radius: 16px 16px 0 0; border-bottom: 0;
    padding: 0 16px max(20px, env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0, 0, 0, .3);
  }
  body.tally-mode #tallyRoot .ty-sheet-title { font-size: 25px; }
  body.tally-mode #tallyRoot .ty-big { font-size: 30px; }
  /* Room to scroll the last rows clear of an open sheet. */
  body.tally-mode.ty-sheet-open #tallyRoot #tallyMain { padding-bottom: 50vh; }
}
@media (max-width: 380px) {
  body.tally-mode #tallyRoot .ty-chg-p { display: none; }
  body.tally-mode #tallyRoot .ty-tape-table { font-size: 14px; }
}
/* Sideways phones: the sheet keeps to the lower part of a short screen. */
@media (max-height: 500px) and (max-width: 1179px) {
  body.tally-mode #tallyRoot #tallyMain { padding-top: 60px; }
  body.tally-mode #tallyRoot .ty-sheet.is-open { max-height: 78vh; max-height: 78dvh; }
}
