:root {
  --bg: #0b0e13;
  --panel: #131821;
  --panel-2: #1a212c;
  --line: #252e3b;
  --text: #e6ebf2;
  --muted: #8592a6;
  --accent: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
video-stream .info { display: none; }  /* go2rtc's own status text - shown in our own message instead */
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .12em; display: flex; align-items: center; gap: 8px; }
.brand-sub { font-weight: 400; color: var(--muted); letter-spacing: .04em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.sharp-ctl { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.sharp-ctl input { width: 90px; accent-color: var(--accent); }
.sharp-ctl span { min-width: 22px; color: var(--text); font-variant-numeric: tabular-nums; }
.layout { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.layout button { background: none; border: 0; padding: 6px 10px; color: var(--muted); }
.layout button.on { background: var(--panel-2); color: var(--text); }
.layout svg rect { fill: currentColor; stroke: none; }
.spacer { flex: 1; }
.clock { color: var(--text); font-variant-numeric: tabular-nums; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; color: var(--muted); display: flex; }

/* ---- main ---- */
.main { flex: 1; display: flex; min-height: 0; }
.grid { flex: 1; display: grid; gap: 8px; padding: 8px; min-width: 0; }
.layout-grid { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.layout-focus { grid-template-columns: 3fr 1fr; grid-template-rows: repeat(3, 1fr); }
.layout-focus .tile.big { grid-row: 1 / span 3; grid-column: 1; }
.layout-single { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.layout-single .tile:not(.big) { display: none; }

/* ---- tile ---- */
.tile {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); min-height: 0; outline: none; container-type: inline-size;
}
@container (max-width: 560px) {  /* small tiles: icon-only buttons, no resolution text */
  .tbtn span, .res { display: none; }
}
.tile:focus-visible, .tile.ptz-on { border-color: var(--accent); }
.stage { position: absolute; inset: 0; }
.stage video-stream, .stage video { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage video { object-fit: contain; background: #000; }
.smooth-view { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; display: none; }
.smooth-view.on { display: block; }
.stage video.smoothed { opacity: 0; }  /* still decoding; the smooth canvas shows it */
.state-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  color: var(--muted); padding: 20px; pointer-events: none;
}
.state-msg:empty { display: none; }
.state-msg b { color: var(--text); }
.state-msg .retry {
  pointer-events: auto; margin: 12px 0 8px; padding: 7px 18px; border-radius: 8px;
  background: var(--accent); color: #04210f; border: 0; font-weight: 600;
}
.state-msg .retry[disabled] { opacity: .6; cursor: wait; }

.tile-top {
  position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px 10px; background: linear-gradient(rgba(0,0,0,.65), transparent); pointer-events: none;
}
.tile-top > * { pointer-events: auto; }
.cam-name { display: flex; align-items: center; gap: 8px; font-weight: 600; text-shadow: 0 1px 2px #000; }
.res { font-weight: 400; color: #b8c2d1; font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tile.live .live-dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.tile-actions { display: flex; gap: 6px; opacity: .85; }
.tbtn {
  display: flex; align-items: center; gap: 6px; background: rgba(15,20,28,.75); border: 1px solid rgba(255,255,255,.12);
  border-radius: 7px; padding: 5px 8px; backdrop-filter: blur(4px);
}
.tbtn:hover { border-color: rgba(255,255,255,.35); }
.tbtn span { font-size: 12px; }
.ptz-toggle.unavailable { opacity: .45; }
.tile.ptz-on .ptz-toggle { background: var(--accent); color: #04210f; border-color: var(--accent); }

/* ---- PTZ ---- */
.ptz-panel {
  position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px; background: rgba(10,14,20,.78); border: 1px solid rgba(255,255,255,.12); border-radius: 14px; backdrop-filter: blur(6px);
}
.joy {
  width: 128px; height: 128px; border-radius: 50%; position: relative; touch-action: none; cursor: grab;
  background: radial-gradient(circle, #1d2531 0 40%, #141a23 41% 100%); border: 1px solid #2c3746;
}
.joy:active { cursor: grabbing; }
.joy-knob {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #4ade80, #15803d); box-shadow: 0 4px 12px rgba(0,0,0,.5);
  transition: transform .12s ease-out;
}
.joy.dragging .joy-knob { transition: none; }
.joy-arrow { position: absolute; width: 0; height: 0; border: 6px solid transparent; opacity: .6; }
.joy-arrow.up { top: 8px; left: calc(50% - 6px); border-bottom-color: #cbd5e1; }
.joy-arrow.down { bottom: 8px; left: calc(50% - 6px); border-top-color: #cbd5e1; }
.joy-arrow.left { left: 8px; top: calc(50% - 6px); border-right-color: #cbd5e1; }
.joy-arrow.right { right: 8px; top: calc(50% - 6px); border-left-color: #cbd5e1; }
.presets { display: flex; gap: 6px; }
.presets select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; max-width: 130px;
}
.presets button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; }
.ptz-hint { font-size: 11px; color: var(--muted); }

/* ---- shut down ---- */
.power-btn:hover { color: var(--danger); border-color: var(--danger); }
dialog#shutdownDlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; max-width: 420px; }
dialog#shutdownDlg::backdrop { background: rgba(0,0,0,.7); }
dialog#shutdownDlg h2 { margin: 0 0 8px; font-size: 17px; }
dialog#shutdownDlg p { color: var(--muted); margin: 0 0 16px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-actions button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; }
.dlg-actions .danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.stopped-screen { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; justify-content: center; text-align: center; }
.stopped-screen p { color: var(--muted); }

/* ---- live network stats ---- */
.net-stat {
  position: absolute; right: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; pointer-events: auto;
  background: rgba(10,14,20,.68); border: 1px solid rgba(255,255,255,.12); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-variant-numeric: tabular-nums; color: #e6ebf2; backdrop-filter: blur(4px);
}
.net-stat .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.net-stat.good .dot { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.net-stat.fair .dot { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }
.net-stat.poor .dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.tile.ptz-on .net-stat { display: none; }
body.wall .net-stat { right: 8px; bottom: 8px; font-size: 11px; padding: 2px 8px; }
.net-total { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- drag & drop ---- */
.cam-name[draggable="true"] { cursor: grab; }
.cam-name[draggable="true"]:active { cursor: grabbing; }
.cam-name[draggable="true"]::after {
  content: "⠿"; font-size: 13px; color: rgba(255,255,255,.55); margin-left: 2px; order: -1;
}
body.dragging-tile .tile .ptz-panel { pointer-events: none; }
.tile.drag-source { opacity: .45; }
.tile.drop-target { outline: 3px dashed var(--accent); outline-offset: -3px; }
.tile.drop-target::after {
  content: "Drop to swap"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(34,197,94,.18); color: #fff; font-weight: 700; font-size: 18px; text-shadow: 0 1px 3px #000; z-index: 3;
}

/* ---- full-screen wall: 4 cameras edge to edge, no bars, no chrome ---- */
.wall-btn {
  display: flex; align-items: center; gap: 6px; background: var(--accent); color: #04210f; border: 0;
  border-radius: 8px; padding: 6px 12px; font-weight: 600;
}
body.wall .topbar { display: none; }
body.wall .grid { gap: 2px; padding: 0; background: #000; }
body.wall .tile { border: 0; border-radius: 0; }
body.wall .stage video { object-fit: cover; }  /* fill the tile: no black bars */
body.wall .tile-top { background: linear-gradient(rgba(0,0,0,.45), transparent); padding: 6px 8px; }
body.wall .cam-name { font-size: 13px; }
body.wall .res { display: none; }
body.wall .tile-actions { opacity: 0; transition: opacity .2s; }
body.wall .tile:hover .tile-actions { opacity: .9; }
.wall-exit {
  position: fixed; right: 12px; bottom: 12px; z-index: 5; display: none;
  background: rgba(10,14,20,.7); color: var(--text); border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px; padding: 6px 12px; backdrop-filter: blur(4px); opacity: 0; transition: opacity .3s;
}
body.wall .wall-exit { display: block; }
body.wall.mouse-active .wall-exit { opacity: 1; }
body.wall:not(.mouse-active) { cursor: none; }

/* ---- recording ---- */
.rec-stat { color: var(--muted); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px; }
.rec-stat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.rec-stat.on::before { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.rec-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .08em; color: #fff; background: var(--danger);
  padding: 1px 6px; border-radius: 4px;
}
dialog#playback {
  width: min(1500px, 97vw); max-height: 97vh; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow: hidden auto;
}
dialog#playback::backdrop { background: rgba(0,0,0,.8); }
dialog#playback:fullscreen { width: 100vw; max-width: none; height: 100vh; max-height: none; border: 0; border-radius: 0; display: flex; flex-direction: column; }
dialog#playback:fullscreen .pb-stage { flex: 1; height: auto; }
dialog#playback:fullscreen .pb-hint { display: none; }
.pb-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.pb-head h2 { margin: 0 6px 0 0; font-size: 16px; }
.pb-head select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; }
.pb-head form { margin: 0; }
.pb-clock { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; margin-left: 8px; }
.pb-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 12px; color: var(--text);
  text-decoration: none; font-size: 13px; white-space: nowrap;
}
.pb-btn[disabled] { opacity: .4; cursor: default; }
.pb-btn.on { border-color: var(--accent); color: var(--accent); }
.pb-play { min-width: 48px; font-weight: 700; }

.pb-stage { height: 62vh; display: grid; gap: 4px; background: #000; border-radius: 8px; overflow: hidden; }
.pb-stage.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.pb-cell { position: relative; overflow: hidden; background: #000; min-height: 0; touch-action: none; cursor: default; }
.pb-stage.n4 .pb-cell { cursor: pointer; }
.pb-cell video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.pb-cell.focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.pb-label {
  position: absolute; left: 8px; top: 6px; display: flex; gap: 6px; font-size: 12px; font-weight: 600;
  text-shadow: 0 1px 2px #000; pointer-events: none;
}
.pb-none { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; }
.pb-empty { color: var(--muted); display: flex; align-items: center; justify-content: center; height: 100%; padding: 20px; text-align: center; }

.pb-controls { display: flex; align-items: center; gap: 8px; margin: 10px 0 8px; flex-wrap: wrap; }
.pb-group { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.pb-group button { background: var(--panel-2); border: 0; border-right: 1px solid var(--line); padding: 5px 10px; font-size: 13px; color: var(--muted); }
.pb-group button:last-child { border-right: 0; }
.pb-group button.on { background: var(--accent); color: #04210f; font-weight: 600; }
.pb-info { color: var(--muted); font-size: 12px; }

.pb-timeline { position: relative; padding: 18px 0 2px; user-select: none; cursor: pointer; touch-action: none; }
.tl-ticks { position: absolute; left: 0; right: 0; top: 0; height: 16px; }
.tl-tick { position: absolute; top: 0; transform: translateX(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-tick::after { content: ""; position: absolute; left: 50%; top: 15px; width: 1px; height: 4px; background: var(--line); }
.tl-lanes { display: flex; flex-direction: column; gap: 3px; }
.tl-lane { position: relative; height: 16px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.pb-stage.n1 ~ .pb-timeline .tl-lane { height: 26px; }
.tl-seg { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 55%, transparent); }
.tl-seg.writing { background: repeating-linear-gradient(45deg, #3b4656 0 4px, #2a3340 4px 8px); }
.tl-seg.damaged { background: color-mix(in srgb, var(--danger) 55%, transparent); }
.tl-name { position: absolute; left: 6px; top: 0; z-index: 1; font-size: 10px; line-height: 16px; color: #fff; text-shadow: 0 1px 2px #000; pointer-events: none; }
.tl-head { position: absolute; top: 14px; bottom: 0; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 4px #000; pointer-events: none; }
.tl-head::before { content: ""; position: absolute; left: -5px; top: -2px; border: 6px solid transparent; border-top-color: #fff; }
.tl-hover {
  position: absolute; top: -6px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px; font-size: 11px; pointer-events: none; font-variant-numeric: tabular-nums; z-index: 2;
}
.pb-hint { color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ---- digital zoom ---- */
.stage { touch-action: none; }
.zoom-chip {
  position: absolute; left: 10px; bottom: 10px; z-index: 3; background: rgba(10,14,20,.78); color: #fff;
  border: 1px solid rgba(255,255,255,.2); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-variant-numeric: tabular-nums;
}
.zoom-chip:hover { border-color: var(--accent); }

/* ---- live sound ---- */
.sound-stream { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: -10px; top: -10px; }
.tbtn.sound .waves { opacity: 0; }
.tbtn.sound.on { background: var(--accent); color: #04210f; border-color: var(--accent); }
.tbtn.sound.on .waves { opacity: 1; }
.sound-bar {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent); font-size: 13px;
}
.sound-bar input { width: 90px; accent-color: var(--accent); }
.sound-bar #soundVolVal { min-width: 36px; font-variant-numeric: tabular-nums; color: var(--text); }
.sound-bar button { background: none; border: 0; color: var(--muted); padding: 0 6px; }
.sound-bar button:hover { color: var(--text); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 10;
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .main { flex-direction: column; }
  .grid, .layout-grid, .layout-focus { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: 56vw; }
  .layout-focus .tile.big { grid-row: auto; }
}
