/* SWM Twin. Colours are tokens (light, then dark); each card has an accent. */
:root {
  --bg: #f3f5f9; --card: #ffffff; --ink: #1b2130; --muted: #5d6677; --line: #dde2ea; --soft: #f7f9fc;
  --human: #2f6fdf; --ai: #0f9d8a; --enemy: #d23c3c; --jam: #d23c3c; --obj: #c98a00; --survivor: #7a8496;
  --grid: #e3e8ef; --land: #eef2e6; --land2: #e6ecdc; --ok: #1e8e3e; --bad: #c5221f; --warn: #b26a00;
  --accent: #2f6fdf; --fire: #e8590c; --flood: #1c7ed6; --evac: #2b8a3e; --water: #b9d7ef; --road-main: #d9822b; --road: #7d8590; --track: #a89f86;
  --c-map: #2f6fdf; --c-measures: #6741d9; --c-console: #7048e8; --c-talk: #0c8599; --c-tasks: #2b8a3e;
  --c-drive: #e8590c; --c-scenario: #495057; --c-chat: #1c7ed6; --c-events: #e67700; --c-decisions: #0f9d8a;
  --r-aerial: #2a78d6; --r-ground: #eb6834; --r-carto: #1baf7a; --c-twin: #6741d9;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --card: #181d26; --ink: #e6e9ef; --muted: #9aa3b2; --line: #2a313d; --soft: #1e2430;
    --human: #6ea0ff; --ai: #3cc9b4; --enemy: #ff6b6b; --jam: #ff6b6b; --obj: #f0b429; --survivor: #9aa3b2;
    --grid: #232a35; --land: #18201a; --land2: #1c251e; --ok: #5bd17a; --bad: #ff7b72; --warn: #f0b429;
    --accent: #6ea0ff; --fire: #ff8a4c; --flood: #4dabf7; --evac: #69db7c; --water: #1d3550; --road-main: #b8692a; --road: #5b6472; --track: #4a4f45;
    --c-map: #6ea0ff; --c-measures: #9775fa; --c-console: #9775fa; --c-talk: #3bc9db; --c-tasks: #69db7c;
    --c-drive: #ff922b; --c-scenario: #adb5bd; --c-chat: #4dabf7; --c-events: #fcc419; --c-decisions: #3cc9b4;
  --r-aerial: #3987e5; --r-ground: #d95926; --r-carto: #199e70; --c-twin: #9775fa;
    --r-aerial: #3987e5; --r-ground: #d95926; --r-carto: #199e70; --c-twin: #9775fa;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --card: #181d26; --ink: #e6e9ef; --muted: #9aa3b2; --line: #2a313d; --soft: #1e2430;
  --human: #6ea0ff; --ai: #3cc9b4; --enemy: #ff6b6b; --jam: #ff6b6b; --obj: #f0b429; --survivor: #9aa3b2;
  --grid: #232a35; --land: #18201a; --land2: #1c251e; --ok: #5bd17a; --bad: #ff7b72; --warn: #f0b429;
  --accent: #6ea0ff; --fire: #ff8a4c; --flood: #4dabf7; --evac: #69db7c; --water: #1d3550; --road-main: #b8692a; --road: #5b6472; --track: #4a4f45;
  --c-map: #6ea0ff; --c-measures: #9775fa; --c-console: #9775fa; --c-talk: #3bc9db; --c-tasks: #69db7c;
  --c-drive: #ff922b; --c-scenario: #adb5bd; --c-chat: #4dabf7; --c-events: #fcc419; --c-decisions: #3cc9b4;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* a class that sets display must not show a hidden element */
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}
a { color: var(--accent); }
kbd { font: 12px ui-monospace, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px;
      border-radius: 4px; padding: 0 4px; background: var(--soft); }
.ic { width: 16px; height: 16px; flex: none; vertical-align: -3px; }

