/* Greenwave control-room theme. Offline: system fonts only. */
:root {
  --bg: #0b1220;
  --panel: #111b2e;
  --border: #1f2d47;
  --road: #1c2a44;
  --text: #e6f0ff;
  --muted: #8ea3c4;
  --go: #3dffa8;
  --stop: #ff5470;
  --wait: #ffb547;
  --data: #38bdf8;
  --siren: #ff3355;
  --font: Bahnschrift, "Segoe UI", system-ui, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% 30%, rgba(56, 189, 248, 0.07), transparent 60%),
    linear-gradient(rgba(31, 45, 71, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 45, 71, 0.35) 1px, transparent 1px);
  background-size: 100% 100%, 40px 40px, 40px 40px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}
.num { font-variant-numeric: tabular-nums; }
kbd {
  font-family: var(--font);
  font-size: 0.72em;
  padding: 1px 5px;
  margin-left: 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--muted);
}

/* ---------- Header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 27, 46, 0.85);
}
.wordmark { font-size: 22px; font-weight: 700; letter-spacing: 0.02em; }
.wordmark span { color: var(--go); text-shadow: 0 0 12px rgba(61, 255, 168, 0.6); }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 9ch; }
.spacer { flex: 1; }
header button { white-space: nowrap; }
.view3d { display: flex; gap: 8px; }
.view3d[hidden] { display: none; }
.pill {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--go);
  color: var(--go);
  font-size: 13px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.pill.bad { border-color: var(--stop); color: var(--stop); }
.pill.warn { border-color: var(--wait); color: var(--wait); }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--data); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--data); outline-offset: 2px; }
button.on { border-color: var(--go); color: var(--go); }
/* Locked controls (everything outside the setup card while the route is being chosen). */
button:disabled { opacity: 0.35; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border); }
button.off { border-color: var(--stop); color: var(--stop); }

/* ---------- Views ---------- */
#views { min-height: 0; padding: 14px 18px; }
#grid-view, #focus-view { height: 100%; min-height: 0; }
body.view-grid #focus-view, body.view-focus #grid-view { display: none; }

