/* app.css: the shell. Tokens, type roles, the page grid and its phone order, title, search
   field, key, tooltip, drawer frame, map control overrides, focus. What goes inside #band,
   #drawer and #rail-body lives in replay.css, block.css and rail.css (docs/site-modules.md). */

/* ---------- tokens (docs/design.md section 10) ---------- */
:root {
  color-scheme: light;
  --ground: #f1f2f6; --raised: #fafafc; --wash: #e7e7ed; --rule: #d3d4db;
  --ink: #131426; --ink-2: #494b60; --ink-3: #65677a;
  --band: #131426; --band-ink: #eaebf1; --band-ink-2: #a2a3b1; --band-rule: #353647; --band-trace: #65677a;
  --signal: #ed4423; --on-signal: #131426;
  --era-0: #121337; --era-1: #2a2776; --era-2: #4543ae; --era-3: #666cc8; --era-4: #8c95dc; --era-none: #a8a8ab;
  --zone-liq: #c03a92; --zone-liq-opacity: 0.26; --zone-liq-tint: #e4c2dc; --zone-liq-line: #8a1f66;
  --zone-slide: #dca81c; --zone-slide-opacity: 0.42; --zone-slide-tint: #e8d39a; --zone-slide-line: #93690d;
  --zone-ap: #131426; --zone-ap-opacity: 0.1; --zone-ap-tint: #dbdce1; --zone-ap-line: #131426;
  --select: #ffffff; --context: #e6e7ee;
  --edge: rgb(19 20 38 / 0.35); /* inset line for swatches too light to hold 3:1 on the ground */
  --hatch: repeating-linear-gradient(135deg, var(--ink-3) 0 1px, transparent 1px 5.66px);
  --map-water: #c3c9d6; --map-park: #e4ece5; --map-road: #fdfdff;
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --wdth-display: 62%; --wdth-tight: 80%; --wdth-text: 100%;
  --t-11: 0.6875rem; --t-12: 0.75rem; --t-14: 0.875rem; --t-16: 1rem; --t-20: 1.25rem; --t-28: 1.75rem; --t-40: 2.5rem; --t-56: 3.5rem;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;
  --radius: 2px; --shadow: 0 8px 24px rgb(19 20 38 / 0.14); --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 120ms; --t-move: 240ms; --t-slow: 480ms;
  --rail-w: 384px; --band-h: 96px; --gutter: 16px;
  --z-map: 0; --z-overlay: 10; --z-panel: 20; --z-band: 30; --z-dropdown: 40; --z-tooltip: 50;
}
@media (min-width: 821px) and (max-width: 1099px) { :root { --rail-w: 320px; } }
@media (max-width: 820px), (max-height: 520px) { :root { --t-56: 2rem; --t-20: 1.125rem; } }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); background: var(--ground);
  font: 400 var(--t-14) / 1.45 var(--font); font-stretch: var(--wdth-text);
  font-variant-numeric: tabular-nums;
}
button, input { font: inherit; font-stretch: inherit; color: inherit; }
button { padding: var(--s-1) var(--s-2); border: 1px solid currentColor; border-radius: var(--radius); background: none; cursor: pointer; }
a { color: inherit; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* The first stop on the page: hidden until focused. */
.skip {
  position: fixed; top: var(--s-2); left: var(--s-2); z-index: calc(var(--z-tooltip) + 1);
  padding: var(--s-2) var(--s-3); background: var(--raised); border: 1px solid var(--ink); border-radius: var(--radius);
  font-weight: 600; text-decoration: none;
}
.skip:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Type roles shared by every module (design.md section 9). */
.display { font: 700 var(--t-28) / 1 var(--font); font-stretch: var(--wdth-display); }
.small { font-size: var(--t-12); line-height: 1.35; }
.axis { font: 500 var(--t-11) / 1.2 var(--font); font-stretch: var(--wdth-tight); }

.swatch { display: inline-block; flex: none; width: 10px; height: 10px; }
.swatch[data-hatch] { background: var(--hatch); }

/* ---------- page grid (desktop) ---------- */
body {
  display: grid; height: 100dvh; overflow: hidden;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--band-h);
}
.rail {
  grid-column: 1; grid-row: 1; min-height: 0; overflow-y: auto; padding: var(--gutter);
  background: var(--ground); border-right: 1px solid var(--rule);
}
.stage { grid-column: 2; grid-row: 1; position: relative; min-height: 0; overflow: hidden; }
.band {
  grid-column: 1 / -1; grid-row: 2; position: relative; z-index: var(--z-band);
  background: var(--band); color: var(--band-ink);
}

