/* Administrative Practice — "Ledger"
 *
 * The form matches the content: this is a set of accounts, so it reads like
 * one. Cream stock, a heavy rule under the masthead, hairline-ruled rows,
 * a serif for every figure, and accounting convention carrying meaning —
 * negatives in oxblood and parenthesized, the cash curve turning green the
 * month it crosses zero.
 *
 * ALL color comes from tokens. Nothing below a token block hardcodes a hex,
 * so the dark theme and the L/D/A toggle come for free.
 */

:root {
  --ground:      #efe9db;
  --surface:     #fbf8f1;
  --surface-2:   #f5efe2;
  --surface-3:   #f0eade;
  --hairline:    #ddd5c4;
  --rule:        #c9bfa8;
  --rule-heavy:  #1a1712;

  --ink:         #1a1712;
  --ink-2:       #4a4336;
  --muted:       #6b6355;

  --accent:      #1c3557;
  --accent-dim:  #122442;
  --accent-ink:  #fbf8f1;
  --accent-tint: #e2e7ef;

  --negative:    #8c2f2f;
  --negative-tint:#f3e3e0;
  --positive:    #2f6b4f;
  --positive-tint:#dfebe2;
  --gold:        #a8801f;
  --gold-tint:   #f2e9d2;

  --shadow:      0 2px 10px rgba(26,23,18,.07);
  --radius:      3px;
  --radius-lg:   4px;

  --sans: -apple-system, system-ui, "Segoe UI", "Helvetica Neue", sans-serif;
  --serif: "Newsreader", Georgia, "Iowan Old Style", serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

:root[data-theme="dark"] {
  --ground:      #17150f;
  --surface:     #201d16;
  --surface-2:   #2a261d;
  --surface-3:   #262319;
  --hairline:    #3a3529;
  --rule:        #4a4335;
  --rule-heavy:  #6b6149;

  --ink:         #f0ebdd;
  --ink-2:       #d3cbb8;
  --muted:       #a89e88;

  --accent:      #7da2d4;
  --accent-dim:  #9cbbe4;
  --accent-ink:  #14120c;
  --accent-tint: #23303f;

  --negative:    #e08070;
  --negative-tint:#3a2620;
  --positive:    #6fbf95;
  --positive-tint:#1f3229;
  --gold:        #d9ab4a;
  --gold-tint:   #332c19;

  --shadow:      0 6px 22px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;            /* the page itself never scrolls */
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  background: var(--ground);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dim); }

/* Every figure is tabular. In a ledger, columns that do not line up are a bug. */
.num, td.num, th.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- boot --- */

/* The app version, pinned to the top-right corner of every screen and inside
   the safe area. Small and muted, but at 4.9:1 or better on every background
   it sits on, in both themes. Never intercepts a tap. */
/* Version badge, top-right: sits in the masthead's 12px top padding, above the L/D/A
   toggle and the icon buttons (which start at 12px), below the notch. Tiny on purpose.
   Measured: --muted is 5.59:1 on the masthead #fbf8f1 and 4.90:1 on the boot/PIN ground
   #efe9db (light); 6.34:1 on #201d16 and 6.88:1 on #17150f (dark). The failure color
   --negative is 7.73:1 / 6.77:1 light and 6.00:1 / 6.51:1 dark (#e08070). */
