/* Explore — /demo and /lab. MIX editorial-spatial: crisp white over a quiet
   map, periwinkle-indigo for progress, orange only for the one live moment
   (the stage running now, the play button, the chosen place). */
:root {
  --brand: #5554C6;
  --brand-deep: #4342A1;
  --brand-wash: rgba(85, 84, 198, 0.08);
  --brand-line: rgba(85, 84, 198, 0.28);
  --action: #FF6017;
  --action-deep: #D94A08;
  --aqua: #84D1DF;
  --ink: #1A1A1A;
  --slate: #5A5763;
  --muted: #8A8690;
  --line: #EAEAEA;
  --canvas: #F9F9F9;
  --white: #FFFFFF;
  --danger-wash: rgba(255, 96, 23, 0.08);

  --graph-kind-site: #5554C6;
  --graph-kind-area: #2E8FA3;
  --graph-kind-person: #A2447F;
  --graph-kind-group: #3E8762;
  --graph-kind-event: #B07A1E;
  --graph-kind-work: #2F72B0;
  --graph-kind-concept: #7C5CC4;
  --graph-kind-unknown: #B9B6BC;

  --font-structure: 'Urbanist', system-ui, sans-serif;
  --font-action: 'Albert Sans', system-ui, sans-serif;
  --font-read: 'Crimson Text', Georgia, serif;
  --font-data: 'Space Mono', ui-monospace, monospace;

  --panel-w: 400px;
  --radius: 14px;
  --shadow: 0 10px 30px -12px rgba(67, 66, 161, 0.28), 0 2px 6px rgba(26, 26, 26, 0.06);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glass: rgba(255, 255, 255, 0.92);
  --map-bg: #EEF0F2;
  --tile-filter: grayscale(1) contrast(.5) brightness(1.28);
  /* Stage marks (placemap-ia key): indigo kept, orange in use, teal context, grey considered / filtered out. */
  --st-kept: #5554C6; --st-live: #E8540F; --st-ctx: #1F8A9E; --st-grey: #8A8690; --st-ctx-fill: rgba(31, 138, 158, .10);
  color-scheme: light;
}
/* The system theme. `--white` is the surface colour throughout this file. */
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #7F7EE6; --brand-deep: #A9A8F5; --brand-wash: rgba(127, 126, 230, 0.14); --brand-line: rgba(127, 126, 230, 0.36);
    --action: #FF6A24; --action-deep: #FF8A52;
    --ink: #F2F1F5; --slate: #B8B4C1; --muted: #8E8A96; --line: #2E2D36; --canvas: #121216; --white: #1B1B21;
    --danger-wash: rgba(255, 106, 36, 0.14); --glass: rgba(27, 27, 33, 0.92); --map-bg: #1A1B1F;
    --tile-filter: invert(1) hue-rotate(180deg) grayscale(1) brightness(.78) contrast(.92);
    --st-kept: #7F7EE6; --st-live: #EE6325; --st-ctx: #35A2B6; --st-grey: #8E8A96; --st-ctx-fill: rgba(53, 162, 182, .14);
    --shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
  .leaflet-control-zoom a { background: var(--white) !important; color: var(--ink) !important; border-color: var(--line) !important; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--canvas);
  color: var(--ink);
  font: 400 15px/1.45 var(--font-structure);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--brand-deep); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.icon { display: block; flex: none; }

/* MARK: - Stage */

.stage { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); }
.leaflet-container { font: inherit; }
.leaflet-tile-pane { opacity: .8; }
.leaflet-tile-pane img.leaflet-tile { filter: var(--tile-filter); -webkit-filter: var(--tile-filter); }
.leaflet-control-attribution { font: 10px/1.4 var(--font-structure); background: var(--glass) !important; color: var(--muted); }
.leaflet-bottom.leaflet-right { margin-right: calc(var(--panel-w) + 24px); }
body[data-surface="chapters"] #map, body.is-inspecting #map { cursor: crosshair; }

/* MARK: - Top bar */

.topbar {
  position: absolute; top: 16px; left: 16px; right: calc(var(--panel-w) + 32px);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; pointer-events: none; z-index: 800;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 12px;
  background: var(--white); border-radius: 999px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink);
}
.brand-title { font: 600 15px/1 var(--font-structure); }
.brand-route { font: 400 11px/1 var(--font-data); color: var(--muted); }

.toggle {
  display: inline-flex; align-items: center; gap: 10px; padding: 7px 14px 7px 8px; min-height: 40px;
  background: var(--white); border: 0; border-radius: 999px; box-shadow: var(--shadow); cursor: pointer;
  font: 700 13px/1 var(--font-action); letter-spacing: 0.02em;
}
.toggle-track { width: 38px; height: 24px; border-radius: 999px; background: var(--line); position: relative; transition: background .25s var(--ease-out); }
.toggle-track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--white); box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .3s var(--ease-out);
}
.toggle[aria-checked="true"] .toggle-track { background: var(--brand); }
.toggle[aria-checked="true"] .toggle-track::after { transform: translateX(14px); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 36px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  font: 600 12px/1 var(--font-structure); color: var(--slate);
}
.chip[aria-disabled="true"] { color: var(--muted); border-style: dashed; cursor: not-allowed; }
.chip-soon { font: 400 10px/1 var(--font-data); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }


.spend { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 2px 4px; padding: 8px 12px; background: var(--white); border-radius: 12px; box-shadow: var(--shadow); }
.spend-num { font: 700 13px/1 var(--font-data); }
.spend-cap { font: 400 11px/1 var(--font-data); color: var(--muted); }
.spend-bar { grid-column: 1 / -1; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.spend-bar > span { display: block; height: 100%; background: var(--brand); transform-origin: left; }
.spend.is-capped .spend-bar > span { background: var(--action); }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--white); box-shadow: var(--shadow); color: var(--brand-deep); cursor: pointer;
}
.icon-btn:hover { color: var(--brand); }

.graph-status {
  position: absolute; left: 16px; bottom: 22px; z-index: 800; max-width: min(420px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px;
  background: var(--glass); box-shadow: var(--shadow); font: 500 12px/1.3 var(--font-structure); color: var(--slate);
}
.graph-status[hidden] { display: none; }
.graph-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; }
.graph-status[data-state="loading"]::before, .graph-status[data-state="slow"]::before { animation: breathe 1.2s ease-in-out infinite; }
.graph-status[data-state="slow"]::before { background: var(--aqua); }
.graph-status[data-state="error"]::before { background: var(--action); }
.graph-status[data-state="zoom"]::before { background: var(--muted); }

/* MARK: - Panel (desktop: floating column; phone: bottom sheet) */

.panel {
  position: absolute; top: 16px; right: 16px; bottom: 16px; width: var(--panel-w); z-index: 900;
  display: flex; flex-direction: column; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 20px 20px 24px; }
