:root {
  --ink: #eef3f6;
  --ink-dim: #a9b8c2;
  --glass: rgba(14, 24, 32, 0.72);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #ffb454;
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; overflow: hidden; background: #9fc4e0; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: grab; touch-action: none; }
#view.dragging { cursor: grabbing; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

#panel {
  position: fixed; top: 16px; left: 16px; width: 248px;
  max-height: calc(100vh - 64px); overflow-y: auto;
  padding: 16px;
}

h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: 0.01em; }
/* city switch: the current city is the title; the others are small buttons below it */
#city-title button {
  padding: 0; border: 0; background: transparent; cursor: default;
  font-size: 20px; font-weight: 650; letter-spacing: 0.01em; color: var(--ink);
}
#city-title button:hover { background: transparent; }
#cities { display: flex; flex-wrap: wrap; gap: 4px; margin: -4px 0 12px; }
#cities button { padding: 1px 7px; font-size: 12px; font-weight: 550; color: var(--ink-dim); }
#cities button:hover { color: var(--ink); }
.sub { margin: 2px 0 12px; color: var(--ink-dim); font-size: 12px; }

#readout { margin: 0 0 12px; padding: 10px 0; border-block: 1px solid var(--line); display: grid; gap: 3px; }
#readout div { display: flex; justify-content: space-between; gap: 8px; }
dt { color: var(--ink-dim); }
dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.field { display: block; margin: 12px 0 5px; color: var(--ink-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }

select, button {
  font: inherit; color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line); border-radius: 6px;
}
select { width: 100%; padding: 6px 8px; }
select option { color: #111; }
button { padding: 6px 10px; cursor: pointer; }
button:hover, select:hover { background: rgba(255, 255, 255, 0.16); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#bookmarks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#bookmarks button {
  width: 100%; text-align: left; border-color: transparent; background: transparent;
  display: flex; gap: 8px; align-items: baseline; padding: 4px 6px;
}
#bookmarks button:hover { background: rgba(255, 255, 255, 0.12); }
#bookmarks .n { color: var(--accent); font-variant-numeric: tabular-nums; width: 1ch; }

#status { margin: 12px 0 10px; min-height: 1.4em; color: var(--ink-dim); font-size: 12px; overflow-wrap: anywhere; }
#status.warn { color: var(--accent); }
#help-btn { width: 100%; }

kbd {
  display: inline-block; min-width: 1.6em; padding: 0 5px; margin: 0 1px;
  font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center;
  color: var(--ink); background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
}

#help {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px)); padding: 20px 22px;
}
#help[hidden] { display: none; }
#help h2 { margin: 0 0 10px; font-size: 16px; }
#help table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
#help td { padding: 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
#help td:first-child { white-space: nowrap; padding-right: 14px; }
#help td:last-child { color: var(--ink-dim); }
#help-close { width: 100%; padding: 8px; background: var(--accent); color: #1c1305; border: 0; font-weight: 600; }
#help-close:hover { background: #ffc477; }

#attribution {
  position: fixed; right: 0; bottom: 0; max-width: calc(100vw - 290px);
  padding: 3px 8px; font-size: 11px; color: #1b2a33;
  background: rgba(255, 255, 255, 0.72); border-top-left-radius: 6px;
}

#fps {
  position: fixed; top: 16px; right: 16px; padding: 3px 8px;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink);
  background: var(--glass); border-radius: 6px; font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  #panel { width: 200px; padding: 12px; }
  #attribution { max-width: 100vw; }
}

/* ---- flight speed multiplier ---- */
#mult { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; }
#mult button { padding: 3px 0; font-size: 11px; font-variant-numeric: tabular-nums; }
#mult button.on { background: var(--accent); color: #1c1305; border-color: transparent; font-weight: 650; }

/* ---- traffic sliders ---- */
.slider { display: flex; justify-content: space-between; margin-top: 4px; color: var(--ink-dim); }
.slider output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; margin: 2px 0 4px; accent-color: var(--accent); }
.note { margin: 2px 0 0; color: var(--ink-dim); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ---- collapsible lists ---- */
details { margin-top: 12px; }
details summary { cursor: pointer; margin: 0 0 5px; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }

#cameras { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#cameras button {
  width: 100%; text-align: left; border-color: transparent; background: transparent;
  display: flex; gap: 8px; align-items: baseline; padding: 4px 6px;
}
#cameras button:hover { background: rgba(255, 255, 255, 0.12); }
#cameras .n { color: #ff6b6b; font-variant-numeric: tabular-nums; width: 2ch; }
#cameras button.on { background: rgba(255, 77, 77, 0.18); }

