/* Risk, everywhere — a cool instrument ground, a warm signal.
   Light is the default; dark is redefined twice so the toggle wins both ways. */
:root {
  --paper: #eef1f4;
  --paper-raised: #f8fafb;
  --paper-sunk: #e2e7ec;
  --ink: #11171d;
  --ink-soft: #38434e;
  --ink-faint: #454f59;
  --line: #ccd5dd;
  --line-strong: #a3b1bd;
  --accent: #9c2a1c;
  --accent-text: #8a2415;
  --accent-tint: #f6e2de;
  --focus: #1d5c86;
  /* the record's own silence: never a colour on the answer scale */
  --unrated: #b7c1ca;
  --unrated-ink: #3e4954;
  --uncoded: #d5dce2;
  --uncoded-ink: #454f59;
  /* five-step answer ramp, pale to intense */
  --c1: #dfe7ec;
  --c2: #f0c88f;
  --c3: #dd9245;
  --c4: #b8541f;
  --c5: #6d1f10;
  --cool: #1d5c86;
  --cool-soft: #7aa8c4;
  --map-land: #dbe2e8;
  --map-line: #b3c0cb;
  --shadow: 0 18px 40px -22px rgba(17, 23, 29, 0.34);
  --measure: 40rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1317;
    --paper-raised: #161d23;
    --paper-sunk: #090d10;
    --ink: #eef3f7;
    --ink-soft: #c3ced8;
    --ink-faint: #a4b1bd;
    --line: #29343d;
    --line-strong: #435159;
    --accent: #f0977a;
    --accent-text: #f4a98e;
    --accent-tint: #3a1d15;
    --focus: #8ec5e6;
    --unrated: #3b4750;
    --unrated-ink: #a4b1bd;
    --uncoded: #232c33;
    --uncoded-ink: #a4b1bd;
    --c1: #2b353d;
    --c2: #6a4526;
    --c3: #a86c33;
    --c4: #d99552;
    --c5: #f6c391;
    --cool: #8ec5e6;
    --cool-soft: #3f6d8a;
    --map-land: #1b232a;
    --map-line: #364149;
    --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.75);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1317;
  --paper-raised: #161d23;
  --paper-sunk: #090d10;
  --ink: #eef3f7;
  --ink-soft: #c3ced8;
  --ink-faint: #a4b1bd;
  --line: #29343d;
  --line-strong: #435159;
  --accent: #f0977a;
  --accent-text: #f4a98e;
  --accent-tint: #3a1d15;
  --focus: #8ec5e6;
  --unrated: #3b4750;
  --unrated-ink: #a4b1bd;
  --uncoded: #232c33;
  --uncoded-ink: #a4b1bd;
  --c1: #2b353d;
  --c2: #6a4526;
  --c3: #a86c33;
  --c4: #d99552;
  --c5: #f6c391;
  --cool: #8ec5e6;
  --cool-soft: #3f6d8a;
  --map-land: #1b232a;
  --map-line: #364149;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.75);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  font-size: 1.0625rem;
  line-height: 1.62;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, h4 { line-height: 1.16; font-weight: 600; letter-spacing: -0.008em; }
a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
p { margin: 0 0 1rem; }
.muted { color: var(--ink-faint); }
.tnum { font-variant-numeric: tabular-nums; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.88em; }
figure { margin: 1.6rem 0; }
figcaption { font-size: 0.875rem; color: var(--ink-faint); line-height: 1.5; margin-top: 0.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--ink-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
summary { cursor: pointer; color: var(--ink-soft); font-size: 0.95rem; padding: 0.3rem 0; }
summary:hover { color: var(--ink); }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

/* ---------------------------------------------------------------- layout */
.page {
  display: grid;
  grid-template-columns: [full-start] minmax(1.1rem, 1fr) [main-start] minmax(0, var(--measure)) [main-end] minmax(1.1rem, 1fr) [full-end];
}
.page > * { grid-column: main; }
.page > .full { grid-column: full; }

.masthead {
  grid-column: full;
  padding: 0.9rem 1.2rem 0;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  font-size: 0.875rem; color: var(--ink-faint);
}
.masthead a { color: var(--ink-faint); text-decoration: none; }
.masthead a:hover { color: var(--ink); text-decoration: underline; }
.mast-tools { display: flex; align-items: center; gap: 0.5rem; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; padding: 0; color: var(--ink-soft);
  background: var(--paper-raised); border: 1px solid var(--line-strong);
  border-radius: 999px; cursor: pointer; flex: none;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-soft); }