.panel-grip { display: none; }

.hello h1 { font: 700 26px/1.1 var(--font-structure); letter-spacing: -0.02em; margin: 4px 0 10px; text-wrap: balance; }
.hello p { font: 400 18px/1.4 var(--font-read); color: var(--slate); margin: 0 0 12px; max-width: 34ch; }
.hello .hint { display: flex; gap: 10px; align-items: center; font: 600 13px/1.3 var(--font-structure); color: var(--brand-deep); margin-top: 18px; }

/* The rail */
.attempt-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 0 10px; }
.attempt-head h2 { font: 700 13px/1 var(--font-action); letter-spacing: .08em; text-transform: uppercase; color: var(--slate); margin: 0; }
.attempt-head .total { font: 400 12px/1 var(--font-data); color: var(--slate); }
.rail { list-style: none; margin: 0 0 16px; padding: 0; position: relative; }
.rail::before { content: ''; position: absolute; left: 7px; top: 12px; bottom: 12px; width: 1.5px; background: var(--line); }
.rail-row {
  position: relative; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; column-gap: 12px; align-items: baseline;
  padding: 8px 0; min-height: 36px;
}
.rail-node {
  grid-row: 1 / span 2; align-self: center; width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--white); position: relative; z-index: 1; transition: all .35s var(--ease-out);
}
.rail-label { font: 600 14px/1.2 var(--font-structure); color: var(--muted); transition: color .3s; }
.rail-note { grid-column: 2; grid-row: 2; font: 400 12.5px/1.35 var(--font-structure); color: var(--slate); }
.rail-note:empty { display: none; }
.rail-num { font: 400 12px/1.2 var(--font-data); color: var(--slate); text-align: right; min-width: 0; }
.rail-cost { color: var(--muted); min-width: 52px; }
.rail-row[data-state="done"] .rail-node { border-color: var(--brand); background: var(--brand); box-shadow: inset 0 0 0 3px var(--white); }
.rail-row[data-state="done"] .rail-label { color: var(--ink); }
.rail-row[data-state="running"] .rail-node { border-color: var(--action); background: var(--action); animation: pulse 1.4s var(--ease-out) infinite; }
.rail-row[data-state="running"] .rail-label { color: var(--ink); }
.rail-row[data-state="running"] .rail-num { color: var(--action-deep); }
.rail-row[data-state="failed"] .rail-node { border-color: var(--action); background: var(--white); border-width: 3px; }
.rail-row[data-state="failed"] .rail-label { color: var(--action-deep); }
.rail-row[data-state="failed"] .rail-note { color: var(--action-deep); }
.rail-row[data-state="skipped"] .rail-node { border-style: dashed; }
.rail-slow { margin: -6px 0 16px 28px; padding: 10px 12px; border-radius: 10px; background: rgba(132, 209, 223, .18); font: 500 12.5px/1.4 var(--font-structure); color: var(--ink); }

.outcome { margin: 4px 0 18px; padding: 16px; border-radius: 12px; background: var(--danger-wash); }
.outcome[data-kind="refused"] { background: var(--brand-wash); }
.outcome h3 { margin: 0 0 6px; font: 700 17px/1.2 var(--font-structure); }
.outcome p { margin: 0 0 8px; font: 400 16px/1.4 var(--font-read); color: var(--ink); }
.outcome .outcome-tech { font: 400 11px/1.4 var(--font-data); color: var(--slate); }
.outcome .outcome-hint { font: 500 13px/1.4 var(--font-structure); color: var(--slate); margin: 4px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 0; cursor: pointer; font: 700 13px/1 var(--font-action); letter-spacing: .06em; text-transform: uppercase;
}
.btn-primary { background: var(--action); color: #fff; box-shadow: 0 6px 16px -8px rgba(217, 74, 8, .7); }
.btn-primary:hover { background: var(--action-deep); }
.btn-secondary { background: var(--brand); color: #fff; }
a.btn { text-decoration: none; }
.btn-ghost { background: transparent; color: var(--brand-deep); box-shadow: inset 0 0 0 1.5px var(--brand-line); }
.btn-ghost:hover { box-shadow: inset 0 0 0 1.5px var(--brand); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* The player */
.player { animation: rise .6s var(--ease-out) both; margin-bottom: 18px; }
.player-where { margin: 0 0 6px; font: 400 11px/1 var(--font-data); letter-spacing: .04em; text-transform: uppercase; color: var(--brand-deep); }
.player-title { margin: 0 0 14px; font: 700 24px/1.12 var(--font-structure); letter-spacing: -0.015em; text-wrap: balance; }
.transport { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; margin: 0 0 16px; }
.play {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--action); color: #fff; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 8px 18px -8px rgba(217, 74, 8, .8); transition: transform .2s var(--ease-out);
}
.play:hover { transform: scale(1.04); }
.player.is-playing .play { background: var(--ink); box-shadow: none; }
.scrub { height: 28px; display: flex; align-items: center; cursor: pointer; position: relative; }
.scrub::before { content: ''; position: absolute; left: 0; right: 0; height: 3px; border-radius: 3px; background: var(--line); }
.scrub-fill { position: absolute; left: 0; right: 0; height: 3px; border-radius: 3px; background: var(--brand); transform-origin: left; transform: scaleX(0); }
.clock { font: 400 12px/1 var(--font-data); color: var(--slate); min-width: 76px; text-align: right; }
.player-silent { font: 500 13px/1.4 var(--font-structure); color: var(--slate); margin: 0 0 12px; }

.script { display: grid; gap: 10px; }
.turn { margin: 0; display: grid; grid-template-columns: 44px 1fr; gap: 10px; font: 400 18px/1.42 var(--font-read); color: var(--ink); transition: color .4s, opacity .4s; }
.turn:not([data-speaker]) { grid-template-columns: 1fr; }
.speaker { font: 700 10.5px/2.3 var(--font-action); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.turn[data-speaker="Kana"] .speaker { color: var(--brand); }
.turn[data-speaker="Polo"] .speaker { color: var(--graph-kind-area); }
.player.is-playing .turn { color: var(--muted); }
.player.is-playing .turn.is-past { color: var(--slate); }
.player .turn.is-now { color: var(--ink); }

.player-foot { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 8px; font: 400 11.5px/1.3 var(--font-data); color: var(--slate); }
.voice-note, .sources { margin: 0 0 6px; font: 400 12px/1.4 var(--font-structure); color: var(--muted); }

.next-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 18px; }

/* Selected graph node */
.node-card h2 { margin: 2px 0 6px; font: 700 22px/1.15 var(--font-structure); }
.node-kind { display: inline-flex; align-items: center; gap: 6px; font: 400 11px/1 var(--font-data); text-transform: uppercase; letter-spacing: .05em; color: var(--slate); }
.node-kind i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.node-links { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 2px; }
.node-links li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font: 500 13.5px/1.3 var(--font-structure); }
.node-links li span:last-child { font: 400 10.5px/1.3 var(--font-data); color: var(--muted); }

/* Drawer (how it works / details) */
.drawer {
  position: absolute; inset: 0; z-index: 2; background: var(--white); display: flex; flex-direction: column;
  transform: translateX(102%); transition: transform .45s var(--ease-out); visibility: hidden;
}
.drawer.is-open { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 20px; }
.drawer-head h2 { margin: 0; font: 700 18px/1.2 var(--font-structure); }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 20px 24px; }
.how { list-style: none; margin: 8px 0 18px; padding: 0; counter-reset: how; }
.how li { display: grid; grid-template-columns: 16px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.how li::before { content: ''; width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; border: 1.5px solid var(--brand); }
.how b { display: block; font: 700 14px/1.3 var(--font-structure); }
.how span { font: 400 16px/1.4 var(--font-read); color: var(--slate); }
.how-foot { font: 400 15px/1.45 var(--font-read); color: var(--slate); }

/* Lab details */
.lab-controls { display: grid; gap: 12px; margin: 0 0 18px; }
.tabs { display: grid; grid-template-columns: repeat(3, auto); gap: 4px; padding: 4px; background: var(--canvas); border-radius: 12px; justify-content: start; }
.tab { border: 0; background: transparent; padding: 9px 12px; min-height: 38px; border-radius: 9px; cursor: pointer; font: 600 13px/1 var(--font-structure); color: var(--slate); }
.tab[aria-selected="true"] { background: var(--white); color: var(--ink); box-shadow: 0 1px 4px rgba(26,26,26,.1); }
.tab[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; }
.field { display: flex; gap: 10px; align-items: center; justify-content: space-between; font: 500 13px/1.2 var(--font-structure); color: var(--slate); }
.field select { font: 500 13px/1 var(--font-structure); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--white); min-height: 36px; max-width: 230px; }
.field input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.lab-note { font: 400 12.5px/1.4 var(--font-structure); color: var(--slate); margin: 0; }
details.section { border-top: 1px solid var(--line); padding: 10px 0; }
details.section > summary { cursor: pointer; font: 700 12px/1.4 var(--font-action); letter-spacing: .06em; text-transform: uppercase; color: var(--slate); list-style: none; display: flex; justify-content: space-between; }
details.section > summary::after { content: '+'; font: 400 14px/1 var(--font-data); }
details.section[open] > summary::after { content: '−'; }
details.section > summary::-webkit-details-marker { display: none; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 10px 0 0; font: 400 12px/1.4 var(--font-structure); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--font-data); font-size: 11.5px; overflow-wrap: anywhere; }
.table { width: 100%; border-collapse: collapse; margin: 10px 0 0; font: 400 12.5px/1.3 var(--font-structure); }
.table th { text-align: left; font: 700 10px/1.2 var(--font-action); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 6px 6px 0; }
.table td { padding: 5px 6px 5px 0; border-top: 1px solid var(--line); vertical-align: top; }
.table td.num { font-family: var(--font-data); font-size: 11.5px; text-align: right; white-space: nowrap; }
.table tr.is-top td:first-child { font-weight: 700; color: var(--brand-deep); }
pre.code { margin: 10px 0 0; padding: 12px; background: var(--canvas); border-radius: 8px; font: 400 11px/1.5 var(--font-data); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto; }
.error-line { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; background: var(--danger-wash); font: 500 13px/1.4 var(--font-structure); color: var(--action-deep); }
.error-line:empty { display: none; }

