:root {
  --bg: #0b0d10;
  --panel: #15181c;
  --border: #262b31;
  --text: #e8eaed;
  --muted: #8b929b;
  --accent: #4f8cff;
  --err: #ff5d5d;
}
* { box-sizing: border-box; }
/* Without this, .wrap's own display:flex beats the browser's default
   [hidden]{display:none} (author rules always win over user-agent rules
   regardless of selector specificity) — so toggling `hidden` via JS on
   #login-view/#events-view/#watch-view would silently do nothing visually. */
[hidden] { display: none !important; }
/* overflow:hidden on body + exact (not min-) height on .wrap: the grid wall
   must fit one screen with no page-level scroll — inner elements (a tile's
   own content, the mobile fallback grid) can still scroll themselves. */
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.wrap { height: 100%; display: flex; flex-direction: column; }

#login-view { align-items: center; justify-content: center; }
.login-box { width: min(360px, 90vw); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 10px; }
.login-box h1 { font-size: 18px; margin: 0 0 8px; }
.login-box label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login-box input { background: #0e1013; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 14px; }
.remember-row { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.remember-row input { width: auto; background: none; border: 1px solid var(--border); border-radius: 3px; padding: 0; accent-color: var(--accent); }
.login-box button { margin-top: 14px; background: var(--accent); border: none; border-radius: 8px; padding: 11px; color: #fff; font-size: 14px; cursor: pointer; }
.login-box button:disabled { opacity: .6; cursor: default; }
.err { background: rgba(255,93,93,.12); border: 1px solid rgba(255,93,93,.35); color: var(--err); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.topbar h1 { font-size: 16px; margin: 0; }
.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-size: 13px; }

.status { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 15px; }

.grid-pager { display: flex; align-items: center; gap: 10px; }
.grid-pager button { padding: 5px 12px; }
#page-label { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* Popup player: a modal overlay above events-view (which stays mounted
   underneath, dimmed) rather than a separate full-page view — matches a DVR
   "focus one camera" popup instead of a page navigation. Near-full-screen
   (thin margin only, no max-width cap) so the focused stream is as large as
   the viewport allows. */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
}
.modal-box {
  width: 100%; height: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column;
}
#player-wrap { position: relative; flex: 1; min-height: 0; background: #000; }
#player { width: 100%; height: 100%; }

/* External WHEP events mount whep-player.html in an iframe instead of an
   OvenPlayer instance (see app.js mountPlayer) — fill the same box either
   way, no player chrome of its own to account for. */
#player iframe, .tile-player iframe { width: 100%; height: 100%; border: 0; display: block; }

/* On an unstable uplink, OvenPlayer treats even a transient ICE hiccup as a
   fatal error and covers the video with its own black .op-message-box error
   overlay (see app.js attachReconnect) — hidden here so the last decoded
   frame (which the <video> element keeps showing on its own) stays visible
   underneath instead of flashing to a blank error card on every wobble. */
#player-wrap .op-message-box, .tile-media .op-message-box { display: none !important; }

/* Small non-blocking "reconnecting" pill shown in place of OvenPlayer's own
   error UI — see app.js attachReconnect. */
.reconnect-pill {
  position: absolute; z-index: 16; top: 8px; right: 8px;
  background: rgba(0,0,0,.65); color: #fff; font: 11px/1.4 -apple-system,sans-serif;
  padding: 3px 9px; border-radius: 20px; pointer-events: none;
  display: flex; align-items: center; gap: 5px;
}
.reconnect-pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #f5a623; animation: reconnect-blink 1s ease-in-out infinite;
}
@keyframes reconnect-blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* Anti-piracy watermark overlay (see js/watermark.js) — low-opacity so it
   doesn't obstruct viewing, transitions position instead of jumping so it
   reads as "burned into the recording" rather than a jarring UI flicker. */
.wm-overlay {
  position: absolute; z-index: 20; pointer-events: none;
  color: rgba(255,255,255,.35); font: 12px/1.4 monospace;
  text-shadow: 0 0 3px rgba(0,0,0,.6);
  transition: top 1.5s ease, left 1.5s ease;
  white-space: nowrap;
}

/* Small-screen cold-open poster (see app.js SMALL_SCREEN_MQ): shown instead
   of auto-starting WebRTC when the popup first opens on a phone, so opening
   a stream to peek doesn't immediately burn mobile data. Tapping it starts
   the real player. */
.player-poster {
  position: absolute; inset: 0; z-index: 15;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.player-poster img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; opacity: .85;
}
.poster-play-btn {
  position: relative; z-index: 1;
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(255,255,255,.15); border: 2px solid rgba(255,255,255,.7);
  color: #fff; font-size: 22px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.player-poster:hover .poster-play-btn { background: rgba(255,255,255,.28); }

/* DVR-wall: up to 8 live channel bays per page (4 columns x 2 rows) — only
   currently-live assignments occupy a bay, so fewer-than-8 live streams just
   leaves the remaining grid cells unused rather than showing empty bays.
   Assignments beyond 8 live page through grid-pager (see app.js WALL_SIZE).
   Fills the viewport under the topbar; each cell's media area takes
   whatever height the grid row gives it (no aspect-ratio box) since row
   height is grid-determined, not content-determined. */
.events-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 10px;
  padding: 10px;
}
@media (max-width: 900px) {
  .events-grid { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(4, 1fr); }
}
@media (max-width: 700px) {
  .events-grid { grid-template-columns: 1fr; grid-template-rows: repeat(8, minmax(180px, 1fr)); overflow-y: auto; }
  /* Popup player stays a contained, aspect-ratio card on phones instead of
     edge-to-edge "fullscreen" — tapping the poster's play button plays right
     here. True fullscreen is still one tap away via OvenPlayer's own
     fullscreen control (controls:true in playSource), it's just not forced. */
  .modal-box { height: auto; max-height: 90vh; }
  #player-wrap { flex: none; width: 100%; aspect-ratio: 16 / 9; }
}
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.tile-media { position: relative; flex: 1; min-height: 0; background: #000; }
.tile-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: pointer; }
/* Inline (in-tile) playback — see app.js playInline/pollInlineStream. The
   player mount sits under the placeholder icon/hint; once .playing is set,
   the icon/hint are hidden so clicks land on the player's own controls
   instead of re-triggering playInline (a no-op, but pointless). */
.tile-player { position: absolute; inset: 0; }
.tile-media.playing .tile-play-ico, .tile-media.playing .tile-play-hint { display: none; }
.tile-play-ico { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.08); color: var(--text); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.tile-placeholder:hover .tile-play-ico { background: rgba(255,255,255,.16); }
.tile-play-hint { font-size: 11.5px; color: var(--muted); }
.tile-info { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.tile-title { flex: 1; font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expand-btn { background: rgba(255,255,255,.08); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 10px; font-size: 11.5px; cursor: pointer; }
.expand-btn:hover { border-color: var(--accent); }

.badge { font-size: 11px; font-weight: 600; letter-spacing: .03em; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.badge.live { background: rgba(255,93,93,.16); color: #ff8080; }
.badge.off { background: rgba(139,146,155,.16); color: var(--muted); }
#back-btn { margin-right: 8px; }
