/* style.css -- Athlone to Nottingham Physarum illustration.
   Palette follows the Elemental Codices house tokens; the map ramp is a single amber hue,
   light to dark on light theme, dim to bright on dark theme (validated: monotone lightness,
   >= 2:1 against the land colour). No external requests: system fonts only. */

:root {
  color-scheme: light dark;
  --ground: #f4f0e6;
  --surface: #fbf8f0;
  --glass: rgba(251, 248, 240, 0.92);
  --ink: #211a10;
  --muted: #6b5d47;
  --rule: #ddd3bd;
  --accent: #8a5a10;
  --accent-soft: #f0e2c8;
  --warn: #a13a2a;
  --warn-soft: #f3e0d8;
  --ok: #4b7a3d;
  --ok-soft: #e3ecdc;
  --code-bg: #ece5d3;

  /* map */
  --sea: #dfe8e6;
  --land: #f6f1e3;
  --coast: #c2b596;
  --road: #a59c86;
  --ferry-line: #7d98a1;
  --halo: #fbf8f0;
  --ramp-0: #de9b4b;
  --ramp-1: #ce841d;
  --ramp-2: #b57213;
  --ramp-3: #9c610b;
  --ramp-4: #835106;
  --ramp-5: #6b4105;
  --ramp-6: #533204;

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-head: "Avenir Next Condensed", "Arial Narrow", ui-sans-serif, -apple-system, "Segoe UI", sans-serif;
  --font-serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #15110a; --surface: #1c1710; --glass: rgba(28, 23, 16, 0.92);
    --ink: #ede6d6; --muted: #b0a58c; --rule: #362c1d;
    --accent: #e0a53f; --accent-soft: #2e2413; --warn: #e2896a; --warn-soft: #2e1b13;
    --ok: #8fbf7a; --ok-soft: #1e2a17; --code-bg: #201a10;
    --sea: #0d1215; --land: #1d1a12; --coast: #40371f; --road: #635b48; --ferry-line: #55737a;
    --halo: #15110a;
    --ramp-0: #7f5c1d; --ramp-1: #9e711e; --ramp-2: #bc8726; --ramp-3: #d99f36;
    --ramp-4: #f6b84d; --ramp-5: #fed89d; --ramp-6: #fff0d9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #15110a; --surface: #1c1710; --glass: rgba(28, 23, 16, 0.92);
  --ink: #ede6d6; --muted: #b0a58c; --rule: #362c1d;
  --accent: #e0a53f; --accent-soft: #2e2413; --warn: #e2896a; --warn-soft: #2e1b13;
  --ok: #8fbf7a; --ok-soft: #1e2a17; --code-bg: #201a10;
  --sea: #0d1215; --land: #1d1a12; --coast: #40371f; --road: #635b48; --ferry-line: #55737a;
  --halo: #15110a;
  --ramp-0: #7f5c1d; --ramp-1: #9e711e; --ramp-2: #bc8726; --ramp-3: #d99f36;
  --ramp-4: #f6b84d; --ramp-5: #fed89d; --ramp-6: #fff0d9;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 16px/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip; /* never a horizontal page scroll (clip keeps position: sticky working) */
}
img, svg, canvas { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
var { font-style: italic; font-family: var(--font-serif); }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; text-wrap: balance; line-height: 1.15; margin: 0; }
p { margin: 0; }

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

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--surface);
  color: var(--ink); border: 1px solid var(--accent); padding: 8px 12px; border-radius: 4px;
}
.skip:focus { top: 8px; }

.wrap { width: 100%; max-width: 1280px; margin-inline: auto; padding-inline: 16px; }

/* ---- banner + header ---------------------------------------------------------------- */
.banner {
  background: var(--accent-soft);
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
  text-align: center;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.005em;
  line-height: 1.35;
}
.head { padding-block: 20px 8px; }
.eyebrow {
  font: 12px/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.head h1 { font-size: clamp(30px, 6.4vw, 48px); margin: 8px 0 10px; letter-spacing: -0.01em; }
.lede { font: 17px/1.55 var(--font-serif); color: var(--muted); max-width: 66ch; }
.fixture-note {
  margin-top: 12px; padding: 8px 12px; max-width: 80ch;
  background: var(--warn-soft); border-left: 3px solid var(--warn); color: var(--ink);
  font-size: 14px; border-radius: 0 4px 4px 0;
}
.callout { border: 1px solid var(--rule); border-left: 3px solid var(--muted); background: var(--surface); padding: 10px 14px; border-radius: 4px; }
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }

