/* AntHocNet — the game's pages (#545, #97): a city-builder for networks and
   ants, drawn as a page of the Colony Arena site. No colour, radius or font is
   defined here: they are the site's tokens (web/shell/tokens.css, added to
   every page by web/shell/inject.py), day and night; the hub's
   tools/check_tokens.py fails on a literal. The ant / packet identity colours
   are the validated set (adjacent CVD dE >= 8.4 in both modes) and every glyph
   also differs by shape. The panels are the hub's cards; the map is the hero. */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-underline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 10; background: var(--surface); padding: 6px 10px; border-radius: var(--r-md); }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; }
.muted { color: var(--ink-3); }
.small { font-size: 0.86rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- controls -------------------------------------------------------------------- */
.bevel, select, input[type=number] {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px 10px; min-height: 32px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.bevel { cursor: pointer; }
.bevel:hover { border-color: var(--accent); }
.bevel:active { transform: translateY(1px); }
.bevel[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.bevel:disabled { opacity: 0.55; cursor: default; }
select, input[type=number] { background: var(--well); color: var(--ink); font-weight: 500; }
input[type=number] { width: 6.5em; }

.window {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--elev);
  min-width: 0; overflow: hidden;
}
.titlebar {
  color: var(--ink-3); font-weight: 700; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.08em; padding: 10px 14px 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.window .body { color: var(--ink); padding: 4px 14px 12px; }
.window .body p { margin: 0 0 0.5rem; }

/* --- the page head: the breadcrumb row (shell.css), then the game's controls,
   under the site's top bar (web/shell/) --------------------------------------- */
.pagehead { margin: 10px 16px 0; }
.menubar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 6px 12px; margin: 8px 16px 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  color: var(--ink);
}
.menu { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink-2); }
.speeds { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); }
.speeds .bevel { min-width: 38px; padding: 3px 6px; border-color: transparent; background: transparent; }
.speeds .bevel[aria-pressed="true"] { background: var(--accent); }

/* --- stage ------------------------------------------------------------------------------ */
.desk {
  display: grid; grid-template-columns: 150px minmax(0, 1fr) 340px; gap: 14px; padding: 14px 16px;
  align-items: start;
}
.toolbox { position: sticky; top: 104px; }
.toolbox .tools { display: grid; grid-template-columns: 1fr; gap: 4px; padding: 4px 8px 8px; }
.toolbox .tools.small { grid-template-columns: repeat(3, 1fr); }
.toolbox .tools.small .bevel { padding: 3px 0; }
.tool { display: flex; align-items: center; gap: 8px; text-align: left; font-size: 0.84rem; padding: 6px 8px; }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tool kbd { margin-left: auto; font: 600 0.68rem var(--mono); opacity: 0.7; }
.overlays { display: grid; gap: 4px; padding: 2px 12px 12px; font-size: 0.84rem; color: var(--ink-2); }
.overlays input, .filters input, input[type=range] { accent-color: var(--accent); }
.mapwin { display: flex; flex-direction: column; }
.mapwin > .titlebar { position: absolute; z-index: 1; margin: 10px; padding: 4px 10px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--ink); letter-spacing: 0.04em;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: var(--elev); pointer-events: none; }
.mapwin { position: relative; }
.map { position: relative; height: min(72vh, 760px); min-height: 400px; background: var(--sky); outline-offset: -3px; }
#view { width: 100%; height: 100%; display: block; touch-action: none; }
.map[data-tool="build"] #view { cursor: crosshair; }
.map[data-tool="bulldoze"] #view { cursor: not-allowed; }
.map[data-tool="move"] #view { cursor: grab; }
.map[data-tool="flow"] #view { cursor: alias; }
.toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); margin: 0; max-width: 90%;
  background: var(--surface); color: var(--ink); padding: 7px 14px; font-weight: 600;
  border: 1px solid var(--border); border-radius: var(--r-pill); box-shadow: var(--elev);
}
.status {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 4px; font: 600 12.5px/1.3 var(--mono);
}
.status > span {
  background: var(--surface-2); color: var(--ink); padding: 4px 10px; font-variant-numeric: tabular-nums;
  border: 1px solid var(--border); border-radius: var(--r-pill);
}
.health { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.meter { width: 80px; height: 8px; border-radius: var(--r-pill); overflow: hidden; background: color-mix(in srgb, var(--good) 20%, var(--surface-2)); display: inline-block; }
.meter > span { display: block; height: 100%; width: 0; background: var(--good); border-radius: var(--r-pill); transition: width 0.3s; }
.ticker {
  display: flex; gap: 10px; align-items: center; margin: 4px 10px 10px; padding: 6px 12px;
  background: var(--surface-2); color: var(--ink); font: 500 13px/1.35 var(--font);
  border: 1px solid var(--border); border-radius: var(--r-pill); overflow: hidden; white-space: nowrap;
}
.ticker .mast { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--link); }
.ticker .mast::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c-linkfail); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-linkfail) 25%, transparent); }
#news { overflow: hidden; text-overflow: ellipsis; }

