/* Design tokens: colours, sizes and layout constants used by every HUD component. */
:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --surface: #f6f8fb; /* subtle fill inside panels */
  --surface-strong: #f1f4f8;
  --track: #e3e8ef; /* progress-bar tracks */
  --line: #e4e8ee;
  --text: #1d2430;
  --muted: #6b7486;
  --faint: #9aa3b2;
  --accent: #2f6fed;
  --accent-strong: #2a63d6;
  --accent-soft: #e8efff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --water-soft: #e9f1fb;
  --warn: #f08c2e;
  --ok: #10a37f;
  --intel: #7c5cff; /* crowd intel (also set from palette.ts at startup) */
  --intel-soft: #f6f4ff;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.05), 0 8px 28px rgba(20, 30, 50, 0.08);
  --shadow-lift: 0 12px 40px rgba(20, 30, 50, 0.25);

  --gutter: 16px;
  --panel-left: 300px;
  --panel-right: 320px;
  --header-h: 64px; /* brand card height incl. gutter */
  --legend-h: 210px; /* reserved below the left panel */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
/* Page, typography and shared controls (cards, buttons, segmented controls, switches, sliders). */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }
body[data-tool="survivor"] #scene canvas,
body[data-tool="crowd"] #scene canvas { cursor: copy; }
body[data-tool="erase"] #scene canvas,
body[data-tool="fail"] #scene canvas { cursor: crosshair; }

.hud { position: fixed; inset: 0; pointer-events: none; font-size: 13px; }
.hud > * { pointer-events: auto; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

h3 { display: flex; gap: 6px; align-items: baseline; margin-bottom: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
h3 em { font-style: normal; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--faint); }
h4 { margin: 14px 0 6px; font-size: 12px; font-weight: 600; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel);
  color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.icon { width: 36px; padding: 0; justify-content: center; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }

/* Segmented control */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-strong); }
.seg button { height: 30px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(20, 30, 50, 0.12); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

/* Status chip */
.chip { display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.chip.danger { background: var(--danger-soft); color: var(--danger); animation: pulse 1.6s ease-in-out infinite; }
.chip.danger.hit { background: var(--water-soft); color: #2f6fb0; animation: none; }
@keyframes pulse { 50% { opacity: 0.6; } }

/* Toggle switch: <label class="switch"><input type="checkbox"><i></i><div><b/><span/></div></label> */
.switch { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; cursor: pointer; }
.switch input { display: none; }
.switch > i { position: relative; flex: none; width: 34px; height: 20px; margin-top: 1px; border-radius: 999px; background: #d6dbe3; transition: background 0.15s; }
.switch > i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); transition: transform 0.15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch b { display: block; font-weight: 600; }
.switch span { display: block; font-size: 12px; color: var(--muted); }
.switch.disabled { opacity: 0.45; cursor: not-allowed; }

/* Checkbox row */
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; cursor: pointer; }
.check input { margin: 0; accent-color: var(--accent); }

/* Sliders and steppers */
.slider { display: grid; grid-template-columns: 110px 1fr 46px; gap: 8px; align-items: center; padding: 3px 0; font-size: 12px; }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.stepper { display: flex; gap: 6px; align-items: center; padding: 4px 0; }
.stepper span { flex: 1; }
.stepper button { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 16px; line-height: 1; cursor: pointer; }
.stepper button:hover { background: var(--surface); }
.stepper output { width: 28px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Disclosure */
details summary { list-style: none; color: var(--muted); font-weight: 600; cursor: pointer; }
details summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }
details[open] summary { margin-bottom: 8px; }

/* Coloured dot (drone colour) */
.dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--faint); }

[hidden] { display: none !important; }

/* Startup failure message */
.startup-error { position: fixed; top: 50%; left: 50%; z-index: 100; max-width: 420px; padding: 20px 24px; transform: translate(-50%, -50%); }
.startup-error h2 { margin-bottom: 8px; font-size: 16px; }
.startup-error p { color: var(--muted); }

