:root {
  --bg: #fff; --fg: #1a1a1a; --muted: #5c6370; --line: #d5d9de;
  --code-bg: #f4f3f5; --link: #6b3fa0; --accent: #6b3fa0; --on-accent: #fff;
  --err-bg: #fdecec; --err: #9b1c1c;
    /* Team-neutral palette: no blue or green (the two Ingress factions); red only for warnings. */
  --stage: #f8f7f6; --grid: #c9c6c2; --c-field: #2b2b2b; --c-field2: #c24f00; --c-poll: #c24f00; --c-in: #d9a400;
  --c-edge: #5c5c5c; --c-merged: #8a5a2b; --c-kept: #7b3fa0; --c-overlap: #e8b300;
  --h0: #f6f1f9; --h1: #ebdff2; --h2: #dcc8e8; --h3: #c9abdb; --h4: #b38ccb; --h5: #9b6dba; --h6: #8352a6; --h7: #6b3c8f; --h8: #532a75; --h9: #3b1a59;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --fg: #e4e6e8; --muted: #9aa3ad; --line: #2e343a;
    --code-bg: #222024; --link: #c9a7ef; --accent: #c9a7ef; --on-accent: #151317;
    --err-bg: #3a1c1c; --err: #f5a3a3;
    --stage: #1c1b1d; --grid: #45424a; --c-field: #ece9e4; --c-field2: #f08a4b; --c-poll: #f08a4b; --c-in: #f2c230;
    --c-edge: #a8a4a0; --c-merged: #d9a066; --c-kept: #c99ae6; --c-overlap: #f2c230;
    --h0: #2a2130; --h1: #34283d; --h2: #40304c; --h3: #4e3a5e; --h4: #5f4673; --h5: #74558b; --h6: #8b68a4; --h7: #a580bd; --h8: #c09dd4; --h9: #dcc2ea;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); }
header, main, footer { max-width: 46rem; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
header {
  display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: baseline;
  padding-top: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
header .site { font-weight: 600; margin-right: auto; }
header a { text-decoration: none; }
header a[aria-current] { font-weight: 600; text-decoration: underline; }
main { padding-top: 20px; padding-bottom: 32px; overflow-wrap: break-word; }
footer { padding-top: 12px; padding-bottom: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; }
h1 { font-size: 1.6rem; line-height: 1.25; }
h2 { font-size: 1.3rem; margin-top: 2rem; }
h3 { font-size: 1.1rem; margin-top: 1.5rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
code { background: var(--code-bg); padding: .1em .3em; border-radius: 3px; }
pre { background: var(--code-bg); padding: 12px; border-radius: 4px; overflow-x: auto; line-height: 1.4; }
pre code { background: none; padding: 0; }
/* Tables scroll inside themselves instead of widening the page. */
table { display: block; overflow-x: auto; max-width: 100%; border-collapse: collapse; margin: 1rem 0; }
th, td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; vertical-align: top; }
th { background: var(--code-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--line); }
img { max-width: 100%; }
/* calculator */
label { display: block; font-weight: 600; margin-top: 12px; }
input[type=text] {
  width: 100%; padding: 8px 10px; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--muted); border-radius: 4px;
}
input:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button {
  font: inherit; padding: 8px 18px; cursor: pointer;
  color: var(--on-accent); background: var(--accent); border: 0; border-radius: 4px;
}
button[disabled] { opacity: .6; cursor: wait; }
.hint { color: var(--muted); font-size: .9rem; }
.eli5 { margin: 1rem 0 0; padding: .6rem .9rem; border-left: 3px solid var(--accent); background: var(--code-bg); }
.actions { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 16px; }
#error { background: var(--err-bg); color: var(--err); padding: 10px 12px; border-radius: 4px; margin-top: 16px; }
#result { margin-top: 24px; }
.mu { font-size: 3rem; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; }
.mu small { font-size: 1rem; font-weight: 400; color: var(--muted); }
details { margin-top: 16px; }
summary { cursor: pointer; font-weight: 600; }
[hidden] { display: none !important; }
/* how-it-works.html: animation players. Colours follow the Okabe-Ito set; every state also has a
   second channel (line style or pattern) so that it does not depend on colour alone. */
body.wide header, body.wide main, body.wide footer { max-width: 62rem; }
.anim, .anim-group { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.anim-group .anim { margin-top: 1.5rem; padding-top: 0; border-top: 0; }
.glossary { margin: 1rem 0; padding: 8px 12px; background: var(--code-bg); border-radius: 6px; }
.glossary summary { cursor: pointer; font-weight: 600; }
.glossary dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0 0; }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 0; }
@media (max-width: 560px) { .glossary dl { grid-template-columns: 1fr; } .glossary dd { margin-bottom: 6px; } }
.anim h2 { margin-top: .5rem; }
.player { margin-top: 12px; }
.stage-wrap { position: relative; background: var(--stage); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stage-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sample-info { position: absolute; top: 8px; left: 8px; right: 8px; padding: 6px; background: var(--bg); color: var(--fg); border: 1px solid var(--muted); font-size: .8125rem; pointer-events: none; }
.base-map { --map-water: #dde3e6; --map-urban: #e3e0dc; --map-road: #918d89; --map-land: #f1ebdf; --map-border: #8f857a; }
.base-map polygon { stroke: none; }
.map-water { fill: var(--map-water); }
.map-urban { fill: var(--map-urban); }
.map-land { fill: var(--map-land); }
.map-border { stroke: var(--map-border); stroke-dasharray: 4 2; }
.base-map polyline { fill: none; stroke-width: 1px; }
.map-road, .map-rail { stroke: var(--map-road); }
.map-rail { stroke-dasharray: 3 3; }
.map-river { stroke: var(--map-water); stroke-width: 2px !important; }
.stage .map-label { fill: var(--muted); font-size: calc(var(--u) * 11px); }
.map-credit { margin: 0; padding: 4px 10px; font-size: .75rem; color: var(--muted); }
.comparison { padding: 8px 10px; border-top: 1px solid var(--line); }
.comparison-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.comparison button { font-size: .8125rem; padding: 6px 10px; }
.comparison button[aria-pressed=true] { background: var(--accent); color: var(--on-accent); }
.comparison-numbers { margin: 8px 0 0; padding-left: 6px; border-left: 3px solid transparent; font-size: .875rem; font-variant-numeric: tabular-nums; }
.comparison-numbers.active { border-left-color: var(--accent); }
@media (prefers-color-scheme: dark) {
  .base-map { --map-water: #2c3236; --map-urban: #353230; --map-road: #67625e; --map-land: #3a3732; --map-border: #7d756c; }
}
.stage { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 8px 10px; border-top: 1px solid var(--line); font-size: .8125rem; color: var(--muted); min-height: 2.4rem; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg.ramp { gap: 0; }
.sw { width: 22px; height: 14px; flex: none; }
.sw.r { width: 8px; }
.ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.ctl input[type=range] { flex: 1 1 8rem; min-width: 6rem; accent-color: var(--accent); }
.ctl .count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .875rem; white-space: nowrap; }
.ctl button { min-height: 40px; min-width: 40px; padding: 6px 14px; }
.ctl button.pri { min-width: 76px; }
button.sec { background: var(--bg); color: var(--accent); border: 1px solid var(--accent); }
button[disabled].sec { opacity: .45; cursor: default; }
select { font: inherit; padding: 6px 8px; color: inherit; background: var(--bg); border: 1px solid var(--muted); border-radius: 4px; min-height: 40px; }
select:focus-visible, input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.side { margin-top: 12px; }
.cap { margin: 0 0 8px; font-size: 1.0625rem; min-height: 3.2em; }
.eq { margin: 0 0 8px; padding: 8px 10px; background: var(--code-bg); border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8125rem; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.tb table, table.sum { font-size: .875rem; margin: .5rem 0; }
.tb tr.hl td { background: var(--code-bg); font-weight: 600; }
table.sum th { font-weight: 600; background: none; white-space: nowrap; }
.bud .bt { margin: 0 0 4px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bud .hint { margin: 4px 0 0; }
.slots { display: flex; flex-wrap: wrap; gap: 3px; }
.slot { width: 16px; height: 16px; border: 2px solid var(--c-kept); border-radius: 3px; box-sizing: border-box; }
.slot.res { background: var(--c-kept); }
.slot.que { background: none; border-style: solid; }
.slot.kid { background: none; border-style: dotted; }
.slot.over { border-color: var(--c-poll); }
.slot.over.res, .slot.over.que, .slot.over.kid { border-color: var(--c-poll); }
.slot.edge { margin-left: 8px; }
@media (min-width: 52rem) {
  .player { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); grid-template-rows: min-content 1fr; grid-template-areas: "stage side" "ctl side"; gap: 0 20px; align-items: start; }
  .player > .stage-wrap { grid-area: stage; }
  .player > .ctl { grid-area: ctl; }
  .player > .side { grid-area: side; margin-top: 0; }
  .player > h3, .player > table, .player > details, .player > p { grid-column: 1 / -1; }
}

/* drawing */
.stage { --u: 1; }
.e { fill: none; stroke: none; transition: opacity .3s ease, fill .3s ease, stroke .3s ease, fill-opacity .3s ease, stroke-width .3s ease; }
.e[data-s=""] { opacity: 0; pointer-events: none; }
.stage text, .sb text { font-size: calc(var(--u) * 12px); fill: var(--fg); stroke: var(--stage); stroke-width: calc(var(--u) * 3px); paint-order: stroke; stroke-linejoin: round; text-anchor: middle; font-variant-numeric: tabular-nums; }
.e.k-t { pointer-events: none; }
.stage .k-t { vector-effect: none; }
.label-leader { stroke: var(--muted); stroke-width: 1px; }
.stage .k-d:focus-visible { outline: none; stroke: var(--accent); stroke-width: 3px; }
.e.k-t[data-s=""] { opacity: 0; }
.sb line { stroke: var(--fg); stroke-width: 3px; }
.sb text { font-size: calc(var(--u) * 11px); }
.k-p[data-s=field] { stroke: var(--c-field); stroke-width: 2.5px; fill: var(--c-field); fill-opacity: .07; }
.k-p[data-s=field2] { stroke: var(--c-field2); stroke-width: 2.5px; stroke-dasharray: 8 4; fill: var(--c-field2); fill-opacity: .1; }
.k-p[data-s=cap] { stroke: var(--muted); stroke-width: 1.2px; stroke-dasharray: 2 4; }
.k-p[data-s=cell] { stroke: var(--muted); stroke-width: 1.2px; }
.k-p[data-s=cell12] { stroke: var(--fg); stroke-width: 2.5px; }
.k-p[data-s=hl] { stroke: var(--c-field2); stroke-width: 2.5px; fill: var(--c-field2); fill-opacity: .12; }
.k-p[data-s=sub] { stroke: var(--muted); stroke-width: .8px; stroke-dasharray: 3 3; }
.k-p[data-s=grid] { stroke: var(--grid); stroke-width: 1px; }
.k-p[data-s=read] { stroke: var(--c-merged); stroke-width: 2px; fill: var(--c-merged); fill-opacity: .2; }
.k-p[data-s=plain] { stroke: var(--c-poll); stroke-width: 2.2px; stroke-dasharray: 5 3; }
.k-p[data-s=wait] { stroke: var(--fg); stroke-width: 1.4px; stroke-dasharray: 5 3; fill: var(--muted); fill-opacity: .16; }
.k-p[data-s=poll] { stroke: var(--c-poll); stroke-width: 3px; fill: var(--c-poll); fill-opacity: .18; }
.k-p[data-s=done] { stroke: var(--muted); stroke-width: .8px; }
.k-p[data-s=miss] { stroke: var(--grid); stroke-width: .8px; stroke-dasharray: 1 4; }
.k-p[data-s=in] { stroke: var(--c-merged); stroke-width: 1.8px; fill: var(--c-in); fill-opacity: .35; }
.k-p[data-s=edge] { stroke: var(--c-edge); stroke-width: 1.4px; }
.k-p[data-s=merged] { stroke: var(--c-merged); stroke-width: 2px; fill: var(--fill-merged, url(#hatch-merged)); }
.k-p[data-s=kept] { stroke: var(--c-kept); stroke-width: 2.2px; fill: var(--fill-kept, url(#hatch-kept)); }
.k-p[data-s=clip] { stroke: none; fill: var(--c-overlap); fill-opacity: .45; }
.k-p[data-s=heat] { stroke: var(--bg); stroke-width: 1px; fill: var(--hv, var(--h5)); fill-opacity: .72; }
.k-d[data-s=dot] { fill: var(--fg); stroke: var(--stage); stroke-width: 1px; }
.k-d[data-s=in] { fill: var(--c-in); stroke: var(--fg); stroke-width: 1.2px; }
.k-d[data-s=ghost] { fill: none; stroke: var(--muted); stroke-width: 1px; stroke-dasharray: 2 2; opacity: .7; }
.k-d[data-s=out] { fill: var(--stage); stroke: var(--fg); stroke-width: 1.6px; }
.k-d[data-s=shift] { fill: var(--stage); stroke: var(--c-poll); stroke-width: 2px; }
.k-l[data-s=link] { stroke: var(--c-poll); stroke-width: 1.4px; }
.k-l[data-s=ptr] { stroke: var(--muted); stroke-width: 1px; }
.k-l[data-s=move] { stroke: var(--c-poll); stroke-width: 1.4px; stroke-dasharray: 4 3; }
.k-t[data-s=t] { fill: var(--fg); }
.k-t[data-s=b] { fill: var(--fg); font-weight: 700; }
.k-t[data-s=m] { fill: var(--muted); }
/* extra generic polygon states */
.k-p[data-s=unread] { stroke: var(--muted); stroke-width: 1.2px; stroke-dasharray: 2 3; fill: var(--muted); fill-opacity: .1; }
.k-p[data-s=hl2] { stroke: var(--c-kept); stroke-width: 2.5px; fill: var(--c-kept); fill-opacity: .12; }
.k-p[data-s=ah] { fill: var(--c-poll); stroke: none; }
.k-p[data-s=ah2] { fill: var(--c-kept); stroke: none; }
.k-p[data-s=bbox] { stroke: var(--muted); stroke-width: 1.2px; stroke-dasharray: 6 3; }
.k-l[data-s=move2] { stroke: var(--c-kept); stroke-width: 1.4px; stroke-dasharray: 4 3; }
.k-p[data-s=fade] { stroke: var(--muted); stroke-width: 1px; stroke-opacity: .6; }
.e[data-d="0"] { --hv: var(--h0); }
.e[data-d="1"] { --hv: var(--h1); }
.e[data-d="2"] { --hv: var(--h2); }
.e[data-d="3"] { --hv: var(--h3); }
.e[data-d="4"] { --hv: var(--h4); }
.e[data-d="5"] { --hv: var(--h5); }
.e[data-d="6"] { --hv: var(--h6); }
.e[data-d="7"] { --hv: var(--h7); }
.e[data-d="8"] { --hv: var(--h8); }
.e[data-d="9"] { --hv: var(--h9); }
.sw .e { transition: none; }
@media (prefers-reduced-motion: reduce) { .e { transition: none; } }
.hb.merged { fill: var(--c-merged); fill-opacity: .12; }
.hb.kept { fill: var(--c-kept); fill-opacity: .12; }
.hl.merged { stroke: var(--c-merged); stroke-opacity: .75; }
.hl.kept { stroke: var(--c-kept); stroke-opacity: .75; }
.hatch-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
