:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b100d;
  color: #f3f7f4;
  --panel: #131c17;
  --line: #2a3a31;
  --muted: #9aada1;
  --accent: #72e59d;
  --accent-dark: #183d26;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top right, #1a2d21 0, #0b100d 36rem); }
button { font: inherit; }
/* Keep playback announcements accessible without an extra permanent status row. */
.visually-hidden, #playback-state:not(.error) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

header, main, footer { width: min(1100px, calc(100% - 32px)); margin-inline: auto; }
header { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 18px 0; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 5vw, 3.2rem); letter-spacing: -0.045em; line-height: 1; }
h2 { font-size: clamp(1.25rem, 3vw, 1.75rem); letter-spacing: -0.025em; }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .15em; margin-bottom: 8px; }
.subtitle, .count, footer { color: var(--muted); }
.subtitle { margin-top: 10px; }

button { border: 1px solid #4c6a58; border-radius: 999px; color: #eafff1; background: #17261d; padding: 10px 16px; cursor: pointer; }
button:hover, button:focus-visible { border-color: var(--accent); background: var(--accent-dark); outline: none; }
button.quiet { background: transparent; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.page-link { border: 1px solid #4c6a58; border-radius: 999px; color: #eafff1; background: #17261d; padding: 10px 16px; text-decoration: none; }
.page-link:hover, .page-link:focus-visible { border-color: var(--accent); background: var(--accent-dark); outline: none; }

.player-panel { border: 1px solid var(--line); border-radius: 14px; padding: 8px; background: rgba(19, 28, 23, .92); box-shadow: 0 24px 70px #0008; margin-bottom: 12px; }
.player-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; gap: 6px 12px; margin-bottom: 6px; }
.player-clip { display: flex; align-items: center; min-width: 0; gap: 8px; }
#player-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; line-height: 1.25; }
.clip-navigation { display: flex; flex: 0 0 auto; gap: 4px; }
.player-heading button { padding: 6px 10px; font-size: .88rem; line-height: 1.25; white-space: nowrap; }
.clip-navigation button { padding-inline: 8px; }
.player-modes { display: flex; gap: 6px; }
.player-modes button[aria-pressed="true"], .clip-navigation button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-dark); }
.player-modes button:disabled, .clip-navigation button:disabled { opacity: .4; cursor: default; }
.motion-note { color: var(--muted); font-size: .85rem; line-height: 1.4; margin-bottom: 6px; }
.playback-status { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .8rem; line-height: 1.4; white-space: nowrap; }
#playback-state.error { position: absolute; top: 100%; right: 0; z-index: 2; max-width: 80vw; padding: 6px 10px; color: #ffb0b0; background: var(--panel); border: 1px solid #ffb0b0; border-radius: 8px; white-space: normal; }
#playback-time { min-width: 84px; font-variant-numeric: tabular-nums; }
#playback-frame { min-width: 222px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.records-panel { min-height: 0; }
body.player-open { height: 100dvh; overflow: hidden; }
body.player-open > header, body.player-open > footer { display: none; }
body.player-open main { width: calc(100% - 16px); height: 100dvh; display: flex; flex-direction: column; overflow: hidden; padding-top: 4px; }
body.player-open .player-panel { flex: 0 0 auto; margin-bottom: 6px; }
/* Reserve the compact toolbar + archive heading + three typical evidence rows.
   The frame depends ONLY on viewport dimensions, never metadata or clip content. */
body.player-open .video-frame { width: min(100%, calc(60dvh * 8 / 3), calc(max(160px, 100dvh - 386px) * 8 / 3)); }
body.player-open .records-panel { flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding-bottom: 8px; }
.video-frame { position: relative; width: min(100%, calc(70vh * 8 / 3)); aspect-ratio: 8 / 3; margin-inline: auto; border-radius: 14px; overflow: hidden; background: #000; }
#video-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.overlay-status { position: absolute; left: 8px; top: 6px; max-width: calc(100% - 16px); padding: 2px 5px; background: #07120ebd; color: #e0ede4; font-size: .7rem; line-height: 1.25; pointer-events: none; border-radius: 4px; }
.overlay-status:empty { display: none; }
.codec-warning { position: absolute; inset: 30% 12px auto; margin: 0; padding: 8px 12px; background: #17241fee; color: #ffe1b4; font-size: clamp(.66rem, 1.4vw, .95rem); line-height: 1.3; text-align: center; pointer-events: none; }
.codec-warning[hidden] { display: none; }
.video-frame:fullscreen { width: 100vw !important; height: 100vh; aspect-ratio: auto; border-radius: 0; margin: 0; }
video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }

.archive-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 2px 6px; border-bottom: 1px solid var(--line); }
.archive-heading h2 { font-size: 1.1rem; line-height: 1.25; }
.archive-detector { margin-left: 8px; color: var(--muted); font-size: .8rem; font-weight: 500; letter-spacing: normal; }
.archive-heading > h2, .archive-heading > .count { flex: 0 0 auto; white-space: nowrap; }
.day-nav { display: flex; flex: 1 1 auto; min-width: 0; gap: 5px; overflow-x: auto; overflow-y: hidden; padding: 1px; scrollbar-width: none; }
.day-nav[hidden] { display: none; }
.day-nav::-webkit-scrollbar { display: none; }
.day-nav button { flex: 0 0 auto; padding: 3px 9px; font-size: .75rem; line-height: 1.2; white-space: nowrap; }
.day-nav button[aria-current="date"] { border-color: var(--accent); background: var(--accent-dark); }
.status { color: var(--muted); padding: 28px 2px; }
.status.error { color: #ff9f9f; }
.clips { list-style: none; margin: 0; padding: 0; }
.clip { display: grid; grid-template-columns: minmax(320px, 1fr) auto; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.clip > button { display: grid; grid-template-columns: 64px minmax(0, 1fr); width: 100%; align-items: center; gap: 16px; padding: 16px 2px; border: 0; border-radius: 0; background: transparent; text-align: left; }
.clip button:hover, .clip button:focus-visible { background: linear-gradient(90deg, transparent, #17251d, transparent); }
.play-icon { display: grid; place-items: center; width: 52px; height: 52px; padding-top: 2px; border-radius: 16px; background: var(--accent-dark); color: var(--accent); font-size: 1.3rem; line-height: 1; text-indent: -1px; }
.clip-title { font-weight: 750; font-size: 1.05rem; }
.clip-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); margin-top: 5px; font-size: .88rem; }
.clip-deterrent { color: #f0b45b; font-weight: 650; }
.clip-objects { display: block; color: var(--accent); margin-top: 7px; font-size: .9rem; font-weight: 650; }
.clip-objects.pending { color: var(--muted); font-weight: 500; }
.clip-objects.error { color: #ffb0b0; font-weight: 500; }
.clip-duration { color: #d8e7dd; font-variant-numeric: tabular-nums; }
.clip-number { color: var(--accent); margin-right: 9px; font-variant-numeric: tabular-nums; }
.clip-thumbnails { display: flex; align-items: center; gap: 10px; max-width: 640px; overflow-x: auto; padding: 8px 2px; scrollbar-width: thin; }
.clip-thumbnail { flex: 0 0 132px; padding: 5px; border-radius: 12px; background: #101914; text-align: left; }
.clip-thumbnail img { display: block; width: 120px; height: 76px; object-fit: cover; border-radius: 8px; background: #000; }
.clip-thumbnail span { display: block; overflow: hidden; margin: 5px 3px 1px; color: var(--muted); font-size: .72rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 50px 2px; color: var(--muted); text-align: center; }
footer { padding: 28px 0 42px; font-size: .82rem; text-align: center; }

.config-panel { max-width: 680px; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: rgba(19, 28, 23, .92); }
.config-panel fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.config-panel legend { padding: 0; font-size: 1.35rem; font-weight: 750; }
.config-help { margin: 8px 0 18px; color: var(--muted); line-height: 1.45; }
.sound-options { display: grid; gap: 10px; }
.sound-option { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: #101914; cursor: pointer; }
.sound-option:hover { border-color: #4c6a58; }
.sound-option input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.sound-option span { font-weight: 650; }
.sound-option > label:first-child { display: flex; min-width: 0; flex: 1 1 auto; align-items: center; gap: 12px; cursor: pointer; }
.sound-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sound-gain-control { display: flex; flex: 0 0 auto !important; align-items: center; gap: 5px !important; cursor: default !important; }
.sound-gain-control input { width: 68px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: #0b120e; font: inherit; text-align: right; }
.sound-gain-control span { color: var(--muted); font-weight: 650; }
.play-sound { flex: 0 0 auto; }
.speaker-status { margin: -8px 0 16px; color: var(--accent); }
.speaker-status.error { color: #ff9f9f; }
.config-actions { display: flex; align-items: center; gap: 14px; margin-top: 20px; }
#config-status { color: var(--muted); }
#config-status.error { color: #ff9f9f; }

@media (max-width: 560px) {
  body:not(.player-open) header { align-items: flex-start; flex-direction: column; gap: 14px; }
  .config-panel { padding: 16px; }
  .sound-option { flex-wrap: wrap; }
  .sound-option > label:first-child { flex-basis: 100%; }
}

/* Readable, denser records while the player is pinned. Photos stay on the right. */
body.player-open .clip { grid-template-columns: minmax(280px, 1fr) minmax(0, auto); gap: 8px; }
body.player-open .clip > button { grid-template-columns: 40px minmax(0, 1fr); gap: 10px; padding: 7px 2px; }
body.player-open .play-icon { width: 36px; height: 36px; border-radius: 11px; }
body.player-open .clip-title { font-size: 1rem; }
body.player-open .clip-meta { margin-top: 3px; gap: 3px 10px; font-size: .82rem; }
body.player-open .clip-objects { margin-top: 3px; font-size: .85rem; }
body.player-open .clip-thumbnails { min-width: 0; padding: 4px 2px; gap: 6px; }
body.player-open .clip-thumbnail { flex-basis: 116px; padding: 4px; border-radius: 9px; }
body.player-open .clip-thumbnail img { width: 106px; height: 56px; border-radius: 5px; }
body.player-open .clip-thumbnail span { margin: 3px 1px 0; }

@media (max-width: 1100px) {
  .player-heading { grid-template-columns: minmax(0, 1fr) auto auto; }
  .playback-status { grid-row: 2; grid-column: 1 / -1; justify-content: flex-end; }
}

@media (min-width: 621px) and (max-width: 900px) {
  .clip { grid-template-columns: minmax(280px, 1fr) minmax(0, 1fr); }
  .clip-thumbnails { min-width: 0; }
}

@media (max-width: 620px) {
  header, main, footer { width: min(100% - 22px, 1100px); }
  header { align-items: flex-start; padding-top: 16px; }
  header button, header .page-link { padding: 9px 12px; }
  .header-actions { flex-direction: column; align-items: stretch; }
  .archive-detector { display: none; }
  .clip, body.player-open .clip { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .clip > button { grid-template-columns: 52px minmax(0, 1fr); gap: 12px; }
  .play-icon { width: 46px; height: 46px; border-radius: 14px; }
  .clip-thumbnails { max-width: 100%; padding: 0 2px 10px 64px; }
  body.player-open .clip-thumbnails { padding: 0 2px 6px 52px; }
  .player-heading { grid-template-columns: minmax(0, 1fr) auto; }
  .player-modes { grid-row: 2; grid-column: 1 / -1; }
  .playback-status { grid-row: 3; justify-content: space-between; gap: 6px; font-size: .75rem; }
  #playback-frame { min-width: 0; }
  #playback-time { min-width: 0; }
  .player-panel { padding: 6px; border-radius: 12px; }
}

@media (max-height: 500px) and (min-width: 621px) {
  body.player-open .video-frame { width: min(100%, calc(38dvh * 8 / 3)); }
}
