:root {
  color-scheme: dark;
  --bg: #000;
  --text: #f4f4f6;
  --text-dim: #b3b3bd;
  --accent: #7cc4ff;
  --surface: rgba(20, 20, 26, 0.62);
  --surface-solid: rgba(16, 16, 20, 0.9);
  --hairline: rgba(255, 255, 255, 0.14);
  --blur: saturate(1.6) blur(18px);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Alleen de tv-pagina staat stil; login/admin scrollen normaal. */
body.tv {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.material-symbols-rounded {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  font-size: 24px;
  line-height: 1;
  user-select: none;
}

[hidden] { display: none !important; }

/* ---------- Hint-toast ---------- */
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 420px);
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: var(--surface-solid);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: var(--shadow);
}

/* ---------- Achtergrondvideo ---------- */
#video-wrap {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  z-index: 0;
}
#video-wrap iframe,
#video-wrap #player {
  /* Overscan: ~90px per rand buiten beeld, zodat de YouTube-titelbalk boven
     en het watermerk onder niet zichtbaar zijn. */
  --os: 180px;
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(100vw + var(--os));
  height: calc(56.25vw + var(--os));
  min-height: calc(100vh + var(--os));
  min-width: calc(177.78vh + var(--os));
  transform: translate(-50%, -50%);
  border: 0;
  pointer-events: none;
}

#audio-yt {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  pointer-events: none;
  z-index: 0;
}

/* ---------- Overlay: klok + cam + nummer ---------- */
#overlay {
  position: fixed;
  left: max(20px, env(safe-area-inset-left));
  bottom: calc(20px + var(--safe-b));
  z-index: 5;
  pointer-events: none;
  text-shadow: 0 1px 20px rgba(0, 0, 0, 0.55), 0 0 4px rgba(0, 0, 0, 0.4);
  max-width: min(70vw, 640px);
}
#clock {
  font-size: clamp(2rem, 6vw, 4.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#cam-name {
  margin-top: 0.5em;
  font-size: clamp(0.95rem, 2.2vw, 1.55rem);
  font-weight: 550;
  color: #fff;
}
#track-name {
  margin-top: 0.3em;
  font-size: clamp(0.78rem, 1.5vw, 1.05rem);
  font-weight: 400;
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  gap: 0.4em;
}
#track-name .material-symbols-rounded { font-size: 1.1em; opacity: 0.75; }

/* ---------- Bedieningsknoppen ---------- */
#controls {
  position: fixed;
  top: calc(18px + var(--safe-t));
  right: max(18px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  gap: 10px;
  opacity: 0.35;
  transition: opacity 0.3s ease;
}
#controls:hover,
#controls:focus-within,
#controls.show { opacity: 1; }

.icon-btn {
  -webkit-tap-highlight-color: transparent;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}
.icon-btn:hover { background: rgba(40, 40, 48, 0.7); border-color: rgba(255, 255, 255, 0.28); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.active { border-color: var(--accent); color: #fff; }
.icon-btn .material-symbols-rounded { font-size: 22px; }

/* ---------- Panelen ---------- */
.panel {
  position: fixed;
  top: calc(18px + var(--safe-t) + 58px);
  right: max(18px, env(safe-area-inset-right));
  z-index: 25;
  width: 300px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 18px - var(--safe-t) - 58px - 18px);
  max-height: calc(100dvh - 18px - var(--safe-t) - 58px - 18px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
  transform-origin: top right;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.panel[hidden] {
  display: block !important;
  opacity: 0;
  transform: scale(0.94) translateY(-6px);
  pointer-events: none;
}
.panel h3 {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.panel .current {
  font-size: 0.95rem;
  font-weight: 550;
  color: #fff;
  margin: 6px 0 14px;
  word-break: break-word;
}

/* Compacte interval-keuze: blokjes i.p.v. een lijst */
.chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.chip {
  -webkit-tap-highlight-color: transparent;
  padding: 10px 4px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 550;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.chip:hover { background: rgba(255, 255, 255, 0.12); }
.chip:active { transform: scale(0.95); }
.chip.active {
  background: rgba(124, 196, 255, 0.18);
  border-color: var(--accent);
  color: #fff;
}

.nav-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.nav-row button {
  flex: 1;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}
.nav-row button:hover { background: rgba(255, 255, 255, 0.12); }
.nav-row button:active { transform: scale(0.94); }
.nav-row button:disabled { opacity: 0.35; cursor: not-allowed; }
.nav-row button .material-symbols-rounded { font-size: 24px; }
.nav-row button.primary {
  flex: 1.4;
  background: rgba(124, 196, 255, 0.16);
  border-color: rgba(124, 196, 255, 0.4);
  color: #fff;
}
.nav-row button.primary:hover { background: rgba(124, 196, 255, 0.26); }
.nav-row button.primary .material-symbols-rounded {
  font-size: 26px;
  font-variation-settings: "FILL" 1;
}

.danger-btn {
  -webkit-tap-highlight-color: transparent;
  width: 100%;
  margin-top: 10px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 120, 120, 0.32);
  background: rgba(255, 90, 90, 0.12);
  color: #ff9a9a;
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}
.danger-btn:hover { background: rgba(255, 90, 90, 0.2); }
.danger-btn:active { transform: scale(0.97); }
.danger-btn .material-symbols-rounded { font-size: 20px; }

.vol-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 2px;
}
.vol-row .material-symbols-rounded { color: var(--text-dim); font-size: 20px; }
input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}

/* ---------- Start-overlay ---------- */
#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, #1c1c24, #000 80%);
}
#start-btn {
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px 16px 22px;
  font-size: 1.05rem;
  font-weight: 550;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.2s ease;
}
#start-btn:hover { background: rgba(40, 40, 48, 0.75); }
#start-btn:active { transform: scale(0.96); }
#start-btn .material-symbols-rounded {
  font-size: 30px;
  font-variation-settings: "FILL" 1;
}