.lang { border: 1px solid var(--line-strong); border-radius: 999px; padding: 0.24rem 0.7rem; background: var(--paper-raised); }

/* ---------------------------------------------------------------- hero */
.hero { padding: 2.6rem 0 0; }
.kicker { font-size: 0.8125rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-text); margin: 0 0 0.8rem; font-weight: 600; }
h1 { font-size: clamp(2.3rem, 7vw, 3.6rem); margin: 0; letter-spacing: -0.022em; }
.deck { font-size: clamp(1.15rem, 2.2vw, 1.4rem); line-height: 1.46; color: var(--ink-soft); margin: 1.1rem 0 0; max-width: 33em; }
.byline { font-size: 0.875rem; color: var(--ink-faint); margin-top: 1.5rem; }

.leads { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 2.2rem 0 0; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); }
.lead { background: var(--paper-raised); padding: 1rem 1.05rem; }
.lead b { display: block; font-size: 1.75rem; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; color: var(--accent-text); }
.lead span { display: block; font-size: 0.875rem; color: var(--ink-soft); margin-top: 0.35rem; line-height: 1.4; }

/* ---------------------------------------------------------------- contents */
.toc { margin: 2.6rem 0 0; padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-raised); }
.toc h2 { font-size: 0.8125rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 0.7rem; }
.toc ol { margin: 0; padding-left: 1.15rem; columns: 2; column-gap: 1.6rem; font-size: 0.9375rem; }
.toc li { margin: 0 0 0.3rem; break-inside: avoid; }
@media (max-width: 34rem) { .toc ol { columns: 1; } }

/* ---------------------------------------------------------------- parts and questions */
.part { margin-top: 4.2rem; padding-top: 1.1rem; border-top: 2px solid var(--ink); }
.part-n { font-size: 0.8125rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-text); font-weight: 600; }
.part h2 { font-size: clamp(1.6rem, 4vw, 2.1rem); margin: 0.35rem 0 0; }
.part-intro { margin-top: 0.9rem; color: var(--ink-soft); }

.q { margin-top: 2.6rem; scroll-margin-top: 1.5rem; }
.q h3 { font-size: 1.28rem; margin: 0; }
.q .var { font-size: 0.8125rem; color: var(--ink-faint); margin: 0.3rem 0 0.85rem; }
.q .var a { color: var(--ink-faint); }
.q .reading { margin: 0 0 1rem; }
.q .limit { font-size: 0.9375rem; color: var(--ink-faint); border-left: 2px solid var(--line-strong); padding: 0.1rem 0 0.1rem 0.8rem; margin: 0.9rem 0 0; }

/* ---------------------------------------------------------------- strips */
.strip-wrap { margin: 0.9rem 0 0; }
.strip { width: 100%; height: auto; display: block; }
.strip-status { font-size: 0.8125rem; color: var(--ink-faint); margin: 0.45rem 0 0; }
.strip-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; margin-top: 0.2rem; }
.counts { margin-top: 0.9rem; }
.counts table { font-size: 0.9rem; }
.swatch { display: inline-block; width: 0.72rem; height: 0.72rem; border-radius: 2px; margin-right: 0.45rem; vertical-align: -1px; border: 1px solid rgba(0,0,0,0.16); }
:root[data-theme="dark"] .swatch, :root:not([data-theme="light"]) .swatch { border-color: rgba(255,255,255,0.16); }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .swatch { border-color: rgba(0,0,0,0.16); } }
.row-unrated td, .row-uncoded td { color: var(--ink-faint); }

