/* Dark only (it's a video page): the light theme was dropped, see server/AGENTS.md ("Pages"). */
:root {
  --bg: #0b0b0d; --surface: #141417; --field: #1c1c20; --border: #2c2c32; --field-border: #6b6b74;
  --text: #f4f4f5; --muted: #a1a1aa;
  --accent: #e11d48; --accent-hover: #be123c; --on-accent: #ffffff;
  --warning: #f5a524; --warning-bg: #2a1f0a; --ok: #4ade80; --info: #60a5fa; --leave: #f87171; --danger: #f87171;
  --blurple: #949cf7; --mention: #c9cdfb; --mention-bg: rgb(88 101 242 / 0.3);
  --chat-0: #f87171; --chat-1: #fb923c; --chat-2: #facc15; --chat-3: #4ade80; --chat-4: #2dd4bf; --chat-5: #60a5fa; --chat-6: #a78bfa; --chat-7: #f472b6;
  --ring: #f4f4f5;
  --radius: 10px; --radius-sm: 8px;
  --ease: 160ms ease-out;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1680px; margin: 0 auto; padding: 16px; }
/* Viewers get the whole window; the height limit on the video keeps the count line in view. */
main:has(#viewer:not([hidden])) { max-width: none; padding: 8px; min-height: 100dvh; display: grid; }
/* A window taller than the picture: the picture sits in the middle, the count line right under it.
   The space above shrinks to nothing first, so a short window keeps the picture at the top. */
#viewer:not([hidden]) { display: flex; flex-direction: column; gap: 8px; }
.watch { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.watch::before { content: ""; flex: 1 1 0; }
#viewer .meta { flex: 1 1 0; align-content: flex-start; }
/* The chat under the picture (live-chat spec 5.1): the picture goes to the top, the chat takes the rest. */
#viewer:has(#chat:not([hidden])) .watch,
#viewer:has(#chat:not([hidden])) .watch::before,
#viewer:has(#chat:not([hidden])) .meta { flex: none; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.375rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 650; color: var(--text); }
.num { font-variant-numeric: tabular-nums; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ video */
.stage { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; }
video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
/* The still before the live, over the black preview (spec 2026-10-09-host-thumbnail 6). */
#thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#thumb-note { position: absolute; inset: 0; margin: 0; padding: 16px; display: grid; place-items: center; text-align: center; color: #fff; }
#thumb-note[hidden] { display: none; }
/* Under the host's stage; hiding the preview also drops its WebRTC connection. */
#preview-toggle { align-self: flex-start; }
#preview-toggle[hidden] { display: none; }
/* main's 16 px padding, the meta line's 10 px margin and its 32 px Chat button, and some slack:
   a picture capped by height never scrolls the page (live-chat spec 5.1). */
#viewer video { max-height: calc(100dvh - 64px); }
/* No pause on a live (page.js plays again): no button for it where the browser lets it go. */
#viewer video::-webkit-media-controls-play-button,
#viewer video::-webkit-media-controls-overlay-play-button { display: none; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; color: #fff; background: rgb(0 0 0 / 0.72);
}
.overlay[hidden] { display: none; }
.message { margin: 0; max-width: 46ch; font-size: 1.0625rem; }
/* Pinch zoom (zoom.js): the browser keeps scrolling the page under one finger until the picture is
   zoomed, then every touch on it is the picture's. */
#viewer video { touch-action: pan-x pan-y; transform-origin: 0 0; }
#viewer .stage.zoomed video { touch-action: none; }
.fullscreen {
  position: absolute; top: 8px; right: 8px; min-height: 44px; width: 44px; padding: 0;
  border: 0; border-radius: 999px; color: #fff; background: rgb(0 0 0 / 0.45);
}
.fullscreen:hover { background: rgb(0 0 0 / 0.7); }
.fullscreen[hidden] { display: none; }
.unmute {
  position: absolute; top: 8px; left: 8px; min-height: 44px;
  border: 0; border-radius: 999px; color: #fff; background: rgb(0 0 0 / 0.6);
}
.unmute:hover { background: rgb(0 0 0 / 0.8); }
.unmute[hidden] { display: none; }
/* The stage goes full screen, not the <video>: the zoom stays inside it. */
.stage:fullscreen { border-radius: 0; }
#viewer .stage:fullscreen video { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }

/* The call's lives as tabs above the picture (call-tabs spec 6.1). */
.lives { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
#lives[hidden] { display: none; }
.lives button { min-height: 36px; padding: 4px 14px; border-radius: 999px; }
.lives button[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* Side by side (call-tabs spec 6.2): one stage per live, stacked on narrow screens, the one with the
   sound marked. */
.stages.side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
@media (min-width: 900px) { .stages.side { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); } }
.stages.side .stage { min-width: 0; }
.stages.side .stage.sounded { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ------------------------------------------------------------ meta line, badge */
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 0; color: var(--muted); font-size: 0.9375rem; }
.meta .sep { width: 4px; height: 4px; border-radius: 50%; background: var(--border); margin: 0 6px; }
.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; }
.top .meta { margin: 0; }
.meta .chime { min-height: 32px; padding: 4px 6px; }
/* The bell and its volume wrap as one: on a phone the slider never ends up alone on a line. */
.chime-group { display: inline-flex; align-items: center; gap: 6px; }
#chime-volume { width: 88px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.title { display: flex; align-items: center; gap: 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600; border: 1px solid var(--border); color: var(--muted);
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge[data-state="live"] { color: #fff; background: var(--accent); border-color: var(--accent); }
.badge[data-state="restarting"], .badge[data-state="reconnecting"] { color: var(--warning); border-color: currentColor; }
.badge[data-state="error"] { color: var(--warning); border-color: currentColor; }

/* ------------------------------------------------------------ host layout */
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 16px; }
@media (max-width: 959.98px) {
  .grid { gap: 12px; }
  .grid > .col { display: contents; }
  #host-chat, .grid .room { order: 1; }
  #discord { order: 2; }
  #preview-toggle { justify-self: start; }
}
@media (min-width: 960px) { .grid { grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); align-items: start; } }
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#host-state, #host-stats, #host-server { margin: 0; color: var(--muted); }
#host-upstream { margin: 0; color: var(--warning); }
[data-level="warn"] { color: var(--warning); }
[data-level="bad"] { color: var(--danger); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
form.card { display: flex; flex-direction: column; gap: 20px; }
#config[hidden] { display: none; }
.group { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 10px; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pair > .wide { grid-column: 1 / -1; }
.advanced { display: flex; flex-direction: column; gap: 10px; }
.advanced summary { cursor: pointer; font-weight: 600; }
#adv-reset { align-self: flex-start; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 0.875rem; font-weight: 500; color: var(--text); margin: 0; }
.help { margin: 0; font-size: 0.8125rem; color: var(--muted); }
.help.warn { color: var(--warning); }
.check { display: flex; align-items: center; gap: 10px; min-height: 32px; cursor: pointer; }
.apps { display: flex; flex-direction: column; max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 12px; }
.apps:empty { display: none; }
.apps .check { overflow-wrap: anywhere; flex-shrink: 0; } /* a long name wraps; rows never squeeze and overlap */
.apps .check input { flex: none; }
.apps .exe { color: var(--muted); font-size: 0.875rem; }
/* Sound that stays out of the stream: a checked app or microphone. */
.apps .check:has(input:checked), .check:has(#mic-out:checked) { text-decoration: line-through; }

/* ------------------------------------------------------------ controls */
select, input[type="number"], input[readonly], #gate-name {
  font: inherit; min-height: 44px; padding: 8px 12px; min-width: 0; width: 100%;
  border-radius: var(--radius-sm); border: 1px solid var(--field-border); background: var(--field); color: var(--text);
  transition: border-color var(--ease);
}
select:hover, input[type="number"]:hover, #gate-name:hover { border-color: var(--muted); }
input[readonly] { color: var(--muted); text-overflow: ellipsis; }
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
input[role="switch"] {
  appearance: none; flex: none; position: relative; width: 40px; height: 22px; border-radius: 999px;
  background: var(--border); transition: background-color var(--ease);
}
input[role="switch"]::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text); transition: transform var(--ease), background-color var(--ease);
}
input[role="switch"]:checked { background: var(--accent); }
input[role="switch"]:not(:checked) { box-shadow: inset 0 0 0 1px var(--muted); }
input[role="switch"]:checked::before { transform: translateX(18px); background: var(--on-accent); }
input[role="switch"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button {
  font: inherit; font-weight: 550; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: var(--field); color: var(--text);
  transition: background-color var(--ease), border-color var(--ease), transform var(--ease);
  touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:active:not(:disabled) { transform: scale(0.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border); }
button.ghost.flush { padding-inline: 0; border-width: 0; }
button.danger { color: var(--leave); }
button.danger:hover:not(:disabled) { color: var(--leave); border-color: currentColor; }
button:disabled, select:disabled, input:disabled { opacity: 0.45; cursor: not-allowed; }
button.done { color: var(--ok); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.buttons #refresh { margin-left: auto; }
.link { display: flex; gap: 8px; margin-top: 8px; }
.link input { flex: 1; }

/* ------------------------------------------------------------ warnings */
.warnings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.warnings li {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--warning); background: var(--warning-bg); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
}
.warnings li .icon { margin-top: 3px; }

/* ------------------------------------------------------------ names in advice and the room */
.warnings .name, .room .name {
  font-weight: 650; color: var(--text); background: var(--field); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 5px; overflow-wrap: anywhere; unicode-bidi: isolate;
}

/* ------------------------------------------------------------ in the room */
.room { display: flex; flex-direction: column; gap: 10px; }
.room h2 { margin: 0; }
.room-group { display: flex; flex-direction: column; gap: 6px; }
.room-group[hidden] { display: none; }
.discord { display: flex; flex-direction: column; gap: 12px; }
.discord h2 { margin: 0; }
.discord[hidden], .discord-part[hidden] { display: none; }
#announce-channel-field[hidden] { display: none; }
#discord-login-row[hidden], #discord-change[hidden], #announce-retry[hidden] { display: none; }
.discord-part { display: flex; flex-direction: column; gap: 10px; }
.discord .help:empty { display: none; }
.discord .help a { color: var(--text); }
/* The call line's names in Discord's own look: the voice channel as a mention pill, the server as
   blurple text. Not --ok: green reads as a status on this page. Contrast ≥ 6.4:1 in both themes. */
.discord-channel {
  color: var(--mention); background: var(--mention-bg); font-weight: 500;
  padding: 0 4px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.discord-guild { color: var(--blurple); font-weight: 600; }
/* One row per viewer, Kick and Ban at its end (kick-ban spec 5.2): wrapped chips made it unclear
   which buttons belonged to which name. */
.names { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.names .freeze { color: var(--danger); font-size: 0.85em; }
.names li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.names .row-actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.names button { min-height: 28px; padding: 2px 8px; font-size: 0.8rem; }
.room-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 0.875rem; color: var(--muted); }
.room-log:empty { display: none; }
.room-log time { font-variant-numeric: tabular-nums; margin-right: 6px; }
/* Each line's action in its own color, with a dot of it before the time. */
.room-log li { --kind: var(--muted); }
.room-log li::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--kind); margin-right: 8px; vertical-align: 0.1em; }
.room-log .action { color: var(--kind); font-weight: 550; }
.room-log [data-kind="watching"] { --kind: var(--ok); }
.room-log [data-kind="page"] { --kind: var(--info); }
.room-log [data-kind="stopped"] { --kind: var(--warning); }
.room-log [data-kind="left"] { --kind: var(--leave); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (max-width: 480px) {
  main { padding: 12px; }
  .pair { grid-template-columns: 1fr; }
  .buttons #refresh { margin-left: 0; }
  /* The bell group often wraps here: its dot would hang at the end of the line above. */
  .top .meta .sep:has(+ .chime-group) { display: none; }
}
/* Phone on its side: the picture gets the whole height; the count line is a scroll away. */
@media (orientation: landscape) and (max-height: 500px) {
  main:has(#viewer:not([hidden])) { padding: 0; }
  #viewer .stage { border-radius: 0; }
  #viewer video { max-height: 100dvh; }
  #viewer .meta { padding: 0 8px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------------------ viewer gate */
.gate { max-width: 400px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 16px; }
.gate[hidden], .gate-part[hidden] { display: none; }
.gate-part { display: flex; flex-direction: column; gap: 12px; }
#gate-name { font-size: 16px; } /* below 16px iOS Safari zooms the page on focus */
.gate-or { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--muted); font-size: 0.8125rem; }
.gate-or::before, .gate-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.gate .help:empty { display: none; }
/* A Discord login in the room list (viewer-name-gate spec 4.3). */
.discord-mark { width: 14px; height: 14px; margin-left: 4px; vertical-align: -2px; color: var(--blurple); }

/* ------------------------------------------------------------ chat (live-chat spec 5, 6) */
.chat {
  display: flex; flex-direction: column; flex: 1 1 280px; min-height: 280px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.chat[hidden] { display: none; }
/* Wide and tall enough: the chat is a column beside the picture, as on Twitch. */
@media (min-width: 900px) and (min-height: 501px) {
  #viewer:not([hidden]) { flex-direction: row; align-items: stretch; }
  #viewer:has(#chat:not([hidden])) .watch { flex: 1 1 auto; }
  #viewer:has(#chat:not([hidden])) .watch::before,
  #viewer:has(#chat:not([hidden])) .meta { flex: 1 1 0; }
  #viewer .chat { flex: none; width: 340px; height: calc(100dvh - 16px); min-height: 0; }
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 4px 12px; border-bottom: 1px solid var(--border); }
.chat-head button { min-height: 36px; width: 36px; padding: 0; }
.chat-body { position: relative; display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.chat-list {
  list-style: none; margin: 0; padding: 8px 12px; flex: 1 1 auto; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px; font-size: 0.9375rem; line-height: 1.4; overflow-wrap: anywhere;
}
.chat-list:empty::before { content: "No messages yet."; color: var(--muted); }
.chat-host {
  display: inline-block; margin-right: 6px; padding: 0 4px; border-radius: 4px; vertical-align: 0.1em;
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.04em; color: var(--on-accent); background: var(--accent);
}
.chat-list .discord-mark, .chat-toasts .discord-mark { margin: 0 4px 0 0; }
.chat-name { font-weight: 650; unicode-bidi: isolate; }
.chat-name::after { content: ":"; margin-right: 6px; }
.chat-text { unicode-bidi: isolate; }
.chat-name[data-color="0"] { color: var(--chat-0); }
.chat-name[data-color="1"] { color: var(--chat-1); }
.chat-name[data-color="2"] { color: var(--chat-2); }
.chat-name[data-color="3"] { color: var(--chat-3); }
.chat-name[data-color="4"] { color: var(--chat-4); }
.chat-name[data-color="5"] { color: var(--chat-5); }
.chat-name[data-color="6"] { color: var(--chat-6); }
.chat-name[data-color="7"] { color: var(--chat-7); }
.chat-more {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); width: max-content; margin: 0 auto;
  min-height: 32px; padding: 4px 12px; border-radius: 999px; font-size: 0.8125rem; box-shadow: 0 2px 8px rgb(0 0 0 / 0.3);
}
.chat-more[hidden] { display: none; }
.chat-form { position: relative; padding: 8px 12px 12px; border-top: 1px solid var(--border); }
/* 16px: below it iOS Safari zooms the page on focus. */
.chat-form input {
  font: inherit; font-size: 16px; width: 100%; min-height: 44px; padding: 8px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--field-border); background: var(--field); color: var(--text);
}
.chat-form input:hover:not(:disabled) { border-color: var(--muted); }
.chat-note, .chat-who { padding: 0 12px 10px; }
.chat-note:empty { display: none; }
.unread {
  min-width: 20px; padding: 0 6px; border-radius: 999px; line-height: 20px; text-align: center;
  font-size: 0.75rem; font-weight: 700; color: var(--on-accent); background: var(--accent);
}
.unread[hidden] { display: none; }
.unread.pulse { animation: chat-pulse 600ms ease-out; }
@keyframes chat-pulse { from { transform: scale(1.4); } to { transform: scale(1); } }
.meta .chat-toggle { min-height: 32px; padding: 4px 8px; gap: 6px; }
/* The host page's card (live-chat spec 6): its title folds it. */
.chat-card { display: flex; flex-direction: column; gap: 4px; padding: 8px 4px 4px; }
.chat-card h2 { padding: 0 8px; }
.chat-fold {
  min-height: 32px; padding: 4px 6px; margin-left: -6px; gap: 8px;
  font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit;
}
/* Grows a line at a time up to 320 px, then scrolls: no tall empty box, and no 200 px jump of the
   cards below (Kick, Ban) when the first message arrives. */
.chat-card .chat-body { max-height: 320px; }
#host-chat-body[hidden] { display: none; }
/* Messages that arrive unseen, over the picture (spec 5.3): never in the way of a click or a touch. */
.chat-toasts {
  position: absolute; left: 12px; bottom: 64px; z-index: 1; margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 6px; max-width: min(70%, 420px); pointer-events: none;
}
.chat-toasts li {
  padding: 6px 10px; border-radius: var(--radius-sm); color: #fff; background: rgb(0 0 0 / 0.65);
  font-size: 0.9375rem; line-height: 1.4; overflow-wrap: anywhere; animation: toast-in 160ms ease-out;
}
.chat-toasts .chat-name[data-color] { color: #fde68a; } /* on the dark toast in both themes */
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .unread.pulse, .chat-toasts li { animation: none; }
}
