/* The Risk Book: teaching-instrument genre, third sibling.
 * Neutral paper (Rate Book is warm, Star Book is cool), navy structure,
 * one berry accent reserved for the score and its accumulation.
 * Palette validated 2026-08-14 with the dataviz validator (dev/palette.html):
 * the berry ramp passes ordinal checks on card and paper, navy+berry passes
 * categorical adjacency, and --berry itself is text-safe (7.13:1 on paper),
 * with --berry-ink deeper still for emphasis text. */

:root {
  --paper: #f5f4f6;
  --card: #ffffff;
  --ink: #1b1d24;
  --ink-soft: #474b56;
  --ink-faint: #63666f;    /* 4.9 on paper, 5.4 on card */
  --navy: #27548c;
  --berry: #8a3355;        /* accent: strokes, fills, and value text (7.1 paper) */
  --berry-ink: #6d2440;    /* emphasis text (9.7 paper) */
  --berry-ramp-1: #d698ae; /* stack: demographic-adjacent lightest step */
  --berry-ramp-2: #b86487; /* stack: condition steps */
  --berry-ramp-3: #8a3355; /* stack: condition steps, darker */
  --berry-ramp-4: #5e1f3a; /* stack: interactions */
  --berry-tint: #f7e9ee;
  --berry-edge: #dfb7c6;
  --zero: #5c5f66;         /* pays-nothing / suppressed state, never for identity.
                              Deepened from #85888f in the 2026-08-15 design pass:
                              at #85888f it measured 3.55 as text on card and 2.77
                              under the selected chip's code text. Same lesson as
                              Star Book's gold: a color that works as a state fill
                              does not automatically work as text. */
  --rule: #e0dfe3;
  --spine-bg: #241b22;
  --spine-label: #a396a0;
  --spine-value: #eeb7cc;
  --spine-money: #f5d9e3;
  --spine-op: #948791;
  --spine-context: #c9bcc5;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(39, 84, 140, 0.07), transparent 60%),
    radial-gradient(700px 380px at 90% 0%, rgba(138, 51, 85, 0.06), transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: "Public Sans", system-ui, sans-serif;
  line-height: 1.6;
}

.mono { font-family: "IBM Plex Mono", monospace; }

a { color: var(--navy); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--berry-ink); }

:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  border-radius: 2px;
}

.back {
  position: absolute;
  top: 18px;
  left: 22px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: var(--ink-faint);
  text-decoration: none;
}
.back:hover { color: var(--ink); }

/* ---------- masthead ---------- */

.masthead {
  max-width: 860px;
  margin: 0 auto;
  padding: 84px 24px 8px;
}

.wordmark {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.14em;
  color: var(--berry-ink);
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.risk-flourish { width: 140px; height: 26px; flex: none; }
.rf-seg { fill: var(--berry); opacity: 0; animation: rf-rise 0.5s ease-out forwards; }
.rf-1 { fill: var(--berry-ramp-1); animation-delay: 0.15s; }
.rf-2 { fill: var(--berry-ramp-2); animation-delay: 0.35s; }
.rf-3 { fill: var(--berry-ramp-3); animation-delay: 0.55s; }
.rf-times {
  stroke: var(--navy);
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
  opacity: 0;
  animation: rf-rise 0.4s ease-out 0.8s forwards;
}
.rf-one {
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
  font-weight: 600;
  fill: var(--navy);
  opacity: 0;
  animation: rf-rise 0.4s ease-out 0.95s forwards;
}
@keyframes rf-rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rf-seg, .rf-times, .rf-one { animation: none; opacity: 1; }
}

.masthead h1 {
  font-size: clamp(30px, 5.5vw, 44px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.12;
  margin: 0 0 14px;
}

.lede {
  font-size: 17px;
  color: var(--ink-soft);
  max-width: 720px;
  margin: 0 0 14px;
}

.meta-line {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin: 0 0 18px;
}

/* ---------- the spine ---------- */

.spine {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--spine-bg);
  padding: 12px 24px 10px;
  box-shadow: 0 2px 14px rgba(27, 29, 36, 0.28);
}

.spine-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.flow-step { display: flex; flex-direction: column; min-width: 74px; }

.flow-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--spine-label);
}

.flow-value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 20px;
  font-weight: 600;
  color: var(--spine-value);
  font-variant-numeric: tabular-nums;
}
.flow-money { color: var(--spine-money); }