/* ---------------------------------------------------------------- panels */
.panel { margin: 2rem 0 0; padding: 1.15rem 1.2rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-raised); }
.panel h3 { margin: 0 0 0.55rem; font-size: 1.12rem; }
.panel p:last-child { margin-bottom: 0; }
.panel.flag { border-left: 3px solid var(--accent); }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.9rem 0; }
.controls label { font-size: 0.875rem; color: var(--ink-soft); }
select, input[type="search"], input[type="text"] {
  font: inherit; font-size: 0.9375rem; padding: 0.34rem 0.55rem;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 6px;
}
input[type="range"] { accent-color: var(--accent); }
button.chip {
  font: inherit; font-size: 0.875rem; padding: 0.28rem 0.7rem; cursor: pointer;
  background: var(--paper); color: var(--ink-soft);
  border: 1px solid var(--line-strong); border-radius: 999px;
}
button.chip[aria-pressed="true"] { background: var(--accent-tint); color: var(--accent-text); border-color: var(--accent); }

/* ---------------------------------------------------------------- grids */
.grid-table { font-size: 0.875rem; }
.grid-table td.cell { text-align: center; font-variant-numeric: tabular-nums; padding: 0.45rem 0.3rem; }
.scroll-x { overflow-x: auto; }

/* ---------------------------------------------------------------- society records */
.records { margin-top: 1.2rem; }
.rec { border-bottom: 1px solid var(--line); }
.rec > summary { display: flex; justify-content: space-between; gap: 1rem; padding: 0.55rem 0; font-size: 1rem; color: var(--ink); }
.rec > summary .yr { color: var(--ink-faint); font-variant-numeric: tabular-nums; font-size: 0.9rem; flex: none; }
.rec-body { padding: 0.3rem 0 1rem; }
.rec-body dl { display: grid; grid-template-columns: minmax(9rem, auto) 1fr; gap: 0.25rem 0.9rem; margin: 0; font-size: 0.9375rem; }
.rec-body dt { color: var(--ink-faint); }
.rec-body dd { margin: 0; }

/* ---------------------------------------------------------------- cases */
.case { margin-top: 2rem; padding-top: 1.1rem; border-top: 1px solid var(--line); }
.case h3 { font-size: 1.15rem; margin: 0 0 0.15rem; }
.case .where { font-size: 0.8125rem; color: var(--ink-faint); margin: 0 0 0.7rem; }
.case .complicates { margin-top: 0.7rem; padding-left: 0.8rem; border-left: 2px solid var(--cool-soft); }
.case .complicates b { color: var(--cool); font-size: 0.9rem; }

/* ---------------------------------------------------------------- footer */
footer { margin: 5rem 0 3rem; padding-top: 1.4rem; border-top: 2px solid var(--ink); font-size: 0.9375rem; color: var(--ink-faint); }
footer a { color: var(--ink-faint); }
footer ul { list-style: none; padding: 0; margin: 0.7rem 0 0; display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; }

.to-top { position: fixed; right: 1rem; bottom: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 20; box-shadow: var(--shadow); }
.to-top.on { opacity: 1; pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .to-top { transition: none; } }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 40; background: var(--paper-raised); border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.5rem 0.8rem; }

/* Reading rail: one dot per section, down the right margin. Only where there is
   room beside the text column; never on a phone, never in print. */
.rail {
  display: none; position: fixed; top: 50%; right: 1.4rem; transform: translateY(-50%);
  flex-direction: column; align-items: flex-end; gap: 0.5rem; z-index: 30;
}
@media (min-width: 76rem) { .rail { display: flex; } }
.rail-dot {
  display: flex; flex-direction: row-reverse; align-items: center; gap: 0.55rem;
  text-decoration: none; padding: 0.15rem 0;
}
.rail-dot .dot {
  display: block; width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--line-strong);
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.rail-dot:hover .dot, .rail-dot:focus-visible .dot { background: var(--ink-soft); }
.rail-dot.active .dot { background: var(--accent); transform: scale(1.45); }
.rail-label {
  font-size: 0.75rem; line-height: 1.2; color: var(--ink-soft);
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: 4px;
  padding: 0.25rem 0.55rem; white-space: nowrap; max-width: 14rem;
  overflow: hidden; text-overflow: ellipsis; box-shadow: var(--shadow);
  opacity: 0; transform: translateX(6px); pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.rail-dot:hover .rail-label, .rail-dot:focus-visible .rail-label { opacity: 1; transform: none; }
.rail-dot.active .rail-label { color: var(--ink); border-color: var(--line-strong); }
@media (prefers-reduced-motion: reduce) { .rail-dot .dot, .rail-label { transition: none; } }
@media print { .rail { display: none; } }