.app-version {
  position: fixed;
  top: calc(var(--safe-t) + 1px);
  right: calc(var(--safe-r) + 6px);
  z-index: 200;   /* above the boot splash (100), panels (60) and toasts (80) */
  font: 500 9px/9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .2px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.app-version.fail { color: var(--negative); font-weight: 700; }

.boot {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--ground);
  padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b));
}
.boot.is-gone { display: none; }
.boot-inner { width: min(360px, 100%); text-align: center; }
.boot-mark { color: var(--accent); display: flex; justify-content: center; margin-bottom: 14px; }
.boot-title { font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.boot-sub { margin-top: 6px; font-size: 13px; color: var(--muted); }

.pin-gate { margin-top: 20px; display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2vh, 18px);
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pin-gate[hidden] { display: none; }
.pin-dots { display: flex; gap: 10px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots span.on { background: var(--ink); }
.pin-gate.busy .pin-dots span.on { animation: pinpulse .9s ease-in-out infinite; }
@keyframes pinpulse { 50% { opacity: .35; } }
.pin-gate.bad .pin-dots { animation: pinshake .35s; }
@keyframes pinshake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-msg { min-height: 1.3em; font-size: 16px; color: var(--muted); text-align: center; }
.pin-pad { display: grid; --k: clamp(60px, min(22vw, 9.5vh), 84px); grid-template-columns: repeat(3, var(--k)); gap: clamp(8px, 1.6vh, 16px); }
.pin-pad button { height: var(--k); border-radius: 50%; border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); font: 600 clamp(26px, 4vh, 32px)/1 var(--serif);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; padding: 0; }
.pin-pad button:active { background: var(--accent); color: var(--accent-ink); }
.pin-pad button:disabled { opacity: .5; }
.pin-pad .pin-del { border: none; background: transparent; font-size: 24px; }

/* ----------------------------------------------------------------- app --- */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* Explicit, and floored at zero. An `auto` column is sized to the widest
     item's MIN-CONTENT, so the five-item tab bar was stretching the whole app
     to 405px inside a 375px phone. The overflow was then invisible, because
     html{overflow:hidden} clips it and scrollWidth reports no overflow at all
     - the layout looked clean to every page-level check while the last tab and
     the right edge of every card sat off screen. */
  grid-template-columns: minmax(0, 1fr);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}
.app[hidden] { display: none; }
/* Grid and flex children default to min-width:auto, which refuses to shrink
   below their content. Everything that lays out here must be allowed to. */
.app > *, .view-grid > *, .split > *, .statgrid > * { min-width: 0; }

/* ----------------------------------------------------------- masthead --- */

.masthead {
  background: var(--surface);
  padding-top: var(--safe-t);
  border-bottom: 2px solid var(--rule-heavy);
}
.masthead-rule { height: 0; }
.masthead-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px clamp(14px, 3vw, 24px) 6px;
}
.masthead-id { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.masthead-title {
  font-family: var(--serif); font-size: clamp(19px, 3.4vw, 25px); font-weight: 600;
  margin: 0; line-height: 1.05; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.masthead-strap {
  padding: 0 clamp(14px, 3vw, 24px) 10px;
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.masthead-tools { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }

.scenario-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 4px 9px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface-2); color: var(--ink-2); cursor: pointer;
  max-width: 100%; white-space: nowrap; overflow: hidden;
}
.scenario-chip:hover { border-color: var(--accent); color: var(--accent); }

.lda { display: flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.lda button {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 600;
  padding: 6px 9px; cursor: pointer; min-width: 30px;
}
.lda button + button { border-left: 1px solid var(--rule); }
.lda button.is-on { background: var(--accent); color: var(--accent-ink); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 34px; padding: 0;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface-2); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* --------------------------------------------------------------- tabs --- */

.tabs {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr));
  background: var(--surface-3);
  border-top: 2px solid var(--rule-heavy);
  padding-bottom: var(--safe-b);
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 3px 11px;
  min-height: 46px; min-width: 0;
  border-top: 2px solid transparent; margin-top: -2px;
}
.tabs button span {
  font-size: 10.5px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tabs button svg { flex-shrink: 0; }
.tabs button.is-active { color: var(--accent); border-top-color: var(--accent); background: var(--surface); }
.tabs button.is-active span { font-weight: 700; }

/* -------------------------------------------------------------- stage --- */

.stage { min-height: 0; overflow: hidden; position: relative; }
.view { height: 100%; overflow: hidden; }
.view[hidden] { display: none; }

/* Each view lays itself out to fit. Where content genuinely cannot fit, only
   the region marked .scroller scrolls, never the page. */
.view-grid {
  height: 100%;
  display: grid;
  gap: clamp(9px, 1.4vw, 14px);
  padding: clamp(10px, 1.6vw, 16px) clamp(12px, 3vw, 24px);
  min-height: 0;
}
.scroller { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; min-height: 0; }

/* --------------------------------------------------------------- card --- */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.card-title {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin: 0; flex-grow: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-body { padding: 13px 14px; min-height: 0; }
.card-body.flush { padding: 0; }

/* -------------------------------------------------------------- chips --- */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .07em;
  padding: 3px 7px; border-radius: 2px; border: 1px solid currentColor;
  white-space: nowrap; flex-shrink: 0;
}
.chip-measured  { color: var(--positive); }
.chip-specified { color: var(--gold); }
.chip-assumed   { color: var(--negative); }
.chip-recon     { color: var(--accent); }

.flag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600;
  padding: 3px 7px; border-radius: 2px;
}
.flag-warn { background: var(--gold-tint); color: var(--gold); }
.flag-bad  { background: var(--negative-tint); color: var(--negative); }
.flag-ok   { background: var(--positive-tint); color: var(--positive); }