.panels { display: flex; flex-direction: column; gap: 14px; }
.legend { list-style: none; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; font-size: 0.82rem; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; line-height: 1.25; }
.legend canvas { flex: none; }
.legend a { color: inherit; text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px; }
.legend a:hover, .legend a:focus-visible { color: var(--link); text-decoration-color: currentColor; }

table.ph { width: 100%; border-collapse: collapse; font-size: 0.84rem; font-variant-numeric: tabular-nums; }
table.ph caption { text-align: left; color: var(--ink-3); font-size: 0.8rem; padding-bottom: 4px; }
table.ph th, table.ph td { text-align: right; padding: 4px; border-bottom: 1px solid var(--rule); }
table.ph th { color: var(--ink-3); font-weight: 600; font-size: 0.76rem; }
table.ph th:first-child, table.ph td:first-child { text-align: left; }
.bar { display: inline-block; height: 6px; border-radius: var(--r-xs); background: var(--ph); vertical-align: middle; }
.chip { display: inline-block; padding: 1px 8px; border-radius: var(--r-pill); font-size: 0.78rem; font-weight: 600; background: var(--accent-soft); color: var(--ink); }

.logwin { margin: 0 16px 16px; }
.logwin .titlebar { justify-content: flex-start; padding-bottom: 8px; }
.logwin .titlebar .bevel { min-height: 26px; padding: 1px 10px; font-size: 0.78rem; text-transform: none; letter-spacing: 0; }
.filters { display: inline-flex; gap: 12px; font-weight: 500; margin-right: auto; text-transform: none; letter-spacing: 0; font-size: 0.82rem; color: var(--ink-2); }
.log {
  list-style: none; margin: 0 8px 8px; padding: 8px 12px; height: 180px; overflow: auto; background: var(--well);
  border: 1px solid var(--rule); border-radius: var(--r-md);
  font: 12px/1.6 var(--mono); color: var(--ink-2);
}
.log li .sw { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: var(--r-xs); }

/* missions */
.mission-goal { font-weight: 700; }
.stars { letter-spacing: 2px; color: var(--stars); }
.progress { height: 8px; background: var(--surface-2); margin: 6px 0; border-radius: var(--r-pill); overflow: hidden; border: 1px solid var(--rule); }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-pill); transition: width 0.3s; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.missions { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 4px; }
.missions button { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 6px; font-weight: 500; }