/* Full-screen drone view / challenge: only overlays marked .immersive-keep stay. */
.hud.immersive > :not(.immersive-keep):not(.toast) { display: none !important; }
/* HTML labels drawn over the 3D scene (CSS2DRenderer). */
.label-layer { position: absolute; inset: 0; pointer-events: none; }
.street-label {
  color: #5d6678; font: 600 11px/1 Inter, system-ui, sans-serif; letter-spacing: 0.01em; white-space: nowrap;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff; pointer-events: none;
}
.crowd-label {
  padding: 3px 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.92); box-shadow: 0 1px 4px rgba(20, 30, 50, 0.15);
  font: 600 11px/1.2 Inter, system-ui, sans-serif; white-space: nowrap; pointer-events: none;
}
.crowd-label.intel { color: var(--intel); }
.area-menu { position: absolute; top: calc(100% + 8px); left: 0; z-index: 20; width: 100%; padding: 12px 14px; }
.area-list { display: flex; flex-direction: column; gap: 2px; }
.area-list button { padding: 7px 8px; border: 0; border-radius: 8px; background: none; text-align: left; font-weight: 600; cursor: pointer; }
.area-list button:hover { background: var(--surface); }
.area-list button.on { background: var(--accent-soft); color: var(--accent); }
.brand { position: absolute; top: var(--gutter); left: var(--gutter); width: var(--panel-left); display: flex; gap: 10px; align-items: center; padding: 10px 14px 10px 10px; z-index: 10; }
.brand-logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; }
.brand h1 { font-size: 14px; font-weight: 700; }
.brand-area { padding: 0; border: 0; background: none; color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer; }
.feed-section { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.feed { display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; padding: 0 6px; overflow-y: auto; }
.feed-row { display: flex; gap: 10px; padding: 7px 4px; border-radius: 8px; animation: feed-in 0.3s; }
.feed-row .dot { margin-top: 4px; }
.feed-row p { font-size: 12.5px; line-height: 1.35; }
.feed-row time { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.feed-survivor { background: #fff1f3; }
.feed-failure { background: var(--danger-soft); }
.feed-impact { background: var(--water-soft); }
.feed-complete { background: #e9f8f2; }
.feed-truck .dot { background: var(--warn); }
@keyframes feed-in { from { opacity: 0; transform: translateY(-4px); } }
.fleet { display: flex; flex-direction: column; gap: 2px; }
.fleet-row { display: grid; grid-template-columns: 10px 28px 1fr 46px; gap: 8px; align-items: center; padding: 6px 8px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.fleet-row:hover { background: var(--surface); }
.fleet-row.following { background: var(--accent-soft); }
.fleet-row.down { opacity: 0.5; }
.fleet-status { overflow: hidden; color: var(--muted); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.fleet-battery { height: 6px; overflow: hidden; border-radius: 99px; background: var(--track); }
.fleet-battery i { display: block; height: 100%; background: var(--ok); }
.fleet-row.low .fleet-battery i { background: var(--warn); }
.fleet-row.down .fleet-battery i { background: var(--faint); }
.data-sources ul { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.data-sources a { color: var(--text); font-size: 12px; font-weight: 600; text-decoration: none; }
.data-sources a:hover { color: var(--accent); }
.data-sources small { display: block; color: var(--muted); font-size: 11px; }
.history-score { display: flex; gap: 6px; align-items: baseline; margin: 4px 0; }
.history-score b { color: var(--accent); font-size: 26px; line-height: 1; }
.history-score b.human { color: #e8890c; }
.history-score span { color: var(--muted); font-size: 11px; }
.history-score i { margin: 0 4px; color: var(--muted); font-size: 11px; font-style: normal; }
.history-note { margin: 4px 0 8px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.history-areas, .history-recent { display: flex; flex-direction: column; gap: 5px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 12px; }
.history-areas li { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; }
.history-areas small, .history-recent small { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.history-recent li { display: flex; flex-direction: column; }
.legend { position: absolute; left: var(--gutter); bottom: var(--gutter); width: var(--panel-left); padding: 12px 14px; }
.legend-keys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; color: var(--muted); font-size: 12px; }
.legend-keys span { display: flex; gap: 7px; align-items: center; }
.legend-swatch { flex: none; width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.06); background: var(--swatch); }
.legend-views { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
/* Swatch colours come from palette.ts (applied as CSS variables at startup). */
.swatch-unsearched { --swatch: var(--map-unsearched); }
.swatch-searched { --swatch: var(--map-searched); }
.swatch-frontier { --swatch: var(--map-frontier); }
.swatch-tall { --swatch: var(--map-tall); }
.swatch-survivor { --swatch: var(--map-survivor); border-radius: 50%; }
.swatch-truck { --swatch: var(--map-truck); }
.mobile-tabs { display: none; }
.place { position: absolute; z-index: 5; width: 248px; padding: 12px 14px; }
.place-pin { margin-bottom: 4px; color: var(--danger); }
.place h4 { margin: 0; font-size: 14px; }
.place small { color: var(--muted); font-variant-numeric: tabular-nums; }
.place-links { display: flex; gap: 6px; margin-top: 10px; }
.place-close { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; color: var(--faint); cursor: pointer; }
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(238, 241, 245, 0.55); backdrop-filter: blur(3px); }
.modal .card { width: 440px; padding: 24px; }
.modal h2 { margin-bottom: 16px; font-size: 20px; }
.results-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.results-grid div { padding: 12px; border-radius: var(--radius-sm); background: var(--surface); }
.results-grid b { display: block; font-size: 20px; }
.results-grid span { color: var(--muted); font-size: 11px; font-weight: 600; }
.results-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.setup-intel:empty { display: none; }
.setup-intel > section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel {
  position: absolute; display: flex; flex-direction: column;
  transition: transform 0.35s var(--ease), opacity 0.35s var(--ease);
}
.panel-body { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; flex: 1; border-radius: inherit; }
.panel-body > section, .panel-body > details { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-body > section:last-child, .panel-body > details:last-child { border-bottom: 0; }

.panel-left { top: calc(var(--gutter) + var(--header-h)); left: var(--gutter); width: var(--panel-left); max-height: calc(100vh - var(--header-h) - var(--legend-h) - var(--gutter)); }
.panel-right { top: var(--gutter); right: var(--gutter); bottom: var(--gutter); width: var(--panel-right); }

/* Slide out of view; the edge tab brings it back. */
.panel-left.collapsed { transform: translateX(calc(-100% - var(--gutter) - 8px)); opacity: 0; pointer-events: none; }
.panel-right.collapsed { transform: translateX(calc(100% + var(--gutter) + 8px)); opacity: 0; pointer-events: none; }

.panel-collapse {
  position: absolute; top: 18px; z-index: 2; display: grid; place-items: center; width: 26px; height: 26px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--muted);
  box-shadow: var(--shadow); cursor: pointer;
}
.panel-collapse:hover { color: var(--accent); }
/* A round handle on the panel's inner edge (toward the map). */
.panel-left .panel-collapse { right: -13px; }
.panel-right .panel-collapse { left: -13px; }

.panel-tab {
  position: absolute; display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
  color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer;
  opacity: 0; pointer-events: none; transition: opacity 0.25s var(--ease), transform 0.35s var(--ease);
}
.panel-tab:hover { color: var(--text); }
.panel-tab.shown { opacity: 1; pointer-events: auto; transform: none; }
.panel-tab-left { top: calc(var(--gutter) + var(--header-h)); left: var(--gutter); transform: translateX(-12px); }
.panel-tab-right { top: var(--gutter); right: var(--gutter); flex-direction: row-reverse; transform: translateX(12px); }

@media (max-width: 1100px) {
  :root { --panel-left: 260px; --panel-right: 280px; }
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); }
.stat.wide { grid-column: span 2; }
.stat > span { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
.stat b { display: block; margin-top: 2px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat b small { margin-left: 3px; color: var(--faint); font-size: 13px; }
.stat .bar { height: 6px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: var(--track); }
.stat .bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.3s; }
.stat-lost b { color: var(--danger); }
.toast { position: absolute; top: 72px; left: 50%; z-index: 40; padding: 8px 14px; border-radius: 999px; background: var(--text); color: #fff; font-size: 12px; font-weight: 600; opacity: 0; transform: translate(-50%, -8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toolbar { position: absolute; bottom: var(--gutter); left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 6px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 74px; padding: 8px 4px 6px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; }
.tool:hover { background: var(--surface); color: var(--text); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.tool[data-tool="fail"].active { background: var(--danger-soft); color: var(--danger); }
.tool-hint {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%); max-width: 520px; padding: 6px 12px;
  border-radius: 999px; background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(6px);
  color: var(--muted); font-size: 12px; text-align: center; pointer-events: none;
}
@media (max-width: 1100px) {
  .tool { width: 60px; }
  .tool span { font-size: 10px; }
}
.transport { position: absolute; top: var(--gutter); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; padding: 6px; z-index: 10; }
.transport-play { min-width: 150px; justify-content: center; }
.transport-play.is-running { background: var(--panel); border-color: var(--line); color: var(--text); }
.transport-cam { color: var(--muted); }
.transport-cam.on { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.transport-clock { padding: 0 8px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
/* Phones: map first; the side panels become bottom sheets chosen from the tab bar. */
@media (max-width: 760px) {
  .brand { top: calc(8px + env(safe-area-inset-top)); left: 8px; right: 8px; width: auto; padding: 8px 10px 8px 8px; }
  .brand h1 { font-size: 13px; }

  .transport { top: calc(64px + env(safe-area-inset-top)); left: 8px; right: 8px; transform: none; justify-content: space-between; padding: 4px; }
  .transport-play { flex: 1; min-width: 0; }
  .transport .seg button { padding: 0 7px; }
  .transport-clock { padding: 0 4px; }
  .transport-cam { width: 36px; padding: 0; justify-content: center; }
  .transport-cam span { display: none; }
  .transport-tsunami { position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); }

  .panel-left, .panel-right {
    display: none; top: auto; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom));
    width: auto; max-height: 62vh; border-radius: 16px 16px 0 0; z-index: 15;
    transform: none !important; opacity: 1 !important; pointer-events: auto !important;
    animation: sheet-up 0.22s ease-out;
  }
  body[data-sheet="setup"] .panel-left,
  body[data-sheet="live"] .panel-right { display: flex; }
  .panel-collapse, .panel-tab { display: none !important; }
  .feed-section { min-height: 200px; }

  .legend, .tool-hint { display: none; }
  .toolbar { bottom: calc(64px + env(safe-area-inset-bottom)); left: 8px; right: 8px; transform: none; justify-content: space-between; padding: 4px; }
  .tool { flex: 1; width: auto; padding: 6px 2px; font-size: 10px; }
  body[data-sheet="setup"] .toolbar,
  body[data-sheet="live"] .toolbar { display: none; }

  .mobile-tabs {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 16; display: flex; gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel);
  }
  .mobile-tabs button { flex: 1; height: 40px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-weight: 700; }
  .mobile-tabs button.on { background: var(--accent-soft); color: var(--accent); }

  .dronecam { top: calc(112px + env(safe-area-inset-top)); right: 8px; width: 46vw; height: 28vw; min-height: 110px; }
  .dronecam [data-telemetry], .dronecam-target { display: none; }
  .place { left: 8px !important; right: 8px; top: auto !important; bottom: calc(130px + env(safe-area-inset-bottom)); width: auto; }
  .modal .card { width: calc(100vw - 32px); padding: 18px; }
  .results-grid { grid-template-columns: repeat(2, 1fr); }
  .area-menu { left: 0; right: 0; }
  .street-label { font-size: 10px; }
}
@keyframes sheet-up { from { transform: translateY(24px); } }
.challenge { position: fixed; inset: 0; z-index: 9; pointer-events: none; color: #fff; }
.challenge-board { position: absolute; top: 14px; left: 50%; display: flex; gap: 6px; transform: translateX(-50%); }
.challenge-side, .challenge-clock { display: flex; flex-direction: column; align-items: center; min-width: 110px; padding: 8px 14px; border-radius: 12px; background: rgba(15, 20, 30, 0.72); backdrop-filter: blur(6px); }
.challenge-side span { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; }
.challenge-side b { font-size: 30px; line-height: 1.1; }
.challenge-side small, .challenge-clock small { font-size: 11px; opacity: 0.75; }
.challenge-side.human b { color: #ffb84d; }
.challenge-side.ai b { color: #6ea8ff; }
.challenge-clock b { font: 700 26px/1.3 ui-monospace, "SF Mono", Menlo, monospace; }
.challenge.hurry .challenge-clock b { color: #ff6b6b; animation: pulse 1s infinite; }
.challenge-help { position: absolute; bottom: 60px; left: 50%; padding: 6px 12px; border-radius: 8px; background: rgba(15, 20, 30, 0.6); font-size: 12px; white-space: nowrap; transform: translateX(-50%); }
.challenge-help kbd { display: inline-block; min-width: 18px; margin: 0 1px; padding: 1px 5px; border: 1px solid rgba(255, 255, 255, 0.4); border-radius: 4px; font: 600 11px ui-monospace, monospace; text-align: center; }
.challenge-count { position: absolute; top: 50%; left: 50%; font-size: 120px; font-weight: 800; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.5); transform: translate(-50%, -50%); }
.challenge-pad { display: none; position: absolute; right: 18px; bottom: 90px; grid-template: repeat(3, 56px) / repeat(3, 56px); pointer-events: auto; }
.challenge-pad button { border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 12px; background: rgba(15, 20, 30, 0.55); color: #fff; font-size: 22px; touch-action: none; }
.challenge-pad [data-key="w"] { grid-area: 1 / 2; }
.challenge-pad [data-key="a"] { grid-area: 2 / 1; }
.challenge-pad [data-key="s"] { grid-area: 3 / 2; }
.challenge-pad [data-key="d"] { grid-area: 2 / 3; }
@media (pointer: coarse) {
  .challenge-pad { display: grid; }
  .challenge-help { display: none; }
}

.challenge-result { position: fixed; top: 50%; left: 50%; z-index: 20; width: min(420px, calc(100vw - 32px)); padding: 22px; transform: translate(-50%, -50%); text-align: center; }
.challenge-result h2 { margin: 0 0 12px; font-size: 22px; }
.challenge-result table { width: 100%; border-collapse: collapse; font-size: 14px; }
.challenge-result th, .challenge-result td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
.challenge-result td:first-child { color: var(--muted); text-align: left; }
.challenge-result p { margin: 14px 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.challenge-actions { display: flex; gap: 8px; justify-content: center; }
.intel-time { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.intel-time input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); font: inherit; }
.intel-shortcuts { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.intel-shortcuts button { padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; }
.intel-shortcuts button:hover { border-color: var(--intel); color: var(--intel); }
.intel-summary { margin: 8px 0 4px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.intel-hotspots { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.intel-hotspots li { padding: 7px 9px; border-radius: 8px; background: var(--intel-soft); }
.intel-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.intel-row span { color: var(--intel); font-weight: 700; white-space: nowrap; }
.intel-hotspots small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.intel-confidence { height: 3px; margin-top: 4px; overflow: hidden; border-radius: 99px; background: #e4def9; }
.intel-confidence i { display: block; height: 100%; background: var(--intel); }
.intel-links { display: flex; gap: 8px; margin-top: 3px; }
.intel-links a { color: var(--intel); font-size: 11px; text-decoration: none; }
.dronecam {
  --drone: var(--accent);
  position: absolute; top: 80px; right: calc(var(--panel-right) + 2 * var(--gutter)); z-index: 8;
  width: 360px; height: 225px; overflow: hidden;
  border: 2px solid var(--drone); border-radius: 12px; background: #1d2430; box-shadow: var(--shadow);
  color: #fff; font: 600 11px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.04em;
  cursor: grab; touch-action: none; user-select: none;
}
.dronecam.dragging { cursor: grabbing; box-shadow: var(--shadow-lift); }
.dronecam-view { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.dronecam.thermal .dronecam-view { filter: grayscale(1) contrast(1.6) brightness(0.9) sepia(1) hue-rotate(-50deg) saturate(4); }
.dronecam-lost { position: absolute; inset: 0; display: none; place-items: center; background: repeating-linear-gradient(0deg, #1d2430 0 2px, #2b3445 2px 4px); font-size: 16px; letter-spacing: 0.2em; }
.dronecam.lost .dronecam-lost { display: grid; }

.dronecam-top, .dronecam-bottom { position: absolute; left: 8px; right: 8px; display: flex; justify-content: space-between; align-items: center; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); }
.dronecam-top { top: 8px; }
.dronecam-bottom { bottom: 8px; }
.dronecam-badge { display: flex; gap: 5px; align-items: center; padding: 4px 7px; border-radius: 6px; background: rgba(0, 0, 0, 0.45); }
.dronecam-badge > i { width: 7px; height: 7px; border-radius: 50%; background: #ff4d4f; animation: pulse 1.2s infinite; }
.dronecam-badge b { color: var(--drone); filter: brightness(1.4); }
.dronecam-target { display: block; max-width: 55%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dronecam-target:empty { display: none; }
.dronecam-buttons { display: flex; gap: 4px; }
.dronecam-buttons button { padding: 4px 7px; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 6px; background: rgba(0, 0, 0, 0.5); color: #fff; font: inherit; cursor: pointer; }
.dronecam-buttons button.on { background: #e8590c; border-color: #e8590c; }

.dronecam-crosshair { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; border: 1.5px solid rgba(255, 255, 255, 0.8); border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.dronecam-crosshair::before, .dronecam-crosshair::after { content: ""; position: absolute; background: rgba(255, 255, 255, 0.8); }
.dronecam-crosshair::before { left: 50%; top: -8px; bottom: -8px; width: 1.5px; transform: translateX(-50%); }
.dronecam-crosshair::after { top: 50%; left: -8px; right: -8px; height: 1.5px; transform: translateY(-50%); }

.dronecam-views { display: flex; margin-right: 4px; }
.dronecam-views button { border-radius: 0; margin-left: -1px; }
.dronecam-views button:first-child { border-radius: 6px 0 0 6px; }
.dronecam-views button:last-child { border-radius: 0 6px 6px 0; }
.dronecam-views button.on { background: var(--drone); border-color: var(--drone); }
.dronecam:not(.full) [data-view="map"] { display: none; }
.dronecam:not(.full) .dronecam-views button:nth-child(2) { border-radius: 0 6px 6px 0; }

/* Full screen: a transparent HUD over the main view (the renderer draws the drone's view there). */
.dronecam.full { position: fixed; inset: 0 !important; width: auto; height: auto; border: 0; border-radius: 0; background: none; box-shadow: none; cursor: default; pointer-events: none; font-size: 13px; }
.dronecam.full .dronecam-view { display: none; }
.dronecam.full .dronecam-top, .dronecam.full .dronecam-bottom { left: 16px; right: 16px; }
.dronecam.full .dronecam-top { top: 16px; }
.dronecam.full .dronecam-bottom { bottom: 16px; }
.dronecam.full button { pointer-events: auto; padding: 7px 11px; }
.dronecam.full .dronecam-badge { padding: 6px 10px; }
.dronecam.full[data-mode="map"] .dronecam-crosshair, .dronecam.full[data-mode="chase"] .dronecam-crosshair { display: none; }
.dronecam.full::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.35); }
.dronecam.full[data-mode="map"]::after { display: none; }
.dronecam.full.thermal::before { content: ""; position: absolute; inset: 0; backdrop-filter: grayscale(1) contrast(1.6) brightness(0.9) sepia(1) hue-rotate(-50deg) saturate(4); pointer-events: none; }

/* Window mode: the buttons stay on one line; the target label gives way. */
.dronecam:not(.full) .dronecam-buttons button { padding: 4px 6px; white-space: nowrap; }
.dronecam:not(.full) .dronecam-target { max-width: 30%; }
.dronecam:not(.full) [data-action="thermal"] { font-size: 0; }
.dronecam:not(.full) [data-action="thermal"]::after { content: "IR"; font-size: 11px; }
