:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-raised: #1f232c;
  --border: #2c313c;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --button: #232833;
  --button-hover: #2d3340;
  --accent: #4ea1ff;
  --grid: rgba(255, 255, 255, 0.08);
  --gap: #22252c;
  --coverage: #2f5d8c;
  --cursor: #ffffff;
  --kind-person: #ff5c8a;
  --kind-animal: #5ed37a;
  --kind-sound: #f5b942;
  --kind-cow: #b98cff;
  --kind-other: #c9ced6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--button);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  min-height: 36px;
}
button { cursor: pointer; }
button:hover { background: var(--button-hover); }
button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #06111f; }
button.icon { min-width: 36px; padding: 6px; }
input[type="date"], input[type="time"] { color-scheme: dark; }

/* ---- Toolbar ---- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { margin: 0 8px 0 0; font-size: 16px; font-weight: 600; }
.cameras, .day-picker, .jump, .zoom, .pan, .languages { display: flex; gap: 4px; }
.languages { margin-left: auto; }
.languages button { min-width: 40px; padding: 6px 8px; font-size: 13px; }
.cameras button { text-transform: capitalize; }

/* ---- Page layout ---- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
  padding: 12px;
}
.watch { min-width: 0; }

/* ---- Videos ---- */
.stage { display: grid; gap: 8px; }
.stage[data-layout="dual"] { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stage:fullscreen { background: #000; align-content: center; padding: 8px; }
.view { margin: 0; min-width: 0; }
.screen {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}
.stage[data-layout="single"] .screen { max-height: 68vh; margin: 0 auto; }
.screen video { display: block; width: 100%; height: 100%; object-fit: contain; cursor: pointer; }
.message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  font-size: 16px;
  pointer-events: none;
}
figcaption {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 2px;
  color: var(--muted);
}
.camera-name { text-transform: capitalize; }
.clock { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }

/* ---- Playback controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 0 10px;
}
.controls .play { min-width: 60px; font-size: 18px; }
.toast { margin-left: auto; color: var(--muted); }

/* ---- Timeline ---- */
.timeline { padding: 8px; background: var(--panel); border-radius: 6px; }
.timeline-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-left: auto; }
.kind { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.kind input { min-height: 0; margin: 0; }
.swatch { width: 12px; height: 12px; border-radius: 2px; background: var(--kind-color); }
[data-kind] { --kind-color: var(--kind-other); }
[data-kind="person"] { --kind-color: var(--kind-person); }
[data-kind="animal"] { --kind-color: var(--kind-animal); }
[data-kind="sound"] { --kind-color: var(--kind-sound); }
[data-kind="cow"] { --kind-color: var(--kind-cow); }
.sound-filter-field { display: inline-flex; align-items: center; gap: 3px; }
.sound-filter-field input { width: 4.2em; min-height: 0; padding: 1px 4px; }
.timeline-track {
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: pan-y;
}
.timeline-track canvas { display: block; width: 100%; height: 52px; cursor: pointer; }
.cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1px;
  width: 2px;
  background: var(--cursor);
  pointer-events: none;
}
.hover-card {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 120px;
  padding: 4px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.hover-card img { width: 200px; aspect-ratio: 16 / 9; border-radius: 4px; background: #000; }

/* ---- POI list ---- */
.events {
  position: sticky;
  top: 64px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  padding: 8px;
  background: var(--panel);
  border-radius: 6px;
  align-self: start;
}
.events h2 { margin: 0 0 6px; font-size: 15px; }
.poi-empty { padding: 8px 4px; color: var(--muted); }
.poi-list { position: relative; flex: 1; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.poi {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  text-align: left;
  background: transparent;
  border: 0;
  border-left: 3px solid var(--kind-color);
  border-radius: 0;
}
.current .poi { background: var(--button-hover); }
.poi-time, .poi-score { color: var(--muted); font-variant-numeric: tabular-nums; }
.poi-kind { color: var(--kind-color); }
.poi-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Help overlay ---- */
.help {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
.help-panel {
  width: calc(100% - 32px);
  max-width: 440px;
  padding: 16px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.help-panel h2 { margin-top: 0; font-size: 16px; }
.help-panel p { color: var(--muted); }
.help-panel dl div { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; }
.help-panel dt { display: flex; gap: 4px; }
.help-panel dd { margin: 0; color: var(--muted); }
kbd {
  padding: 0 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 12px ui-monospace, monospace;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---- Window-filling video where the fullscreen API is missing (e.g. a plain WebView) ---- */
body.window-fill { overflow: hidden; }
body.window-fill .watch {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: #000;
}
body.window-fill .stage { flex: 1; min-height: 0; grid-auto-rows: minmax(0, 1fr); }
body.window-fill .view { display: flex; flex-direction: column; min-height: 0; }
body.window-fill .screen { flex: 1; aspect-ratio: auto; max-height: none; min-height: 0; width: 100%; }
body.window-fill .timeline, body.window-fill figcaption { display: none; }
body.window-fill .controls { padding: 4px 0 0; }

/* ---- Touch screens: finger-sized targets ---- */
@media (pointer: coarse) {
  button, select, input { min-height: 44px; }
  button.icon { min-width: 44px; }
  .kind { min-height: 44px; }
  .kind input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; }
  .sound-filter-field input { min-height: 40px; }
  .poi { min-height: 44px; }
}

/* ---- Phones and narrow windows ---- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .events { position: static; max-height: 45vh; }
}
@media (max-width: 600px) {
  .brand { display: none; }
  .layout { padding: 6px; gap: 8px; }
  .toolbar { position: static; padding: 6px; gap: 6px; }
  .legend { margin-left: 0; }
  /* Two thumb rows under the video: events, ±15 s and a big play button; then ±1 min, speed,
     sound and full screen. */
  .controls { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .controls button { padding: 6px 4px; }
  .controls > * { order: 20; }
  [data-action="previousPoi"] { order: 1; }
  [data-action="back15s"] { order: 2; }
  .controls .play { order: 3; min-width: 0; font-size: 22px; }
  [data-action="forward15s"] { order: 4; }
  [data-action="nextPoi"] { order: 5; }
  [data-action="back1m"] { order: 6; }
  .controls .speed { order: 7; }
  .controls .speed select { width: 100%; padding: 6px 2px; }
  #mute-button { order: 8; }
  #fullscreen-button { order: 9; }
  [data-action="forward1m"] { order: 10; }
  .controls .toast { order: 11; grid-column: 1 / -1; margin: 0; text-align: center; }
  .controls button, .controls select { min-height: 48px; }
}

/* ---- Phones held sideways: the video fills the screen height, the rest scrolls below ---- */
@media (orientation: landscape) and (max-height: 500px) {
  .toolbar { position: static; }
  .brand { display: none; }
  .layout { padding: 4px 6px; }
  .stage[data-layout="single"] .screen { max-height: calc(100vh - 8px); max-height: calc(100dvh - 8px); }
  .events { max-height: 90vh; }
}
