:root {
  --bg: #0f1419;
  --panel: #182028;
  --panel-2: #212b35;
  --line: #2c3742;
  --text: #e8edf2;
  --muted: #8b98a5;
  --accent: #2f9bff;
  --accent-2: #1b7fe0;
  --ding: #ffb020;
  --danger: #ff5a5f;
  --ok: #34c77b;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; font-size: .9rem; }

/* ---------- forms + buttons ---------- */
label { display: block; margin: 0 0 .9rem; font-size: .9rem; color: var(--muted); }
input:not([type=checkbox]) {
  display: block; width: 100%; margin-top: .35rem; padding: .75rem .9rem;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; color: var(--text); }
button:disabled { opacity: .6; cursor: progress; }
.primary { background: var(--accent); padding: .7rem 1.1rem; font-weight: 600; }
.primary:hover { background: var(--accent-2); }
.secondary { background: var(--panel-2); padding: .7rem 1.1rem; }
.secondary.small { padding: .45rem .8rem; font-size: .85rem; }
.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }
.link.danger { color: var(--danger); text-decoration: none; font-size: .85rem; }
.icon-btn { background: none; font-size: 1.2rem; padding: .4rem .55rem; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.row { display: flex; gap: .75rem; }
.row > * { flex: 1; }

/* ---------- login / setup ---------- */
.card-view { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 2rem 1.5rem; }
.card .primary { width: 100%; margin-top: .5rem; }
.logo { font-size: 2.5rem; margin-bottom: .5rem; }

/* ---------- main ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .5rem;
  padding: .75rem 1rem; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; margin-right: auto; }
.status { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); background: var(--panel); padding: .3rem .65rem; border-radius: 99px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state=connected] .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status[data-state=connecting] .dot { background: var(--ding); animation: blink 1s infinite; }
.status[data-state=error] .dot { background: var(--danger); }
@keyframes blink { 50% { opacity: .3; } }

.banner { margin: 1rem; padding: .85rem 1rem; background: color-mix(in srgb, var(--ding) 15%, var(--panel)); border: 1px solid color-mix(in srgb, var(--ding) 40%, transparent); border-radius: var(--radius); }

main { max-width: 760px; margin: 0 auto; padding: 1rem; }

.camera { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
/* Ring head-to-toe doorbells are square (1536×1536): show the whole frame, never crop. */
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; opacity: .9; }
.thumb-empty { display: grid; place-items: center; height: 100%; font-size: 2.5rem; opacity: .3; }
.thumb .play {
  position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%);
  width: 64px; height: 64px; border-radius: 50%; font-size: 1.4rem; padding-left: 4px;
  background: rgb(0 0 0 / .55); backdrop-filter: blur(6px); border: 2px solid rgb(255 255 255 / .8);
}
.thumb-age { position: absolute; left: .6rem; bottom: .6rem; font-size: .75rem; background: rgb(0 0 0 / .6); padding: .15rem .45rem; border-radius: 6px; }
.camera-info { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1rem; }
.camera-name { font-weight: 600; }

.filters { display: flex; gap: .5rem; margin-bottom: .75rem; }
.chip { background: var(--panel); border: 1px solid var(--line); padding: .35rem .85rem; border-radius: 99px; font-size: .85rem; color: var(--muted); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.events { list-style: none; margin: 0; padding: 0; }
.events .day { font-size: .8rem; color: var(--muted); margin: 1.1rem 0 .4rem; font-weight: 600; }
.event { display: flex; align-items: center; gap: .85rem; padding: .7rem .85rem; background: var(--panel); border-radius: 12px; margin-bottom: .4rem; }
.event:has(.event-thumb) { cursor: pointer; }
.event-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-2); flex: none; }
.event.ding .event-icon { background: color-mix(in srgb, var(--ding) 25%, var(--panel-2)); }
.event-text { flex: 1; min-width: 0; }
.event-title { font-weight: 600; }
.event-thumb { width: 72px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }

/* ---------- dialogs ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 1.5rem; max-width: min(520px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgb(0 0 0 / .65); backdrop-filter: blur(3px); }

dialog.fullscreen { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: #000; }
dialog.fullscreen[open] { overflow: hidden; }
.live-wrap { position: relative; width: 100%; height: 100%; display: grid; place-items: center; overflow: hidden; }
/* Pinned to the edges: inside a centred grid, height:100% fell back to the stream's own 1536 px and overflowed (= "zoomed in"). */
#live-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#live-video.fill { object-fit: cover; }
#live-res { margin-left: auto; font-weight: 400; }
.live-top { position: absolute; top: calc(env(safe-area-inset-top) + 1rem); left: 1rem; right: 1rem; display: flex; align-items: center; gap: .75rem; font-weight: 600; text-shadow: 0 1px 4px #000; }
.live-badge { display: flex; align-items: center; gap: .35rem; background: var(--danger); padding: .15rem .5rem; border-radius: 6px; font-size: .75rem; text-shadow: none; }
.rec { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: blink 1.2s infinite; }
.live-state { position: absolute; background: rgb(0 0 0 / .6); padding: .6rem 1rem; border-radius: 10px; }
.live-controls { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 1.5rem); display: flex; gap: 1.25rem; align-items: center; }
.live-controls button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; -webkit-tap-highlight-color: transparent; }
.live-hint { position: absolute; bottom: calc(env(safe-area-inset-bottom) + .4rem); font-size: .75rem; color: rgb(255 255 255 / .6); text-shadow: 0 1px 3px #000; }
.round { width: 60px; height: 60px; border-radius: 50%; background: rgb(255 255 255 / .15); backdrop-filter: blur(8px); font-size: 1.4rem; }
.round.talk { width: auto; padding: 0 1.4rem; border-radius: 99px; display: flex; align-items: center; gap: .5rem; font-size: 1.1rem; }
.round.talk span { font-size: 1rem; font-weight: 600; }
.round.talk.active { background: var(--ok); animation: talkpulse 1.5s infinite; }
.round.hangup { background: var(--danger); }
@keyframes talkpulse { 0%,100% { box-shadow: 0 0 0 0 rgb(52 199 123 / .6); } 50% { box-shadow: 0 0 0 12px rgb(52 199 123 / 0); } }

dialog.ding { text-align: center; width: 360px; }
.ding-pulse { font-size: 3rem; animation: ring 0.6s ease-in-out 4; }
@keyframes ring { 0%,100% { transform: rotate(0); } 25% { transform: rotate(18deg); } 75% { transform: rotate(-18deg); } }
#ding-img { width: 100%; border-radius: 12px; margin: .5rem 0 1rem; }
dialog.ding .row { margin-top: 1rem; }

dialog.photo { padding: 1rem; text-align: center; }
dialog.photo img { max-width: 100%; border-radius: 12px; display: block; }

dialog.sheet { width: 520px; max-height: 90dvh; overflow-y: auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.sheet-head h2 { margin: 0; }
.block { border-top: 1px solid var(--line); padding: 1.25rem 0 .5rem; }
.steps { padding-left: 1.2rem; margin: 0 0 .5rem; }
.copy-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.copy-row code { flex: 1; background: var(--bg); padding: .55rem .7rem; border-radius: 8px; font-size: .85rem; overflow-x: auto; white-space: nowrap; }
.toggle { display: flex; align-items: center; gap: .6rem; color: var(--text); font-size: .95rem; margin: .6rem 0; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.users { list-style: none; padding: 0; margin: 0 0 1rem; }
.users li { display: flex; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.users .spacer { flex: 1; }
.tag { font-size: .7rem; background: var(--panel-2); color: var(--muted); padding: .1rem .45rem; border-radius: 99px; }
.inline-form input { margin: 0 0 .5rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 1.5rem); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .65rem 1.1rem; border-radius: 99px; font-weight: 600; z-index: 100;
  box-shadow: 0 8px 24px rgb(0 0 0 / .4); max-width: calc(100vw - 2rem);
}