/* -------------------------------------------------------------- stats --- */

.statgrid { display: grid; gap: 9px; }
.stat {
  border: 1px solid var(--hairline); border-radius: var(--radius);
  background: var(--surface-2); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.stat-label { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-family: var(--serif); font-size: clamp(17px, 2.4vw, 23px); font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat-note  { font-size: 11px; color: var(--muted); }
.stat-value.is-neg { color: var(--negative); }
.stat-value.is-pos { color: var(--positive); }

.hero-figure {
  font-family: var(--serif); font-weight: 600; line-height: 1;
  font-size: clamp(30px, 5.6vw, 46px); letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------- table --- */

.table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  min-width: 0;
}
.table-scroll > .ledger-table { min-width: max-content; }
.ledger-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ledger-table th, .ledger-table td { padding: 6px 9px; font-size: 12px; white-space: nowrap; }
.ledger-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--muted);
  font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  text-align: right; border-bottom: 2px solid var(--rule-heavy);
}
.ledger-table thead th:first-child { text-align: left; }
.ledger-table td { text-align: right; border-bottom: 1px solid var(--hairline); color: var(--ink-2); }
.ledger-table td:first-child { text-align: left; color: var(--ink); font-weight: 600; }

/* The ledger is ten columns wide and a phone is not. The table scrolls
   sideways INSIDE its own card, never the page, and the period column stays
   pinned so a row is still identifiable once the money columns are in view. */
.ledger-table th:first-child,
.ledger-table td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--hairline);
}
.ledger-table thead th:first-child { z-index: 3; background: var(--surface-2); }
.ledger-table tbody tr:hover td:first-child { background: var(--surface-2); }
.ledger-table tr.is-total td:first-child { background: var(--surface-3); }
.ledger-table tbody tr:hover td { background: var(--surface-2); }
.ledger-table tr.is-yearend td { border-bottom: 2px solid var(--rule); }
.ledger-table tr.is-total td { font-weight: 700; color: var(--ink); background: var(--surface-3); border-bottom: 2px solid var(--rule-heavy); }
.neg { color: var(--negative); }
.pos { color: var(--positive); }

/* --------------------------------------------------------------- misc --- */

.btn {
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 7px 12px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--rule); background: var(--surface-2); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); border-color: var(--accent-dim); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-sm { font-size: 11.5px; padding: 5px 9px; min-height: 28px; }

.rowline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex-grow: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.tiny { font-size: 10.5px; }
.serif { font-family: var(--serif); }

.note {
  font-size: 12px; color: var(--ink-2); line-height: 1.5;
  border-left: 2px solid var(--rule); padding-left: 10px;
}

/* ------------------------------------------------------------- panels --- */

.panel {
  position: fixed; inset: 0; z-index: 60;
  background: var(--ground);
  display: grid; grid-template-rows: auto 1fr;
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
  padding-left: var(--safe-l); padding-right: var(--safe-r);
}
.panel[hidden] { display: none; }
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px clamp(12px, 3vw, 24px);
  background: var(--surface); border-bottom: 2px solid var(--rule-heavy);
}
.panel-head h2 { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 0; flex-grow: 1; }
.panel-body { overflow-y: auto; overscroll-behavior: contain; padding: clamp(12px, 2vw, 18px) clamp(12px, 3vw, 24px) 28px; }