/* --- top bar ------------------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { width: 24px; height: 24px; }
h1 { font-size: 16px; margin: 0; white-space: nowrap; }
/* The three modes: tabs (one is on), not buttons that do something */
.modes { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.modes button { border: 0; background: transparent; color: var(--muted); font-weight: 600; padding: 5px 14px; border-radius: 7px; }
.modes button:hover:not(.on) { color: var(--ink); background: var(--card); }
.modes button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(20, 30, 50, .18); }
.modes .badge { margin-left: 4px; }
.onscreen { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.title small { font-weight: normal; color: var(--muted); margin-left: 6px; }
/* Status: plain text with a dot. Never boxed, so it doesn't look like something to press. */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; cursor: help; }
.status i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok i { background: var(--ok); } .status.warn i { background: var(--warn); } .status.bad i { background: var(--bad); }
.status.bad { color: var(--bad); }
.status.live { color: var(--ok); font-weight: 600; }
.status.live i { animation: pulse 2s infinite; }
.clockbox { display: flex; align-items: center; gap: 10px; }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
#clock { font: 600 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
#clockSub { color: var(--muted); font-size: 11px; white-space: nowrap; }
.tools { display: flex; gap: 6px; }
label { color: var(--muted); font-size: 13px; }
select, button, input:not([type]), input[type="text"] {
  font: inherit; color: var(--ink); background: var(--soft);
  border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; min-width: 0;
}
select { max-width: 260px; }
button { cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-align: left; }
button.link:hover { text-decoration: underline; }
button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.icon-btn { padding: 4px 7px; }
.icon-btn.small { padding: 2px 5px; }
/* A state in a list (running, finished): a dot and a word, like the status */
.state { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state.running { color: var(--ok); } .state.running::before { background: var(--ok); animation: pulse 2s infinite; }
.state.failed { color: var(--bad); } .state.failed::before { background: var(--bad); }
.state.wait { color: var(--warn); } .state.wait::before { background: var(--warn); }
/* Scripted movement: one line per unit, its state from its newest MOVE record */
.movestate { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: -2px 0 8px; font-size: 12px; }
.movestate .movest { display: inline-flex; align-items: center; gap: 7px; }
.movestate .muted { color: var(--muted); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(30, 142, 62, .45); } 50% { box-shadow: 0 0 0 5px rgba(30, 142, 62, 0); } }
@media (prefers-reduced-motion: reduce) { .status.live i, .state.running::before { animation: none; } }

/* --- layout and cards -------------------------------------------------------------- */
main {
  flex: 1; display: grid; gap: 14px; padding: 14px 16px;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
}
@media (max-width: 960px) { main { grid-template-columns: minmax(0, 1fr); } }
.mapcol, .side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card {
  --c: var(--accent);
  background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--c);
  border-radius: 10px; padding: 10px 14px 12px; box-shadow: var(--shadow); min-width: 0;
}
.card[data-card="map"] { --c: var(--c-map); }        .card[data-card="measures"] { --c: var(--c-measures); }
.card[data-card="console"] { --c: var(--c-console); } .card[data-card="talk"] { --c: var(--c-talk); }
.card[data-card="tasks"] { --c: var(--c-tasks); }     .card[data-card="drive"] { --c: var(--c-drive); }
.card[data-card="scenario"] { --c: var(--c-scenario); } .card[data-card="chat"] { --c: var(--c-chat); }
.card[data-card="events"] { --c: var(--c-events); }   .card[data-card="decisions"] { --c: var(--c-decisions); }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 10px; }
h2 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
     display: flex; align-items: center; gap: 7px; }
.card-head h2 { margin: 0; }
h2 .ic { color: var(--c); width: 18px; height: 18px; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }
.toggle-head { cursor: pointer; user-select: none; }
.toggle-head::after { content: "▾"; margin-left: auto; font-size: 12px; color: var(--muted); transition: transform .15s; }
.card.collapsed .toggle-head::after { transform: rotate(-90deg); }
.card.collapsed .card-body, .card.collapsed > .card-head ~ .card-body { display: none; }
.card.collapsed h2 { margin-bottom: 0; }
.count { margin-left: 6px; font-size: 12px; color: var(--c); text-transform: none; letter-spacing: 0; }
details.card > summary { list-style: none; cursor: pointer; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2::after { content: "▾"; margin-left: auto; font-size: 12px; }
details.card:not([open]) > summary h2 { margin-bottom: 0; }

/* chips (map layers, measures) */
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--soft);
        color: var(--muted); cursor: pointer; user-select: none; }