/* MARK: - Map flow layer */

.flow-node { transform-box: fill-box; transform-origin: center; fill: var(--brand); fill-opacity: .7; stroke: var(--white); stroke-width: 1.5; animation: appear .5s var(--ease-out) both; transition: fill .4s, fill-opacity .4s, stroke .4s; }
.flow-node.is-dim { fill: var(--muted); fill-opacity: .35; stroke-opacity: .5; }
.flow-node.is-eligible { fill: var(--brand); fill-opacity: .9; stroke-width: 1.5; }
.flow-node.is-top { fill: var(--brand-deep); fill-opacity: 1; stroke: var(--white); stroke-width: 2.5; }
.flow-node.is-chosen { fill: var(--action); fill-opacity: 1; stroke: var(--white); stroke-width: 3; }
.flow-chosen-ring { fill: none; stroke: var(--action); stroke-width: 1.5; animation: ring 2.2s var(--ease-out) infinite; transform-box: fill-box; transform-origin: center; }
.flow-tether { stroke: var(--action); stroke-width: 2; stroke-dasharray: 2 7; stroke-linecap: round; fill: none; animation: tether 1s linear infinite; }
.flow-sweep { fill: var(--white); fill-opacity: .35; stroke: var(--brand); stroke-opacity: .35; stroke-width: 1; stroke-dasharray: 3 6; }
.flow-sweep.is-scanning { animation: sweep 1.6s var(--ease-out) infinite; transform-box: fill-box; transform-origin: center; }
.is-making .pin:not(.is-selected) { opacity: .25; transition: opacity .4s; }
.stage-node.is-dim, .stage-node.is-eligible { transition-delay: .8s; } /* the packet read first, then its grading */
.hex-grid { fill: none; stroke: var(--brand); stroke-opacity: .16; stroke-width: 1; }
.hex-heard { fill: var(--brand); fill-opacity: .1; stroke: var(--brand); stroke-opacity: .4; stroke-width: 1; }
.hex-now { fill: var(--action); fill-opacity: .14; stroke: var(--action); stroke-width: 2; }
.flow-tip { font: 600 12px/1.2 var(--font-structure); border: 0; box-shadow: var(--shadow); border-radius: 8px; padding: 6px 9px; }

.listener-pin { position: relative; }
.listener-dot { position: absolute; inset: 3px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 3px var(--white), 0 3px 8px rgba(0,0,0,.35); }
.listener-ring { position: absolute; inset: -6px; border-radius: 50%; border: 1.5px solid var(--brand); opacity: 0; }
.listener-pin.is-scanning .listener-ring { animation: ping 1.6s var(--ease-out) infinite; }
.listener-pin.is-scanning .listener-ring-2 { animation-delay: .8s; }

