  :root { color-scheme: light dark; --bg:#f4f1e8; --ink:#2a2720; --dim:#635d4d;
    --line:#c8c0ad; --road:#c3bba7; --accent:#a23a1c; --good:#176235; }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --bg:#15140f; --ink:#ebe6d8; --dim:#b8b09b; --line:#5d5748;
      --road:#4a4336; --accent:#ff9568; --good:#8de5a0; }
  }
  :root[data-theme="dark"] { color-scheme:dark; --bg:#15140f; --ink:#ebe6d8; --dim:#b8b09b; --line:#5d5748;
      --road:#4a4336; --accent:#ff9568; --good:#8de5a0; }
  :root[data-theme="light"] { color-scheme:light; }
  * { box-sizing:border-box; }
  html, body { margin:0; }
  .viewer { background:var(--bg); color:var(--ink);
    font:13px/1.45 ui-monospace, Consolas, monospace; }
  .viewer { display:flex; flex-direction:column; min-height:0; }
  .viewer:only-child { flex:1; }
  body.legacy-viewer { display:flex; height:100dvh; }
  .legacy-viewer .viewer { width:100%; height:100%; }
  .viewer header, .viewer .toolbar { padding:8px 12px; border-bottom:1px solid var(--line); }
  .viewer header, .viewer .toolbar { overflow-wrap:anywhere; }
  .viewer header strong { color:var(--accent); }
  #legend { display:flex; flex-wrap:wrap; gap:0 12px; }
  #legend .world-foundations { flex-basis:100%; }
  .foundation-bar { display:flex; height:0.75em; border:1px solid var(--dim); border-radius:2px; overflow:hidden; }
  .foundation-bar > span { flex-basis:0; background:var(--area-light); }
  .foundation-profile h3 { font-size:inherit; margin:8px 0 4px; }
  .foundation-profile ul { list-style:none; margin:4px 0; padding:0; }
  .foundation-profile .dot { background:var(--area-light); }
  .corner-profile li { margin-bottom:5px; }
  .corner-profile meter { display:block; width:100%; height:0.85em; accent-color:var(--accent); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) :is(.foundation-bar > span, .foundation-profile .dot) { background:var(--area-dark); }
  }
  #atlas-screen { position:absolute; inset:0; display:flex; flex-direction:column; padding:8px 12px; }
  #atlas-body { flex:1; min-height:0; display:flex; gap:12px; }
  #atlas-column { flex:1; min-width:0; display:flex; flex-direction:column; }
  #atlas-map { position:relative; flex:1; min-height:190px; }
  #atlas-about { flex:0 0 min(19rem, 32%); overflow:auto; border-left:1px solid var(--line); padding:2px 0 8px 12px;
    font:14px/1.5 system-ui, sans-serif; }
  #atlas-about h2 { font:600 15px/1.3 system-ui, sans-serif; margin:0 0 6px; color:var(--accent); }
  #atlas-about h3 { font:600 13px/1.3 system-ui, sans-serif; margin:12px 0 4px; }
  #atlas-about p { margin:0 0 8px; }
  #atlas-about ul { padding-left:18px; margin:0 0 8px; }
  @media (max-width:760px) {
    #atlas-body { flex-direction:column; }
    #atlas-about { flex:0 0 auto; max-height:30%; border-left:0; border-top:1px solid var(--line); padding:8px 0 0; }
  }
  #atlas-map canvas { position:absolute; inset:0; cursor:default; }
  .atlas-region, .atlas-road { position:absolute; background:transparent; border:0; padding:0; }
  .atlas-region { display:flex; flex-direction:column; justify-content:center; align-items:center;
    gap:2px; transform:translate(-50%, -50%); border-radius:50%; font-size:clamp(10px, 3vw, 13px); }
  .atlas-region span { color:var(--dim); }
  .atlas-region[aria-disabled=true] { cursor:default; }
  .atlas-road { transform-origin:left center; }
  #atlas-details { height:4.35em; flex-shrink:0; overflow:auto; }
  .viewer main.folding > :is(#info, #raid, #selection) { visibility:hidden; }
  .dot { display:inline-block; width:9px; height:9px; margin-right:5px; vertical-align:middle; }
  .proof-fog { border-radius:50%; background:radial-gradient(#929fb0, transparent 75%); }
  .proof-dashed { border:1px dashed currentColor; border-radius:50%; }
  #shape-key, #road-key { display:flex; flex-wrap:wrap; column-gap:12px; }
  #road-key i { display:inline-block; width:18px; border-top:2px solid currentColor; vertical-align:middle; }
  #road-key .down { border-top-style:dashed; }
  #road-key .chain { border-top:3px dashed currentColor; }
  .shape { display:inline-block; width:10px; height:10px; background:currentColor; vertical-align:middle; }
  .prism { clip-path:polygon(25% 0,75% 0,100% 50%,75% 100%,25% 100%,0 50%); }
  .sphere { border-radius:50%; width:8px; height:8px; }
  .octahedron { clip-path:polygon(50% 0,100% 50%,50% 100%,0 50%); }
  .slab { height:4px; }
  .ring { border:1px dashed currentColor; border-radius:50%; background:none; }
  .neighbours h3 { font-size:inherit; margin:6px 0 0; }
  .neighbours button { text-align:left; overflow-wrap:anywhere; }
  .neighbours li { margin-block:3px; }
  .toolbar, #crumbs { display:flex; align-items:center; flex-wrap:wrap; gap:4px; min-width:0; }
  :where(.viewer) button, :where(.viewer) select, .viewer .panel a { font:inherit; color:var(--ink); background:var(--bg); border:1px solid var(--line);
    padding:3px 7px; border-radius:3px; cursor:pointer; max-width:100%; }
  button[aria-pressed=true] { border-color:var(--accent); color:var(--accent); }
  :focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
  #places { width:min(29ch, 100%); }
  #place-search { position:relative; z-index:4; max-width:100%; }
  #place-search input, #selection input { font:inherit; max-width:100%; }
  #place-search ul, #place-search output { position:absolute; top:100%; left:0; margin:0;
    width:min(65ch, calc(100vw - 24px)); background:var(--bg); border:1px solid var(--line); }
  #place-search ul { list-style:none; padding:0; max-height:min(50vh, 26em); overflow:auto; }
  #place-search li, #place-search output { padding:4px 8px; overflow-wrap:anywhere; }
  #place-search li { cursor:pointer; }
  #place-search li[aria-selected=true], #place-search li:hover { background:var(--line); }
  [hidden] { display:none !important; }
  .viewer main { position:relative; flex:1; min-height:220px; overflow:hidden; }
  .viewer canvas { display:block; width:100%; height:100%; touch-action:none; cursor:grab; }
  .viewer canvas:focus-visible { outline-offset:-3px; }
  #labels, #compass-labels { position:absolute; inset:0; pointer-events:none; overflow:hidden; opacity:var(--label-opacity, 1); }
  #labels span, #compass-labels span { position:absolute; top:0; left:0; max-width:calc(100% - 8px); overflow:hidden; text-overflow:ellipsis;
    white-space:nowrap; font-weight:700; text-shadow:0 0 3px var(--bg), 0 0 5px var(--bg); }
  #compass-labels span { font-size:11px; font-weight:400; color:var(--dim); }
  .panel { position:absolute; background:var(--bg); border:1px solid var(--line); padding:6px 10px;
    width:max-content; max-width:min(380px, calc(100% - 16px)); max-height:72%; overflow:auto; overflow-wrap:anywhere; }
  .dim { color:var(--dim); }
  #info { left:8px; bottom:8px; }
  #selection { right:8px; bottom:8px; z-index:2; }
  #raid { left:8px; top:8px; z-index:1; max-width:min(340px, calc(100% - 16px)); max-height:42%; }
  #raid-summary { font-weight:700; }
  #raid li { margin-block:6px; }
  #raid li > .dim { display:block; }
  #raid li > .raid-facts { display:block; color:var(--dim); font-size:12px; }
  #raid .impact-bar { display:block; height:4px; margin-block:3px; background:var(--line); }
  #raid .impact-bar > span { display:block; height:100%; background:var(--accent); }
  #raid button:disabled { cursor:default; color:var(--dim); }
  .viewer h2 { margin:0 0 4px; font-size:13px; }
  .viewer p { margin:4px 0; }
  .place-texts section { border-top:1px solid var(--line); margin-top:8px; }
  .place-texts h3 { margin:6px 0 4px; font-size:inherit; }
  .place-texts small { font-weight:normal; }
  .place-texts pre, .place-doc { white-space:pre-wrap; overflow-wrap:anywhere; }
  .place-doc a, .place-texts section > a { color:var(--accent); }
  .panel .place-texts a { border:0; padding:0; background:none; }
  .viewer :is(ul, ol) { margin:4px 0; padding-left:18px; }
  #ground { background:var(--bg); color:var(--ink); border:1px solid var(--line); padding:12px;
    max-width:min(380px, calc(100% - 16px)); overflow-wrap:anywhere; }
  #ground::backdrop { background:#0005; }
  #tip { position:fixed; pointer-events:none; z-index:3; padding:3px 7px; background:var(--bg);
    border:1px solid var(--line); max-width:80vw; overflow-wrap:anywhere; }
  #status { margin:2px 0 0; font-weight:700; }
  #status[data-state=pass] { color:var(--good); }
  #status[data-state=fail] { color:var(--accent); }
  #benchmark { margin:2px 0 0; }
  /* The whole-proof question and its progress (full.js), under the status line. */
  .whole-proof { display:flex; flex-wrap:wrap; align-items:center; gap:4px 8px; margin:4px 0 0; }
  .whole-proof p { margin:0; }
  .viewer button:disabled { cursor:default; color:var(--dim); }
  #place-search li .dim { color:var(--dim); }
  #benchmark-rate:not(:empty) + #profile-summary::before { content:" · "; }
  #profile-summary { font-size:0.85rem; }
  #profile { right:8px; top:8px; white-space:pre-wrap; overflow-wrap:anywhere; }
  @media (max-width:640px) {
    #crumbs { max-height:6em; overflow:auto; }
    #selection { bottom:44px; }
    #raid { max-height:34%; }
    #raid:not([hidden]) ~ #selection { max-height:34%; }
  }
  :root[data-theme="dark"] :is(.foundation-bar > span, .foundation-profile .dot) { background:var(--area-dark); }
  .viewer header > a { color:var(--accent); }
  /* District names are set large and scaled down with distance, so they stay sharp when near. */
  #labels span.district { font-size:26px; transform-origin:0 0; text-shadow:0 0 5px var(--bg), 0 0 9px var(--bg); }
  .atlas-labels { position:absolute; inset:0; pointer-events:none; overflow:hidden; }
  .atlas-labels span { position:absolute; top:0; left:0; font-size:24px; line-height:1.2; white-space:nowrap;
    transform-origin:0 0; color:var(--ink); text-shadow:0 0 5px var(--bg), 0 0 9px var(--bg); }
  .draw-distance { display:inline-flex; align-items:center; gap:4px; max-width:100%; }
  .draw-distance[hidden] { display:none; }
  .atlas-labels span.atlas-island-name { font-size:15px; font-weight:600; letter-spacing:0.08em; text-transform:uppercase;
    color:var(--dim); }
  .draw-distance input { width:7em; accent-color:var(--accent); }
  .draw-distance output { min-width:9ch; color:var(--dim); }
  /* Title row with the show/hide switches; grouped toolbar; What you see tabs. */
  .title-row { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:4px 12px; }
  #view-toggles { display:flex; flex-wrap:wrap; gap:4px; }
  #legend-block { margin-top:4px; }
  .viewer .toolbar { gap:6px 10px; }
  .tool-group { display:flex; flex-wrap:wrap; align-items:center; gap:4px; min-width:0; }
  .tool-group + .tool-group { border-left:1px solid var(--line); padding-left:10px; }
  .group-name { color:var(--dim); font-size:11px; text-transform:uppercase; letter-spacing:.06em; }
  .toolbar select:disabled { opacity:.65; cursor:not-allowed; }
  #info { min-width:min(300px, calc(100% - 16px)); }
  #info h2 { display:flex; justify-content:space-between; align-items:center; gap:8px; }
  #info-close { padding:0 7px; line-height:1.4; }
  #info-tabs { display:flex; gap:2px; border-bottom:1px solid var(--line); margin-bottom:6px; }
  #info-tabs [role=tab] { border:0; border-bottom:2px solid transparent; border-radius:0; background:none; padding:3px 8px; }
  #info-tabs [role=tab][aria-selected=true] { border-bottom-color:var(--accent); color:var(--accent); }
  #world-metrics { display:grid; grid-template-columns:max-content 1fr; gap:2px 10px; margin:0 0 6px; }
  #world-metrics dt { font-weight:700; }
  #world-metrics dd { margin:0; }
  #explanation p { margin:0 0 6px; }
  @media (max-width:640px) {
    .tool-group + .tool-group { border-left:0; padding-left:0; }
    .group-name { display:none; }
  }
  .atlas-view-toggle[aria-pressed=true] { border-color:var(--accent); color:var(--accent); }
  /* A narrow viewer (a phone, or the map beside the tools drawer) keeps the toolbar compact. */
  .viewer { container-type: inline-size; container-name: viewer; }
  @container viewer (max-width: 720px) {
    .viewer header, .viewer .toolbar { padding:6px 8px; }
    .viewer .toolbar { gap:4px 6px; }
    .tool-group + .tool-group { border-left:0; padding-left:0; }
    .group-name { display:none; }
    #info { max-width:min(300px, calc(100% - 16px)); max-height:45%; }
    #selection { max-height:55%; }
  }
  /* In the game the location trail replaces Back and the Atlas button (app.js marks them). A lesson step that
     points at one of them still shows it while it is the step's target. */
  .viewer #back.game-trail-replaced:not([data-lesson-target]) { display:none; }
  .viewer #world-trail.game-trail-replaced:not(:has([data-lesson-target])) { display:none; }
  .viewer #world-trail.game-trail-replaced #world-path { display:none; }
  /* Progressive disclosure (game-shell.md §2, design step 3): View opens a small panel under the header with the
     camera switch, Speed, Layout, Colour by, Road flow and Gates. A lesson step that points inside it shows it. */
  .viewer header { position:relative; }
  #view-menu { position:absolute; top:100%; right:8px; z-index:10; display:grid; gap:8px;
    width:max-content; max-width:min(360px, calc(100% - 16px)); padding:8px 10px;
    background:var(--bg); border:1px solid var(--line); box-shadow:0 4px 12px #0003; }
  #view-menu:not([data-open]):not(:has([data-lesson-target])) { display:none; }
  #view-button[aria-expanded=true] { border-color:var(--accent); color:var(--accent); }
  #view-menu .tool-group + .tool-group { border-left:0; padding-left:0; border-top:1px solid var(--line); padding-top:8px; }
  #view-menu .group-name { display:block; flex-basis:100%; }
  #view-menu select:disabled { opacity:.65; cursor:not-allowed; }
  /* The key: one panel with the legend and what this world shows. */
  #info h3 { margin:6px 0 4px; font-size:inherit; color:var(--dim); }
  #key-world { border-top:1px solid var(--line); margin-top:6px; }
  #info #legend-block { margin-top:0; }
  /* Enter place, select place and depth appear once a place is chosen (app.js). */
  #place-actions { display:inline-flex; flex-wrap:wrap; align-items:center; gap:4px; }
  /* The raid layer (game-shell.md §2, design step 2): in the game the raid panel is a side panel along the left of
     the map, with the board (stats, land bar, quests, critical path) or one quest card. The Key moves beside it. */
  #raid.raid-layer { top:8px; bottom:8px; left:8px; z-index:3; width:min(360px, calc(100% - 16px));
    max-width:none; max-height:none; }
  .viewer main:has(#raid.raid-layer:not([hidden])) #info { left:calc(min(360px, 100% - 16px) + 16px); }
  #raid .raid-head { display:flex; justify-content:space-between; align-items:center; gap:8px; }
  #raid-close { padding:0 7px; line-height:1.4; }
  #raid h3 { font-size:inherit; margin:10px 0 4px; }
  #raid h4 { font-size:inherit; margin:8px 0 4px; color:var(--dim); }
  #raid .raid-stats { display:grid; grid-template-columns:1fr 1fr; gap:4px; margin:6px 0; }
  #raid .raid-stats > div { border:1px solid var(--line); border-radius:3px; padding:3px 6px; }
  #raid .raid-stats dt { color:var(--dim); font-size:11px; text-transform:uppercase; letter-spacing:.04em; }
  #raid .raid-stats dd { margin:0; font:inherit; }
  #raid .raid-stats dd:first-of-type { font-weight:700; }
  #raid .raid-stats dd.dim { font-size:11px; line-height:1.3; }
  #raid .land-bar { display:flex; height:6px; margin-bottom:6px; overflow:hidden; border-radius:3px; background:var(--line); }
  #raid .land-bar .land { background:var(--good); }
  #raid .land-bar .assumed { flex:1; min-width:3px; background:var(--accent); }
  #raid ol[aria-label="Quests by impact"] { list-style:none; padding:0; }
  #raid .raid-quest { display:block; padding:6px 0; border:0; border-top:1px solid var(--line); border-radius:0; }
  #raid .raid-quest[data-ready="true"] { border-inline-start:3px solid var(--good); padding-inline-start:6px; }
  #raid .raid-quest > button { display:block; margin-top:3px; font-size:12px; }
  #raid a[data-quest], #raid .raid-card-back { border:0; padding:0; background:none; color:var(--accent); }
  #raid a[data-quest] { font-weight:700; }
  #raid .critical-path li { padding-bottom:6px; }
  #raid-card pre { white-space:pre-wrap; overflow-wrap:anywhere; }
  #raid-card .proof-actions { display:flex; flex-wrap:wrap; gap:4px 12px; }
  @container viewer (max-width: 720px) {
    #raid.raid-layer { bottom:auto; max-height:50%; }
    .viewer main:has(#raid.raid-layer:not([hidden])) #info { left:8px; }
  }
  /* Map facts (28.11): a small block in the map's top-left corner that says what height, left-right and colour mean
     in the current view, with the frame rate. On by default; View › Map facts (on the atlas, beside 3D) hides it.
     Its heading folds it to one line; it starts folded on a narrow map. */
  .map-facts { position:absolute; left:8px; top:8px; z-index:2; width:max-content; max-width:min(320px, calc(100% - 16px));
    max-height:40%; overflow:auto; overflow-wrap:anywhere; padding:4px 8px; font-size:12px; line-height:1.4;
    background:var(--bg); background:color-mix(in srgb, var(--bg) 88%, transparent);
    border:1px solid var(--line); border-radius:3px; }
  .map-facts-head { display:flex; align-items:baseline; gap:8px; }
  .map-facts h2 { margin:0; font-size:inherit; }
  .viewer .map-facts h2 button { border:0; padding:0; background:none; font-weight:700; color:var(--accent); }
  .map-facts h2 button::before { content:"▾ "; content:"▾ " / ""; }
  .map-facts h2 button[aria-expanded=false]::before { content:"▸ "; content:"▸ " / ""; }
  #map-facts-fps { color:var(--dim); font-variant-numeric:tabular-nums; }
  #map-facts-name { margin:2px 0; font-weight:700; }
  #map-facts-list { display:grid; grid-template-columns:max-content minmax(0, 1fr); gap:1px 8px; margin:0 0 4px; }
  #map-facts-list dt { color:var(--dim); }
  #map-facts-list dd { margin:0; }
  .viewer .map-facts #map-facts-key { border:0; padding:0; background:none; color:var(--accent); text-align:left;
    text-decoration:underline; font-size:inherit; }
  /* Beside the raid panel, as the Key is; on a narrow map the raid panel takes the corner. */
  .viewer main:has(#raid:not([hidden])) .map-facts { left:calc(min(360px, 100% - 16px) + 16px); }
  #atlas-map .map-facts { z-index:1; }
  @container viewer (max-width: 720px) {
    .map-facts { font-size:11px; max-height:32%; }
    #map-facts-list { grid-template-columns:minmax(0, 1fr); }
    #map-facts-list dd { margin-bottom:2px; }
    .viewer main:has(#raid:not([hidden])) .map-facts { display:none; }
  }
  /* The Key stays clear of Map facts above it (renderer.js sets --facts-height on the map). */
  .viewer main:has(> .map-facts:not([hidden])) #info { max-height:min(72%, calc(100% - var(--facts-height, 0px) - 24px)); }
  @container viewer (max-width: 720px) {
    .viewer main:has(> .map-facts:not([hidden])) #info { max-height:min(45%, calc(100% - var(--facts-height, 0px) - 24px)); }
  }
