:root {
  --bg: #0f1216; --panel: #181c22; --line: #262c35; --text: #e8ecf1; --mute: #8b95a3;
  --accent: #3d8bfd; --rec: #3a4a5e; --motion: #f0a030; --live: #e5484d;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
h1 { font-size: 18px; margin: 0; font-weight: 600; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); margin: 18px 0 8px; font-weight: 600; }
.view { display: none; min-height: 100vh; padding-bottom: calc(16px + var(--safe-b)); }
.view.on { display: block; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px; background: rgba(15,18,22,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.bar h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ghost { padding: 8px 12px; border-radius: 10px; color: var(--mute); }
.ghost:active { background: var(--panel); }
.primary { background: var(--accent); color: #fff; padding: 12px; border-radius: 12px; font-weight: 600; width: 100%; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--panel); color: var(--mute); }
.badge.live { background: var(--live); color: #fff; }
.badge.rec { background: var(--motion); color: #111; }

.login { max-width: 360px; margin: 12vh auto 0; padding: 28px 22px; display: grid; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }
.logo { display: flex; justify-content: center; } .logo img { width: 64px; height: 64px; }
.login h1 { text-align: center; font-size: 22px; }
label { display: grid; gap: 6px; color: var(--mute); font-size: 13px; }
input:not([type=checkbox]) { font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; }
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.msg { color: var(--live); min-height: 1.4em; margin: 0; text-align: center; font-size: 14px; }

.grid { display: grid; gap: 12px; padding: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tile { position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: var(--panel);
  border: 1px solid var(--line); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .name { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 12px 9px; font-weight: 600;
  background: linear-gradient(transparent, rgba(0,0,0,.75)); display: flex; justify-content: space-between; }
.tile .age { font-weight: 400; color: #cfd6df; font-size: 12px; }
.tile .err { position: absolute; inset: 0; display: grid; place-items: center; color: var(--mute); font-size: 14px; padding: 12px; text-align: center; }
.hint { text-align: center; color: var(--mute); font-size: 12px; }

.stage { position: relative; background: #000; aspect-ratio: 16 / 9; max-height: 70vh; width: 100%; }
.video, .video video-stream, .video video { width: 100%; height: 100%; display: block; }
.video video { object-fit: contain; background: #000; }
.overlay { position: absolute; inset: 0; display: none; place-items: center; text-align: center; padding: 20px;
  color: #dfe5ec; background: rgba(0,0,0,.45); font-size: 14px; pointer-events: none; }
.overlay.on { display: grid; }

.tabs { display: flex; gap: 6px; padding: 10px 14px 0; }
.tab { flex: 1; padding: 10px; border-radius: 10px; background: var(--panel); color: var(--mute); font-weight: 600; }
.tab.on { background: var(--accent); color: #fff; }
.pane { padding: 4px 14px; }
.camswitch { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.camswitch button { padding: 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); text-align: left; }
.camswitch button.on { border-color: var(--accent); color: #fff; }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; font-weight: 600; }
.daynav .ghost { font-size: 22px; padding: 4px 16px; }
.timeline { position: relative; height: 64px; margin-top: 8px; touch-action: pan-y; }
.tl-track { position: absolute; left: 0; right: 0; top: 6px; height: 30px; background: var(--panel);
  border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.tl-seg { position: absolute; top: 0; bottom: 0; background: var(--rec); }
.tl-mot { position: absolute; top: 0; bottom: 0; background: var(--motion); min-width: 2px; }
.tl-cursor { position: absolute; top: 0; height: 42px; width: 2px; background: #fff; display: none; box-shadow: 0 0 0 1px #000; }
.tl-hours { position: absolute; left: 0; right: 0; top: 40px; height: 18px; font-size: 11px; color: var(--mute); }
.tl-hours span { position: absolute; transform: translateX(-50%); }
.controls { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.controls .ghost { background: var(--panel); color: var(--text); }
.ctime { font-variant-numeric: tabular-nums; font-weight: 600; }
.compat { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }
.events { display: flex; flex-wrap: wrap; gap: 8px; }
.events button { padding: 8px 11px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; }
.events button::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--motion); margin-right: 7px; vertical-align: 1px; }
.events .none { color: var(--mute); font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translate(-50%, 30px); opacity: 0;
  background: #2a313b; padding: 10px 16px; border-radius: 12px; transition: .25s; pointer-events: none; z-index: 20; max-width: 90vw; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  .stage { max-height: 72vh; }
  #player .tabs, #player .pane { max-width: 900px; margin-left: auto; margin-right: auto; }
}