/* ---------- title ---------- */
/* Two words offset along one hairline, like the two sides of a strike-slip fault. */
.title {
  margin: 0; text-transform: uppercase; letter-spacing: 0;
  font: 800 var(--t-56) / 0.88 var(--font); font-stretch: var(--wdth-display);
}
.title a { display: block; color: inherit; text-decoration: none; }
.title span { display: block; }
.title span:first-child { padding-bottom: 0.08em; border-bottom: 1px solid var(--ink); }
.title span:last-child { padding: 0.12em 0 0 0.5em; }

/* ---------- search field ---------- */
.search { position: relative; margin-top: var(--s-5); }
.search input {
  display: block; width: 100%; height: 44px; padding: 0 var(--s-3);
  border: 1px solid var(--ink); border-radius: var(--radius); background: var(--raised);
  font-size: var(--t-16); -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--ink-3); opacity: 1; }
#q-list {
  position: absolute; top: calc(100% + var(--s-1)); left: 0; right: 0; z-index: var(--z-dropdown);
  margin: 0; padding: 0; list-style: none;
  background: var(--raised); border: 1px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------- rail body: the roles the shell sets; the contents are rail.css ---------- */
.headline {
  margin: var(--s-5) 0 0; text-wrap: balance;
  font: 500 var(--t-20) / 1.3 var(--font); font-stretch: var(--wdth-text);
}
.headline b, .headline strong { font-weight: 700; }
.rail-body h2 { margin: var(--s-6) 0 var(--s-3); font: 600 var(--t-14) / 1.2 var(--font); font-stretch: var(--wdth-text); }

/* ---------- map ---------- */
.map-frame { position: absolute; inset: 0; background: var(--ground); }
#map { position: absolute; inset: 0; z-index: var(--z-map); font: inherit; }
/* Inset ring: the canvas fills the frame, so an outside ring would be clipped. */
#map .maplibregl-canvas:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
/* Rings on the roofs of the selected and lit buildings (rings.js): ink, cased in the ground
   color so they read on a dark roof and on the pale ground alike. */
