:root {
  --bg: #0b1016;
  --surface: #121a23;
  --surface-2: #1a2531;
  --border: #263445;
  --text: #e6edf3;
  --muted: #9fb0c2;
  --accent: #2dd4bf;
  --accent-ink: #04201c;
  --danger: #f87171;
  --danger-ink: #2a0606;
  --warn: #fbbf24;
  --ok: #4ade80;
  --radius: 14px;
  --gap: 16px;
  --tap: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--accent); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.boot, .noscript { padding: 48px 16px; text-align: center; color: var(--muted); }
#app { min-height: 100%; outline: none; }

/* Layout */
.page { max-width: 640px; margin: 0 auto; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 32px); }
.topbar { display: flex; align-items: center; gap: 8px; min-height: var(--tap); margin-bottom: 12px; }
.topbar h1 { margin: 0; font-size: 1.25rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .ic { width: 28px; height: 28px; color: var(--accent); }
.stack { display: grid; gap: var(--gap); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card h2 { margin-bottom: .4em; }
ul.card, ol.card { margin: 0; }
ul.card { list-style: none; }
ol.card { padding-left: 2.2em; }
.feat { display: flex; align-items: center; gap: 12px; }
.feat .ic { color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; touch-action: manipulation; user-select: none;
}
.btn:hover { border-color: #3a4d63; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.icon { width: var(--tap); padding: 0; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger[aria-pressed="true"], .btn.alert[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }

.choice { display: flex; align-items: center; gap: 16px; text-align: left; padding: 20px; width: 100%; min-height: 96px; }
.choice .ic { width: 36px; height: 36px; color: var(--accent); }
.choice strong { display: block; font-size: 1.1rem; }
.choice span { display: block; font-weight: 400; color: var(--muted); font-size: .9rem; }

/* Forms */
label.field { display: grid; gap: 6px; font-weight: 600; }
input[type="text"], input[type="url"], input[type="number"], select {
  width: 100%; min-height: var(--tap); padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch input { width: 48px; height: 28px; accent-color: var(--accent); }

/* Chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: rgba(11,16,22,.72); border: 1px solid var(--border); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.chip .ic { width: 14px; height: 14px; }
.dot { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.rec { background: var(--danger); animation: blink 1s steps(2) infinite; }
.chip.warn { color: var(--warn); }
@keyframes blink { 50% { opacity: .2; } }

/* Camera list */
.cams { display: grid; gap: 12px; }
.cam-item { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 14px; min-height: 80px; }
.cam-item .thumb { width: 72px; height: 54px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; flex: none; overflow: hidden; }
.cam-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.cam-item .meta { flex: 1; min-width: 0; }
.cam-item .name, .cam-item .sub { display: block; }
.cam-item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam-item .sub { color: var(--muted); font-size: .85rem; font-weight: 400; }

/* Stage (camera + live) */
.stage { position: fixed; inset: 0; background: #000; display: flex; flex-direction: column; }
.stage video.main { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage.cover video.main { object-fit: cover; }
.stage video.lowlight { filter: brightness(1.9) contrast(1.25) saturate(.85); }
.stage .hud-top, .stage .hud-bottom { position: relative; z-index: 2; padding: 12px; display: flex; gap: 8px; align-items: center; }
.stage .hud-top { padding-top: calc(var(--safe-t) + 12px); background: linear-gradient(rgba(0,0,0,.65), transparent); flex-wrap: wrap; }
.stage .hud-top .chips { flex: 1 1 100%; }
.stage .hud-bottom { margin-top: auto; padding-bottom: calc(var(--safe-b) + 16px); background: linear-gradient(transparent, rgba(0,0,0,.75)); flex-direction: column; align-items: stretch; }
.stage .title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 2px #000; }
.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.ctl { flex-direction: column; gap: 4px; width: 68px; min-height: 60px; padding: 6px 2px; font-size: .72rem; font-weight: 600; background: rgba(18,26,35,.85); white-space: nowrap; }
.ctl .ic { width: 24px; height: 24px; }
.overlay-msg { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }
.overlay-msg[hidden] { display: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.meter { height: 4px; border-radius: 2px; background: rgba(255,255,255,.15); overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.meter.hot > i { background: var(--danger); }

.dim { position: fixed; inset: 0; z-index: 50; background: #000; display: grid; place-items: center; color: #3b4652; text-align: center; padding: 24px; border: 0; width: 100%; font: inherit; cursor: pointer; }
.dim[hidden] { display: none; }

.prestart { position: absolute; inset: 0; z-index: 3; overflow-y: auto; background: var(--bg); }

/* Tabs + events */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; max-height: 75vh; overflow-y: auto; background: var(--surface); border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; padding: 16px 16px calc(var(--safe-b) + 16px); }
.sheet[hidden] { display: none; }
.clips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.clip { display: grid; gap: 4px; padding: 0; overflow: hidden; text-align: left; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); color: var(--text); cursor: pointer; font: inherit; }
.clip img, .clip .noimg { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; display: block; }
.clip .cap { padding: 6px 8px 8px; font-size: .8rem; }
.clip .cap b { display: block; font-size: .85rem; }

dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0,0,0,.75); }
dialog video { width: 100%; max-height: 60vh; background: #000; border-radius: 10px; }
.progress { width: 100%; height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); }

/* QR */
.qr { background: #fff; padding: 16px; border-radius: 12px; width: min(280px, 100%); margin: 0 auto; }
.qr svg { display: block; width: 100%; height: auto; }
.linkbox { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; background: var(--bg); border: 1px solid var(--border); padding: 10px; border-radius: 10px; user-select: all; }

.notice { border-left: 4px solid var(--warn); padding: 10px 12px; background: rgba(251,191,36,.08); border-radius: 8px; font-size: .9rem; }
.notice.danger { border-color: var(--danger); background: rgba(248,113,113,.08); }

/* Toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 16px); z-index: 200; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); display: flex; gap: 10px; align-items: center; }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast button { margin-left: auto; }

@media (min-width: 720px) {
  .ctl { width: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
