:root {
  --bg: #0A0A0A;
  --bg-card: #1A1A1A;
  --bg-raised: #141414;
  --border: #242424;
  --text: #FFFFFF;
  --text2: rgba(255,255,255,.5);
  --text3: rgba(255,255,255,.28);
  --gold: #C9A84C;
  --green: #10B981;
  --red: #EF4444;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
/* The `hidden` attribute must win over any class that sets `display` (e.g. .ov uses
   display:flex). Without this the overlay stays on screen forever and its × can't close it. */
[hidden] { display: none !important; }
html, body { height: 100%; font-family: 'Space Grotesk', system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
body { display: flex; flex-direction: column; overflow: hidden; }
button { font-family: inherit; cursor: pointer; }
img { display: block; }

/* ── Header ── */
.hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--st) + 10px) 16px 10px; gap: 12px;
  border-bottom: 1px solid var(--border); background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.hdr-title { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 1.05rem; letter-spacing: .2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text3); flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 8px rgba(16,185,129,.6); }
.dot.off { background: var(--red); }
.hdr-actions { display: flex; gap: 8px; }
.hbtn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 10px; padding: 8px 14px; font-size: .9rem; font-weight: 500;
}
.hbtn:active { background: var(--bg-raised); }
.hbtn-live { border-color: var(--gold); color: var(--gold); }
.hbtn-live.on { background: var(--gold); color: #000; }

/* ── Main scroll area ── */
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px calc(var(--sb) + 24px); }
.msg { text-align: center; color: var(--text2); padding: 48px 20px; line-height: 1.5; }
.msg b { color: var(--text); }
.msg-why { margin-top: 10px; font-size: .75rem; color: var(--text3); word-break: break-all; }

/* ── Recorder sections ── */
.rec { margin-bottom: 22px; }
.rec-h { font-size: .95rem; font-weight: 600; color: var(--text); margin: 4px 2px 10px; display: flex; align-items: center; gap: 8px; }
.rec-n { font-size: .72rem; color: var(--text2); background: var(--bg-raised); border: 1px solid var(--border); padding: 1px 8px; border-radius: 999px; font-weight: 500; }

/* ── Camera grid ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 12px; overflow: hidden; padding: 0; text-align: left; display: block;
}
.tile:active { border-color: var(--gold); }
.tile-img { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; }
.tile-img img, .tile-img video-stream, .tile-img video { width: 100%; height: 100%; object-fit: cover; }
.tile-wait { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: .78rem; }
.tile.off .tile-img { opacity: .55; }
.tile-name { padding: 7px 10px; font-size: .82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Password gate ── */
.gate { min-height: 70vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate-card { width: 100%; max-width: 340px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; text-align: center; }
.gate-card h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: 6px; }
.gate-sub { color: var(--text2); font-size: .9rem; margin-bottom: 18px; }
.gate-why { color: var(--red); font-size: .9rem; margin-bottom: 18px; }
.gate-card form { display: flex; flex-direction: column; gap: 10px; }
.gate-card input { background: var(--bg-raised); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 12px 14px; font-size: 1rem; }
.gate-card input:focus { outline: none; border-color: var(--gold); }
.gate-card button { background: var(--gold); color: #000; border: none; border-radius: 10px; padding: 12px; font-size: 1rem; font-weight: 600; }
.gate-card button:active { opacity: .85; }

/* ── Full-screen overlay ── */
.ov { position: fixed; inset: 0; background: #000; z-index: 100; display: flex; flex-direction: column; }
/* The control row sits ABOVE the video iframe so its buttons always take the tap
   (an iframe will otherwise swallow touches that land over it). */
.ov-top { position: relative; z-index: 2; display: flex; align-items: center; gap: 12px; padding: calc(var(--st) + 10px) 16px 10px; background: rgba(0,0,0,.55); }
.ov-name { flex: 1; font-weight: 600; font-size: 1rem; }
.ov-q { background: rgba(255,255,255,.14); color: #fff; border: none; border-radius: 10px; min-width: 56px; height: 44px; padding: 0 14px; font-weight: 600; font-size: .9rem; }
.ov-x { background: rgba(255,255,255,.14); color: #fff; border: none; border-radius: 10px; width: 48px; height: 44px; font-size: 1.5rem; line-height: 1; }
.ov-q, .ov-x { -webkit-tap-highlight-color: rgba(255,255,255,.3); touch-action: manipulation; }
.ov-frame { position: relative; z-index: 1; flex: 1; min-height: 0; }
.ov-frame iframe { width: 100%; height: 100%; border: 0; background: #000; }
.ov-hint { text-align: center; color: var(--text3); font-size: .78rem; padding: 10px 16px calc(var(--sb) + 14px); }

/* ── Toast ── */
.toast { position: fixed; left: 50%; bottom: calc(var(--sb) + 20px); transform: translateX(-50%); background: var(--bg-card); border: 1px solid var(--border); color: var(--text); padding: 10px 18px; border-radius: 10px; font-size: .88rem; z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