@keyframes appear { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: none; } }
@keyframes ping { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(4.5); opacity: 0; } }
@keyframes sweep { 0% { transform: scale(.15); fill-opacity: .12; } 100% { transform: scale(1); fill-opacity: .02; } }
@keyframes ring { 0% { transform: scale(.7); opacity: .9; } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes tether { to { stroke-dashoffset: -9; } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 96, 23, .45); } 50% { box-shadow: 0 0 0 6px rgba(255, 96, 23, 0); } }
@keyframes breathe { 50% { opacity: .35; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* MARK: - Phone (375-430 px): full-bleed map, bottom sheet, 16 px gutters, 44 px targets */

.needs-tap .play { animation: pulse 1.4s var(--ease-out) infinite; }

@media (max-width: 760px) {
  :root { --panel-w: 100vw; --gutter: 16px; }
  body { font-size: 16px; }
  .topbar {
    top: max(10px, env(safe-area-inset-top)); left: var(--gutter); right: var(--gutter); gap: 8px;
  }
  .brand { padding: 0 14px 0 12px; min-height: 44px; align-items: center; }
  .brand-route { display: none; }
  .toggle, .seg button, .icon-btn { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .spend { padding: 7px 10px; }
  .spend-cap { display: none; }
  .leaflet-control-zoom { display: none; }
  .leaflet-bottom.leaflet-right { margin-right: 0; bottom: calc(var(--sheet-h, 50vh) + 4px); }
  .leaflet-control-attribution { font-size: 9px; }
  .graph-status {
    top: auto; bottom: calc(var(--sheet-h, 50vh) + 24px); left: var(--gutter); right: var(--gutter);
    max-width: none; border-radius: 14px;
  }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 52vh; max-height: none; min-height: 0;
    border-radius: 20px 20px 0 0; box-shadow: 0 -10px 30px -12px rgba(67, 66, 161, .38);
    transition: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.is-dragging { transition: none; }
  .panel-grip {
    /* The visual bar is small; the hit area is the full-width 44 px strip. */
    display: grid; place-items: center; flex: none; width: 100%; height: 44px; margin-bottom: -16px; padding: 0;
    border: 0; background: transparent; cursor: grab; touch-action: none;
  }
  .panel-grip span { width: 44px; height: 5px; border-radius: 5px; background: var(--muted); opacity: .55; }
  .panel-scroll { padding: 12px var(--gutter) 24px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
  .drawer { border-radius: 20px 20px 0 0; }
  .drawer-head { padding: 12px var(--gutter) 4px; }
  .drawer-body { padding: 4px var(--gutter) 24px; }

  .hello h1 { font-size: 23px; }
  .hello p { font-size: 17px; max-width: none; }
  .tab, .btn { min-height: 44px; }

  .rail-row { min-height: 44px; }
  .rail-note { font-size: 13px; }
  .rail-num { font-size: 12.5px; }
  .strip-label { font-size: 12px; }
  .player-title { font-size: 21px; }
  .transport { grid-template-columns: 52px 1fr auto; }
  .scrub { height: 44px; }
  .clock { min-width: 0; font-size: 12.5px; }
  .turn { font-size: 17.5px; grid-template-columns: 40px 1fr; }
  .facts, .voice-note, .sources { font-size: 12.5px; }
  .next-actions .btn, .row .btn { flex: 1 1 auto; }

  .tabs { display: flex; flex-wrap: wrap; }
  .tab { flex: 1 1 auto; }
  .field { flex-wrap: wrap; }
  .field select { flex: 1 1 60%; max-width: none; min-height: 44px; }
  details.section > summary { min-height: 44px; align-items: center; }
  .table { display: block; overflow-x: auto; }
  pre.code { max-width: 100%; }

}

/* A checkbox dressed as the same switch */
.toggle:has(input:checked) .toggle-track { background: var(--brand); }
.toggle:has(input:checked) .toggle-track::after { transform: translateX(14px); }
.toggle:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }

/* The folded rail above a finished beat */
.strip { margin: 0 0 18px; }
.strip ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
.strip li { padding: 7px 6px 6px; border-top: 2px solid var(--brand); display: grid; gap: 3px; }
.strip li[data-state="skipped"], .strip li[data-state="pending"] { border-top-color: var(--line); }
.strip li[data-state="failed"] { border-top-color: var(--action); }
.strip-label { font: 600 11px/1.15 var(--font-structure); color: var(--slate); overflow-wrap: anywhere; }
.strip-num { font: 400 11px/1 var(--font-data); color: var(--ink); }
.strip-sum { margin: 6px 0 0; font: 400 11px/1 var(--font-data); color: var(--muted); text-align: right; }

/* Surface switch (Explore | 36 hours) */
.seg { display: inline-flex; gap: 2px; padding: 4px; background: var(--white); border-radius: 999px; box-shadow: var(--shadow); }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 8px 14px; min-height: 36px; cursor: pointer;
  font: 700 13px/1 var(--font-action); color: var(--slate); display: inline-flex; align-items: center; gap: 6px; }
.seg button[aria-selected="true"] { background: var(--brand); color: #fff; }
.seg button[aria-selected="true"] .chip-soon { color: rgba(255,255,255,.8); }

@media (max-width: 760px) {
  .seg button { padding: 0 12px; font-size: 12.5px; }
}

/* Phone overrides for blocks defined after the main phone section. */
@media (max-width: 760px) {
  .seg button { min-height: 44px; }
  .sources a { display: inline-block; padding: 13px 0; margin: -13px 0; }
  .lab-controls, .lab-controls > * { min-width: 0; }
  .field { min-height: 44px; }
  .field select {
    width: 100%; min-width: 0; height: 44px; -webkit-appearance: none; appearance: none; padding: 0 32px 0 12px;
    background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235A5763' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
    font-size: 16px;
  }
  .tabs .tab { white-space: normal; }
  .brand-title, .seg .chip-soon, .spend-bar { display: none; }
  .brand { padding: 0 14px; }
  .strip li { padding: 7px 3px 6px; }
  .strip-label { font-size: 12px; }
  .strip-num, .strip-sum { font-size: 12px; }
}

/* Chapter mode, lab-only extras (the player itself is shared, below) */
.chapter-issues { margin: 10px 0; padding-left: 18px; font: 400 12px/1.4 var(--font-structure); color: var(--slate); }
.chapter-issues li[data-severity="error"] { color: var(--action-deep); font-weight: 600; }
.chapter-rail { margin: 14px 0; }
.chapter-rail h3 { margin: 0; font: 700 12px/1.2 var(--font-action); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chapter-cost td:nth-child(2) { color: var(--slate); }
.chapter-heard { list-style: none; margin: 4px 0 10px; padding: 0; font: 400 12px/1.5 var(--font-structure); color: var(--slate); }
.chapter-heard li[data-state="none"] { color: var(--muted); }
.chapter-heard li[data-state="partial"] { color: var(--brand-deep); }
.is-inspecting .panel-scroll { overflow-x: hidden; }
body:not(.is-inspecting) .inspector-only { display: none; }
.is-inspecting .jump { flex: 0 1 160px; min-width: 130px; max-width: 160px; } /* room for the Lab's fourth tab */
details.run-row > summary { flex-wrap: wrap; gap: 2px 10px; font: 600 14px/1.3 var(--font-structure); letter-spacing: 0; text-transform: none; color: var(--ink); }
details.run-row > summary > span:first-child { flex: 1; }
details.run-row > summary .meta { flex-basis: 100%; margin: 0; }
.chapter-cost { table-layout: fixed; }
.chapter-cost td, .chapter-cost th { overflow-wrap: anywhere; }
.chapter-cost th:nth-child(3), .chapter-cost td:nth-child(3) { width: 96px; }

/* MARK: - Jump to (search + preset cities) */
.jump { position: relative; flex: 0 1 280px; min-width: 200px; }
.jump-form { display: flex; align-items: center; gap: 8px; padding: 0 14px; min-height: 40px; background: var(--white); border-radius: 999px; box-shadow: var(--shadow); color: var(--slate); }
.jump-form:focus-within { box-shadow: var(--shadow), inset 0 0 0 1.5px var(--brand); }
.jump input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: 500 14px/1 var(--font-structure); color: var(--ink); padding: 10px 0; }
.jump input::placeholder { color: var(--slate); }
.jump input::-webkit-search-cancel-button { display: none; }
.jump-menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; list-style: none; margin: 0; padding: 6px; background: var(--white); border-radius: 14px; box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto; }
.jump-menu li[data-jump] { display: grid; gap: 2px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.jump-menu li[data-jump]:hover, .jump-menu li[data-jump]:focus { background: var(--brand-wash); outline: 0; }
.jump-name { font: 600 14px/1.2 var(--font-structure); color: var(--ink); }
.jump-detail { font: 400 12px/1.2 var(--font-structure); color: var(--muted); }
.jump-note { padding: 8px 10px 6px; font: 500 12px/1.3 var(--font-structure); color: var(--muted); }

/* MARK: - Empty state */
.hello h1 { font-size: 30px; }
.hello-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 4px; }
.hello-sub { margin: 26px 0 8px; font: 700 12px/1.2 var(--font-action); letter-spacing: .08em; text-transform: uppercase; color: var(--slate); }
.hello-foot { margin-top: 18px; }
.featured { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.featured-item { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center; padding: 10px 12px 10px 10px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; transition: border-color .2s, background .2s; }
.featured-item:hover { border-color: var(--brand-line); background: var(--brand-wash); }
.featured-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.featured-play { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-wash); color: var(--brand-deep); }
.featured-play .icon { width: 18px; height: 18px; }
.featured-text { display: grid; gap: 3px; min-width: 0; }
.featured-title { font: 700 15px/1.25 var(--font-structure); color: var(--ink); }
.featured-where { font: 400 12.5px/1.2 var(--font-structure); color: var(--slate); }

/* MARK: - Writing your chapter */
.chapter-progress { margin: 0 0 18px; animation: rise .5s var(--ease-out) both; }
.chapter-progress-kicker { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; font: 400 11px/1.2 var(--font-data); letter-spacing: .04em; text-transform: uppercase; color: var(--brand-deep); }
.chapter-progress-kicker .icon { width: 16px; height: 16px; }
.chapter-progress-title { margin: 0 0 14px; font: 700 24px/1.12 var(--font-structure); letter-spacing: -0.015em; text-wrap: balance; }
/* Once the player is up, the steps shrink to a quiet box above it until the first voice. */
.chapter-progress:has(+ .chapter-player) { margin-bottom: 12px; padding: 10px 12px 0; border-radius: 12px; background: var(--canvas); animation: none; }
.chapter-progress:has(+ .chapter-player) .chapter-progress-kicker, .chapter-progress:has(+ .chapter-player) .chapter-progress-title { display: none; }
.chapter-progress:has(+ .chapter-player) .rail { margin-bottom: 4px; }

/* MARK: - The chapter player */
.chapter-subtitle { margin: -6px 0 0; font: italic 400 17px/1.35 var(--font-read); color: var(--slate); text-wrap: balance; }
.chapter-transport { grid-template-columns: 52px 1fr; margin: 16px 0 10px; }
.chapter-now { display: grid; gap: 3px; min-width: 0; }
.chapter-now-label { font: 600 14px/1.25 var(--font-structure); color: var(--ink); }
.chapter-now-suite { font: 400 12px/1.2 var(--font-structure); color: var(--muted); }
.chapter-beats { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 2px; }
.chapter-beat { border-radius: 12px; padding: 2px 4px; transition: background .3s; }
.chapter-beat.is-playing { background: var(--brand-wash); padding-bottom: 12px; }
.chapter-beat-title { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; width: 100%; min-height: 44px; border: 0; background: none; padding: 6px 8px 6px 4px; cursor: pointer; text-align: left; font: 600 15px/1.3 var(--font-structure); color: var(--ink); border-radius: 10px; }
button.chapter-beat-title:hover .chapter-beat-name { color: var(--brand-deep); }
.chapter-beat.is-past .chapter-beat-name { color: var(--slate); }
.chapter-beat.is-playing .chapter-beat-name { color: var(--brand-deep); }
.chapter-beat-n { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--white); font: 700 11px/1 var(--font-data); color: var(--slate); }
.chapter-beat.is-past .chapter-beat-n { border-color: var(--brand); background: var(--brand); color: #fff; }
.chapter-beat.is-playing .chapter-beat-n { border-color: var(--action); background: var(--action); color: #fff; }
.chapter-beat.is-writing .chapter-beat-n { border-style: dashed; }
.chapter-beat.is-writing .chapter-beat-name { color: var(--muted); font-weight: 500; }
.chapter-beat-len { font: 400 11.5px/1 var(--font-data); color: var(--muted); }
.chapter-beat-extra { display: block; padding: 0 8px 4px 42px; font: 400 11.5px/1.3 var(--font-data); color: var(--muted); }
.chapter-beat .script { margin: 4px 8px 0 42px; }
.chapter-beat .turn { font-size: 17px; }
.chapter-player .turn { color: var(--ink); }
.chapter-player.is-playing .turn { color: var(--muted); }
.chapter-player.is-playing .turn.is-past { color: var(--slate); }
.chapter-player .turn.is-now { color: var(--ink); }
.chapter-music { display: flex; align-items: center; gap: 10px; padding: 2px 8px 2px 13px; min-height: 26px; font: italic 400 14px/1.2 var(--font-read); color: var(--muted); }
.chapter-music-icon { width: 10px; font: 400 12px/1 var(--font-structure); color: var(--brand); opacity: .6; text-align: center; }
.chapter-music.is-playing { color: var(--brand-deep); }
.chapter-music.is-playing .chapter-music-icon { color: var(--action); opacity: 1; animation: breathe 1.2s ease-in-out infinite; }
.chapter-facts { margin: 0 0 12px; }
.chapter-notice { margin: 0 0 12px; }
.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 10px; }
.eq i { width: 2px; height: 100%; background: currentColor; transform-origin: bottom; animation: eq .9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.3s; }
.eq i:nth-child(3) { animation-delay: -.6s; }
@keyframes eq { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }
.dot-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); animation: breathe 1.2s ease-in-out infinite; }

