:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --fg: #f5f7fa;
  --muted: #8a97a6;
  --accent: #3b82f6;
  --band: #111821;
  --line: #1b2430;
  --lyric-bg: #1c1c1f;          /* very dark gray — lower-third footer, distinct from captions (CHTR-6) */
  --tap: 44px; /* minimum comfortable touch target */
  /* CHTR-37: page font. Default Arial; the operator can override it via ?font= (app.js
     rewrites this variable, and loads the web font if it isn't web-safe). */
  --font-family: Arial, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* Author display rules below would otherwise beat the UA [hidden] rule, so keep
   hidden authoritative for the picker / view / settings toggles. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-family);
  font-size: 18px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;            /* the document never scrolls — only the inner panes do */
  overscroll-behavior: none;
}
button, input { font: inherit; }

/* Bounded viewport-height column. Header/search stay put; only the inner list /
   caption pane scrolls. height (not min-height) is what keeps the header pinned. */
main { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#picker, #view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* #view is the positioning context for the lower-third lyrics overlay (CHTR-6);
   overflow:hidden clips the footer while it's parked below the bottom edge. */
#view { position: relative; overflow: hidden; }

/* ── No event key (CHTR-24): the scan-a-QR prompt ──────────────────── */
.no-event { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.no-event-card { text-align: center; max-width: 22rem; }
.no-event-icon {
  width: 64px; height: 64px; margin: 0 auto 20px;
  display: block; fill: var(--accent);
}
.no-event-card h1 { margin: 0; font-size: 22px; font-weight: 600; line-height: 1.35; }

/* ── Language picker (first connect) ───────────────────────────────── */
.picker-head {
  flex: none;
  padding: 14px 16px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.picker-title { margin: 0 0 12px; font-size: 19px; font-weight: 600; text-align: center; }
.search {
  width: 100%;
  height: var(--tap);
  padding: 0 14px;
  border: 1px solid #2a3744;
  border-radius: 12px;
  background: var(--band);
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
}
.search::placeholder { color: var(--muted); }
.search:focus { outline: none; border-color: var(--accent); }

.picker-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 12px max(12px, env(safe-area-inset-bottom));
}
.section-head {
  padding: 14px 6px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

.lang-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  margin: 4px 0;
  padding: 9px 14px;
  border: 1px solid #223;
  border-radius: 12px;
  background: var(--band);
  color: var(--fg);
  cursor: pointer;
  text-align: start;
  -webkit-tap-highlight-color: transparent;
}
.lang-btn:active { border-color: var(--accent); background: #16202b; }
/* native + English side by side to keep rows short */
.lang-btn .labels { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.lang-btn .native { font-size: 17px; font-weight: 600; white-space: nowrap; }
.lang-btn .en { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Flag chip — reserved slot so names stay aligned whether or not a flag exists */
.flag {
  flex: none;
  display: block;
  width: 31px;
  height: 21px;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.flag svg { display: block; width: 100%; height: 100%; }
.flag-empty { box-shadow: none; background: none; } /* keeps the slot width, no empty box */

/* ── Caption view ──────────────────────────────────────────────────── */
.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.iconbtn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* CHTR-104: size to the icon, not a 44px-wide box, so the header items pack tightly — the
     visible gap between icons is then just the .bar gap (~½ an icon), equal across the row.
     Height stays var(--tap) for a comfortable vertical touch target. */
  width: auto;
  height: var(--tap);
  padding: 0;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.iconbtn:active { background: var(--band); color: var(--fg); }
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
/* CHTR-79: the spoken-audio toggle lights up bright green (not the blue accent) while audio is
   enabled, so "sound is on" reads at a glance and matches the page's green = active/live cue. */
#audio-toggle[aria-pressed="true"] { color: #22c55e; }
/* Swap the muted/active glyphs from the button's pressed state. MUST be CSS, not JS: the icons
   are <svg> and SVGElement has no `hidden` IDL property, so setting el.hidden never reflects to
   the attribute and the icons would never swap (only the colour would change). */
#audio-toggle .icon-audio-on { display: none; }
#audio-toggle[aria-pressed="true"] .icon-audio-off { display: none; }
#audio-toggle[aria-pressed="true"] .icon-audio-on { display: block; }

/* CHTR-104: the language label is tappable (changes language); dim it briefly on press. */
.lang-current { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  cursor: pointer; -webkit-tap-highlight-color: transparent; }
.lang-current:active { opacity: 0.6; }
.lang-current .flag { width: 27px; height: 18px; }
/* CHTR-104: stack the English name UNDER the native name to save horizontal space. */
.lang-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; line-height: 1.15; }
.lang-native { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lang-en { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* CHTR-104: status badge as a rounded pill. The border + text share currentColor, so each
   state just sets one colour. Three states: live (green), wait (amber, while connecting /
   reconnecting), idle (red — operator stopped; styled now, emitted by the CHTR-105 follow-up). */
.status {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  padding: 4px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--muted);
}
.status.live { color: #34d399; }   /* green  — connected (and, post-CHTR-105, operator running) */
.status.wait { color: #f59e0b; }   /* amber  — connecting / reconnecting */
.status.idle { color: #ef4444; }   /* red    — operator stopped */

.captions {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px clamp(16px, 5vw, 48px);
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* The lower-third band overlays the bottom of the view, so when it slides in app.js
     grows this padding to reserve matching space — the band SHRINKS the caption area
     rather than hiding its last lines. Eased to match the band's 1s slide. */
  transition: padding-bottom 1s cubic-bezier(0.22, 1, 0.36, 1);
}
.caption { margin: 0; font-size: clamp(20px, 5vw, 30px); color: var(--muted); }
.caption:last-child { color: var(--fg); font-weight: 600; }
/* CHTR-63: a provisional (in-flight progressive) caption is dimmed + italic until its
   corrected final replaces it in place. */
.caption.provisional { opacity: 0.55; font-style: italic; }

/* CHTR-61: per-speaker colour legend — a thin row of swatch+label chips above the captions,
   shown only when 2+ speakers are detected (toggled via [hidden] in app.js). */
.legend {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 8px clamp(16px, 5vw, 48px);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend-label { font-size: 12px; color: var(--muted); }

/* CHTR-62/105: "translation incoming" ellipsis — a subtle three-dot animation shown the
   instant someone starts speaking and cleared when the caption lands. CHTR-105 places it
   INLINE as the last row of the caption stream (where the next line will appear) so it reads
   in context. min-height matches a caption line so it occupies that next-line slot.
   Pointer-events:none so it never blocks the stream. */
.typing {
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: clamp(20px, 5vw, 30px);
  pointer-events: none;
}
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  opacity: 0.4;
  animation: typing-blink 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-blink {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 0.9; transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
  .typing-dot { animation: none; opacity: 0.6; }
}

/* "New" pill — shown only when the user has scrolled up and fresh text arrives */
.jump {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 9px 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

/* Lower-third lyrics footer (CHTR-6, reworked CHTR-26). A FIXED lower-third band pinned
   to the bottom, set apart from the captions by a very dark gray background. The whole
   slide is scaled by JS to fit the band (never scrolls). It animates by sliding:
   parked = translated below the edge (visibility:hidden once gone); .shown = slid up.
   A slide CHANGE cross-fades between two stacked layers (no slide). */
.lyric {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 33%;                  /* the fixed lower third */
  overflow: hidden;
  background: var(--lyric-bg);
  border-top: 1px solid #000;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.55);
  visibility: hidden;
  transform: translateY(100%);  /* parked below the screen edge when there are no lyrics */
  transition: transform 1s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 1s;
  will-change: transform;
}
/* Slide up to reveal; flip to visible immediately on the way in. A smooth 1s slide. */
.lyric.shown {
  visibility: visible;
  transform: translateY(0);
  transition: transform 1s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}
/* Two stacked layers; a slide change cross-fades the incoming over 1s (CHTR-26). */
.lyric-fit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px clamp(12px, 4vw, 40px);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
}
.lyric-fit.on { opacity: 1; }
.lyric-text {
  display: flex;               /* one .lyric-line per row (CHTR-28) */
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-weight: 600;
  line-height: 1.2;
  font-size: 30px;             /* base; per-line size is relative (em); block scaled to fit */
  transform-origin: center center;
}
.lyric-line {
  white-space: pre;            /* keep a line intact; JS scales the block to fit the band */
  font-size: 1em;             /* overridden inline per line for relative sizing */
}
@media (prefers-reduced-motion: reduce) {
  .lyric { transition: visibility 0s linear 1s; }
  .lyric.shown { transition: none; }
  .lyric-fit { transition: none; }
  .captions { transition: none; }
}

/* ── Settings placeholder sheet ────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.sheet-card {
  width: min(460px, 100%);
  background: var(--band);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 22px 22px max(22px, env(safe-area-inset-bottom));
  animation: rise 200ms ease;
}
.sheet-card h2 { margin: 0 0 6px; font-size: 18px; }
.sheet-card p { margin: 0 0 18px; color: var(--muted); }
/* CHTR-120: settings rows (e.g. the chat text-size slider). */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 18px; }
.setting-row label { color: var(--fg); font-size: 15px; }
.setting-range { flex: 1; max-width: 60%; accent-color: var(--accent); }
.sheet-close {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid #2a3744;
  border-radius: 12px;
  background: none;
  color: var(--fg);
  cursor: pointer;
}
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Chat forum (CHTR-112 A6/A7/A8) ─────────────────────────────────── */
/* The chat view overlays the caption area inside #view; it lifts above the on-screen
   keyboard via --kb (driven by visualViewport in app.js). Shown only with .chat-open. */
.chat {
  position: absolute;
  inset: 0;
  bottom: var(--kb, 0px);
  display: none;
  flex-direction: column;
  background: var(--bg);
  z-index: 6;
  transition: bottom 0.18s ease;
}
#view.chat-open .chat { display: flex; }
/* Hide the live-caption stack while chat is open (it keeps updating underneath). */
#view.chat-open .captions,
#view.chat-open .legend,
#view.chat-open .jump,
#view.chat-open .lyric { display: none !important; }

.chat-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px clamp(12px, 4vw, 24px);
  border-bottom: 1px solid var(--line);
}
.chat-return {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-return svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chat-return:active { color: var(--fg); background: var(--band); }
.chat-title { flex: 1; min-width: 0; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-forum {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 32px 0 10px;
  border: 1px solid #2a3744;
  border-radius: 10px;
  background: var(--band);
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
  /* a chevron so the combobox reads as a dropdown (native arrow is removed above) */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a97a6' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px clamp(12px, 4vw, 28px);
  /* CHTR-120: chat renders SMALLER than captions, scaled by the settings slider (--chat-scale). */
  font-size: calc(16px * var(--chat-scale, 1));
}
.chat-msg {
  max-width: 85%;
  align-self: flex-start;
  padding: 7px 12px;
  border-radius: 14px;
  background: var(--band);
  border: 1px solid var(--line);
  border-left: 3px solid var(--author, var(--muted)); /* per-author colour (CHTR-120) */
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg .chat-author { display: block; font-size: 0.72em; font-weight: 700; color: var(--author, var(--muted)); margin-bottom: 1px; }
.chat-msg .chat-body { display: block; color: var(--fg); }
.chat-empty { margin: auto; padding: 24px; color: var(--muted); text-align: center; font-size: 15px; }

.chat-composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px clamp(12px, 4vw, 24px) max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.chat-name {
  height: 34px;
  padding: 0 12px;
  border: 1px solid #2a3744;
  border-radius: 10px;
  background: var(--band);
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
}
.chat-name::placeholder, .chat-text::placeholder { color: var(--muted); }
.chat-input-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-text {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid #2a3744;
  border-radius: 14px;
  background: var(--band);
  color: var(--fg);
  line-height: 1.3;
}
.chat-text:focus, .chat-name:focus, .chat-forum:focus { outline: none; border-color: var(--accent); }
.chat-send {
  flex: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.chat-send svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }
.chat-send:active { filter: brightness(0.9); }
.chat-note { margin: 0; min-height: 1em; font-size: 12px; color: #f59e0b; }