#grid-view { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.map-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  gap: 8px;
}
.map-panel h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.03em; }
.map-panel.greenwave h2 { color: var(--go); }
.map-box { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.map-box canvas[hidden] { display: none !important; }
.map-box canvas { display: block; aspect-ratio: 1; max-width: 100%; max-height: 100%; width: 100%; height: auto; }

/* Map column only as wide as the (square) map can be; the scoreboard gets the rest. */
#focus-view { display: grid; grid-template-columns: minmax(0, min(58%, calc(100vh - 150px))) minmax(0, 1fr); gap: 18px; }
/* 3D: the city takes most of the width; the scoreboard is a narrow column beside it. */
body.r3d #focus-view { grid-template-columns: minmax(0, 1fr) clamp(200px, 24%, 340px); }
body.r3d .focus-left .map-box { flex: 1; }
/* 3D canvases fill their box at any shape (absolute, so the canvas never props its box open). */
body.r3d .map-box { position: relative; }
body.r3d .map-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; aspect-ratio: auto; }
.focus-left { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.focus-tabs { display: flex; gap: 8px; }
.focus-tabs button.active { border-color: var(--go); color: var(--go); box-shadow: 0 0 12px rgba(61, 255, 168, 0.25); }

/* ---------- Stat strips & scoreboard ---------- */
.stat-strip { display: grid; grid-template-columns: 1fr; gap: 6px; }
.stat { background: rgba(11, 18, 32, 0.6); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; min-width: 0; text-align: center; }
.stat small, .sb-label { display: block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stat b { font-size: clamp(16px, 1.5vw, 26px); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat i, .sb-sub { display: block; font-style: normal; font-size: 11px; color: var(--muted); white-space: nowrap; }
.best { color: var(--go); text-shadow: 0 0 14px rgba(61, 255, 168, 0.55); }
.zero { color: var(--go); }
.nonzero { color: var(--stop); }

/* Focus view scoreboard: a title and one tall card per panel, filling the column beside the map. */
#scoreboard { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.sb-title { font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); text-align: center; }
.sb-card {
  flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; text-align: center;
}
.sb-card.is-best { border-color: var(--go); box-shadow: 0 0 18px rgba(61, 255, 168, 0.18); }
.sb-name { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0.03em; }
.sb-card.gw .sb-name { color: var(--go); }
.sb-val { font-size: clamp(26px, 3.4vw, 64px); font-variant-numeric: tabular-nums; line-height: 1.05; white-space: nowrap; }
.sb-sub { font-size: 12px; color: var(--muted); }

/* ---------- Dock ---------- */
#dock {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 18px 14px;
  border-top: 1px solid var(--border);
  background: rgba(17, 27, 46, 0.85);
}
.group { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px 8px; position: relative; }
.group > span.title { position: absolute; top: -9px; left: 10px; padding: 0 6px; background: var(--panel); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.speed { min-width: 3ch; text-align: center; color: var(--text); font-weight: 600; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: 64px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 10; pointer-events: none; }
/* Focus view: the scoreboard owns the top-right, so toasts sit in the free space below it, above the dock. */
body.view-focus #toasts { top: auto; bottom: 84px; flex-direction: column-reverse; }
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--data);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  transition: opacity 300ms ease, transform 300ms ease;
}
.toast.kind-stop { border-left-color: var(--stop); }
.toast.kind-go { border-left-color: var(--go); }
.toast.kind-data { border-left-color: var(--data); }
.toast.enter, .toast.leave { opacity: 0; transform: translateX(12px); }

/* ---------- Setup card (choose ambulance route, then start) ---------- */
#setup, #finish {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20;
  display: none; flex-direction: column; gap: 8px; min-width: min(560px, calc(100vw - 32px));
  background: rgba(17, 27, 46, 0.96); border: 1px solid #c77dff; border-radius: var(--radius);
  padding: 12px 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 24px rgba(199, 125, 255, 0.25);
}
body.setup #setup, body.finished #finish { display: flex; }
/* Focus view: the map is on the left, so the card sits over the scoreboard instead. */
body.view-focus #setup, body.view-focus #finish { left: auto; right: 18px; transform: none; }
#finish { border-color: var(--go); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 24px rgba(61, 255, 168, 0.25); }
#finish .title { color: var(--go); }
#finish-times { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.finish-time { background: rgba(11, 18, 32, 0.6); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.finish-time small { display: block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.finish-time b { font-size: 24px; }
.finish-time.best { border-color: var(--go); }
.finish-time.best b { color: var(--go); text-shadow: 0 0 14px rgba(61, 255, 168, 0.55); }
.setup-head { display: flex; align-items: center; gap: 14px; justify-content: space-between; }
.setup-head .title { font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: #d9b3ff; }
.seg { display: flex; gap: 0; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; border-left: none; }
.seg button.active { border-color: #c77dff; color: #e9d2ff; background: rgba(199, 125, 255, 0.16); }
#setup-status { margin: 0; color: var(--text); font-size: 15px; }
.setup-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#setup-edit { display: flex; gap: 8px; }
#setup-edit[hidden] { display: none; }
button.primary { border-color: var(--go); color: var(--bg); background: var(--go); font-weight: 600; margin-left: auto; }
button.primary kbd { color: var(--bg); border-color: rgba(11, 18, 32, 0.4); }
button.primary:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary:disabled:hover { border-color: var(--go); }

/* ---------- "?" explainers ---------- */
.map-panel { position: relative; }
.map-box { position: relative; }
button.help {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 24px; height: 24px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; font-weight: 700; line-height: 1;
  color: var(--muted); background: rgba(17, 27, 46, 0.9); border: 1px solid var(--border);
}
button.help:hover, button.help[aria-expanded="true"] { color: var(--data); border-color: var(--data); }
#help-pop {
  position: fixed; z-index: 30; width: min(320px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--data); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
#help-pop[hidden] { display: none; }
#help-pop b { display: block; margin-bottom: 4px; font-size: 15px; color: var(--data); }
#help-pop p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--text); }

/* ---------- Show messages key ---------- */
.msg-key {
  position: absolute; left: 8px; bottom: 8px; z-index: 3;
  display: flex; flex-direction: column; gap: 3px;
  background: rgba(11, 18, 32, 0.85); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--text); pointer-events: none;
}
.msg-key[hidden] { display: none; }
.msg-key .title { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.msg-key span { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.msg-key .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.msg-key .dot.car { background: #ffe14d; box-shadow: 0 0 6px #ffe14d; }
.msg-key .dot.emv { background: #ff3df0; box-shadow: 0 0 6px #ff3df0; width: 12px; height: 12px; }

/* Laptop screens: keep the dock on one row so the maps get the height. */
@media (max-width: 1500px), (max-height: 760px) {
  header { padding: 6px 14px; gap: 10px; }
  .wordmark { font-size: 18px; }
  .pill { font-size: 11px; padding: 3px 9px; }
  button { padding: 4px 9px; font-size: 13px; }
  #dock { gap: 6px; padding: 10px 8px 8px; }   /* tight: all four groups must fit one row at ~1160 px */
  .group { padding: 5px 7px; gap: 6px; }
  .hint { display: none; }
  header button kbd { display: none; }
  .pill { letter-spacing: 0.02em; }
  #views { padding: 8px 14px; }
  .map-panel { padding: 8px; gap: 6px; }
  .map-panel h2 { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