/* --- how it works -------------------------------------------------------------------- */
.about { margin: 8px 16px 0; padding: 24px 4px 8px; }
.about h2 { font-size: 1.35rem; letter-spacing: -0.015em; margin: 0 0 4px; }
.about > p { color: var(--ink-2); margin: 0 0 16px; max-width: 70ch; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.steps li { padding: 16px; }
.steps h3 { margin: 0 0 6px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.steps h3 .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.steps p { margin: 0; color: var(--ink-2); }
.foot { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 20px 20px 28px; color: var(--ink-3); font-size: 0.86rem; }
.foot a { color: var(--ink-2); font-weight: 600; }

@media (max-width: 1100px) {
  .desk { grid-template-columns: 150px minmax(0, 1fr); }
  .panels { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 680px) {
  .desk { grid-template-columns: 1fr; padding: 8px; gap: 10px; }
  .mapwin { order: 1; }
  .toolbox { order: 2; position: static; }
  .panels { order: 3; }
  .toolbox .tools:not(.small) { grid-template-columns: repeat(5, 1fr); }
  .toolbox .tools:not(.small) .tool span, .tool kbd { display: none; }
  .tool { justify-content: center; }
  .overlays { grid-template-columns: 1fr 1fr; }
  .map { height: 58vh; min-height: 300px; }
  .menubar { padding: 6px 8px; gap: 6px 10px; margin: 8px 8px 0; }
  .pagehead { margin: 8px 8px 0; }
  .health { margin-left: 0; }
  .logwin { margin: 0 8px 12px; }
  .about { margin: 0 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- the hub (#628): the site's home, over the running world --------------------- */
.hub {
  position: fixed; inset: 0; z-index: 40; overflow: auto; padding: 104px 16px 16px;
  background: var(--veil);
  backdrop-filter: blur(1.5px); -webkit-backdrop-filter: blur(1.5px);
}
body.hub-open .ahn-bar { z-index: 60; }
.hub-card {
  display: block; padding: 18px 20px; border-radius: var(--r-xl); text-decoration: none;
  background: color-mix(in srgb, var(--surface) 94%, transparent); color: var(--ink);
  border: 1px solid var(--border); box-shadow: var(--elev);
}
.hub-card .k { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--link); }
.hub-card h1 { font-size: 1.6rem; margin: 6px 0 8px; letter-spacing: -0.02em; }
.hub-card p { margin: 0 0 10px; color: var(--ink-2); }
/* One start card (#93): the title, one Play button, the other ways in below it. */
.hub { display: grid; place-items: center; }
.hub[hidden] { display: none; }
.hub-start { width: min(560px, 100%); text-align: center; padding: 28px 32px 22px; }
.hub-start h1 { font-size: clamp(1.8rem, 4.6vw, 2.7rem); line-height: 1.08; margin: 8px 0 10px; text-wrap: balance; }
.hub-start .hub-lede { font-size: 1.05rem; margin-bottom: 20px; }
.hub-start .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 800; }
.hub-go { font-size: 1.25rem; padding: 12px 30px; border-radius: var(--r-lg); }
.hub-start .row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0 14px; }
.hub-start .hub-note { font-size: 0.85rem; color: var(--ink-3); margin: 6px 0 0; }
@media (max-width: 720px) {
  .hub { position: static; padding: 0 6px 6px; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* --- the in-game reader (#630): a docs page over the running world ----------------- */
.reader {
  position: fixed; top: 102px; right: 12px; bottom: 12px; width: min(560px, calc(100vw - 24px)); z-index: 45;
  display: flex; flex-direction: column; margin: 0; overflow: hidden;
}
.reader[hidden] { display: none; }  /* display: flex above would keep a closed reader on the page */
.reader-bar { display: flex; align-items: center; gap: 8px; }
.reader-bar #readerTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-live { font-size: 0.72rem; font-weight: 700; color: var(--ink-3); white-space: nowrap; }
.reader-bar .bevel { min-height: 28px; width: 30px; padding: 0; display: inline-grid; place-items: center; text-decoration: none; }
.reader-body { overflow: auto; padding: 4px 20px 24px; color: var(--ink); line-height: 1.6; outline: none; }
.reader-body h1 { font-size: 1.45rem; letter-spacing: -0.02em; margin: 12px 0 8px; }
.reader-body h2 { font-size: 1.15rem; margin: 22px 0 6px; }
.reader-body h3 { font-size: 1rem; margin: 16px 0 4px; }
.reader-body p, .reader-body li { color: var(--ink-2); }
.reader-body a { color: var(--link); }
.reader-body code { font: 0.86em var(--mono); background: var(--surface-2); padding: 1px 4px; border-radius: var(--r-sm); }
.reader-body pre { overflow: auto; background: var(--surface-2); padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--border); }
.reader-body pre code { background: none; padding: 0; }
.reader-body table { border-collapse: collapse; display: block; overflow: auto; font-size: 0.85rem; }
.reader-body th, .reader-body td { border-bottom: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.reader-body img { max-width: 100%; height: auto; border-radius: var(--r-md); }
.reader-body blockquote { margin: 10px 0; padding: 4px 12px; border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 0 var(--r-md) var(--r-md) 0; }
.reader-body .ahn-try { display: none; }
.reader-body .ahn-cards > p { display: grid; gap: 8px; }
.reader-body .ahn-cards a { display: block; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-lg); text-decoration: none; }
.reader-body .ahn-cards a span { display: block; color: var(--ink-3); font-size: 0.85rem; }
.reader-note { font-size: 0.85rem; color: var(--ink-3); }
@media (max-width: 720px) { .reader { top: auto; left: 6px; right: 6px; width: auto; height: 70vh; bottom: 6px; } }

/* --- the Workshop (#634): the Nest (#635) and the install quest (#636) ------------- */
.ws { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 14px; padding: 12px 16px 16px; }
.ws > .window { margin: 0; }
.ws-quest, .ws-bench { grid-column: 1 / -1; }
.ws-cmd { overflow: auto; background: var(--well); border: 1px solid var(--border); border-radius: var(--r-md); padding: 8px 10px; font: 12.5px var(--mono); }
.ws-live, .ws-score { margin-left: auto; font-size: 0.75rem; font-weight: 700; color: var(--ink-3); }
.ws-nest .titlebar, .ws-quest .titlebar { display: flex; gap: 8px; }
.ws-map svg { display: block; width: 100%; height: auto; }
.ws-foot { padding: 0 14px 10px; margin: 0; }
/* ns-3 replay (#641) */
.rp { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 14px; padding: 12px 16px 16px; }
.rp > .window { margin: 0; }
.rp-stage .titlebar { display: flex; gap: 8px; align-items: center; }
.rp-pick { margin-left: auto; }
.rp-map canvas { display: block; width: 100%; height: min(62vh, 560px); }
.rp-controls { display: flex; gap: 8px; align-items: center; padding: 8px 12px 0; }
.rp-controls input[type=range] { flex: 1; min-width: 0; }
.rp-stats { padding: 6px 12px 10px; margin: 0; font-size: 0.8rem; color: var(--ink-2); }
@media (max-width: 760px) { .rp { grid-template-columns: 1fr; } }
#nest .sky { fill: var(--sky); }
#nest .soil { fill: var(--nest-soil); }
#nest .tunnel { fill: none; stroke: var(--nest-tunnel); stroke-width: 20; stroke-linecap: round; }
#nest .label-sm { font: 700 12px var(--font); fill: var(--ink-2); }
#nest .surface rect { fill: var(--surface); stroke: var(--border); }
#nest .surface .title, #nest .chamber .title { font: 800 15px var(--font); fill: var(--nest-ink); }
#nest .surface .title { fill: var(--ink); }
#nest .cls { font: 700 12px var(--mono); fill: var(--nest-code); }
#nest .surface .cls { fill: var(--link); }
#nest .chamber { cursor: pointer; --heat: 0; }
#nest .chamber .room { fill: var(--nest-room); stroke: var(--nest-room-edge); stroke-width: 2; }
#nest .chamber .glow { fill: var(--nest-glow); opacity: var(--heat); filter: blur(10px); transform-box: fill-box; transform-origin: center; transform: scale(1.12); }
#nest .chamber:hover .room, #nest .chamber:focus .room { stroke: var(--accent); stroke-width: 4; }
#nest .chamber:focus { outline: none; }
#nest .chamber.on .room { stroke: var(--accent); stroke-width: 5; }
.ws-classes { padding-left: 18px; }
.ws-classes li { margin-bottom: 6px; color: var(--ink-2); }
.ws-classes a { font-family: var(--mono); font-weight: 700; color: var(--link); }
.ws-classes small { color: var(--ink-3); }
.ws-livevals { font: 600 12.5px var(--mono); color: var(--ink); background: var(--surface-2); border-left: 4px solid var(--good); border-radius: var(--r-md); padding: 8px 10px; }
.ws-steps { list-style: none; padding: 0; margin: 8px 0 12px; display: grid; gap: 6px; }
.ws-step { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-2); }
.ws-step p { margin: 2px 0 0; font-size: 0.85rem; color: var(--ink-2); }
.ws-step code { font-size: 0.8rem; color: var(--ink-3); }
.ws-icon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: var(--on-status); background: var(--lock); }
.ws-step.ok .ws-icon { background: var(--good); }
.ws-step.warn .ws-icon { background: var(--warn); }
.ws-step.fail .ws-icon { background: var(--critical); }
.ws-label { display: block; font-weight: 700; margin: 6px 0 4px; }
.ws-quest textarea { width: 100%; box-sizing: border-box; font: 12.5px var(--mono); background: var(--well); color: var(--ink); border: 1px solid var(--border); border-radius: var(--r-md); padding: 8px; }
.ws-quest .row { display: flex; gap: 8px; margin-top: 8px; }
.ws-quest .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (max-width: 900px) { .ws { grid-template-columns: 1fr; } }

/* --- campaign (#566): map, briefing, debrief, HUD and device dock --------------------- */
.campaign {
  position: absolute; inset: 0; z-index: 5; overflow: auto; padding: 14px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.campaign[hidden] { display: none; }
.sheet-card { max-width: 720px; margin: 0 auto; }
.sheet-card h3 { font-size: 1rem; margin: 12px 0 6px; }
.sheet-card .choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.bevel.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chapter { border-top: 1px solid var(--rule); padding-top: 4px; }
.chips { list-style: none; margin: 6px 0 4px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.chip-btn { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; }
.chip-btn .lvl { font: 700 0.78rem var(--mono); color: var(--ink-3); }
.chip-btn .stars { margin-left: auto; }
.chip-btn.done { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.later { margin: 4px 0; padding-left: 18px; color: var(--ink-2); font-size: 0.9rem; }
.goals { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 3px; }
.goals li.done { color: var(--ink); font-weight: 600; }
.goals li.missed { color: var(--ink-3); }
.device-cards { list-style: none; padding: 0; margin: 4px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.device-cards li { padding: 8px 10px; display: grid; gap: 4px; }
.hud {
  position: absolute; z-index: 3; left: 10px; right: 10px; top: 46px; max-width: 560px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--elev); padding: 8px 12px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); font-size: 0.88rem;
}
.hud[hidden], .dock[hidden] { display: none; }
.hud-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.hud-top .bevel { min-height: 28px; padding: 2px 10px; font-size: 0.82rem; }
.hud .quiz { margin-top: 6px; display: grid; gap: 4px; }
.hud .quiz .bevel { text-align: left; font-weight: 500; }
.dock {
  position: absolute; z-index: 3; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: calc(100% - 20px);
  display: flex; gap: 6px; padding: 6px; overflow-x: auto;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--elev);
}
.dock-btn { display: grid; grid-template-columns: auto 1fr; column-gap: 6px; text-align: left; min-width: 130px; }
.dock-btn kbd { grid-row: span 2; font: 700 0.75rem var(--mono); opacity: 0.75; align-self: center; }
.dock-btn .small { font-weight: 500; }
@media (max-width: 680px) {
  /* Phone: the dock becomes a bottom sheet of chips; the HUD shrinks to the top. */
  .hud { top: 8px; left: 6px; right: 6px; padding: 6px 8px; font-size: 0.8rem; }
  .dock { left: 0; right: 0; bottom: 0; transform: none; max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .dock-btn { min-width: 110px; }
  .campaign { padding: 6px; }
}
/* In a level the HUD owns the top of the map; messages rise above the dock. */
body.in-level .toast { top: auto; bottom: 86px; }

/* The tuning bench (#638). */
.bench summary { cursor: pointer; font-weight: 600; }
.bench-row { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr) 4.5rem; gap: 2px 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--rule); }
.bench-row p { grid-column: 1 / -1; margin: 0; }
.bench-row.moved label code { color: var(--link); font-weight: 700; }
.bench-row input[type="range"] { width: 100%; }
.bench-row output { text-align: right; font-variant-numeric: tabular-nums; }
.bench-badges .chip { margin-right: 4px; }
.bench-pre { white-space: pre-wrap; word-break: break-all; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px 8px; margin: 4px 0; }
.bench-stats table { width: 100%; }

/* The X-ray (#637): one colour per wire field, swatch in the table and the bytes. */
.xray-bytes { font: 12px/1.7 var(--mono); word-break: break-word; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px 8px; }
.xr { border-radius: var(--r-xs); padding: 0 2px; color: var(--xr-ink); }
.xr-sw { display: inline-block; width: 10px; height: 10px; border-radius: var(--r-xs); margin-right: 6px; vertical-align: -1px; }
.xr-version { background: var(--xr-version); } .xr-type, .xr-direction { background: var(--xr-type); }
.xr-src, .xr-dst { background: var(--xr-addr); } .xr-seqNum { background: var(--xr-seq); }
.xr-timeStart, .xr-lifeAnt { background: var(--xr-time); } .xr-broadcastBudget { background: var(--xr-budget); }
.xr-visited { background: var(--xr-visited); } .xr-history { background: var(--xr-history); } .xr-helloDests { background: var(--xr-hello); }
.xray-fields th { white-space: nowrap; }

/* Take it to ns-3 (#640). */
.kit-row { gap: 6px; flex-wrap: wrap; }

/* --- the game on a phone (#98): the field first ------------------------------------------
   Below 760 px the page is: the top bar, one line of breadcrumb, one line of
   controls (pause, one speed, a button that opens World, Seed, Step, the other
   speeds and Language), the field down to the bottom of the screen, and the
   five tools as a bar of icons fixed there. The level's HUD keeps its title,
   Run and the next goal; its other goals and Hint, Retry and Map open from "⋯".
   Nothing is removed: every control is the same element as on a wide screen. */
.menu-more, .hud-more { display: none; }
@media (max-width: 760px) {
  .pagehead { flex-wrap: nowrap; gap: 8px; margin: 6px 8px 0; }
  .pagehead .ahn-crumb ol { flex-wrap: nowrap; }
  .pagehead .ahn-crumb li { white-space: nowrap; }
  .pagehead .ahn-pair { flex: none; min-height: 44px; padding: 4px 14px; }
  .pagehead .ahn-pair span:not([aria-hidden]) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

  .menubar { margin: 6px 8px 0; padding: 4px 6px; gap: 6px 8px; }
  .menubar .bevel, .menubar select, .menubar input { min-height: 44px; }
  .speeds .bevel { min-width: 44px; }
  .menu-more { display: inline-block; margin-left: auto; }
  .menubar:not(.open) > .menu, .menubar:not(.open) > #step,
  .menubar:not(.open) .speeds .bevel:not([data-speed="0"], [data-speed="0.25"], [aria-pressed="true"]) { display: none; }
  .menubar.open > .menu { display: flex; flex: 1 1 100%; min-width: 0; }
  .menubar.open > .menu select { flex: 1 1 0; min-width: 0; width: 100%; }

  /* One column from here down, not only below 680 px: with the tools in the
     bottom bar, a side column would hold the view buttons alone. */
  .desk { grid-template-columns: 1fr; padding: 6px 8px 8px; gap: 8px; }
  .mapwin { order: 1; }
  .toolbox { order: 2; position: static; }
  .panels { order: 3; }
  .toolbox .tools:not(.small) .tool span, .tool kbd { display: none; }
  .overlays { grid-template-columns: 1fr 1fr; }
  /* The field takes what the three rows above and the tool bar below leave. */
  .map { height: calc(100vh - 236px); height: calc(100dvh - 236px); min-height: 300px; }
  .mapwin > .titlebar { display: none; }
  .status { padding: 6px 8px 2px; }

  .toolbox > .titlebar:first-child { display: none; }
  .toolbox .tools:not(.small) {
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; grid-template-columns: repeat(5, 1fr); gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--elev);
  }
  .toolbox .tools:not(.small) .tool { min-height: 44px; justify-content: center; padding: 6px 0; }
  .toolbox .tools:not(.small) .tool svg { width: 24px; height: 24px; }
  .toolbox .tools.small { grid-template-columns: repeat(5, 1fr); }
  .toolbox .tools.small .bevel { min-height: 44px; }
  /* The front panel is the page until Play: the tools come with the field. */
  body.hub-open .toolbox .tools:not(.small) { display: none; }
  body:has(.toolbox) { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }

  .hud { top: 6px; left: 6px; right: 6px; padding: 6px 8px; }
  .hud-top > b { flex: 1 1 100%; }  /* the level's name on its own line: the row under it never wraps Run away from "⋯" */
  .hud-top .bevel { min-height: 44px; padding: 4px 14px; font-size: 0.9rem; }
  .hud-more { display: inline-block; min-width: 44px; font-weight: 800; }
  .hud:not(.open) .hud-extra, .hud:not(.open) .goals li:not(.next) { display: none; }
  .dock-btn { min-height: 44px; }
}