.roof-rings { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.roof-ring {
  position: absolute; top: 0; left: 0; box-sizing: border-box; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border: 2.5px solid var(--ink); border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--ground), inset 0 0 0 1.5px var(--ground);
}
.roof-ring.lit { width: 14px; height: 14px; margin: -7px 0 0 -7px; border-width: 1.25px; box-shadow: 0 0 0 1px var(--ground), inset 0 0 0 1px var(--ground); }
.roof-ring[hidden] { display: none; }
.map-off { margin: 0; padding: var(--s-5); max-width: 32ch; }
/* No map (no WebGL) or no data: the search, the key and the replay have nothing to act on. */
/* #band by id: replay.css sets its display on the id. */
:is([data-nomap], [data-nodata]) :is(.search, .key, #band, .map-ramp) { display: none; }
body:is([data-nomap], [data-nodata]) { grid-template-rows: minmax(0, 1fr); } /* no band, no row for it */
/* The error the rail shows when the data does not load: its retry is the base button. */
.rail-body > p > button, #load-failed > a { margin-left: var(--s-2); }
.map-ramp { display: none; }

.maplibregl-map { font: inherit; }
.maplibregl-ctrl-top-left .maplibregl-ctrl { margin: var(--s-3) 0 0 var(--s-3); }
.maplibregl-ctrl-top-right .maplibregl-ctrl { margin: var(--s-3) var(--s-3) 0 0; }
.maplibregl-ctrl-group:not(:empty) { border-radius: var(--radius); box-shadow: none; border: 1px solid var(--rule); background: var(--ground); }
.maplibregl-ctrl-group button { border-radius: 0; }
.maplibregl-ctrl-group button + button { border-top-color: var(--rule); }
.maplibregl-ctrl-group button:focus-visible { box-shadow: none; outline: 2px solid var(--ink); outline-offset: 2px; }
.maplibregl-ctrl-attrib { font-size: var(--t-11); }
.maplibregl-ctrl-attrib.maplibregl-compact { border-radius: var(--radius); background: var(--ground); color: var(--ink-2); }
.maplibregl-ctrl-attrib.maplibregl-compact-show { background: var(--raised); }
/* Above the open drawer (drawer.js sets --drawer-covers; 0 on the phone), so the credits stay reachable. */
.maplibregl-ctrl-bottom-right { bottom: var(--drawer-covers, 0px); transition: bottom var(--t-move) var(--ease); }
.maplibregl-cooperative-gesture-screen { font: 600 var(--t-16) / 1.3 var(--font); }

/* ---------- key ---------- */
.key {
  position: absolute; top: var(--s-3); left: var(--s-3); z-index: var(--z-overlay); width: max-content;
  padding: var(--s-3); background: var(--ground); border: 1px solid var(--rule); border-radius: var(--radius);
  font-size: var(--t-12); line-height: 1.35;
}
/* Each group is titled like a rail section, at key size. */
.key-group + .key-group { margin-top: var(--s-3); }
.key-title { margin: 0 0 var(--s-2); font: 600 var(--t-12) / 1.2 var(--font); font-stretch: var(--wdth-text); }

/* The ramp and the detached "No year" swatch on one row; the years and its label on the next. */
.ramp {
  --sw: 32px; --sh: 10px; --nw: 20px;
  display: grid; grid-template-columns: calc(var(--sw) * 5) max-content; column-gap: var(--s-3); justify-content: start;
}
.ramp-swatches { display: flex; outline: 1px solid var(--edge); outline-offset: -1px; }
.ramp-swatches i { width: var(--sw); height: var(--sh); }
.ramp-none { width: var(--nw); height: var(--sh); background: var(--era-none); box-shadow: inset 0 0 0 1px var(--edge); }
.ramp-ticks { position: relative; display: block; height: 1.2em; margin-top: var(--s-1); color: var(--ink-2); }
.ramp-ticks span { position: absolute; top: 0; left: calc(var(--sw) * var(--i)); transform: translateX(-50%); }
.ramp-none-label { margin-top: var(--s-1); color: var(--ink-2); white-space: nowrap; }

/* One column: the three switches are a list, "Not evaluated" a plain legend row under them.
   Opening the definitions only reveals text; nothing reflows. */
.key-rows { display: grid; grid-template-columns: 1fr; gap: var(--s-1); margin: 0; padding: 0; list-style: none; }
/* The zones' title row carries the disclosure for the definitions. */
.key-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-2); }
.key-head .key-title { margin: 0; }
.key-more {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none;
  color: var(--ink-2); font: inherit; cursor: pointer;
}
.key-more:hover { color: var(--ink); }
.key-more:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; } /* the switches' ring */
.key-more::after {
  content: ""; width: 6px; height: 6px; margin-top: -3px; border: solid currentColor; border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg); transition: transform var(--t-fast) var(--ease);
}
.key-more[aria-expanded="true"]::after { margin-top: 3px; transform: rotate(-135deg); }
/* width 0 / min-width 100%: the sentences wrap to the key's width instead of setting it. */
.key-def { display: none; width: 0; min-width: 100%; margin: 0; color: var(--ink-2); }
.key-zones[data-defs] .key-def { display: block; }
.key-zones[data-defs] { width: 296px; }
.key-zones[data-defs] .key-rows { gap: var(--s-2); }
.key-lead { margin-bottom: var(--s-3); color: var(--ink); }
.key-rows .key-def { margin-top: var(--s-1); padding-left: 31px; } /* 1 border + 8 pad + 14 swatch + 8 gap */
.key-foot { margin-top: var(--s-3); padding-left: 31px; }
.key-foot a { color: var(--ink); }
.key-row {
  display: flex; align-items: center; gap: var(--s-2); width: 100%; min-height: 28px; padding: 0 var(--s-2);
  border: 1px solid transparent; border-radius: var(--radius); background: none; text-align: left; white-space: nowrap;
}
.key .swatch { width: 14px; height: 14px; border: 1px solid transparent; }
/* The liquefaction tint with the map's stipple on it. */
.key .swatch[data-zone="liq"] {
  border-color: var(--zone-liq-line);
  background:
    radial-gradient(circle, var(--zone-liq-line) 0.7px, transparent 1.1px) 0 0 / 6px 6px,
    radial-gradient(circle, var(--zone-liq-line) 0.7px, transparent 1.1px) 3px 3px / 6px 6px,
    var(--zone-liq-tint);
}
.key .swatch[data-zone="sl"] { background: var(--zone-slide-tint); border-color: var(--zone-slide-line); }
/* The fault zone tint with a trace across it: the switch shows the traces too. */
.key .swatch[data-zone="ap"] {
  border: 1px dashed var(--zone-ap-line);
  background: linear-gradient(var(--zone-ap-line), var(--zone-ap-line)) center / 100% 1px no-repeat, var(--zone-ap-tint);
}
.zone-switch {
  border-color: var(--rule); background: var(--raised); cursor: pointer;
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.zone-switch:hover { background: var(--wash); }
.zone-switch[aria-checked="false"] { background: none; color: var(--ink-3); }
.zone-switch[aria-checked="false"]:hover { background: var(--wash); }
.key .zone-switch[aria-checked="false"] .swatch { background: none; border: 1px solid var(--ink-3); }

/* ---------- tooltip ---------- */
.tip {
  position: absolute; top: 0; left: 0; z-index: var(--z-tooltip); max-width: 280px; padding: var(--s-2) var(--s-3);
  background: var(--raised); border-radius: var(--radius); box-shadow: var(--shadow);
  pointer-events: none; font-size: var(--t-12); line-height: 1.35; will-change: transform;
}
.tip p { margin: 0; }
.tip-title { font-size: var(--t-14); font-weight: 600; }
.tip-quiet { color: var(--ink-2); }
.tip-counts { display: grid; grid-template-columns: auto auto 1fr; gap: 0 var(--s-2); align-items: center; margin: var(--s-1) 0 0; }
.tip-counts dt { display: contents; }
.tip-counts dd { margin: 0; text-align: right; }

/* ---------- drawer frame (contents: block.css) ---------- */
/* As tall as its content, up to 62% of the stage; past that the content scrolls inside. */
.drawer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: var(--z-panel); max-height: 62%;
  overflow: auto; background: var(--ground); border-top: 1px solid var(--ink); box-shadow: var(--shadow);
  transform: translateY(100%); visibility: hidden;
  transition: transform var(--t-move) var(--ease), visibility 0s linear var(--t-move);
}
.drawer[data-open] { transform: none; visibility: visible; transition-delay: 0s; }