.flow-op {
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
  color: var(--spine-op);
  white-space: nowrap;
}
.flow-op-num { font-size: 12px; }

.spine-context {
  max-width: 860px;
  margin: 6px auto 0;
  font-size: 13px;
  color: var(--spine-context);
}

/* ---------- chapters ---------- */

main { max-width: 860px; margin: 0 auto; padding: 10px 24px 40px; }

.chapter { margin: 46px 0; }

.ch-kicker {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--berry-ink);
  margin: 0 0 4px;
}

.chapter h2 {
  font-size: clamp(22px, 3.6vw, 30px);
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
}

.chapter p { max-width: 720px; }

/* ---------- panels ---------- */

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 18px 20px;
  margin: 20px 0;
  box-shadow: 0 1px 2px rgba(27, 29, 36, 0.04);
}

.panel-title {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  margin: 0 0 12px;
}

.panel-sub { font-size: 14px; color: var(--ink-soft); margin: -6px 0 12px; }

.callout {
  background: var(--berry-tint);
  border: 1px solid var(--berry-edge);
  border-radius: 12px;
  padding: 14px 18px;
  margin: 20px 0;
  max-width: 720px;
}
.callout p { margin: 0; font-size: 15px; }
.callout-title {
  font-weight: 700;
  margin: 0 0 4px !important;
}

/* ---------- controls ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 14px 22px; }

.ctl { display: flex; flex-direction: column; gap: 5px; border: 0; padding: 0; margin: 0; }

.ctl-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.ctl input[type="number"] {
  width: 76px;
  font: 600 16px "IBM Plex Mono", monospace;
  padding: 7px 9px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.seg { flex-direction: column; }
.seg legend { padding: 0; margin-bottom: 5px; }
.seg { display: flex; }
.seg > label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.seg > label + label { margin-top: 4px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink-soft);
  min-width: 64px;
  text-align: center;
}
.seg input:checked + span {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.seg input:focus-visible + span {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

.ctl-hint {
  font-size: 13px;
  color: var(--ink-faint);
  margin: 10px 0 0;
  min-height: 1.2em;
}

.base-readout { border-top: 1px solid var(--rule); margin-top: 14px; padding-top: 12px; }
.base-segment { font-size: 13px; color: var(--ink-faint); margin: 0 0 4px; }
.base-line { font-size: 16px; margin: 0 0 4px; }
.score-ink {
  font-family: "IBM Plex Mono", monospace;
  color: var(--berry-ink);
  font-variant-numeric: tabular-nums;
}
.base-note { font-size: 13px; color: var(--ink-faint); margin: 6px 0 0; max-width: 680px; }

/* ---------- diagnosis picker ---------- */