.chip:hover { border-color: var(--c, var(--accent)); color: var(--ink); }
.chip.on { background: color-mix(in srgb, var(--c, var(--accent)) 14%, var(--card)); border-color: var(--c, var(--accent)); color: var(--ink); }
.chip.on::before { content: "✓ "; color: var(--c, var(--accent)); font-weight: 700; }
.chip:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- map --------------------------------------------------------------------------- */
.map-card { display: flex; flex-direction: column; }
.mapwrap { position: relative; margin-top: 8px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
#map { width: 100%; height: min(64vh, 660px); min-height: 320px; display: block; background: var(--land); cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map.aim { cursor: crosshair; }
#map .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
#map text { fill: var(--muted); paint-order: stroke; stroke: var(--land); stroke-width: 3px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#map .unit { cursor: pointer; }
.maphint { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: var(--muted); background: var(--card);
           opacity: .85; padding: 1px 7px; border-radius: 6px; pointer-events: none; }
.followbadge { position: absolute; left: 8px; top: 8px; z-index: 2; display: flex; align-items: center; gap: 6px; font-size: 12px;
               font-weight: 600; color: var(--accent); background: var(--card); border: 1px solid var(--accent); border-radius: 999px;
               padding: 1px 3px 1px 10px; box-shadow: var(--shadow); }
.followbadge[hidden] { display: none; }
.tip { position: absolute; z-index: 3; pointer-events: none; background: var(--card); border: 1px solid var(--line);
       border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); max-width: 260px; }
.tip b { display: block; font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); padding-top: 8px; align-items: center; }
.legend svg { width: 16px; height: 16px; vertical-align: -4px; margin-right: 4px; }