@media (max-width: 760px) {
  .topbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; }
  .topbar .seg { justify-self: start; }
  .seg button { white-space: nowrap; padding: 0 10px; }
  /* Row 2: search, then the spend meter beside it. */
  .jump { grid-column: 1 / span 2; grid-row: 2; flex: none; min-width: 0; }
  .topbar #spend { grid-column: 3; grid-row: 2; }
  .topbar .seg ~ #spend { grid-row: 2; }
  .jump-form { min-height: 44px; }
  .jump input { font-size: 16px; }
  .hello h1 { font-size: 26px; }
  .hello-actions .btn { flex: 1 1 auto; }
  .chapter-beat .script { margin-left: 8px; }
  .chapter-beat-extra { padding-left: 8px; }
}

/* MARK: - Listener view and Under the hood */
.chapter-progress.is-listener .chapter-waiting { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font: 400 17px/1.4 var(--font-read); color: var(--slate); }
.chapter-player.is-listener .chapter-beat-len { display: none; }
.chapter-player.is-listener .chapter-beats { gap: 0; }
.hood { margin: 20px 0 8px; padding-top: 14px; border-top: 1.5px dashed var(--line); }
.hood-head { margin: 0 0 8px; font: 700 12px/1.2 var(--font-action); letter-spacing: .08em; text-transform: uppercase; color: var(--brand-deep); }
.hood-lede { margin: 0 0 6px; font: 500 13px/1.35 var(--font-structure); color: var(--slate); }
.hood-places { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.hood-places li { display: grid; grid-template-columns: 58px 1fr; gap: 8px; font: 500 13px/1.35 var(--font-structure); color: var(--ink); }
.hood-n { font: 400 11px/1.6 var(--font-data); color: var(--muted); }
.hood-plan { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 8px; }
.hood-plan b { display: block; font: 700 13.5px/1.3 var(--font-structure); }
.hood-plan span { font: 400 14.5px/1.4 var(--font-read); color: var(--slate); }
.hood-section .kv dd { font-family: var(--font-structure); font-size: 12.5px; }

@media (max-width: 760px) {
  .sight-row { min-height: 44px; }
}
@media (max-width: 760px) { .topbar:not(:has(#spend)) .jump { grid-column: 1 / -1; } }

/* MARK: - Place Map (placemap-ia): lenses, today, this browser, sights, the Lab's stages */
.top-tools { display: flex; gap: 8px; align-items: center; margin-left: auto; }
body[data-lens] .jump { flex: 1 1 240px; min-width: 150px; }
body[data-lens] .topbar { z-index: 860; } /* its popover over the map key and stage strip, under the panel */
body:has(#popover:not([hidden])) .topbar { z-index: 1100; } /* an open popover (a typed code, the Lab password) over the panel too */
.toggle-small { min-height: 34px; padding: 5px 12px 5px 6px; box-shadow: none; background: var(--canvas); font-size: 12px; }
.toggle-small .toggle-track { width: 30px; height: 18px; }
.toggle-small .toggle-track::after { width: 12px; height: 12px; }
.toggle-small[aria-checked="true"] .toggle-track::after { transform: translateX(12px); }
body[data-lens="explore"] #map { cursor: crosshair; }

.today { display: grid; gap: 5px; padding: 9px 14px; min-width: 170px; background: var(--white); border-radius: 12px; box-shadow: var(--shadow); }
.today-label { font: 600 12.5px/1.2 var(--font-structure); color: var(--ink); white-space: nowrap; }
.today-bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.today-bar > span { display: block; height: 100%; background: var(--brand); transform-origin: left; transition: transform .6s var(--ease-out); }
.today.is-low .today-bar > span { background: linear-gradient(90deg, var(--brand), var(--action)); }
.today.is-out .today-bar > span { background: var(--action); }
.today.is-out .today-label { color: var(--action-deep); }
.today-code { justify-self: start; padding: 0; border: 0; background: none; font: 600 11.5px/1.2 var(--font-structure); color: var(--brand); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.today-code:hover { color: var(--brand-deep); }
.fuel-out { background: var(--brand-wash); }

.popover { position: absolute; top: calc(100% + 8px); right: 0; width: min(340px, calc(100vw - 32px)); padding: 16px 18px;
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); pointer-events: auto; }
.popover[hidden] { display: none; }
.popover h2 { margin: 0 0 6px; font: 700 17px/1.2 var(--font-structure); }
.popover p { margin: 0 0 12px; font: 400 16px/1.4 var(--font-read); color: var(--slate); }
.popover .meta { overflow-wrap: anywhere; }
.popover input, .conceit { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: var(--canvas); color: var(--ink); }
.popover input:focus, .conceit:focus { outline: 0; border-color: var(--brand); }
.popover input { min-height: 44px; margin: 0 0 12px; padding: 0 14px; font: 500 16px/1 var(--font-structure); }

.map-key { position: absolute; left: 16px; bottom: 22px; z-index: 800; display: grid; gap: 8px; padding: 10px 12px;
  background: var(--glass); border-radius: 12px; box-shadow: var(--shadow); }
.map-key[hidden] { display: none; }
.key-title { margin: 0; font: 700 10px/1 var(--font-action); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.key { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font: 500 12px/1 var(--font-structure); color: var(--slate); }
.key li { display: flex; align-items: center; gap: 8px; }
.key .mk, .pin-sample, .place-sample { position: relative; display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 50%; }
.mk-considered { border: 1.5px solid var(--st-grey); background: var(--white); }
.mk-kept { background: var(--st-kept); }
.mk-used { background: var(--st-live); }
.mk-ctx { border: 1.5px dashed var(--st-ctx); background: var(--st-ctx-fill); }
.mk-dropped::before, .mk-dropped::after { content: ""; position: absolute; left: 50%; top: 50%; width: 11px; height: 1.8px; background: var(--st-grey);
  transform: translate(-50%, -50%) rotate(45deg); }
.mk-dropped::after { transform: translate(-50%, -50%) rotate(-45deg); }
.pin-sample { box-shadow: 0 0 0 2px var(--brand); background: var(--brand-wash); }
.place-sample { width: 8px; height: 8px; background: var(--st-grey); margin: 0 2px; }

/* Map marks: sight pins (a photo in a ring), all places, and the Lab's stage key. */
/* Leaflet positions a marker with `transform`, so the pop animates the pin's photo, never the pin. */
.pin { border-radius: 50%; padding: 3px; background: var(--white); box-shadow: 0 0 0 2px var(--brand), var(--shadow); cursor: pointer; }
.pin img, .pin i { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: var(--brand-wash);
  animation: sight-pop .5s var(--ease-out) both; }
.pin i { background: radial-gradient(circle, var(--brand) 0 4px, var(--brand-wash) 5px); }
.pin.is-selected { box-shadow: 0 0 0 3px var(--action), var(--shadow); }
@keyframes sight-pop { 0% { transform: scale(0); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
.place-dot { fill: var(--st-grey); fill-opacity: .55; stroke: var(--white); stroke-width: 1; }
.st-considered { fill: var(--white); stroke: var(--st-grey); stroke-width: 1.5; }
.st-kept { fill: var(--st-kept); stroke: var(--white); stroke-width: 1.5; }
.st-used { fill: var(--st-live); stroke: var(--white); stroke-width: 1.5; }
.st-hex { fill: var(--brand); fill-opacity: .14; stroke: var(--st-live); stroke-width: 2.5; }
.st-box { fill: none; stroke: var(--slate); stroke-width: 1.2; stroke-dasharray: 3 4; }
.st-ctx { fill: var(--st-ctx-fill); stroke: var(--st-ctx); stroke-width: 1.5; stroke-dasharray: 6 5; }
.leaflet-marker-icon.mk-dropped { opacity: .85; }
.st-label { background: var(--white); border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.15); color: var(--st-ctx); font: 700 10px/1 var(--font-data); padding: 3px 5px; }
.st-label::before { display: none; }

/* The stage strip: one chip per stage along the bottom of the map. */
.stage-strip { position: absolute; left: 16px; right: calc(var(--panel-w) + 32px); bottom: 22px; z-index: 850; display: flex; gap: 6px;
  align-items: stretch; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.stage-strip[hidden] { display: none; }
body.is-inspecting .map-key:not([hidden]) { bottom: 112px; }
.stage-chip { display: grid; gap: 4px; min-width: 128px; padding: 9px 12px; border: 0; border-radius: 12px; background: var(--white); box-shadow: var(--shadow);
  text-align: left; cursor: pointer; }
.stage-chip[aria-pressed="true"] { box-shadow: var(--shadow), inset 0 0 0 2px var(--brand); }
.stage-label { font: 700 11px/1 var(--font-action); letter-spacing: .06em; text-transform: uppercase; color: var(--slate); }
.stage-count { font: 500 12px/1 var(--font-structure); color: var(--muted); }
.stage-count b { font: 700 18px/1 var(--font-structure); color: var(--ink); }
.stage-bar { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.stage-bar > span { display: block; height: 100%; background: var(--st-kept); transform-origin: left; }
.stage-meta, .stage-total { font: 400 10.5px/1 var(--font-data); color: var(--muted); }
.stage-total { align-self: center; padding: 0 8px; white-space: nowrap; }

/* The stage detail in the panel. */
.stage-title { margin: 0 0 2px; font: 700 24px/1.12 var(--font-structure); }
.stage-title span { font: 500 15px/1 var(--font-structure); color: var(--slate); }
.meta { margin: 0 0 12px; font: 400 11px/1.4 var(--font-data); color: var(--muted); }
.numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 14px; }
.numbers div { display: flex; flex-direction: column-reverse; gap: 4px; padding: 10px; border-radius: 10px; background: var(--canvas); min-width: 0; }
.numbers dd { margin: 0; font: 700 17px/1.2 var(--font-structure); color: var(--ink); overflow-wrap: anywhere; }
.numbers dt { font: 500 11.5px/1.3 var(--font-structure); color: var(--muted); }
.ask { margin: 0 0 14px; padding: 10px 12px; background: var(--brand-wash); border-radius: 10px;
  font: 400 15.5px/1.4 var(--font-read); color: var(--ink); }
.dist { margin: 0 0 14px; }
.dist-bars { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 64px; border-bottom: 1px solid var(--line); }
.dist-bars > span { flex: 1; min-height: 1px; background: var(--st-kept); border-radius: 2px 2px 0 0; }
.dist-bars > span.is-below { background: var(--st-grey); opacity: .5; }
.dist-floor { position: absolute; top: -4px; bottom: 0; width: 0; border-left: 1.5px dashed var(--st-live); }
.dist figcaption { margin-top: 5px; font: 400 11px/1.3 var(--font-data); color: var(--muted); }
.reasons { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.reasons li { display: grid; grid-template-columns: 1fr 90px 36px; gap: 8px; align-items: center; font: 500 13px/1.2 var(--font-structure); color: var(--slate); }
.reasons b { font: 700 12px/1 var(--font-data); color: var(--ink); text-align: right; }
.reason-bar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; }
.reason-bar > span { display: block; height: 100%; background: var(--st-grey); transform-origin: left; }
.stage-rows tr.is-dropped td { color: var(--muted); }
.stage-rows tr.is-dropped td:first-child { text-decoration: line-through; text-decoration-color: var(--st-grey); }
.conceit { padding: 10px 12px; font: 400 16px/1.4 var(--font-read); resize: vertical; }

/* Sights in the panel. */
.sights-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 2px; }
.sight-row { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center;
  min-height: 48px; padding: 4px 8px; border-radius: 10px; cursor: pointer; }
.sight-row:hover { background: var(--brand-wash); }
.sight-row:focus-visible { outline: 2px solid var(--brand); }
.sight-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--brand-wash); }
.sight-name { display: grid; gap: 3px; font: 600 14.5px/1.25 var(--font-structure); color: var(--ink); }
.sight-kind { font: 400 12px/1 var(--font-structure); color: var(--slate); }
.sights-loading span { animation: breathe 1.4s ease-in-out infinite; }
.sights-note { margin: 0 0 10px; }
.sight-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; margin: 0 0 14px; background: var(--brand-wash); }
.sight-preview .read { margin: 0 0 12px; font: 400 18px/1.45 var(--font-read); color: var(--slate); }

@media (max-width: 760px) {
  body[data-lens] .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  body[data-lens] .topbar .seg { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  body[data-lens] .topbar .seg button { flex: 1; justify-content: center; }
  body[data-lens] .topbar .jump { grid-column: 1 / -1; grid-row: 3; }
  .top-tools { grid-column: 2; grid-row: 1; }
  .today { min-width: 0; padding: 7px 10px; }
  .today-label { font-size: 11.5px; white-space: normal; max-width: 110px; }
  .brand-title { display: none; }
  .stage-strip { left: var(--gutter); right: var(--gutter); bottom: calc(var(--sheet-h, 50vh) + 10px); }
  .stage-chip { min-width: 112px; min-height: 44px; }
  .map-key { bottom: calc(var(--sheet-h, 50vh) + 12px); left: var(--gutter); }
  body.is-inspecting .map-key:not([hidden]) { display: none; }
}

/* Walks (placemap-ia 4-walk): the painter, routes, stop numbers, the Lab's regions. */
.hx-paint { fill: var(--brand); fill-opacity: .42; stroke: var(--brand); stroke-opacity: .9; stroke-width: .6; }
.hx-paint.is-broken { fill: var(--action); fill-opacity: .3; stroke: var(--action); }
.route-walk { fill: none; stroke: var(--brand); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.walk-start { fill: var(--brand); fill-opacity: .9; stroke: var(--white); stroke-width: 2.5; }
.walk-num { display: grid; place-items: center; background: var(--action); color: #fff; font: 700 11px/1 var(--font-action); border: 2px solid var(--white);
  border-radius: 50%; box-shadow: var(--shadow); }
.walk-you { background: var(--brand); border: 3px solid var(--white); border-radius: 50%; box-shadow: 0 0 0 6px var(--brand-wash), 0 2px 6px rgba(0, 0, 0, .3); }
.st-line-alt { fill: none; stroke: var(--st-grey); stroke-opacity: .6; stroke-width: 2; stroke-dasharray: 2 6; stroke-linecap: round; }
.st-line-chosen { fill: none; stroke: var(--st-live); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.is-painting #map { cursor: crosshair; touch-action: none; }
.crumb { margin: 0 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-wash); color: var(--brand-deep); }
button.chip { cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.paint-tools { align-items: center; }
.range { width: 100%; accent-color: var(--brand); }
.hello-sub .num { font: 700 13px/1 var(--font-data); letter-spacing: 0; text-transform: none; color: var(--ink); margin-left: 6px; }
.region-rank { display: grid; place-items: center; font: 700 12px/1 var(--font-data); color: var(--brand-deep); background: var(--brand-wash); }

/* Neighborhoods layer (demo/neighbourhoods.mjs): what Place Graph's /v1/locality knows. Brand = a neighbourhood
   outline locality answers with; ink = a city it answers with; grey dashed = in the graph, never answered. */
.nb-outline { stroke: var(--brand); stroke-width: 1.6; stroke-opacity: .9; fill: var(--brand); fill-opacity: .12; }
.nb-city { stroke: var(--ink); stroke-width: 1.4; stroke-opacity: .55; fill: none; }
.nb-district { stroke: var(--ink); stroke-width: 1.2; stroke-opacity: .7; stroke-dasharray: 1 4; fill: none; }
.nb-off { stroke: var(--st-grey); stroke-width: 1.2; stroke-opacity: .8; stroke-dasharray: 4 3; fill: none; }
.nb-point { stroke: var(--white); stroke-width: 1.5; fill: var(--brand); fill-opacity: 1; }
.leaflet-tooltip.nb-label { padding: 0; border: 0; background: none; box-shadow: none; font: 600 11px/1 var(--font-structure); color: var(--brand-deep);
  text-shadow: 0 0 2px var(--white), 0 0 2px var(--white), 0 0 3px var(--white); }
.leaflet-tooltip.nb-label::before { display: none; }
.leaflet-container:not(.nb-labels) .nb-label { display: none; }
.nb-sample { display: inline-block; flex: none; width: 14px; height: 10px; border-radius: 2px; }
.nb-sample-outline { background: var(--brand-wash); border: 1.5px solid var(--brand); }
.nb-sample-city { border: 1.5px solid var(--ink); opacity: .6; }
.nb-sample-district { border: 1.5px dotted var(--ink); }
.nb-sample-off { border: 1.5px dashed var(--st-grey); }
.nb-sample-point { width: 10px; border-radius: 50%; background: var(--brand); }
.nb-note { margin: 0; max-width: 220px; font: 500 11px/1.35 var(--font-structure); color: var(--muted); }
.nb-pop { font: 500 13px/1.35 var(--font-structure); min-width: 200px; }
.nb-pop b { font-size: 14px; }
.nb-kind { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.nb-row { display: grid; grid-template-columns: 82px 1fr; gap: 6px; padding: 2px 0; }
.nb-row > span:first-child { color: var(--muted); }
.nb-yes { color: var(--brand); }
.nb-no { color: var(--action); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--white); color: var(--ink); }
.nb-pop a { color: var(--brand-deep); }
@media (max-width: 720px) {
  .map-key .nb-legend { grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 11px; }
  .map-key .nb-legend + .nb-note { display: none; }
}

/* Public Place Map: listening leads; secondary controls stay behind the browser menu. */
.first-listen { margin: 18px 0 22px; background: var(--brand-wash); width: 100%; min-height: 68px; }
.first-listen .featured-play { color: var(--white); background: var(--brand); }
.sight-thumb:not(img) { display: grid; place-items: center; }
.sight-thumb:not(img)::before { content: ""; width: 10px; height: 10px; border: 2px solid var(--brand); border-radius: 50%; }
.today-code { min-height: 24px; }
@media (max-width: 760px) {
  body[data-lens] .topbar { gap: 8px; }
  .top-tools { gap: 6px; }
  .today-label { max-width: 150px; font-size: 12px; }
  .today { padding: 6px 10px; }
  .today-code { min-height: 28px; }
  .map-key .key { display: none; }
  .map-key { gap: 5px; padding: 6px 8px; }
  .map-key .toggle { min-height: 44px; }
}

.walk-setup { display: flex; gap: 12px; padding: 0; margin: 8px 0 22px; list-style: none; }
.walk-setup li { flex: 1; display: grid; gap: 6px; font-size: 12px; color: var(--slate); }
.walk-setup li span { display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 50%; }
.walk-setup li[aria-current] { color: var(--brand-deep); font-weight: 700; }
.walk-setup li[aria-current] span { background: var(--brand); color: var(--white); border-color: var(--brand); }
.walk-duration { display: block; font: 700 28px/1.3 var(--font-structure); margin: 16px 0; }

.pin.is-available { outline: 2px dashed var(--brand); outline-offset: 1px; box-shadow: var(--shadow); }
.pin.is-ready { background: var(--brand); }
.pin.is-ready i { background: var(--brand); border: 3px solid var(--white); }
.walk-sample { width: 12px; height: 12px; border-radius: 3px; background: var(--brand); }
body.is-inspecting .stage-strip:not([hidden]) { display: flex; }
body:not(.is-inspecting) .stage-strip { display: none; }
.inspector-only { display: none; }
body.is-inspecting .inspector-only { display: inline-flex; }

.search-toggle { display: none; }
@media (max-width: 760px) {
  .search-toggle { display: grid; }
  body[data-lens] .topbar .jump { display: none; }
  body.is-searching[data-lens] .topbar .jump { display: block; }
}

.packet-details pre { overflow: auto; max-height: 24rem; font-size: 0.75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