/* ---------- Mobiel staand: panelen als bottom-sheet ---------- */
@media (max-width: 640px) and (min-height: 521px) {
  #controls { gap: 8px; }
  .icon-btn { width: 44px; height: 44px; }

  .panel {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: calc(12px + var(--safe-b));
    width: auto;
    max-width: none;
    max-height: calc(100dvh - 84px - var(--safe-t) - var(--safe-b));
    border-radius: 24px;
    padding: 20px 18px calc(20px + var(--safe-b));
    transform-origin: bottom center;
  }
  .panel[hidden] { transform: translateY(12px) scale(0.98); }
  .nav-row button { height: 50px; }
}

/* ---------- Lage viewport (liggend telefoon/tablet): compact + scrollbaar ---------- */
@media (max-height: 520px) {
  #controls { top: calc(10px + var(--safe-t)); gap: 8px; }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn .material-symbols-rounded { font-size: 20px; }

  .panel {
    top: calc(8px + var(--safe-t) + 48px);
    right: max(10px, env(safe-area-inset-right));
    width: 280px;
    max-height: calc(100dvh - 8px - var(--safe-t) - 48px - 10px);
    padding: 14px;
    border-radius: 18px;
  }
  .panel h3 { margin-bottom: 2px; }
  .panel .current { margin: 4px 0 10px; font-size: 0.9rem; }
  .chip { padding: 8px 4px; }
  .nav-row { margin-top: 10px; }
  .nav-row button { height: 40px; }
  .vol-row { margin: 2px 0; }
}

/* ---------- Login & admin ---------- */
.sheet {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(28px + var(--safe-t)) 18px calc(96px + var(--safe-b));
}
.sheet h1 { font-size: 1.4rem; font-weight: 650; letter-spacing: -0.01em; }
.sheet h2 {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 34px 0 0;
}
.card {
  background: var(--surface-solid);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 18px;
  margin-top: 12px;
}
.sheet input[type="text"],
.sheet input[type="password"],
.sheet input:not([type]),
.sheet select {
  width: 100%;
  padding: 12px 14px;
  margin-top: 6px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: #0e0e12;
  color: var(--text);
  font-size: 16px;
}
.sheet label { display: block; margin-top: 14px; font-size: 0.88rem; color: var(--text-dim); }
.sheet button {
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #06121f;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.sheet button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--hairline);
}
.sheet .actions { display: flex; gap: 10px; align-items: center; margin-top: 24px; flex-wrap: wrap; }
.sheet a { color: var(--accent); }

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0 -4px;
  max-height: 70vh;
  border-radius: 10px;
}
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
th {
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.8rem;
  position: sticky;
  top: 0;
  background: #14141a;
  z-index: 1;
}
td code { font-size: 0.82rem; color: var(--text-dim); }
.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  color: var(--text-dim);
  white-space: nowrap;
}
.row-del {
  padding: 6px 12px !important;
  border-radius: 10px !important;
  background: transparent !important;
  color: #ff9a9a !important;
  border: 1px solid var(--hairline) !important;
  font-size: 0.82rem !important;
  white-space: nowrap;
}
.status { margin-top: 16px; font-size: 0.9rem; min-height: 1.2em; }
.status.ok { color: #6ee7a8; }
.status.err { color: #ff8a8a; }

@media (max-width: 560px) {
  #add-cam { flex-direction: column; align-items: stretch !important; }
  #add-cam > div { width: 100%; }
  #add-cam button { width: 100%; }
}
