/* selfcast public site — DESIGN.md §4 tokens, mobile-first. No external fonts or images. */

:root {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1c2130;
  --border: #2a3142;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --accent: #e11d48;
  --accent-contrast: #ffffff;
  --live: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --hh: 56px;                       /* site header height */
  --name-l: 68%;                    /* chat name lightness (per theme) */
  --mention-bg: rgba(245, 158, 11, 0.16);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fa;
    --surface: #ffffff;
    --surface-2: #eef0f5;
    --border: #dde1ea;
    --text: #12141a;
    --muted: #5b6475;
    --name-l: 36%;
    --mention-bg: rgba(245, 158, 11, 0.2);
    --shadow: 0 10px 30px rgba(18, 20, 26, 0.15);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
}

img, svg, video { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
p { margin: 0 0 0.75em; }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent); }
.prose a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 8px; top: -60px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

.muted { color: var(--muted); }
.spacer { flex: 1; }
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ------------------------------------------------------------------ buttons, chips, badges */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-accent:hover { filter: brightness(1.1); color: var(--accent-contrast); border-color: var(--accent); }
.btn-danger { color: var(--err); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.875rem; }
.btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 1.05rem; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 999px;
  background: transparent; color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.linkish {
  border: 0; background: none; padding: 4px 6px;
  color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
  min-height: 32px;
}

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
}
.chip-warn { color: var(--warn); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge-live { background: var(--live); color: #fff; }
.badge-live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.badge-warn { background: var(--warn); color: #1a1205; }
.badge-dur { background: rgba(0, 0, 0, 0.75); color: #fff; }

/* ------------------------------------------------------------------ header + footer */
/* viewport-fit=cover: the page runs under the notch / status bar / home indicator — keep content in the safe area */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: calc(var(--hh) + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 8px;
  padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
  font-weight: 800; font-size: 1.05rem;
  text-decoration: none;
}
.brand img { width: 28px; height: 28px; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-nav { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.site-nav a {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 10px;
  border-radius: 999px;
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.92rem;
}
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.nav-live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); }
.btn .ic, .icon-btn .ic { max-width: none; }
.notify-btn { min-width: 40px; min-height: 40px; padding: 0 10px; }
.notify-btn .lbl { display: none; }
@media (min-width: 640px) {
  .site-header { padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); gap: 16px; }
  .notify-btn .lbl { display: inline; }
}
@media (max-width: 380px) {
  .site-nav a { padding: 0 8px; font-size: 0.85rem; }
  .brand { font-size: 0.95rem; }
}

main { display: block; max-width: 1480px; margin: 0 auto; padding: 16px; }

.site-footer {
  max-width: 1480px; margin: 24px auto 0; padding: 24px 16px calc(40px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.875rem;
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center;
}
.site-footer a { color: var(--muted); }

/* ------------------------------------------------------------------ offline hero (home) */
.hero {
  position: relative;
  text-align: center;
  padding: 40px 16px;
  border-radius: var(--radius);
  background:
    radial-gradient(120% 120% at 50% 0%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}
.hero h1 { font-size: clamp(1.6rem, 6vw, 2.6rem); margin-bottom: 0.25em; overflow-wrap: anywhere; }
.hero .tagline { color: var(--muted); font-size: 1.05rem; margin-bottom: 1.5em; }
.hero-status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px; margin-bottom: 16px;
  border-radius: 999px; background: var(--surface-2);
  color: var(--muted); font-weight: 600; font-size: 0.875rem;
}
.hero-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.next-card {
  display: inline-block;
  max-width: 100%;
  margin: 0 auto 20px;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.next-card .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.next-card .title { font-size: 1.2rem; font-weight: 700; margin: 4px 0; overflow-wrap: anywhere; }
.countdown { font-size: clamp(1.3rem, 5vw, 1.8rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.countdown.due { color: var(--accent); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.starting-banner {
  margin: 0 auto 16px; max-width: 560px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--live) 20%, var(--surface));
  border: 1px solid var(--live);
  font-weight: 600;
}
.poll-error { margin-top: 12px; color: var(--warn); font-size: 0.875rem; }

/* ------------------------------------------------------------------ replays grid */
.section-head { display: flex; align-items: baseline; gap: 12px; margin: 28px 0 12px; }
.section-head h2 { margin: 0; font-size: 1.25rem; }
.section-head a { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px 16px;
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; }
}
.card { display: block; text-decoration: none; color: var(--text); min-width: 0; border-radius: var(--radius-sm); }
.card:hover { color: var(--text); }
.card:hover .card-title { color: var(--accent); }
.card-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.card-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-noimg { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; color: var(--muted); font-size: 2rem; }
.card-thumb .badge { position: absolute; right: 6px; bottom: 6px; }
.card-thumb .badge-live { left: 6px; right: auto; top: 6px; bottom: auto; }
.card-body { padding: 8px 2px 0; }
.card-title {
  margin: 0; font-size: 0.98rem; font-weight: 650;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.card-meta { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }
.load-more { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 24px 0; }
.form-err, .load-error { color: var(--err); }
.empty { color: var(--muted); padding: 24px 0; }
.search { display: flex; gap: 8px; margin: 0 0 16px; max-width: 520px; }
.search input {
  flex: 1; min-width: 0; height: 40px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); font-size: 16px;
}

/* ------------------------------------------------------------------ prose pages */
.prose { max-width: 760px; }
.prose h1 { font-size: 1.8rem; }
.prose h2 { font-size: 1.25rem; margin-top: 1.6em; }
.prose ul { padding-left: 1.2em; }
.links, .prose ul.links { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.prose .btn { color: var(--text); text-decoration: none; }
.prose .btn-accent { color: var(--accent-contrast); }

/* ------------------------------------------------------------------ watch layout */
.watch { display: flex; flex-direction: column; }
.stage { min-width: 0; }
.title-row { padding: 12px 0 4px; }
.title-row h1 {
  font-size: 1.2rem; margin: 0 0 6px;
  overflow-wrap: anywhere;
}
.title-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; color: var(--muted); font-size: 0.875rem; }
.title-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; position: relative; }
.share-menu {
  position: absolute; z-index: 30; top: 46px; right: 0;
  display: flex; flex-direction: column; min-width: 220px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.share-menu button { justify-content: flex-start; border: 0; background: transparent; border-radius: 6px; }
.share-menu button:hover { background: var(--surface); }
.new-stream {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  margin: 0 0 12px; padding: 10px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--live);
  background: color-mix(in srgb, var(--live) 15%, var(--surface));
}
.desc { color: var(--text); overflow-wrap: anywhere; }
.desc-box { padding: 12px 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; min-height: 44px;
  border: 0; border-bottom: 3px solid transparent;
  background: transparent; color: var(--muted); font-weight: 700; cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.show-chat { display: none; }
.chat-off { color: var(--muted); padding: 16px; }

/* Phones: player on top, title, then Chat | About tabs filling the rest of the screen. */
@media (max-width: 899px) {
  .page-watch main { padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
  .page-watch .site-footer { display: none; }
  .watch {
    min-height: calc(100vh - var(--hh) - env(safe-area-inset-top, 0px));
    height: calc(100vh - var(--hh) - env(safe-area-inset-top, 0px));
    height: calc(100dvh - var(--hh) - env(safe-area-inset-top, 0px));
  }
  .stage { flex: none; }
  .stage .pl { border-radius: 0; max-height: 45vh; max-height: 45dvh; }
  .title-row { padding: 10px 16px 0; }
  .title-row h1 { font-size: 1.05rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .title-actions { margin-top: 8px; }
  .stage .desc-box { display: none; }
  .watch-tabs { flex: none; margin-top: 8px; padding: 0 8px; }
  .panes { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .pane { flex: 1; min-height: 0; }
  .pane-about { overflow-y: auto; padding: 12px 16px; }
  .watch[data-tab="chat"] .pane-about, .watch[data-tab="about"] .pane-chat { display: none; }
  /* the composer is the last thing on the screen: keep it above the home indicator */
  .pane-chat .chat { border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; height: 100%; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .chat-collapse { display: none; }
  .new-stream { margin: 8px 16px 0; }
  .title-meta { gap: 4px 10px; }
  .title-actions .btn { min-height: 40px; padding: 0 14px; }
  .share-lbl { display: none; }
  /* the title row's "Watch from the beginning" is right under the player on phones (embeds have no title row) */
  .page-watch .pl:not(.pl-fullscreen) .pl-startchip { display: none; }
}
/* Landscape phones: there is no room for a fixed-height column — let the page scroll. */
@media (max-width: 899px) and (max-height: 520px) {
  .watch { height: auto; }
  .stage .pl { max-height: none; }
  .pane-chat { height: 80vh; }
}

@media (min-width: 900px) {
  .watch {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 16px;
    align-items: start;
  }
  .watch-tabs, .pane-about { display: none; }
  .panes { position: sticky; top: calc(var(--hh) + env(safe-area-inset-top, 0px) + 16px); height: calc(100vh - var(--hh) - env(safe-area-inset-top, 0px) - 32px); min-height: 420px; }
  .pane-chat { height: 100%; }
  .pane-chat .chat { height: 100%; }
  .stage .pl { max-height: calc(100vh - var(--hh) - 170px); }
  .watch.chat-collapsed { grid-template-columns: minmax(0, 1fr) 0; gap: 0; }
  .watch.chat-collapsed .panes { display: none; }
  .watch.chat-collapsed .show-chat { display: inline-flex; }
  .title-row h1 { font-size: 1.35rem; }
}
@media (min-width: 1300px) {
  .watch { grid-template-columns: minmax(0, 1fr) 380px; }
}

/* ------------------------------------------------------------------ player */
.pl {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  color: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;       /* no double-tap zoom on the player (taps toggle the controls) */
  isolation: isolate;
}
.pl-video, .pl-surface, .pl-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.pl-video { object-fit: contain; background: #000; z-index: 0; }
.pl-art { z-index: 1; display: flex; align-items: center; justify-content: center; background: #000; }
.pl-art img { width: 100%; height: 100%; object-fit: contain; opacity: 0.45; }
.pl-art-label { position: absolute; padding: 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.7); font-weight: 700; }
.pl-surface { z-index: 2; }
.pl.pl-idle { cursor: none; }

.pl-spinner {
  position: absolute; left: 50%; top: 50%; z-index: 3;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: pl-spin 0.9s linear infinite;
  pointer-events: none;
}
@keyframes pl-spin { to { transform: rotate(360deg); } }

.pl-bigplay {
  position: absolute; left: 50%; top: 50%; z-index: 4;
  width: 76px; height: 76px; margin: -38px 0 0 -38px;
  border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.62); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.pl-bigplay .ic { width: 40px; height: 40px; margin-left: 4px; }
.pl-bigplay:hover { background: var(--accent); }

.pl-banner {
  position: absolute; z-index: 5; top: 10px; left: 10px; right: 10px;
  margin: 0 auto; max-width: 560px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--warn);
  background: rgba(10, 12, 18, 0.86);
  font-size: 0.875rem; line-height: 1.35;
  pointer-events: none;
}
.pl-banner-warn { border-left-color: var(--err); }
.pl-banner-info { border-left-color: var(--accent); }

.pl-chip {
  position: absolute; z-index: 5;
  min-height: 40px; padding: 0 14px;
  border: 0; border-radius: 999px;
  background: rgba(10, 12, 18, 0.82); color: #fff;
  font-weight: 700; font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.pl-chip:hover { background: var(--accent); }
.pl-startchip { left: 12px; bottom: 86px; background: var(--accent); }
.pl-startchip:hover { filter: brightness(1.1); }
/* same corner as the "Resume at …?" toast: when both are up, the chip sits above it */
.pl-toast:not([hidden]) ~ .pl-startchip { bottom: 140px; }
.pl-unmute { right: 12px; top: 12px; }
.pl-banner:not([hidden]) ~ .pl-unmute { top: 64px; }

.pl-toast {
  position: absolute; z-index: 6; left: 12px; bottom: 86px;
  display: flex; align-items: center; gap: 8px;
  max-width: calc(100% - 24px);
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.9);
  font-size: 0.9rem;
}
.pl-toast:not([hidden]) ~ .pl-overlay { display: none; }
.pl-x { width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.pl-overlay {
  position: absolute; inset: 0; z-index: 7;
  display: flex; align-items: center; justify-content: center;
  padding: 16px 16px 70px;
  background: rgba(5, 6, 10, 0.78);
  text-align: center;
}
.pl-card { max-width: 440px; }
.pl-card h2 { font-size: clamp(1rem, 3.5vw, 1.35rem); margin-bottom: 6px; }
.pl-card p { color: #cfd4de; font-size: 0.92rem; }
.pl-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.pl-overlay .btn:not(.btn-accent) { background: rgba(255, 255, 255, 0.12); border-color: transparent; color: #fff; }
.pl-overlay-unsupported, .pl-overlay-error { padding-bottom: 16px; }

.pl-controls {
  position: absolute; z-index: 8; left: 0; right: 0; bottom: 0;
  padding: 28px 8px 2px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0.35) 65%, transparent);
  transition: opacity 0.25s;
}
.pl.pl-idle .pl-controls, .pl.pl-idle .pl-startchip, .pl.pl-idle .pl-toast { opacity: 0; pointer-events: none; }
.pl-overlay-error ~ .pl-controls, .pl-overlay-unsupported ~ .pl-controls { display: none; }

.pl-seek {
  position: relative;
  height: 24px;
  display: flex; align-items: center;
  margin: 0 6px;
  cursor: pointer;
  touch-action: none;
}
.pl-seek:focus-visible { outline-offset: 0; }
/* the track grows on hover with a transform (no layout per frame); the knob lives outside it so it isn't squashed */
.pl-track {
  position: relative; width: 100%; height: 6px;
  background: rgba(255, 255, 255, 0.24);
  border-radius: 3px;
  transform: scaleY(0.667);
  transition: transform 0.1s;
}
.pl-seek:hover .pl-track, .pl-seek.dragging .pl-track, .pl-seek:focus-visible .pl-track { transform: none; }
.pl-buffered span { position: absolute; top: 0; bottom: 0; background: rgba(255, 255, 255, 0.42); border-radius: 2px; }
.pl-played { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 2px; }
.pl-knob {
  position: absolute; top: 50%;
  width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3);
  transform: scale(0.85);
  transition: transform 0.1s;
}
.pl-seek:hover .pl-knob, .pl-seek.dragging .pl-knob { transform: scale(1.15); }
.pl-tip {
  position: absolute; bottom: 26px;
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(10, 12, 18, 0.92);
  font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap;
  pointer-events: none;
}

.pl-bar { display: flex; align-items: center; gap: 2px; min-height: 44px; }
.pl-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 40px; height: 40px; padding: 0 8px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: #fff;
  cursor: pointer;
  flex: none;
}
.pl-btn:hover { background: rgba(255, 255, 255, 0.14); }
.pl-btn .ic { width: 24px; height: 24px; }
.pl-volwrap { display: flex; align-items: center; }
.pl-vol { width: 84px; accent-color: var(--accent); }
.pl-time {
  padding: 0 6px;
  font-size: 0.82rem; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden;
  min-width: 0;
}
.pl-rest { color: #cfd4de; }
.pl-spacer { flex: 1; min-width: 0; }
.pl-live {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px; margin: 0 4px;
  border: 0; border-radius: 999px;
  background: rgba(255, 255, 255, 0.18); color: #fff;
  font-weight: 800; font-size: 0.75rem; letter-spacing: 0.05em;
  cursor: pointer; flex: none; white-space: nowrap;
}
.pl-live .dot { width: 8px; height: 8px; border-radius: 50%; background: #c3c8d3; }
.pl-live.at-edge { background: var(--live); cursor: default; }
.pl-live.at-edge .dot { background: #fff; }
.pl-live:not(.at-edge):hover { background: var(--accent); }
.pl-start-lbl { font-size: 0.82rem; font-weight: 600; }
.pl-q-badge {
  position: absolute; right: 0; top: 2px;
  padding: 0 3px; border-radius: 3px;
  background: var(--accent); color: #fff;
  font-size: 0.55rem; font-weight: 800; line-height: 1.4;
}
.pl-q-badge:empty { display: none; }
.pl-menu {
  position: absolute; right: 8px; bottom: 58px; z-index: 9;
  min-width: 210px; max-width: calc(100% - 16px); max-height: calc(100% - 68px); overflow-y: auto;
  padding: 6px;
  border-radius: var(--radius-sm);
  background: rgba(16, 19, 27, 0.97);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  overscroll-behavior: contain;
}
.pl-speedrow { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 2px 2px; }
.pl-speedrow .pl-mi { width: auto; flex: 1 0 auto; justify-content: center; padding: 0 8px; }
.pl-speedrow .pl-mi::before { display: none; }
.pl-speedrow .pl-mi[aria-checked="true"] { background: var(--accent); color: #fff; }
.pl-mgroup + .pl-mgroup { border-top: 1px solid rgba(255, 255, 255, 0.12); margin-top: 4px; padding-top: 4px; }
.pl-mhead { padding: 4px 10px; color: #9aa3b5; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.pl-mi {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 6px;
  background: transparent; color: #fff; text-align: left; font-size: 0.9rem;
  cursor: pointer;
}
.pl-mi::before { content: ""; width: 14px; flex: none; text-align: center; }
.pl-mi[aria-checked="true"]::before { content: "✓"; color: var(--accent); font-weight: 800; }
.pl-mi:hover, .pl-mi:focus-visible { background: rgba(255, 255, 255, 0.12); }

.pl.pl-fullscreen { border-radius: 0; aspect-ratio: auto; width: 100%; height: 100%; max-height: none !important; }
/* CSS full screen for devices without element full screen (iPhone): cover the page and keep our own controls */
.pl.pl-pseudofs {
  position: fixed; inset: 0; z-index: 100;
  width: auto; height: auto;
  touch-action: none;               /* nothing behind may scroll or zoom */
}
.pl-pseudofs .pl-menu { touch-action: pan-y; }
html.sc-pseudofs, html.sc-pseudofs body { overflow: hidden; overscroll-behavior: none; }
/* full screen on notched phones: controls and chips stay out of the notch and off the home indicator */
.pl.pl-fullscreen .pl-controls {
  padding-left: max(4px, env(safe-area-inset-left, 0px));
  padding-right: max(4px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(2px + env(safe-area-inset-bottom, 0px));
}
.pl.pl-fullscreen .pl-banner { top: calc(10px + env(safe-area-inset-top, 0px)); }
.pl.pl-fullscreen .pl-unmute { top: calc(12px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); }
.pl.pl-fullscreen .pl-banner:not([hidden]) ~ .pl-unmute { top: calc(64px + env(safe-area-inset-top, 0px)); }
.pl.pl-fullscreen .pl-startchip, .pl.pl-fullscreen .pl-toast { left: max(12px, env(safe-area-inset-left, 0px)); }

@media (hover: none), (pointer: coarse) {
  .pl-vol { display: none; }
  .pl-seek { height: 32px; }
  .pl-live { height: 36px; }
}
@media (max-width: 639px) {
  .pl-start-lbl { display: none; }
}
/* PiP is never hidden by width: feature detection already decides whether it exists */
@media (max-width: 480px) {
  .pl-vol { display: none; }
  .pl-bar { gap: 0; }
  .pl-btn { min-width: 38px; padding: 0 6px; }
  .pl-live { padding: 0 9px; margin: 0 2px; }
  .pl-time { font-size: 0.76rem; padding: 0 4px; }
  .pl-controls { padding-left: 4px; padding-right: 4px; }
  .pl-startchip { bottom: 82px; font-size: 0.85rem; }
  .pl-banner { font-size: 0.8rem; }
}
/* 320–400 px: the time must stay readable. The in-bar "From start" goes (the title row has "Watch from the
   beginning", the seek bar reaches 0:00), and behind live the time shortens to how far behind you are. */
@media (max-width: 399px) {
  .pl-start { display: none; }
  .pl-time.is-behind .pl-pos, .pl-time.is-behind .pl-sep { display: none; }
}
@media (max-width: 359px) {
  .pl-btn { min-width: 34px; padding: 0 3px; }
  .pl-btn .ic { width: 22px; height: 22px; }
  .pl-live { padding: 0 8px; margin: 0 1px; letter-spacing: 0.02em; }
  .pl-live:not(.at-edge) .dot { display: none; }
}

/* ------------------------------------------------------------------ embed */
.page-embed, .page-embed body { background: #000; }
.page-embed main { padding: 0; max-width: none; }
.embed-wrap { position: fixed; inset: 0; }
.embed-wrap .pl { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; }
.embed-brand {
  position: absolute; z-index: 10; top: 8px; left: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.8rem; font-weight: 700; text-decoration: none;
}
.embed-offline { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px; color: #fff; text-align: center; }

/* ------------------------------------------------------------------ chat */
.chat {
  display: flex; flex-direction: column;
  min-height: 0; height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-head {
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 4px 6px 4px 14px;
  border-bottom: 1px solid var(--border);
}
.chat-title { margin: 0; font-size: 0.95rem; }
.chat-mode { color: var(--muted); font-size: 0.8rem; }
.chat-mode-live::before { content: "● "; color: var(--live); }
.chat-modebtn {
  min-height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
}
.chat-conn { padding: 6px 14px; font-size: 0.82rem; background: var(--surface-2); color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chat-conn.warn { color: var(--warn); }
.chat-pinned {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.88rem; overflow-wrap: anywhere;
}
.pin-ic { width: 14px; height: 14px; color: var(--accent); align-self: center; }
.chat-mod { border-bottom: 1px solid var(--border); }
.chat-modbar summary { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; cursor: pointer; font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.chat-modbar .row { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.chat-modbar select { height: 36px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 10px; font-size: 0.85rem; }
.chat-listwrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-list {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 10px;
  font-size: 0.92rem;
}
.chat-list:focus-visible { outline-offset: -3px; }
.cm {
  position: relative;
  padding: 3px 34px 3px 6px;
  border-radius: 6px;
  line-height: 1.42;
  overflow-wrap: anywhere;
}
.cm:hover { background: var(--surface-2); }
.cm-time { display: none; margin-right: 4px; color: var(--muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.cm:hover .cm-time, .cm:focus-within .cm-time, .cm.cm-showtime .cm-time { display: inline; }   /* touch: tap a line */
.cm-name { font-weight: 700; color: hsl(var(--h, 210) 75% var(--name-l)); }
/* Right-to-left text in a message (or a pinned line) must not visually reorder around the name (SECURITY.md IMP-5). */
.cm-name, .cm-text, .chat-pinned .cm-name, .chat-pinned .cm-text { unicode-bidi: isolate; }
/* Tags come only from server fields: new chatter, evader flag (mods), held line. */
.cm-tag {
  display: inline-block; margin-left: 0.35em; padding: 0 0.4em; border-radius: 4px; font-size: 0.7rem;
  font-weight: 600; vertical-align: 0.1em; background: var(--surface-2); color: var(--muted);
}
.cm-tag-flag { background: rgba(234, 88, 12, 0.18); color: #ea580c; }
.cm-tag-held { background: rgba(202, 138, 4, 0.18); color: #ca8a04; }
.cm-held-line { opacity: 0.75; }
.card-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0.5rem 0 0; }
.card-list dt { color: var(--muted); }
.card-list dd { margin: 0; overflow-wrap: anywhere; }
.cm-guest { font-style: italic; }
.cm-sep { color: var(--muted); }
.cm-badge {
  display: inline-block; margin-right: 4px; padding: 0 5px;
  border-radius: 4px; vertical-align: 1px;
  font-size: 0.66rem; font-weight: 800; letter-spacing: 0.04em;
  background: var(--surface-2); color: var(--text);
}
.cm-admin { background: var(--accent); color: var(--accent-contrast); }
.cm-mod { background: var(--ok); color: #05210f; }
.cm-at { font-weight: 600; }
.cm-at-me { color: var(--warn); }
.cm-mention { background: var(--mention-bg); box-shadow: inset 3px 0 0 var(--warn); }
.cm-text a { color: var(--accent); }
.cm-sys { color: var(--muted); font-style: italic; font-size: 0.85rem; }
.cm-act {
  position: absolute; right: 2px; top: 0;
  width: 32px; height: 28px;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; cursor: pointer;
}
.cm:hover .cm-act, .cm-act:focus-visible, .menu-open .cm-act { opacity: 1; }
@media (hover: none) {
  .cm-act { opacity: 0.6; }
  /* mods long-press a line for its menu: no text selection / iOS callout getting in the way */
  .chat.is-mod .cm { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}
.cm.cm-held { background: var(--surface-2); }
.msg-menu {
  position: absolute; right: 4px; top: 100%; z-index: 20;
  display: flex; flex-direction: column;
  min-width: 210px; padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.msg-menu-up { top: auto; bottom: 100%; }
.mm-item { min-height: 36px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-align: left; cursor: pointer; font-size: 0.88rem; }
.mm-item:hover, .mm-item:focus-visible { background: var(--surface); }
.mm-item.danger { color: var(--err); }
.chat-newpill {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  min-height: 34px; padding: 0 14px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 700; font-size: 0.82rem; cursor: pointer;
  box-shadow: var(--shadow);
}
.chat-note { padding: 6px 14px; font-size: 0.82rem; color: var(--muted); border-top: 1px solid var(--border); }
.chat-note.err { color: var(--warn); }
.chat-form { padding: 8px 10px; border-top: 1px solid var(--border); }
.chat-rules { display: flex; flex-wrap: wrap; gap: 4px; }
.chat-rules:not(:empty) { margin-bottom: 6px; }
.chat-err { margin-bottom: 6px; padding: 6px 10px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--err) 14%, var(--surface)); color: var(--text); font-size: 0.85rem; }
.chat-compose { display: flex; gap: 8px; }
.chat-input {
  flex: 1; min-width: 0; height: 42px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2);
  font-size: 16px;               /* <16px makes iOS zoom the page on focus */
}
.chat-send { min-height: 42px; }
.chat-counter { display: block; text-align: right; font-size: 0.72rem; color: var(--muted); min-height: 0; }
.chat-counter:empty { display: none; }
.chat-counter.over { color: var(--err); font-weight: 700; }
.chat-blocked p { margin: 0 0 8px; color: var(--muted); font-size: 0.9rem; }
.chat-blocked .row { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-who { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; padding: 0 12px 8px; font-size: 0.8rem; color: var(--muted); }
.chat-pick { padding: 8px 10px; border-top: 1px solid var(--border); }
.name-form { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.name-form .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.name-form input { flex: 1 1 10em; min-width: 0; }
.name-form-title { margin: 0; color: var(--text); font-size: 0.9rem; }
.name-form .pow { margin-bottom: 0; }
.name-form .form-err { margin: 0; font-size: 0.85rem; }
.chat-who .name-form { padding-top: 4px; }
.chat-who strong { color: var(--text); }

/* ------------------------------------------------------------------ dialogs + toasts */
dialog.modal {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 4px 20px; }
.modal-head h2 { margin: 0; flex: 1; font-size: 1.15rem; }
.modal .tabs { margin: 0 20px; }
.modal-body, .auth-form { padding: 12px 20px 20px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 600; font-size: 0.9rem; }
.field input {
  height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 16px; font-weight: 400;
}
.field small { font-weight: 400; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.end { justify-content: flex-end; }
.pow { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }
.pow progress { width: 100%; accent-color: var(--accent); }
.notify-status { margin: 0 0 12px; }
.notify-status.ok { color: var(--ok); }
.notify-status.warn { color: var(--warn); }
.notify-status.err { color: var(--err); }
.notify-ios ol { padding-left: 1.2em; margin: 0 0 12px; }
.notify-more { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.9rem; }

.toasts {
  position: fixed; z-index: 200; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  padding: 10px 16px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 0.9rem;
  box-shadow: var(--shadow);
  transition: opacity 0.4s;
}
.toast-err { background: var(--err); color: #fff; }
.toast.out { opacity: 0; }

/* ------------------------------------------------------------------ error page */
.error-page { text-align: center; padding: 60px 16px; }
.error-page .code { font-size: 3.5rem; font-weight: 900; color: var(--accent); line-height: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .pl-spinner { border-top-color: rgba(255, 255, 255, 0.25); border-color: rgba(255, 255, 255, 0.7); }
}