/* --- measures ------------------------------------------------------------------------ */
.measures { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.measure { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px 4px; background: var(--soft); cursor: pointer; }
.measure .mh { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.measure .mv { font: 600 18px/1.2 ui-monospace, Menlo, monospace; color: var(--ink); }
.measure svg { width: 100%; height: 60px; display: block; }
.measure .why { font-size: 11px; color: var(--muted); }
.measures .empty { color: var(--muted); font-style: italic; font-size: 13px; }

/* --- feeds --------------------------------------------------------------------------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.feed li { padding: 5px 4px; border-top: 1px solid var(--line); display: flex; gap: 9px; align-items: flex-start; border-radius: 4px; }
.feed li:first-child { border-top: 0; }
.feed li.seek { cursor: pointer; }
.feed li.seek:hover { background: var(--soft); }
.feed .t { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; font-size: 12px; padding-top: 2px; }
.feed .who { font-weight: 600; }
.feed .lost { color: var(--bad); font-size: 12px; }
.feed .empty { color: var(--muted); font-style: italic; }
.feed .tag { font-size: 11px; color: var(--muted); background: var(--soft); border-radius: 4px; padding: 0 5px; margin-left: 4px; white-space: nowrap; }
.av { flex: none; width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.av svg { width: 14px; height: 14px; }
.ev { flex: none; width: 16px; height: 16px; color: var(--c-events); margin-top: 2px; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.state-SUCCEEDED { color: var(--ok); } .state-FAILED, .state-CANCELED { color: var(--bad); }
.state-ASSIGNED { color: var(--accent); } .state-CREATED { color: var(--muted); }
.progress { height: 6px; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.progress div { height: 100%; width: 0; background: var(--c-tasks); transition: width .3s; }

/* --- console and talk ---------------------------------------------------------------- */
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.form { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.check { display: inline-flex; align-items: center; gap: 4px; }
.grow { flex: 1 1 220px; min-width: 0; }   /* wraps to its own line on a phone */
#talk .row + .row { margin-top: 8px; }
.runs { list-style: none; margin: 0; padding: 0; }
.startbox { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.startbox > summary { cursor: pointer; font-weight: 600; color: var(--c-console); list-style: none; }
.startbox > summary::before { content: "▸ "; } .startbox[open] > summary::before { content: "▾ "; }
.startbox > summary::-webkit-details-marker { display: none; }
h3.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 2px 0 4px; }
.runs li.on { background: color-mix(in srgb, var(--accent) 8%, transparent); box-shadow: inset 3px 0 0 var(--accent); padding-left: 8px; border-radius: 4px; }
.runs .desc { color: var(--muted); font-size: 12px; }
.runs li { border-top: 1px solid var(--line); padding: 8px 0; display: flex; flex-direction: column; gap: 5px; }
.runs .head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; }
.runs .name { font-weight: 600; }
.runs .join { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--soft);
              border: 1px dashed var(--c-console); border-radius: 6px; padding: 3px 7px; }
.runs .buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.log { max-height: 220px; overflow: auto; font-size: 11px; background: var(--soft); border: 1px solid var(--line);
       border-radius: 6px; padding: 8px; margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; }
#control .note { margin: 8px 0 0; }
#control.driving { border-color: var(--ai); box-shadow: 0 0 0 1px var(--ai) inset; }
#driveStatus:empty { display: none; }
.note { color: var(--muted); font-size: 12px; }

/* --- player (footer) ------------------------------------------------------------------ */
.player {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 16px; background: var(--card); border-top: 1px solid var(--line); position: sticky; bottom: 0; z-index: 4;
}
.player .buttons { display: flex; gap: 4px; align-items: center; }
.player .play { background: var(--accent); border-color: var(--accent); color: #fff; padding: 5px 10px; }
.timeline { flex: 1; min-width: 180px; position: relative; display: flex; flex-direction: column; }
#time { width: 100%; accent-color: var(--accent); margin: 0; }
.ticks { width: 100%; height: 8px; display: block; }
.ticks rect { cursor: pointer; }
#live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
/* Run and Live: a progress strip instead of the playback controls (the game runs in real time) */
.progressbar { height: 8px; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 4px 0; }
.progressbar div { height: 100%; width: 0; background: var(--accent); transition: width .5s linear; }
body[data-mode="replay"] .forLive, body:not([data-mode="replay"]) .forReplay { display: none !important; }
body:not([data-mode="run"]) .forRun { display: none !important; }
.progtext { font: 600 13px ui-monospace, Menlo, monospace; color: var(--muted); white-space: nowrap; }

/* --- start/stop state, confirmations, the map's waiting message --- */
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.running-now { margin: 0; font-size: 12px; color: var(--ok); }
.running-now::before { content: "● "; }
.modal-card.small { max-width: 460px; margin-top: 10vh; }
.modal-card.small.warn { border-top-color: var(--bad); }
.row.end { justify-content: flex-end; margin-top: 12px; }
.mapmsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
          padding: 24px; color: var(--muted); font-size: 15px; background: color-mix(in srgb, var(--land) 85%, transparent); }
.mapmsg b { color: var(--ink); }

/* --- the end of a run: banner, confetti; bell; measure groups; tick legend --- */
.banner { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 25; width: min(560px, calc(100vw - 32px));
          background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: 12px;
          padding: 14px 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); animation: drop .35s ease-out; }