/* ------------------------------------------------------------ details --- */

details.group {
  border: 1px solid var(--rule); border-radius: var(--radius-lg);
  background: var(--surface); margin-bottom: 10px; overflow: hidden;
}
details.group > summary {
  list-style: none; cursor: pointer;
  padding: 11px 14px; display: flex; align-items: center; gap: 9px;
  font-size: 12.5px; font-weight: 700; color: var(--ink);
  background: var(--surface-2);
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary .caret { transition: transform .15s ease; color: var(--muted); flex-shrink: 0; }
details.group[open] > summary .caret { transform: rotate(90deg); }
details.group > summary .count { font-size: 10.5px; font-weight: 600; color: var(--muted); }
details.group .group-body { padding: 4px 14px 12px; border-top: 1px solid var(--hairline); }

/* ---------------------------------------------------------- parameter --- */

.param { padding: 11px 0; border-bottom: 1px solid var(--hairline); }
.param:last-child { border-bottom: 0; }
.param-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.param-name { font-size: 13px; font-weight: 600; flex-grow: 1; min-width: 120px; }
.param-val {
  font-family: var(--serif); font-size: 15px; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--accent); min-width: 68px; text-align: right;
}
.param-ctl { display: flex; align-items: center; gap: 9px; margin-top: 7px; }
.param-ctl input[type="range"] { flex-grow: 1; accent-color: var(--accent); min-width: 0; }
.param-ctl input[type="number"], .param-ctl select {
  font: inherit; font-size: 12.5px; padding: 5px 7px; width: 96px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface-2); color: var(--ink);
}
.param-note { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin-top: 6px; }
.param.is-dirty { background: var(--accent-tint); margin-inline: -14px; padding-inline: 14px; }
.param.is-loadbearing .param-name::after {
  content: "load-bearing"; margin-left: 7px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em;
  color: var(--negative); border: 1px solid currentColor; border-radius: 2px; padding: 1px 5px;
  vertical-align: 1px;
}

/* ------------------------------------------------------------ tornado --- */

.tornado-row { display: grid; grid-template-columns: minmax(96px, 30%) 1fr; gap: 9px; align-items: center; padding: 5px 0; }
.tornado-label { font-size: 11.5px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; min-width: 0; }
.tornado-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tornado-bar { position: relative; height: 19px; background: var(--surface-2); border-radius: 2px; }
.tornado-bar i { position: absolute; top: 0; bottom: 0; display: block; border-radius: 2px; }
.tornado-bar i.lo { background: var(--negative); opacity: .75; }
.tornado-bar i.hi { background: var(--positive); opacity: .75; }
.tornado-axis { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--rule-heavy); }

/* -------------------------------------------------------------- meter --- */

.meter { height: 8px; background: var(--surface-3); border-radius: 2px; overflow: hidden; border: 1px solid var(--hairline); }
.meter i { display: block; height: 100%; background: var(--positive); }
.meter.is-warn i { background: var(--gold); }
.meter.is-over i { background: var(--negative); }

/* ------------------------------------------------------------- toasts --- */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + var(--safe-b)); z-index: 80;
  display: flex; flex-direction: column; gap: 7px; align-items: center;
  width: min(440px, calc(100vw - 28px)); pointer-events: none;
}
.toast {
  background: var(--rule-heavy); color: var(--ground);
  font-size: 12.5px; padding: 9px 13px; border-radius: var(--radius);
  box-shadow: var(--shadow); width: 100%;
}
:root[data-theme="dark"] .toast { background: var(--surface-2); color: var(--ink); border: 1px solid var(--rule); }
.toast.is-bad { background: var(--negative); color: #fff; }

/* ------------------------------------------------------------ spinner --- */

.busy { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: apSpin .7s linear infinite; }
@keyframes apSpin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------- responsive --- */

/* Phone first: everything stacks, the content region scrolls. */
#view-ledger .view-grid  { grid-template-rows: auto minmax(0, 1fr); }
#view-cash .view-grid    { grid-template-rows: auto minmax(0, 1fr); }
#view-hiring .view-grid  { grid-template-rows: auto minmax(0, 1fr); }
#view-capacity .view-grid{ grid-template-rows: auto auto minmax(0, 1fr); }
#view-case .view-grid    { grid-template-rows: minmax(0, 1fr); }

/* Three stats go in one compact row on a phone rather than wrapping to two,
   which buys back about 100px - enough for the explanatory note under the
   chart to fit whole instead of being cut off. */
.statgrid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.statgrid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 619px) {
  .statgrid-3 .stat { padding: 7px 8px; gap: 1px; }
  .statgrid-3 .stat-label { font-size: 8.5px; letter-spacing: .04em; }
  .statgrid-3 .stat-value { font-size: 15px; }
  .statgrid-3 .stat-note { font-size: 9.5px; line-height: 1.3; }
}