/* ---- layout ------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding-block: 12px 32px;
  align-items: start;
}
.left { display: contents; }
.side { min-width: 0; display: grid; gap: 12px; }
.stage {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--ground);
  padding-block: 4px 6px;
  min-width: 0;
}
.notes { min-width: 0; }

@media (min-width: 960px) {
  .app { grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr); gap: 24px; padding-block: 16px 48px; }
  .left { display: block; align-self: stretch; }
  .stage { top: 12px; padding-block: 0; background: transparent; }
}
@media (min-width: 700px) { .wrap { padding-inline: 24px; } }
/* keep focused controls clear of the sticky map on narrow screens */
@media (max-width: 959px) { html { scroll-padding-top: calc(clamp(230px, 40vh, 440px) + 24px); } }
@media (min-width: 960px) {
  /* title left, lede right: saves height so the map is on screen at load */
  .head { padding-block: 14px 4px; }
  .head .wrap { display: grid; grid-template-columns: auto minmax(0, 64ch); column-gap: 48px; align-items: end; }
  .head .eyebrow { grid-column: 1 / -1; }
  .head h1 { margin: 6px 0 4px; }
  .head .lede { font-size: 16px; padding-bottom: 6px; }
  .head .fixture-note { grid-column: 1 / -1; }
}

/* ---- map ---------------------------------------------------------------------------- */
.map-wrap {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  background: var(--sea);
  height: clamp(230px, 40vh, 440px);
}
@media (min-width: 960px) { .map-wrap { height: clamp(440px, calc(100vh - 210px), 780px); } }
#map {
  display: block; width: 100%; height: 100%;
  touch-action: none;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
#map.dragging { cursor: grabbing; }
#map.over-edge { cursor: pointer; }
#map:focus-visible { outline-offset: -3px; }

.hud {
  position: absolute; left: 8px; top: 8px;
  font: 11.5px/1.3 var(--font-mono);
  background: var(--glass);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 3px 7px;
  color: var(--ink);
  pointer-events: none;
  max-width: calc(100% - 64px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.hud:empty { display: none; }
.map-tools { position: absolute; right: 8px; top: 8px; display: grid; gap: 4px; }
.tool {
  width: 32px; height: 32px; padding: 0;
  font: 600 17px/1 var(--font-ui);
  background: var(--glass); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 6px;
  cursor: pointer;
}
.tool:hover { border-color: var(--accent); }
@media (pointer: coarse) { .tool { width: 40px; height: 40px; } }

.edge-card {
  position: absolute; left: 8px; bottom: 8px;
  width: min(272px, calc(100% - 16px));
  background: var(--glass);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.35;
  pointer-events: none;
}
.edge-title { font-weight: 650; font-size: 13.5px; overflow-wrap: anywhere; }
.edge-sub { color: var(--muted); margin-top: 1px; }
.edge-dl { margin: 6px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
.edge-dl div { min-width: 0; }
.edge-dl dt { color: var(--muted); font-size: 11px; }
.edge-dl dd { margin: 0; font: 600 12.5px var(--font-mono); font-variant-numeric: tabular-nums; }
.edge-act { margin-top: 5px; color: var(--muted); font-size: 11.5px; }
.edge-card.closed { border-color: var(--warn); }
.edge-card.closed .edge-title::before { content: "× "; color: var(--warn); }
.edge-dl .sh-t { display: none; }
.edge-title, .edge-sub { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.edge-title { -webkit-line-clamp: 2; line-clamp: 2; }
.edge-sub { -webkit-line-clamp: 2; line-clamp: 2; }
@media (max-width: 599px) {
  .edge-card { width: calc(100% - 16px); padding: 6px 8px; font-size: 12px; }
  .edge-title { -webkit-line-clamp: 1; line-clamp: 1; font-size: 13px; }
  .edge-sub { -webkit-line-clamp: 1; line-clamp: 1; }
  .edge-dl { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px 8px; margin-top: 4px; }
  .edge-dl .lg-t { display: none; }
  .edge-dl .sh-t { display: inline; }
  .edge-dl dt { font-size: 10.5px; }
  .edge-dl dd { font-size: 11.5px; }
  .edge-act { display: none; }
}

.map-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: min(360px, 86%); text-align: center;
  background: var(--glass); border: 1px solid var(--warn); color: var(--ink);
  padding: 10px 14px; border-radius: 6px; font-size: 14px;
}
.zoom-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: var(--glass); border: 1px solid var(--rule); color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  pointer-events: none; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis;
}
.zoom-hint[hidden] { display: none; }
.loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--sea); color: var(--muted); font: 14px var(--font-mono);
}
.loading[hidden] { display: none; }