.banner.win { border-top-color: var(--ok); }
.banner h3 { margin: 0 0 6px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.banner h3 .ic { width: 24px; height: 24px; color: var(--ok); }
.banner ul { margin: 6px 0 10px; padding-left: 18px; } .banner li { margin: 2px 0; }
@keyframes drop { from { transform: translate(-50%, -14px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 40; }
#notifyBtn.on { color: var(--accent); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-right: 4px; }
.seg button { border: 0; border-radius: 0; font-size: 12px; padding: 2px 10px; background: var(--soft); color: var(--muted); }
.seg button.on { background: var(--c-measures); color: #fff; }
.measure.dev { border-left: 3px solid var(--c-events); } .measure.research { border-left: 3px solid var(--c-measures); }
.tick-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tick-legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 2px; }
.modal-card .k { font-size: 11px; }
@media (prefers-reduced-motion: reduce) { .banner { animation: none; } }

/* --- key numbers, tabs, paired chat, timeline lanes --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.kpis:empty { display: none; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; box-shadow: var(--shadow); min-width: 0; }
.kpi .kl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .kv2 { font: 600 19px/1.25 ui-monospace, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .kv2.long { font-size: 14px; line-height: 1.75; }
.kpi.warn { border-color: var(--warn); } .kpi.warn .kv2 { color: var(--warn); }
.kpi.ok .kv2 { color: var(--ok); } .kpi.bad { border-color: var(--bad); } .kpi.bad .kv2 { color: var(--bad); }
.badge { background: var(--ok); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }
.chatfeed .reply { display: flex; gap: 8px; margin: 4px 0 0; padding: 4px 8px; border-left: 3px solid var(--c-decisions); background: var(--soft); border-radius: 0 6px 6px 0; }
.chatfeed .qa { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chatfeed .intent { font-size: 11px; color: var(--c-decisions); background: color-mix(in srgb, var(--c-decisions) 12%, transparent); border-radius: 4px; padding: 0 5px; margin-left: 4px; white-space: nowrap; }
.chatfeed .estate { font-size: 11px; color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-radius: 4px; padding: 0 5px; margin-left: 4px; white-space: nowrap; }
.lanes { display: grid; grid-template-columns: max-content 1fr; gap: 0 10px; align-items: stretch; }
.lanes .ln { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; height: 26px; white-space: nowrap; }
.lanes svg { width: 100%; display: block; cursor: pointer; }
.lanes .empty { grid-column: 1 / -1; color: var(--muted); font-style: italic; font-size: 13px; }

/* --- presentation mode, menus, servers, bookmarks --- */
.menu { position: relative; }
.menu-pop { position: absolute; bottom: 110%; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
            box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column; min-width: 280px; z-index: 6; }
.menu-pop button { border: 0; background: transparent; text-align: left; justify-content: flex-start; padding: 6px 8px; }
.menu-pop button:hover { background: var(--soft); }
#presentBtn.on { color: var(--accent); border-color: var(--accent); }
.card[data-card="servers"] { --c: var(--c-scenario); }
.card[data-card="lanes"] { --c: var(--c-events); }
.servers { list-style: none; margin: 0; padding: 0; }
.servers li { display: flex; gap: 9px; align-items: center; padding: 7px 6px; border-top: 1px solid var(--line); border-radius: 4px; }
.servers li:first-child { border-top: 0; }
.servers li.pick { cursor: pointer; } .servers li.pick:hover { background: var(--soft); }
.servers li.on { background: color-mix(in srgb, var(--accent) 8%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.servers .who { font-weight: 600; }
.servers .dotx { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); flex: none; }
.servers .dotx.ok { background: var(--ok); }
#markText { width: 100%; margin-top: 6px; }
body.present { font-size: 16px; }
body.present .side > .card:not([data-card="chat"]):not([data-card="tasks"]),
body.present #markBtn, body.present .menu, body.present .maphint, body.present .modes, body.present #toList { display: none !important; }
body.present .kpi .kv2 { font-size: 26px; } body.present .kpi .kl { font-size: 12px; }
body.present .kpi .kv2.long { font-size: 17px; line-height: 1.95; }
body.present #map { height: min(72vh, 820px); }
body.present h1 { font-size: 20px; }

/* --- compare, tour --- */
.compare { font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.compare select { font-size: 12px; max-width: 220px; }
.measure .cmp { font-size: 12px; color: var(--muted); }
.tour-hole { position: fixed; z-index: 45; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(10, 14, 22, .6);
             outline: 3px solid var(--accent); pointer-events: none; transition: all .25s; }
.tour-pop { position: fixed; z-index: 46; width: min(360px, calc(100vw - 32px)); background: var(--card); border-radius: 12px;
            border-top: 4px solid var(--accent); padding: 14px 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.tour-pop h3 { margin: 2px 0 6px; font-size: 16px; } .tour-pop p { margin: 0 0 6px; }
.tour-step { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
@media (prefers-reduced-motion: reduce) { .tour-hole { transition: none; } }

/* --- help, toasts ---------------------------------------------------------------------- */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 22, .55); z-index: 20; display: flex;
         align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { position: relative; background: var(--card); border-radius: 12px; padding: 18px 22px; max-width: 860px; width: 100%;
              border-top: 4px solid var(--accent); box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal-card h2 { font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 0 0 10px; }
.modal-card h3 { font-size: 14px; margin: 12px 0 4px; color: var(--accent); }
.modal-card p { margin: 0 0 6px; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 26px; }
.close { position: absolute; top: 10px; right: 12px; font-size: 18px; line-height: 1; }
.toasts { position: fixed; right: 16px; bottom: 72px; display: flex; flex-direction: column; gap: 8px; z-index: 30; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px;
         padding: 8px 12px; box-shadow: 0 4px 18px rgba(0, 0, 0, .18); font-size: 13px; }
.toast.bad { border-left-color: var(--bad); } .toast.ok { border-left-color: var(--ok); }
@media (max-width: 600px) {
  .topbar { padding: 8px 12px; } main { padding: 12px; }
  .clock #clock { font-size: 18px; }
  .tools .icon-btn span { display: none; }
  .onscreen { flex-basis: 100%; }
  .clockbox { flex-basis: 100%; flex-wrap: wrap; justify-content: space-between; }
  .clock { align-items: flex-start; }
  .tools { margin-left: auto; }
  .maphint { display: none; }
}
.side > .mode-off { display: none !important; }

/* --- Replay: the list of recorded runs --- */
.library { padding: 14px 16px; flex: 1; }
.card[data-card="library"] { --c: var(--accent); }
.filters { gap: 6px 14px; }
.filters input[type="search"] { font: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; background: var(--soft); color: var(--ink); min-width: 180px; }
.tablewrap { overflow-x: auto; margin-top: 8px; }
.runlist { width: 100%; border-collapse: collapse; font-size: 13px; }
.runlist th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.runlist td { padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.runlist .num { text-align: right; font-variant-numeric: tabular-nums; }
.runlist tbody tr { cursor: pointer; }
.runlist tbody tr:hover { background: var(--soft); }
.runlist .muted { color: var(--muted); }
.runlist .livenow { color: var(--ok); font-weight: 600; font-size: 12px; margin-left: 6px; }
.runlist .livenow::before { content: "● "; }
.runlist .dbtag { font-size: 11px; margin-left: 6px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.runlist td.act button { font-size: 12px; padding: 1px 8px; color: var(--muted); }
body[data-view="list"] main, body[data-view="list"] .player { display: none !important; }
body[data-empty="1"] .side > .card:not([data-card="console"]):not([data-card="servers"]),
body[data-empty="1"] .player > *, body[data-empty="1"] .kpis { display: none !important; }
#toList { white-space: nowrap; flex: none; }

/* The twins (twin.py): item grids per teammate, probe classes, drift charts, what-if. */
.card[data-card="twins"], .card[data-card="team"] { --c: var(--c-twin); }
.twins { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.twins .why { color: var(--muted); font-size: 12px; }
.twitems { gap: 6px; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.twitems select { font-size: 12px; }
.twins .tw-role { display: flex; flex-direction: column; gap: 4px; }
.twins .tw-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.twins .tw-head b { color: var(--ink); }
.twins .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.twins .num { font: 600 13px ui-monospace, Menlo, monospace; }
.grid-items { display: grid; grid-template-columns: 62px repeat(4, 13px 13px 13px 3px); gap: 2px; align-items: center; justify-content: start; }
.grid-items .gl { font-size: 10px; color: var(--muted); white-space: nowrap; }
.grid-items .cell { width: 13px; height: 13px; border-radius: 3px; border: 1px solid var(--line); box-sizing: border-box; }
.grid-items .cell.right { background: color-mix(in srgb, var(--ok) 55%, transparent); border-color: transparent; }
.grid-items .cell.wrong { background: var(--bad); border-color: transparent; }
.grid-items .cell.unknown { background: transparent; }
.grid-items .cell.na { background: repeating-linear-gradient(45deg, var(--line) 0 2px, transparent 2px 5px); border-color: transparent; }
.tw-key { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); align-items: center; }
.tw-key .cell { display: inline-block; width: 11px; height: 11px; vertical-align: -1px; margin-right: 3px; border-radius: 3px; border: 1px solid var(--line); }
.tw-key .cell.right { background: color-mix(in srgb, var(--ok) 55%, transparent); border-color: transparent; }
.tw-key .cell.wrong { background: var(--bad); border-color: transparent; }
.tw-key .cell.na { background: repeating-linear-gradient(45deg, var(--line) 0 2px, transparent 2px 5px); border-color: transparent; }
.classes { display: flex; gap: 6px; flex-wrap: wrap; }
.classes .cls { font-size: 11px; border-radius: 4px; padding: 1px 6px; border: 1px solid var(--line); color: var(--ink); }
.classes .cls b { font-family: ui-monospace, Menlo, monospace; }
.classes .cls.correct { border-color: var(--ok); } .classes .cls.stale { border-color: var(--warn); }
.classes .cls.extraction_error, .classes .cls.confabulation { border-color: var(--bad); }
.probelist { list-style: none; margin: 0; padding: 0; font-size: 12px; max-height: 160px; overflow: auto; }
.probelist li { padding: 2px 0; border-bottom: 1px solid var(--line); }
.probelist .tag { font-size: 11px; border-radius: 4px; padding: 0 5px; margin-left: 4px; border: 1px solid var(--line); }
.driftchart { display: flex; flex-direction: column; gap: 2px; }
.driftchart > svg { width: 100%; height: 72px; display: block; cursor: pointer; }
.driftchart .dl svg { width: 18px; height: 8px; vertical-align: middle; }
.driftchart .dl { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.driftchart .dl b { color: var(--ink); font-weight: 600; }
.driftchart .dt { font-size: 12px; color: var(--ink); font-weight: 600; }
.whatif summary { cursor: pointer; font-weight: 600; color: var(--c-twin); }
.whatif .row { margin-top: 6px; }
.simtag { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--c-twin); border: 1px dashed var(--c-twin); border-radius: 4px; padding: 0 4px; }
.lanes .driftrow svg { cursor: pointer; }

/* The login page (#203) and the user chip in the top bar. */
body.loginpage { min-height: 100vh; display: grid; place-items: center; }
.login { width: min(440px, 94vw); }
.login-card { padding: 22px 24px; }
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.login-card .brand h1 { margin: 0; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.login-card input { font-size: 18px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--soft); color: var(--ink); }
.login-card .form { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.login-card .bad, .adminpage .bad { color: var(--bad); }
.login-card .small { font-size: 11px; }
.me { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.me b { color: var(--ink); font-weight: 600; }
.me .role { border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.me a { color: var(--accent); }

/* The admin panel (#204). */
.adminpage main.admin { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(640px, 100%), 1fr)); gap: 12px; padding: 12px; align-items: start; }
.adminpage main.admin .card { padding: 12px 14px; overflow-x: auto; }
/* Health (#204): a summary line, then tiles grouped by kind; the left edge and dot are the status */
.adminpage .health-card, .adminpage [data-card="servers"] { grid-column: 1 / -1; }
.adminpage .health-sum { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 2px 0 10px; font-weight: 600; }
.adminpage .health-sum .muted { font-weight: 400; color: var(--muted); }
.adminpage .health { display: flex; flex-wrap: wrap; gap: 12px 22px; }
.adminpage .hbox { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.adminpage .hrow { display: flex; flex-wrap: wrap; gap: 10px; }
.adminpage .hgroup { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.adminpage .htile { background: var(--soft); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 10px; padding: 8px 10px 9px; width: 228px; max-width: 100%; }
.adminpage .htile .hname { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.adminpage .htile .hname span:nth-child(2) { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adminpage .htile .hst { margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.adminpage .htile .hval { font-size: 19px; font-weight: 650; margin: 3px 0 2px; font-variant-numeric: tabular-nums; color: var(--ink); }
.adminpage .htile .hdet { font-size: 12px; color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; }
.adminpage .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--line); }
.adminpage .ok > .dot, .adminpage .htile.ok .dot { background: var(--ok); }
.adminpage .warn > .dot, .adminpage .htile.warn .dot { background: var(--warn); }
.adminpage .bad > .dot, .adminpage .htile.bad .dot { background: var(--bad); }
.adminpage .htile.ok { border-left-color: var(--ok); } .adminpage .htile.ok .hst { color: var(--ok); }
.adminpage .htile.warn { border-left-color: var(--warn); } .adminpage .htile.warn .hst { color: var(--warn); }
.adminpage .htile.bad { border-left-color: var(--bad); } .adminpage .htile.bad .hst { color: var(--bad); }
.adminpage .htile.off { opacity: .75; }
.adminpage main.admin h2 small { font-weight: 400; color: var(--muted); }
.adminpage .log { max-height: 320px; overflow: auto; white-space: pre-wrap; }
.adminpage td.act, .adminpage th.act { white-space: nowrap; text-align: right; }
.adminpage td.act button { font-size: 12px; padding: 1px 8px; margin-right: 4px; }
/* Units: an icon for the kind, a status pill, and only the actions that fit the status */
.adminpage td.unit .uname { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.adminpage td.unit .uname .ic { color: var(--muted); }
.adminpage td.unit .who { margin-left: 23px; }
.adminpage .pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 10px 2px 8px;
  border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--soft); white-space: nowrap; }
.adminpage .pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.adminpage .pill.running { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.adminpage .pill.running::before { animation: pulse 2s infinite; }
.adminpage .pill.failed { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.adminpage .pill.busy { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
@media (prefers-reduced-motion: reduce) { .adminpage .pill.running::before { animation: none; } }
.adminpage td.act button.uact { padding: 3px 10px; margin: 0 0 0 6px; }
.adminpage td.act button.uact .ic { width: 13px; height: 13px; }
.adminpage td.act button.uact.start { color: var(--ok); }
.adminpage td.act button.uact.stop { color: var(--bad); }
.adminpage td.act button.uact.stop:hover:not(:disabled) { border-color: var(--bad); }
.adminpage .row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.adminpage .row.wrap { flex-wrap: wrap; }
.adminpage .grow { flex: 1; }
.adminpage .tag { font-size: 11px; border-radius: 4px; padding: 0 6px; margin-left: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.adminpage .tag.warn { border-color: var(--warn); color: var(--warn); }
.adminpage h3.sub { font-size: 13px; margin: 12px 0 4px; }
.adminpage .who { font-size: 12px; color: var(--muted); }
.lockbanner { position: static !important; margin: 8px 12px 0; padding: 8px 12px; border-radius: 8px; color: #fff; background: var(--warn); font-weight: 600; }
.toast.bad { border-left: 3px solid var(--bad); }

/* Phones (#206): the map, then one panel at a time, picked in a strip of tabs under the top bar. */
.phonetabs { display: none; }
@media (max-width: 720px) {
  .phonetabs { display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px; background: var(--card); border-bottom: 1px solid var(--line);
               position: sticky; top: 0; z-index: 4; scrollbar-width: none; }
  .phonetabs button { flex: none; border: 1px solid var(--line); background: var(--soft); color: var(--muted); border-radius: 999px;
                      padding: 4px 12px; font-weight: 600; font-size: 13px; }
  .phonetabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  body[data-view="list"] .phonetabs { display: none; }
  main .card[data-card]:not([data-card="map"]):not(.panel-on) { display: none !important; }
  .topbar { position: static; }
  .map-card .mapwrap { height: 46vh; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