/* ---- camera overlay windows ---- */
#cctv-layer { position: fixed; inset: 0; pointer-events: none; }
.cctv {
  position: absolute; display: flex; flex-direction: column; pointer-events: auto;
  min-width: 200px; min-height: 140px; resize: both; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.cctv header {
  flex: none; height: 26px; display: flex; align-items: center; gap: 7px; padding: 0 4px 0 9px;
  background: rgba(10, 14, 18, 0.92); cursor: move; user-select: none; font-size: 12px;
}
.cctv header .name { color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.cctv header .x { padding: 0 7px; line-height: 18px; font-size: 16px; border: 0; background: transparent; }
.cctv header .x:hover { background: rgba(255, 255, 255, 0.15); }
.cctv .rec { width: 8px; height: 8px; border-radius: 50%; background: #ff3b3b; animation: rec 1.2s steps(2, start) infinite; }
@keyframes rec { to { visibility: hidden; } }
/* the 3D view is painted into the canvas underneath this transparent screen */
.cctv .screen {
  position: relative; flex: 1; cursor: default;
  backdrop-filter: saturate(0.55) contrast(1.12) brightness(1.04);
  -webkit-backdrop-filter: saturate(0.55) contrast(1.12) brightness(1.04);
  background:
    repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.13) 2px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}
.osd {
  position: absolute; font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: #fff;
  text-shadow: 0 0 2px #000, 0 0 4px #000; letter-spacing: 0.04em; white-space: nowrap;
}
.osd.tl { top: 7px; left: 8px; max-width: calc(100% - 160px); overflow: hidden; text-overflow: ellipsis; }
.osd.tr { top: 7px; right: 8px; }
.osd.bl { bottom: 7px; left: 8px; }
.osd.br { bottom: 7px; right: 8px; color: #ff6b6b; }

/* drone camera feed: cleaner image, crosshair */
.cctv.drone header b { color: #7fd6ff; }
.cctv.drone .screen {
  backdrop-filter: saturate(0.9) contrast(1.05);
  -webkit-backdrop-filter: saturate(0.9) contrast(1.05);
  background: radial-gradient(ellipse at center, transparent 65%, rgba(0, 0, 0, 0.35) 100%);
}
.cctv.drone .osd { color: #bfeaff; }
.cctv.drone .osd.bl2 { bottom: 22px; left: 8px; }
.crosshair {
  position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; transform: translate(-50%, -50%);
  border: 1px solid rgba(191, 234, 255, 0.7); border-radius: 50%; pointer-events: none;
}
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: rgba(191, 234, 255, 0.7); }
.crosshair::before { left: 50%; top: -9px; bottom: -9px; width: 1px; }
.crosshair::after { top: 50%; left: -9px; right: -9px; height: 1px; }

#drone-cams { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }

#drone-cams .wide { grid-column: 1 / -1; }
.cctv header .follow { padding: 0 8px; line-height: 18px; font-size: 11px; }
.cctv header .follow.on { background: #7fd6ff; color: #0b1a22; border-color: transparent; font-weight: 650; }
#chase {
  position: fixed; bottom: 34px; left: calc(50% + 124px); transform: translateX(-50%); padding: 7px 14px;
  display: flex; gap: 8px; align-items: baseline; white-space: nowrap; font-size: 12px;
}
#chase[hidden] { display: none; }
#chase b { color: #7fd6ff; }
#chase .kind { color: var(--ink-dim); }
#chase .hint { color: var(--ink-dim); font-size: 11px; margin-left: 6px; }
@media (max-width: 900px) { #chase .hint { display: none; } }

/* live webcams: the stream fills the screen; the 3D twin uses the normal CCTV screen */
.cctv.webcam header b { color: #fff; background: #d0202c; padding: 0 5px; border-radius: 3px; font-size: 11px; }
.cctv.webcam .modes { display: flex; gap: 2px; }
.cctv.webcam .mode { padding: 0 7px; line-height: 18px; font-size: 11px; }
.cctv.webcam .mode.on { background: var(--accent); color: #1c1305; border-color: transparent; font-weight: 650; }
.cctv.webcam .stream { display: none; position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.cctv.webcam.live .stream { display: block; }
.cctv.webcam.live .screen { backdrop-filter: none; -webkit-backdrop-filter: none; background: #000; }
.cctv.webcam.live .osd:not(.src) { display: none; }
.cctv.webcam .osd.src { top: auto; bottom: 7px; right: 8px; left: auto; color: #fff; text-decoration: none; font-size: 10px; z-index: 1; }
.cctv.webcam.live .osd.src { bottom: auto; top: -999px; } /* the YouTube player shows its own branding */
.cctv.webcam:not(.live) .osd.br { display: none; }
#webcams { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#webcams button {
  width: 100%; text-align: left; border-color: transparent; background: transparent;
  display: flex; gap: 8px; align-items: baseline; padding: 4px 6px;
}
#webcams button:hover { background: rgba(255, 255, 255, 0.12); }
#webcams .n { color: #fff; background: #d0202c; border-radius: 3px; font-size: 9px; font-weight: 700; padding: 0 4px; }
#webcams button.on { background: rgba(255, 77, 77, 0.18); }

/* image webcams (operator embed: still image linked to the live page) */
.cctv.webcam .stream.still { display: none; position: absolute; inset: 0; background: #000; }
.cctv.webcam.live .stream.still { display: flex; align-items: center; justify-content: center; }
.cctv.webcam .stream.still img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cctv.webcam.live .osd.src.always { top: auto; bottom: 7px; }