.split { display: grid; gap: clamp(9px, 1.4vw, 14px); min-height: 0; grid-template-columns: 1fr; }

@media (min-width: 620px) {
  .statgrid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .statgrid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .split { grid-template-columns: 1fr 1fr; }
  .split-wide { grid-template-columns: 1.35fr 1fr; }
  .tabs { grid-template-columns: repeat(8, minmax(0, 130px)); justify-content: center; }
}

/* Landscape phone: the masthead strap is the first thing to go. */
@media (max-height: 460px) {
  .masthead-strap { display: none; }
  .masthead-row { padding-top: 7px; padding-bottom: 4px; }
  .tabs button { padding: 6px 3px 7px; min-height: 40px; }
  .tabs button span { font-size: 9.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Chart boxes are measured before they are drawn, so they need a real size
   in the layout before anything is painted into them. */
/* The chart is the only part of a card that gives up space. Without this the
   note below it gets flex-shrunk to less than its own text height and the
   card, which clips, cuts the sentence in half. */
.chart { flex-grow: 1; flex-shrink: 1; min-height: 110px; padding: 10px 12px; }
/* ...but a .scroller must still be allowed to shrink, or it takes its full
   content height and pushes the card past its own box. */
.card > .card-body:not(.chart):not(.scroller) { flex-shrink: 0; }
.card > .card-body.scroller { flex-shrink: 1; flex-grow: 1; }
.chart svg { display: block; width: 100%; height: 100%; }

/* On a short screen the explanatory note under a chart is the first thing
   to go. Clipping it mid-sentence, which is what happened before, reads as
   a rendering bug rather than a deliberate omission. */
/* A note that stops mid-word reads as a rendering bug, so nothing is ever
   half-shown: either the view finds room for it or it is dropped outright. */
@media (max-height: 700px) {
  .note-optional { display: none; }
}

/* Claude's read of a scenario. Prose inside a ledger, so it stays quiet:
   no card of its own, just indented text against a rule. */
.ai-read { font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.ai-read p { margin: 0 0 10px; }
.ai-read p:last-child { margin-bottom: 0; }
.ai-read strong { color: var(--ink); }

/* Plan view — the commitments.
   Prose in two columns, NOT a table: .ledger-table carries min-width:max-content
   so a long sentence in a cell blows the table out to thousands of pixels and
   forces a horizontal scroll to read it. This wraps instead, and stacks below
   the point where two columns stop being readable. */
.commitments { display: grid; gap: 0; }
.commit {
  display: grid;
  grid-template-columns: minmax(180px, 30%) 1fr;
  gap: 4px 18px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  align-items: start;
}
.commit:first-child { border-top: 0; padding-top: 4px; }
.commit-what { font-weight: 600; font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.commit-why { font-size: 12.5px; line-height: 1.6; color: var(--ink-2); }
.commit-why strong { color: var(--ink); }
@media (max-width: 720px) {
  .commit { grid-template-columns: 1fr; gap: 5px; }
}

/* Plan view — the quarter timeline.
   Two renderings of the same figures: the table for a real screen, stacked
   cards for a phone. A ten-column table at 375px is a sideways scroll with
   three words a line, which is not something anyone holds themselves to. */
.plan-cards { display: none; }
.plan-table .qprose,
.plan-table .qnotes { text-align: left; white-space: normal; font-size: 11px; line-height: 1.5; }
.plan-table .qprose { color: var(--muted); }

@media (max-width: 760px) {
  .plan-table { display: none; }
  .plan-cards { display: block; padding: 11px 12px 4px; }
  .qcard {
    border: 1px solid var(--rule);
    border-radius: var(--radius-lg);
    padding: 11px 12px;
    margin-bottom: 9px;
    background: var(--surface);
  }
  .qcard-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
    padding-bottom: 8px; margin-bottom: 9px; border-bottom: 1px solid var(--rule);
  }
  .qcard-head strong { font-size: 15px; }
  .qcard-head span { font-size: 12px; color: var(--muted); }
  .qcard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 14px; }
  .qcell-k {
    font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 1px;
  }
  .qcell-v { font-size: 13.5px; font-variant-numeric: tabular-nums; }
  .qcell-v .tiny { display: block; }
  .qcard-from { margin-top: 10px; font-size: 11.5px; color: var(--muted); }
  .qcard-notes {
    margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--rule);
    font-size: 12px; line-height: 1.55;
  }
  .qcard-notes div { margin-bottom: 2px; }
}

/* Explain — the video player. */
.split-video { display: grid; grid-template-columns: 1fr; gap: 9px; min-height: 0; }
@media (min-width: 1000px) {
  .split-video { grid-template-columns: 1.6fr 1fr; }
}
.vid-stage {
  background: #000; border-radius: var(--radius); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
/* The canvas is a fixed 1280x720 and scales to whatever room it has. The
   aspect-ratio keeps the box the right shape before the canvas has painted. */
.vid-stage canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.vid-bar { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.vid-bar input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.vid-time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.vid-note { margin-top: 9px; font-size: 12px; line-height: 1.55; color: var(--muted); min-height: 32px; }
.vid-note.is-pos { color: var(--positive); }
.vid-note.is-neg { color: var(--negative); }

.ep-list { display: flex; flex-direction: column; }
.ep {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 12px; align-items: start;
  width: 100%; text-align: left; background: transparent; border: 0;
  border-bottom: 1px solid var(--hairline);
  padding: 13px 14px; cursor: pointer; font: inherit; color: var(--ink);
}
.ep:last-child { border-bottom: 0; }
.ep:hover:not(:disabled) { background: var(--surface-2); }
.ep:disabled { opacity: .5; cursor: default; }
.ep[aria-current="true"] { background: var(--accent-tint); }
.ep-n {
  font-size: 12px; font-weight: 700; color: var(--accent-ink); background: var(--accent);
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.ep-t { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ep-t strong { font-size: 14px; }
.ep-t span { font-size: 12px; line-height: 1.5; color: var(--muted); }
.ep-d { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Explain on a phone. The player must stay the largest thing on screen, so the
   episode list moves below it and loses its own scroll region: with seven tabs
   and a 16:9 stage there is not enough height left to give a nested scroller
   anything useful to scroll. */
@media (max-width: 999px) {
  .split-video { grid-template-rows: auto 1fr; }
  .ep { grid-template-columns: 26px 1fr auto; padding: 11px 12px; gap: 10px; }
  .ep-t strong { font-size: 13.5px; }
  .ep-t span { font-size: 11.5px; }
  .vid-note { font-size: 11.5px; }
}


.plan-note {
  margin: 0; padding: 11px 14px; font-size: 12px; line-height: 1.55;
  color: var(--muted); border-bottom: 1px solid var(--hairline);
}
.plan-note strong { color: var(--ink); }

/* Plan — the quarterly bill breakdown. */
.qbill { color: var(--muted); margin-bottom: 5px; }
.qcard-bill { margin-top: 8px; font-size: 11px; line-height: 1.55; color: var(--muted); }

/* Medical records by state: one collapsible row per jurisdiction, so fifty-one
   of them are a list rather than a wall. The statute text stays in the DOM
   while collapsed, which is what lets the search filter reach it. */
.rec-row { border-bottom: 1px solid var(--hairline); }
.rec-row > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 2px; cursor: pointer; list-style: none;
}
.rec-row > summary::-webkit-details-marker { display: none; }
.rec-row > summary:hover { background: var(--surface-2); }
.rec-row .grow { min-width: 0; }
