/* Variant C, "City planner": flat top-down puzzle-game look. */
:root {
  --page: #eef4ee;
  --land: #cfe3d4;
  --block: #bcd7c3;
  --tree: #a6cbb0;
  --water: #9cc9e0;
  --road: #3b4252;
  --coral: #ff7a59;
  --sun: #ffc745;
  --violet: #8c6cf0;
  --ink: #23283a;
  --muted: #5b6275;
  --panel: #fff;
  --ok: #2bb673;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', system-ui, sans-serif;
  --r: 14px;
  --press: 0 4px 0 var(--ink);
}

* { box-sizing: border-box; }
html { background: var(--page); color: var(--ink); }
body { margin: 0; font: 400 1.0625rem/1.62 var(--body); -webkit-font-smoothing: antialiased; overflow-x: clip; }
.prose { position: relative; } /* keeps KaTeX's hidden MathML from widening the page */
:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; border-radius: 6px; }
a { color: inherit; }

/* ---------- hero ---------- */
.hero { max-width: 76rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.hero-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3.5rem; font: 700 1rem var(--display); }
.logo { display: inline-flex; align-items: center; gap: .55rem; }
.logo::before { content: ''; width: 1.6rem; height: 1.6rem; border-radius: 8px; background: var(--coral); border: 2px solid var(--ink); box-shadow: .45rem .45rem 0 -2px var(--violet); }
.total-stars { color: var(--muted); }
.total-stars::before { content: '★ '; color: #e0a800; }
.hero-main { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 2.5rem; align-items: center; margin-bottom: 2.5rem; }
.hero-town .citymap svg { border-radius: 22px; border: 2px solid var(--ink); box-shadow: 0 6px 0 var(--ink); }
.hero h1 { font: 800 clamp(2.5rem, 6.6vw, 5.2rem)/0.96 var(--display); letter-spacing: -0.035em; margin: 0; max-width: 16ch; }
.subtitle { font: 400 1.2rem/1.45 var(--body); max-width: 38rem; margin: 1.25rem 0 .5rem; }
.authors { color: var(--muted); margin: 0; font-size: .98rem; }

.levels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .9rem; }
.level-card {
  display: flex; flex-direction: column; gap: .2rem; text-decoration: none;
  background: var(--panel); border: 2px solid var(--ink); border-radius: var(--r);
  padding: .9rem 1rem 1rem; box-shadow: var(--press); transition: transform .12s, box-shadow .12s;
}
.level-card:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.level-card:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.level-card .lv { font: 700 .82rem var(--display); color: var(--muted); }
.level-card strong { font: 750 1.2rem/1.15 var(--display); }
.level-card .blurb { font-size: .9rem; line-height: 1.35; color: var(--muted); flex: 1; }
.level-card:nth-child(1) { border-top: 8px solid var(--coral); }
.level-card:nth-child(2) { border-top: 8px solid var(--sun); }
.level-card:nth-child(3) { border-top: 8px solid var(--violet); }
.level-card:nth-child(4) { border-top: 8px solid var(--ok); }
.level-card:nth-child(5) { border-top: 8px solid var(--water); }
.stars { display: inline-flex; gap: .1rem; font-size: 1.15rem; letter-spacing: .05em; }
.stars i { font-style: normal; color: #d4dcd5; transition: color .3s, transform .3s; }
.stars i.on { color: #f2b200; text-shadow: 0 1px 0 var(--ink); }

/* ---------- levels ---------- */
main { padding: 0 1.25rem 4rem; }
.level { max-width: 76rem; margin: 0 auto; padding: 3.5rem 0 1rem; border-top: 2px dashed #b9cbbd; }
.level-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.lv-badge { background: var(--ink); color: #fff; font: 700 .9rem var(--display); border-radius: 999px; padding: .2rem .8rem; }
.lv-name { font: 700 1.05rem var(--display); }
.level h2, .plain h2 { font: 760 clamp(1.8rem, 3.4vw, 2.6rem)/1.08 var(--display); letter-spacing: -0.02em; margin: .6rem 0 1.5rem; max-width: 24ch; }
.level-grid > *, .panel-row > *, .board > * { min-width: 0; }
.level-grid { display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.25fr); gap: 2.5rem; align-items: start; }
.board-wrap.stick { position: sticky; top: 1rem; }
.board {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 20px;
  padding: 1rem; display: flex; flex-direction: column; gap: .85rem; box-shadow: 0 6px 0 var(--ink);
  min-height: 20rem;
}
.after { max-width: 40rem; margin: 2rem 0 0; }

.prose p { margin: 0 0 1em; max-width: 36rem; }
.prose strong { font-weight: 700; }
.prose ol { padding-left: 0; list-style: none; counter-reset: step; }
.prose ol li { counter-increment: step; position: relative; padding-left: 2.4rem; margin: .5rem 0; }
.prose ol li::before {
  content: counter(step); position: absolute; left: 0; top: .05rem; width: 1.65rem; height: 1.65rem; border-radius: 50%;
  background: var(--sun); border: 2px solid var(--ink); font: 800 .85rem/1.45rem var(--display); text-align: center;
}
.prose ul { padding-left: 1.2rem; }
.prose li { margin: .4rem 0; }
.briefing .katex-display { font-size: .92em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .4rem 0; margin: .6rem 0 1.1rem; }

/* ---------- board furniture ---------- */
.board-top { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; }
.hint { font-size: .92rem; color: var(--muted); }
.board-map { position: relative; }
.citymap { position: relative; }
.citymap svg { display: block; width: 100%; height: auto; }
.panel-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.panel { border: 2px solid var(--ink); border-radius: var(--r); padding: .75rem .9rem; min-width: 0; }
.label { font: 700 .85rem var(--display); color: var(--muted); margin-bottom: .25rem; }
.big { font: 800 2.2rem/1.05 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.unit { font: 700 1rem var(--display); color: var(--muted); }
.delta { display: block; font: 700 .9rem var(--display); }
.delta.good { color: #178a55; }
.delta.bad { color: #d4502f; }
.note { margin: .3rem 0 0; font-size: .95rem; min-height: 1.5em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.verdict { margin-top: .5rem; padding: .5rem .7rem; background: #eaf7f0; border-radius: 10px; font-size: .93rem; }

.goals { list-style: none; padding: 0; margin: 0; font-size: .93rem; }
.goals li { padding-left: 1.7rem; position: relative; margin: .3rem 0; line-height: 1.35; }
.goals li::before { content: '★'; position: absolute; left: 0; color: #cfd8d1; font-size: 1.1rem; line-height: 1.2; }
.goals li.done::before { color: #f2b200; text-shadow: 0 1px 0 var(--ink); }
.goals li.done { font-weight: 700; }

.routes { display: flex; flex-direction: column; gap: .35rem; }
.route-row { display: grid; grid-template-columns: 3.2rem 1fr auto; align-items: center; gap: .6rem; font-size: .92rem; }
.route-row .share { height: .7rem; border-radius: 99px; background: linear-gradient(90deg, var(--coral) var(--w), #eef2ee var(--w)); border: 1.5px solid var(--ink); }

.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.btn {
  font: 750 1rem var(--display); color: #fff; background: var(--ink); border: 2px solid var(--ink);
  border-radius: 12px; padding: .55rem 1.1rem; cursor: pointer; box-shadow: 0 4px 0 #000; transition: transform .08s, box-shadow .08s;
}
.btn:hover { background: #343b52; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.btn.ghost { background: var(--panel); color: var(--ink); box-shadow: var(--press); }
.btn.ghost:hover { background: #f3f7f3; }
.btn[aria-pressed="true"] { background: var(--coral); color: var(--ink); }
.seg { display: inline-flex; flex-wrap: wrap; border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; background: var(--panel); }
.seg button { font: 700 .9rem var(--display); border: 0; background: none; padding: .45rem .8rem; cursor: pointer; color: var(--ink); }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--sun); }

.knob { display: grid; grid-template-columns: 1fr auto; gap: 0 .6rem; align-items: baseline; font: 700 .9rem var(--display); }
.knob output { font-variant-numeric: tabular-nums; }
.knob input { grid-column: 1 / -1; width: 100%; accent-color: var(--violet); height: 1.6rem; }
.check { display: flex; align-items: center; gap: .4rem; font: 700 .92rem var(--display); margin-bottom: .4rem; }
.check input { accent-color: var(--violet); width: 1.1rem; height: 1.1rem; }
.drawer { border: 2px solid var(--ink); border-radius: var(--r); padding: .6rem .9rem; }
.drawer summary { font: 750 .95rem var(--display); cursor: pointer; }
.knobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .6rem 1.2rem; margin-top: .7rem; }

/* ---------- map ---------- */
.land { fill: var(--land); }
.block { fill: var(--block); }
.tree { fill: var(--tree); }
.river { fill: none; stroke: var(--water); stroke-width: 30; stroke-linecap: round; }
.bridge { stroke: #eef1ea; stroke-width: 26; stroke-linecap: round; }
.halo { fill: none; stroke-linecap: round; transition: stroke-width .35s; }
.halo.calm { stroke: var(--ok); opacity: .3; }
.halo.busy { stroke: var(--sun); opacity: .65; }
.halo.jam { stroke: var(--coral); opacity: .7; }
.road { fill: none; stroke: var(--road); stroke-linecap: round; transition: stroke-width .35s; }
.mark { fill: none; stroke: #fff; stroke-dasharray: 6 8; opacity: .8; }
.chev { fill: none; stroke: #fff; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.hit { fill: none; stroke: transparent; stroke-linecap: round; cursor: pointer; }
.hit:hover, .hit.selected { stroke: rgba(255, 199, 69, .45); }
.hit:focus { outline: none; } /* Safari outlines clicked SVG roads with a box; the road highlight is enough */
.hit:focus-visible { outline: none; stroke: rgba(140, 108, 240, .5); }
.junction { fill: #fff; stroke: var(--road); stroke-width: 3; }
.home { fill: var(--coral); stroke: var(--ink); stroke-width: 2.5; }
.work { fill: var(--violet); stroke: var(--ink); stroke-width: 2.5; }
.glyph { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.place { font: 800 12px var(--display); fill: var(--ink); text-anchor: middle; paint-order: stroke; stroke: var(--land); stroke-width: 4px; }
.car { stroke: rgba(35, 40, 58, .55); stroke-width: 1; }
.route { fill: none; stroke-linecap: round; pointer-events: none; }
.route.fastest { stroke: var(--sun); stroke-width: 6; stroke-dasharray: 10 9; animation: march 1s linear infinite; }
.route.drawn { stroke: var(--violet); stroke-width: 5; opacity: .22; }
.route.picked { stroke: var(--coral); stroke-width: 6; }
.route.caught { stroke: var(--ok); stroke-width: 7; }
.route.missed { stroke: var(--ink); stroke-width: 3; stroke-dasharray: 3 7; }
@keyframes march { to { stroke-dashoffset: -19; } }
.badge { cursor: pointer; }
.badge rect { fill: #fff; stroke: var(--ink); stroke-width: 1.6; }
.badge text { font: 800 11px var(--display); text-anchor: middle; fill: var(--ink); }

.popover {
  position: absolute; z-index: 5; transform: translate(-50%, calc(-100% - 16px));
  background: var(--panel); border: 2px solid var(--ink); border-radius: var(--r); box-shadow: 0 4px 0 var(--ink);
  padding: .6rem .8rem .7rem; width: min(17rem, 80vw); display: flex; flex-direction: column; gap: .45rem; font-size: .9rem;
}
.popover[hidden] { display: none; }
.popover.moved { transform: none; z-index: 50; } /* dragged: positioned on the page itself */
.pop-head { display: flex; align-items: center; gap: .45rem; font-family: var(--display); cursor: grab; touch-action: none; user-select: none; }
.pop-head strong { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pop-head:active { cursor: grabbing; }
.pop-head .grip { width: 10px; height: 14px; flex: none; background: radial-gradient(circle, var(--muted) 1.2px, transparent 1.6px) 0 0 / 5px 5px; }
.pop-head .x { border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted); }
.pop-lanes { display: flex; align-items: center; justify-content: space-between; font: 700 1rem var(--display); }
.pop-lanes b { font-size: 1.6rem; }
.round { width: 2.4rem; height: 2.4rem; border-radius: 50%; border: 2px solid var(--ink); background: var(--sun); font: 800 1.3rem/1 var(--display); cursor: pointer; box-shadow: 0 3px 0 var(--ink); color: var(--ink); }
.round:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.pop-meta { color: var(--muted); font-size: .85rem; line-height: 1.35; }
.pop-msg { color: #c2412a; font-size: .85rem; min-height: 0; }
.pop-msg:empty { display: none; }

/* ---------- charts ---------- */
.chart-box { width: 100%; }
.chart-box.tall { cursor: crosshair; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.axis text { font: 600 11px var(--display); fill: var(--muted); }
.axis line { stroke: #c4cfc7; }
.axis .grid { stroke: #e3eae4; }
.line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.c-violet { stroke: var(--violet); }
.c-sun { stroke: #e0a800; }
.c-coral { stroke: var(--coral); }
.thick { stroke-width: 3.5; }
.ref { stroke: var(--ink); stroke-dasharray: 4 4; stroke-width: 1.5; }
.ref.you { stroke: var(--coral); stroke-width: 2; }
.ref.ok { stroke: var(--ok); }
.ref-text { font: 700 11px var(--display); fill: var(--ink); }
.ref-text.you { fill: #d4502f; }
.flag { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 3 3; }
.flag-head { fill: var(--ink); }
.flag.ok { stroke: var(--ok); } .flag-head.ok { fill: var(--ok); }
.flag.miss { stroke: var(--coral); } .flag-head.miss { fill: var(--coral); }
.kink { fill: var(--coral); stroke: #fff; stroke-width: 2.5; }
.here { fill: var(--ink); stroke: #fff; stroke-width: 2.5; }
.chord { stroke: var(--violet); stroke-width: 3; stroke-linecap: round; }
.probe { fill: var(--violet); stroke: #fff; stroke-width: 2; }
.band { display: flex; height: 1.6rem; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; font: 700 .78rem/1.45rem var(--display); }
.band span { text-align: center; white-space: nowrap; overflow: hidden; }
.band span + span { border-left: 2px solid var(--ink); }
.seg-1 { background: var(--land); } .seg-2 { background: #ffe39b; } .seg-3 { background: #cfc2fa; }

.meter { position: relative; height: 1.3rem; border: 2px solid var(--ink); border-radius: 99px; background: #eaf7f0; overflow: hidden; margin: .35rem 0; }
.meter .fill { height: 100%; background: repeating-linear-gradient(45deg, var(--coral) 0 10px, #ff9478 10px 20px); transition: width .35s; border-right: 2px solid var(--ink); }
.meter-scale { display: flex; justify-content: space-between; font: 700 .75rem var(--display); color: var(--muted); margin-top: -.2rem; }
.meter-scale span:first-child { color: #178a55; }

/* ---------- level 4 ---------- */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .75rem; }
.scoreboard .side { border: 2px solid var(--ink); border-radius: var(--r); padding: .6rem .9rem; }
.scoreboard .you { background: #ffe4dc; }
.scoreboard .zos { background: #e8e1fd; text-align: right; }
.scoreboard .big { font-size: 2rem; }
.scoreboard .zos .unit { display: block; }
.vs { font: 800 1rem var(--display); width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; background: var(--sun); }

/* ---------- level 5 ---------- */
.hand { display: flex; flex-wrap: wrap; gap: .45rem; min-height: 0; }
.card {
  width: 4.1rem; height: 5.2rem; border: 2px solid var(--ink); border-radius: 10px; background: #fff;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .1rem; position: relative;
  box-shadow: 0 3px 0 var(--ink); animation: deal .35s both;
}
.card b { font: 800 1rem var(--display); }
.card span { font-size: .72rem; color: var(--muted); }
.card.pick { background: #fff4d1; transform: translateY(-6px); border-color: var(--ink); box-shadow: 0 6px 0 var(--ink); }
.card.best::after { content: '★'; position: absolute; top: .1rem; right: .3rem; color: #f2b200; font-size: .9rem; }
@keyframes deal { from { opacity: 0; transform: translateY(-14px) rotate(-6deg); } }
.deck-stats { display: flex; flex-direction: column; gap: .6rem; }
.deck-row { display: grid; grid-template-columns: 1fr; gap: .05rem; font-size: .9rem; opacity: .7; }
.deck-row.active { opacity: 1; }
.kbar { display: block; height: .55rem; border-radius: 99px; border: 1.5px solid var(--ink); background: linear-gradient(90deg, var(--violet) var(--k), #f0ecfd var(--k)); margin-top: .15rem; }
.hist { display: flex; align-items: flex-end; gap: .25rem; height: 8rem; padding-top: .4rem; }
.hist .bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.hist .count { width: 100%; height: var(--h); background: var(--block); border: 1.5px solid var(--ink); border-radius: 4px 4px 0 0; }
.hist .bar.has-best .count { background: var(--sun); }
.hist .draw { position: absolute; left: -2px; right: -2px; bottom: calc(1.1rem + var(--h)); height: 3px; background: var(--violet); border-radius: 2px; transition: bottom .3s; }
.hist small { font: 700 .72rem/1.1rem var(--display); color: var(--muted); }

/* ---------- interlude, debrief, finale ---------- */
.plain { max-width: 44rem; margin: 3.5rem auto 0; background: var(--panel); border: 2px solid var(--ink); border-radius: 20px; padding: 1.75rem 2rem 1rem; box-shadow: 0 6px 0 var(--ink); }
.plain.interlude { background: #fffaf0; }
.plain.interlude h2::before { content: 'Between levels'; display: block; font: 700 .9rem var(--display); color: var(--muted); margin-bottom: .4rem; letter-spacing: 0; }
.plain.debrief h2::before { content: 'Debrief'; display: block; font: 700 .9rem var(--display); color: var(--muted); margin-bottom: .4rem; letter-spacing: 0; }
.plain.finale { background: var(--violet); color: #fff; }
.plain.finale h2 { color: #fff; }
.plain.finale strong { font: 800 1.35rem var(--display); }
.prose table { width: 100%; border-collapse: separate; border-spacing: 0; border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; font-size: .93rem; margin: 1rem 0 1.4rem; }
.prose th { background: var(--sun); text-align: left; padding: .5rem .65rem; font-family: var(--display); border-bottom: 2px solid var(--ink); }
.prose td { padding: .5rem .65rem; border-bottom: 1.5px solid #dfe6e0; vertical-align: top; }
.prose tr:last-child td { border-bottom: 0; }

footer { max-width: 44rem; margin: 3rem auto 0; padding: 0 1.25rem 4rem; color: var(--muted); font-size: .92rem; }
.big-total { font: 800 1.6rem var(--display); color: var(--ink); }
footer pre { background: var(--panel); border: 2px solid var(--ink); border-radius: var(--r); padding: 1rem; overflow-x: auto; font-size: .78rem; color: var(--ink); }

/* ---------- small screens ---------- */
@media (max-width: 980px) {
  .hero-main { grid-template-columns: 1fr; gap: 1.5rem; }
  .levels { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 13rem; overflow-x: auto; padding-bottom: .6rem; scroll-snap-type: x mandatory; }
  .level-card { scroll-snap-align: start; }
  .level-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  .board-wrap, .board-wrap.stick { position: static; order: -1; }
}
@media (max-width: 560px) {
  .scoreboard { grid-template-columns: 1fr auto 1fr; gap: .4rem; }
  .scoreboard .side { padding: .5rem .6rem; }
  .vs { width: 2rem; height: 2rem; font-size: .8rem; }
  .hero-top { margin-bottom: 2rem; }
  .board { padding: .65rem; border-radius: 16px; }
  .panel-row { grid-template-columns: 1fr; }
  .plain { padding: 1.25rem 1.1rem .5rem; }
  .scoreboard .big { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.tangent { stroke: var(--ink); stroke-width: 1.6; stroke-dasharray: 5 4; opacity: .55; }
.share.road-1 { fill: var(--coral); }
.share.road-2 { fill: var(--sun); }
.share.road-3 { fill: var(--violet); }
.share-frame { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.axis-label { font: 700 11px var(--display); fill: var(--muted); }
.bridge-rail { fill: none; stroke: var(--ink); stroke-width: 24; stroke-linecap: butt; }
.bridge { fill: none; stroke: #f4f1e6; stroke-width: 19; stroke-linecap: butt; }
.road.shortcut { stroke: #59617a; }
.time-tag text { font: 800 12px var(--display); fill: var(--ink); text-anchor: middle; paint-order: stroke; stroke: var(--land); stroke-width: 4px; }
.time-tag.short text { fill: var(--violet); stroke: #f4f1e6; }