.dx-group { margin: 0 0 12px; }
.dx-group-name {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin: 0 0 6px;
}
.dx-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.dx-chip {
  font: 600 13px "Public Sans", system-ui, sans-serif;
  padding: 7px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
  min-height: 34px;
}
.dx-chip .dx-code {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
  font-size: 11px;
  color: var(--ink-faint);
  margin-left: 6px;
}
.dx-chip:hover { border-color: var(--berry); }
.dx-chip[aria-pressed="true"] {
  background: var(--berry);
  border-color: var(--berry);
  color: #fff;
}
.dx-chip[aria-pressed="true"] .dx-code { color: #f0d3de; }
.dx-chip.pays-nothing[aria-pressed="true"] {
  background: var(--zero);
  border-color: var(--zero);
}
.dx-chip.pays-nothing[aria-pressed="true"] .dx-code { color: #e6e6e9; }

.chip-demo {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 7px;
}
.pays-nothing-demo { background: #ececee; color: #55585f; border: 1px solid #d4d4d8; }

/* ---------- the chain ---------- */

.chain { border-top: 1px solid var(--rule); margin-top: 16px; padding-top: 14px; }
.chain-list { list-style: none; margin: 0; padding: 0; }
.chain-list li {
  font-size: 14px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
}
.chain-list li:last-child { border-bottom: 0; }
.chain-code { font-family: "IBM Plex Mono", monospace; font-size: 13px; color: var(--ink); font-weight: 600; }
.chain-arrow { color: var(--ink-faint); }
.chain-out { color: var(--ink-soft); }
.chain-zero { color: var(--zero); }
.chain-zero .chain-badge { background: #ececee; color: #55585f; }
.chain-suppressed { color: var(--zero); }
.chain-badge {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 8px;
  background: var(--berry-tint);
  color: var(--berry-ink);
  border: 1px solid var(--berry-edge);
}
.chain-coeff { font-family: "IBM Plex Mono", monospace; color: var(--berry-ink); font-weight: 600; margin-left: auto; }
.chain-coeff.chain-zero-coeff { color: var(--zero); font-weight: 500; text-decoration: line-through; }
.chain-empty { color: var(--ink-faint); font-size: 14px; padding: 6px 0; }

/* ---------- the stack figure ---------- */

.stack-figure {
  height: 40px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--rule);
  overflow: hidden;
  display: flex;
  padding: 4px;
  gap: 2px; /* the dataviz 2px surface gap between stacked fills */
}
.stack-seg { border-radius: 4px; min-width: 3px; transition: flex-grow 0.35s ease; }
.stack-seg.s-demo { background: var(--navy); }
.stack-seg.s-hcc { background: var(--berry-ramp-2); }
.stack-seg.s-hcc.s-alt { background: var(--berry-ramp-3); }
.stack-seg.s-inter { background: var(--berry-ramp-4); }
.stack-seg.s-count { background: var(--berry-ramp-1); }
@media (prefers-reduced-motion: reduce) { .stack-seg { transition: none; } }

.stack-legendless { list-style: none; margin: 12px 0 0; padding: 0; }
.stack-legendless li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 14px;
  padding: 4px 0;
}
.stack-swatch {
  width: 10px; height: 10px; border-radius: 3px; flex: none;
  position: relative; top: 1px;
}
.stack-val {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  color: var(--berry-ink);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.stack-total {
  border-top: 1px solid var(--rule);
  margin-top: 4px;
  padding-top: 8px !important;
  font-weight: 700;
}

/* ---------- chapter 3 arithmetic ---------- */

.arith-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.arith-step { display: flex; flex-direction: column; }
.arith-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}
.arith-value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 26px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.arith-final .arith-value { color: var(--berry-ink); }
.arith-op {
  font-family: "IBM Plex Mono", monospace;
  font-size: 15px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
}
.arith-why { font-size: 10px; color: var(--ink-faint); letter-spacing: 0.05em; }

/* ---------- chapter 4 county figure ---------- */

.county-ctl { max-width: 420px; margin-bottom: 12px; }
.county-ctl select {
  font: 600 14px "Public Sans", system-ui, sans-serif;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  max-width: 100%;
}

.county-figure { margin-top: 14px; }
.county-row {
  display: grid;
  grid-template-columns: 170px 1fr 84px;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  font-size: 13px;
}
.county-name { color: var(--ink-soft); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.county-row.is-current .county-name { color: var(--berry-ink); font-weight: 700; }
.county-bar-track { height: 16px; display: flex; }
.county-bar {
  background: var(--berry-ramp-2);
  border-radius: 0 4px 4px 0; /* rounded data end, flat baseline end */
  min-width: 2px;
  transition: width 0.35s ease;
}
.county-row.is-current .county-bar { background: var(--berry-ramp-4); }
.county-val {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.county-row.is-current .county-val { color: var(--berry-ink); }
@media (prefers-reduced-motion: reduce) { .county-bar { transition: none; } }

/* ---------- sources ---------- */

.source-list { max-width: 720px; padding-left: 20px; }
.source-list li { margin: 8px 0; font-size: 14px; color: var(--ink-soft); overflow-wrap: anywhere; }

.foot {
  text-align: center;
  padding: 26px 0 34px;
  font-size: 13px;
  color: var(--ink-faint);
}

/* Touch targets: Star Book's 375px audit found its toggle at 31px against the
 * 44px guideline. Same fix here, before it ships rather than after. */
@media (pointer: coarse) {
  .dx-chip { min-height: 44px; padding: 10px 14px; }
  .seg span { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .ctl input[type="number"] { min-height: 44px; }
  .county-ctl select { min-height: 44px; }
}

/* ---------- small screens ---------- */

@media (max-width: 560px) {
  .spine { position: static; box-shadow: none; border-bottom: 1px solid var(--rule); }
  .flow-value { font-size: 17px; }
  .county-row { grid-template-columns: 110px 1fr 74px; }
  .back { position: static; display: inline-block; margin: 14px 0 0 22px; }
  .masthead { padding-top: 20px; }
}