.map-help { font-size: 13px; color: var(--muted); margin: 10px 0 8px; max-width: 78ch; }
.legend {
  display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted);
  padding-bottom: 6px;
}
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg svg { flex: none; }
.lg svg.x { color: var(--warn); }
.lg svg.mk-o circle { fill: var(--accent); stroke: var(--ink); stroke-width: 1.5; }
.lg svg.mk-d rect { fill: var(--ink); stroke: var(--accent); stroke-width: 1.5; }
.lg > svg:not(.x):not(.mk-o):not(.mk-d) { color: var(--ferry-line); }
.ramp {
  display: inline-block; width: 44px; height: 8px; border-radius: 2px; flex: none;
  background: linear-gradient(90deg, var(--ramp-0), var(--ramp-2), var(--ramp-4), var(--ramp-6));
}
:root[data-theme="dark"] .ramp { background: linear-gradient(90deg, var(--ramp-0), var(--ramp-2), var(--ramp-4), var(--ramp-6)); }

/* ---- panels ------------------------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 16px 12px;
  min-width: 0;
}
.panel h2 { font-size: 19px; margin-bottom: 8px; }
.panel h3 { font-size: 15px; margin: 0 0 6px; }
.panel h3 .sub { font: 400 11.5px var(--font-mono); color: var(--muted); letter-spacing: 0; margin-left: 6px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.hint + .hint { margin-top: 4px; }
.settle-hint {
  margin-top: 8px; padding: 6px 10px; color: var(--ink);
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 4px 4px 0;
}

.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.btn {
  font: 600 14px/1 var(--font-ui);
  min-height: 40px; padding: 0 16px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 6px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
:root[data-theme="dark"] .btn.primary { color: #15110a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #15110a; } }
@media (pointer: coarse) { .btn { min-height: 44px; } }

.field { margin: 14px 0 0; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 2px; width: 100%;
}
output { font: 600 13px var(--font-mono); color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
input[type="range"] { width: 100%; height: 30px; margin: 0; accent-color: var(--accent); background: transparent; }
@media (pointer: coarse) { input[type="range"] { height: 40px; } }
select {
  font: 14px var(--font-ui); color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 6px; min-height: 36px; padding: 0 8px; max-width: 100%;
}

.mu-scale { display: grid; grid-template-columns: 1fr auto 1fr; font-size: 11.5px; color: var(--muted); margin-top: -2px; }
.mu-scale .z { border-top: 2px solid var(--rule); padding-top: 3px; line-height: 1.3; }
.mu-scale .lt { text-align: left; }
.mu-scale .eq { text-align: center; padding-inline: 8px; }
.mu-scale .gt { text-align: right; }
.mu-scale .z.on { color: var(--ink); border-top-color: var(--accent); font-weight: 600; }

.regimes p {
  margin-top: 8px; padding: 8px 10px;
  font: 14.5px/1.5 var(--font-serif);
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 4px 4px 0;
}
.regimes p[hidden] { display: none; }

.models .opt { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; cursor: pointer; font-size: 14px; }
.models .opt input { margin-top: 4px; accent-color: var(--accent); flex: none; }
.models .eq { font: 13px var(--font-serif); font-style: italic; color: var(--muted); white-space: nowrap; }
.models .hint { margin-top: 4px; }
.models legend { margin-bottom: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.chip {
  font: 500 13.5px/1.2 var(--font-ui); color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 999px;
  padding: 8px 13px; min-height: 36px; cursor: pointer; text-align: left;
}
.chip::first-letter { text-transform: uppercase; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 650; }
.chip.ghost { border-style: dashed; color: var(--muted); }
@media (pointer: coarse) { .chip { min-height: 44px; } }
.closed-summary { font-size: 13.5px; margin-top: 8px; }
.closed-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.closed-list button {
  max-width: 100%; overflow-wrap: anywhere;
  font: 500 12.5px var(--font-ui); color: var(--ink);
  background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 4px;
  padding: 5px 8px; cursor: pointer; text-align: left;
}
.closed-list button::before { content: "× "; color: var(--warn); font-weight: 700; }
.closed-list button::after { content: " — reopen"; color: var(--muted); }

.ind { margin: 6px 0 0; }
.ind > div {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px solid var(--rule);
}
.ind dt { color: var(--muted); font-size: 13.5px; }
.ind dd { margin: 0; font: 600 13.5px var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.ind dd.warn { color: var(--warn); }

.defs { margin-top: 10px; font-size: 13.5px; }
.defs summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.defs dl { margin: 8px 0 0; }
.defs dt { font-weight: 650; margin-top: 8px; }
.defs dd { margin: 2px 0 0; color: var(--muted); }

.bars { list-style: none; margin: 8px 0 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; margin-bottom: 11px; align-items: baseline; }
.bars .nm { font-size: 14px; overflow-wrap: anywhere; }
.bars .pc { font: 600 13.5px var(--font-mono); font-variant-numeric: tabular-nums; }
.bars .track { grid-column: 1 / -1; position: relative; height: 10px; background: var(--code-bg); border-radius: 0 4px 4px 0; }
.bars .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); border-radius: 0 4px 4px 0; }
.bars .tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: 0.85; display: none; }
.bars li.shut .nm { color: var(--muted); text-decoration: line-through; }
.bars li.shut .pc::after { content: " closed"; color: var(--warn); font: 600 11px var(--font-ui); }

.pinch { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 560px) and (max-width: 959px) { .pinch { grid-template-columns: 1fr 1fr; } }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--rule); }
.rows .main {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: var(--ink);
  font: 13.5px/1.35 var(--font-ui); padding: 7px 2px; cursor: pointer; overflow-wrap: anywhere;
}
.rows .main:hover .lab { text-decoration: underline; text-underline-offset: 3px; }
.rows .main .meta { display: block; color: var(--muted); font-size: 12px; }
.rows .val { font: 600 13px var(--font-mono); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rows .val.warn { color: var(--warn); }
.rows .mini {
  flex: none; font: 600 12px var(--font-ui); color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 4px; padding: 4px 8px; cursor: pointer; min-height: 28px;
}
.rows .mini:hover { border-color: var(--accent); }
.rows .mini[aria-pressed="true"] { background: var(--warn-soft); border-color: var(--warn); }
@media (pointer: coarse) { .rows .mini { min-height: 36px; } }
.rows li.sel { background: var(--accent-soft); }

.about h3 { font-size: 16px; margin: 10px 0 4px; }
.about ul { margin: 0; padding-left: 1.15em; font: 15px/1.5 var(--font-serif); }
.about li { margin-bottom: 6px; }

/* ---- footer ------------------------------------------------------------------------- */
.foot { border-top: 1px solid var(--rule); padding-block: 14px 40px; color: var(--muted); font-size: 13.5px; }
.foot .attrib { margin-top: 8px; }
.foot .attrib.small { font-size: 12.5px; }
.data-details { margin: 0 0 6px; }
.data-details table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.data-details th, .data-details td { text-align: left; vertical-align: top; padding: 4px 10px 4px 0; border-bottom: 1px solid var(--rule); overflow-wrap: anywhere; }
.data-details th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.data-details code { font: 12px var(--font-mono); background: var(--code-bg); padding: 0 3px; border-radius: 3px; }
.data-body-wrap { overflow-x: auto; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---- phones: compact header, shorter help, so the map comes early ------------------------ */
@media (max-width: 599px) {
  .eyebrow { display: none; }
  .head { padding-block: 12px 2px; }
  .head h1 { font-size: 30px; margin: 0 0 6px; }
  .lede { font-size: 15.5px; line-height: 1.5; }
  .fixture-note { font-size: 13px; margin-top: 8px; padding: 6px 10px; }
  .kbd-help { display: none; }
  .map-help { font-size: 12.5px; margin: 8px 0 6px; }
  .legend { font-size: 12px; gap: 4px 12px; }
  .banner { font-size: 13px; padding: 7px 12px; }
}