/* ---------- phone: one column, the page scrolls ---------- */
@media (max-width: 820px), (max-height: 520px) {
  body { display: flex; flex-direction: column; height: auto; min-height: 100svh; overflow: visible; }
  /* The rail and the stage dissolve; their children become items of the page column. */
  .rail, .stage, .rail-body { display: contents; }

  .axis { font-size: var(--t-12); }
  .title { order: 1; margin: var(--gutter) var(--gutter) 0; }
  .title span:first-child { padding-bottom: 0.06em; }
  .title span:last-child { padding: 0; margin-top: 0.12em; }
  .title a { display: flex; align-items: flex-start; gap: 0.22em; }
  .rail-body > .headline { order: 2; margin: var(--s-4) var(--gutter) 0; }
  .search { order: 3; margin: var(--s-4) var(--gutter) 0; }

  /* The frame is its own stack: the ramp sits over the canvas and under MapLibre's controls
     (z-index 2), so the opened attribution covers the ramp. */
  .map-frame { order: 5; position: relative; inset: auto; flex: none; height: 64svh; min-height: min(360px, calc(100svh - var(--s-4))); margin-top: var(--s-3); isolation: isolate; }
  body[data-drawer] .map-frame { height: 44svh; min-height: 0; }
  #map { z-index: auto; }
  .map-ramp {
    display: block; position: absolute; left: var(--s-2); bottom: var(--s-2); z-index: 1;
    padding: 6px var(--s-2) 2px; background: var(--ground); border: 1px solid var(--rule); border-radius: var(--radius);
  }
  .map-ramp .ramp { --sw: 28px; --sh: 8px; --nw: 16px; column-gap: var(--s-2); }
  .map-ramp .key-title { margin-bottom: var(--s-1); font-size: var(--t-12); }

  .drawer {
    order: 6; position: static; flex: none; max-height: none; overflow: visible; transform: none; visibility: visible;
    box-shadow: none; transition: none; scroll-margin-top: var(--s-2);
  }
  .drawer:not([data-open]) { display: none; }

  .band { order: 7; flex: none; }

  /* The year group rides on the map (#map-ramp); the zone switches sit right above the map,
     so the map and an open block panel stay together under them. */
  .key { order: 4; position: static; width: auto; margin-top: var(--s-4); padding: 0 var(--gutter); border: 0; border-radius: 0; background: none; box-shadow: none; font-size: var(--t-14); }
  .key .key-era { display: none; }
  .key .key-zones { margin-top: 0; } /* the first group shown: no gap from a hidden one */
  .key-title { font-size: var(--t-12); }
  .key-head { align-items: center; min-height: 28px; margin-bottom: var(--s-2); }
  .key-more::before { content: ""; position: absolute; inset: -12px -8px; } /* a 44px touch target */
  /* The three switches in one row (2 + 1 on the narrowest phones), "Not evaluated" under them;
     open, one column again, each row with its sentence. */
  .key-rows { display: flex; flex-wrap: wrap; gap: var(--s-2); }
  .key-plain { flex-basis: 100%; }
  .key-plain .key-row { min-height: 28px; }
  .key-zones[data-defs] { width: auto; }
  .key-zones[data-defs] .key-rows { display: grid; grid-template-columns: 1fr; }
  .key-row { min-height: 44px; }

  .rail-body > * { order: 8; margin-left: var(--gutter); margin-right: var(--gutter); }
  .rail-body > :last-child { margin-bottom: var(--s-6); }
}

@media (prefers-reduced-motion: reduce) {
  .drawer, .zone-switch, .key-more::after, .maplibregl-ctrl-bottom-right { transition: none; }
}
