/*
 * HeapFile Link — call client styles.
 *
 * Design language: "the quiet stage". See docs/product/LINK_DESIGN_LANGUAGE.md.
 *
 *   1. Dark-first. The call is a deep navy field; the shared screen and the
 *      people are the only bright things on it.
 *   2. Chrome recedes, content advances. Panels are elevation and a hairline,
 *      not heavy fills. Nothing competes with the stage.
 *   3. Colour carries one meaning each — cyan = live presence, blue = the
 *      action you can take, yellow = attention/consent, red = capture or danger.
 *   4. Security is ambient: always present, quiet while it is satisfied, loud
 *      the moment it is not. It is never hidden or truncated.
 *   5. Motion is short, physical and optional (prefers-reduced-motion).
 *
 * Tokens follow the shipped HeapFile brand (sites/heapfile-ai + HeapFile-UI):
 * navy #020914–#08213b, blue #087dff, cyan #00c9ff, yellow #ffd51f, Inter.
 *
 * Everything is one same-origin stylesheet so it satisfies the Link
 * Content-Security-Policy (style-src 'self'; no inline styles, no <style>).
 * Dynamic values arrive through CSS custom properties set via the CSSOM
 * (link.js sets --zoom on #stage).
 */

/* ----------------------------------------------------------------------------
 * Tokens
 * -------------------------------------------------------------------------- */
:root {
  color-scheme: light dark;

  /* Brand core — HeapFile navy / cyan / blue / yellow (HeapFile-UI palette) */
  --navy-950: #020914;
  --navy-900: #03101f;
  --navy-850: #06182b;
  --navy-800: #08213b;
  --brand-ink: #071221;
  --brand-blue: #087dff;
  --brand-cyan: #00c9ff;
  --brand-yellow: #ffd51f;
  --brand-yellow-deep: #f0b800;
  --brand-paper: #f5f9ff;

  /* Type */
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas, monospace;
  --fs-display: clamp(2rem, 4.5vw, 3rem);
  --fs-h1: clamp(1.5rem, 3.4vw, 2.1rem);
  --fs-h2: 1.25rem;
  --fs-h3: 1.02rem;
  --fs-body: 1rem;
  --fs-sm: 0.86rem;
  --fs-xs: 0.74rem;
  --lh-body: 1.55;

  /* Spacing scale (4px base) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --space-12: 48px; --space-16: 64px;

  /* Radius */
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-xl: 22px; --radius-pill: 999px;

  /* Shell metrics — banners, the stage and the control bar all derive from
   * these instead of repeating magic numbers. */
  --topbar-h: 64px;
  --controlbar-h: 84px;
  --stage-inset: var(--space-4);
  /* The stage's floor. Shared by .stage's min-height and the grid track that
   * holds it — if the two disagree the stage overflows its row onto the
   * caption below it. */
  --stage-min: 200px;

  /* Z layers */
  --z-rail: 20; --z-controlbar: 40; --z-reconnect: 50; --z-banner: 60; --z-toast: 70; --z-dialog: 80; --z-overlay: 90;

  /* Motion */
  --dur: 160ms;
  --dur-slow: 320ms;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --hover-lift: translateY(-2px);

  /* Focus — brand yellow ring (per the HeapFile design system) */
  --focus: #e0a800;
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--focus) 60%, transparent);
}

/* Light theme (default) */
:root,
:root[data-theme="light"] {
  --bg: var(--brand-paper);
  --bg-grad-1: rgba(8, 125, 255, .08);
  --bg-grad-2: rgba(0, 201, 255, .06);
  --surface: #ffffff;
  --surface-2: #eef4fc;
  --surface-raised: #ffffff;
  --text: #071221;
  --text-muted: #4a5f75;
  --text-faint: #5b6e84;
  --line: #d7e3f2;
  --line-strong: #bcd0e6;
  --accent: #0a6fe0;
  --accent-hover: #0858b8;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(8, 125, 255, .10);
  --warm: #056f8a;
  --warm-soft: rgba(0, 170, 210, .12);
  --danger: #c0362e;
  --danger-contrast: #ffffff;
  --danger-soft: rgba(192, 54, 46, .10);
  --warn: #7a6000;
  --warn-soft: rgba(255, 213, 31, .18);
  --success: #0f7a4f;
  --info: #0a6fe0;
  --speaking: #0b6ea8;
  --controller-active: #b3261e;
  --controller-paused: #8a6d00;
  --controller-stopped: #138a5a;
  /* Banner fills carry safety text, so they are specified as a contrast pair
   * rather than reusing a state colour that only has to work as an accent.
   * white/#b3261e = 6.5:1, #2a2100/#f0b800 = 8.8:1. */
  --banner-danger-bg: #b3261e;
  --banner-danger-fg: #ffffff;
  --banner-danger-ink: #9c1f18;
  --banner-warn-bg: #f0b800;
  --banner-warn-fg: #2a2100;
  --banner-warn-ink: #4a3800;
  --tile-bg: #eef4fc;
  --focus: #c98a00;
  --shadow-1: 0 1px 2px rgba(7, 18, 33, .10);
  --shadow-2: 0 10px 28px rgba(7, 18, 33, .12);
  --shadow-3: 0 24px 64px rgba(7, 18, 33, .18);
  --scrim: rgba(3, 16, 31, .45);
  /* Stage: the one surface that stays dark in both themes, so a shared screen
   * and a dark IDE never sit in a white box. */
  --stage-bg: #0b1626;
  --stage-edge: rgba(123, 198, 255, .22);
  --stage-fog-1: rgba(8, 125, 255, .20);
  --stage-fog-2: rgba(0, 201, 255, .12);
  --chrome-blur: saturate(140%) blur(18px);
  --glow-live: 0 0 0 1px rgba(0, 201, 255, .35), 0 18px 48px rgba(8, 125, 255, .18);
}

/* Dark theme — explicit selection wins over the media query below */
:root[data-theme="dark"] {
  --bg: var(--navy-950);
  --bg-grad-1: rgba(0, 151, 255, .18);
  --bg-grad-2: rgba(0, 201, 255, .10);
  --surface: var(--navy-850);
  --surface-2: var(--navy-800);
  --surface-raised: var(--navy-800);
  --text: #f7fbff;
  --text-muted: #a9bed3;
  --text-faint: #93a9c0;
  --line: rgba(123, 198, 255, .18);
  --line-strong: rgba(123, 198, 255, .32);
  --accent: #087dff;
  --accent-hover: #3a97ff;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(8, 125, 255, .20);
  --warm: #00c9ff;
  --warm-soft: rgba(0, 201, 255, .16);
  --danger: #ff6b74;
  --danger-contrast: #2a0a08;
  --danger-soft: rgba(255, 107, 116, .18);
  --warn: #ffd51f;
  --warn-soft: rgba(255, 213, 31, .16);
  --success: #3ee094;
  --info: #00c9ff;
  --speaking: #00c9ff;
  --controller-active: #ff5a5f;
  --controller-paused: #ffd51f;
  --controller-stopped: #3ee094;
  /* #ff5a5f is a fine accent but only 3.1:1 behind white text, so the banner
   * fill is its own deeper red: white/#a81d23 = 7.3:1. */
  --banner-danger-bg: #a81d23;
  --banner-danger-fg: #ffffff;
  --banner-danger-ink: #8f1a1f;
  --banner-warn-bg: #ffd51f;
  --banner-warn-fg: #1b1200;
  --banner-warn-ink: #4a3800;
  --tile-bg: #06182b;
  --shadow-1: 0 1px 2px rgba(0, 4, 12, .5);
  --shadow-2: 0 10px 28px rgba(0, 4, 12, .5);
  --shadow-3: 0 24px 64px rgba(0, 4, 12, .6);
  --scrim: rgba(1, 6, 15, .66);
  --focus: #ffd51f;
  --stage-bg: #040d1a;
  --stage-edge: rgba(123, 198, 255, .20);
  --stage-fog-1: rgba(8, 125, 255, .22);
  --stage-fog-2: rgba(0, 201, 255, .12);
  --chrome-blur: saturate(140%) blur(18px);
  --glow-live: 0 0 0 1px rgba(0, 201, 255, .30), 0 22px 60px rgba(0, 4, 12, .55);
}

/* Auto theme follows the OS when no explicit data-theme is set. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: var(--navy-950);
    --bg-grad-1: rgba(0, 151, 255, .18);
    --bg-grad-2: rgba(0, 201, 255, .10);
    --surface: var(--navy-850);
    --surface-2: var(--navy-800);
    --surface-raised: var(--navy-800);
    --text: #f7fbff;
    --text-muted: #a9bed3;
    --text-faint: #93a9c0;
    --line: rgba(123, 198, 255, .18);
    --line-strong: rgba(123, 198, 255, .32);
    --accent: #087dff;
    --accent-hover: #3a97ff;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(8, 125, 255, .20);
    --warm: #00c9ff;
    --warm-soft: rgba(0, 201, 255, .16);
    --danger: #ff6b74;
    --danger-contrast: #2a0a08;
    --danger-soft: rgba(255, 107, 116, .18);
    --warn: #ffd51f;
    --warn-soft: rgba(255, 213, 31, .16);
    --success: #3ee094;
    --info: #00c9ff;
    --speaking: #00c9ff;
    --controller-active: #ff5a5f;
    --controller-paused: #ffd51f;
    --controller-stopped: #3ee094;
    --banner-danger-bg: #a81d23;
    --banner-danger-fg: #ffffff;
    --banner-danger-ink: #8f1a1f;
    --banner-warn-bg: #ffd51f;
    --banner-warn-fg: #1b1200;
    --banner-warn-ink: #4a3800;
    --tile-bg: #06182b;
    --shadow-1: 0 1px 2px rgba(0, 4, 12, .5);
    --shadow-2: 0 10px 28px rgba(0, 4, 12, .5);
    --shadow-3: 0 24px 64px rgba(0, 4, 12, .6);
    --scrim: rgba(1, 6, 15, .66);
    --focus: #ffd51f;
    --stage-bg: #040d1a;
    --stage-edge: rgba(123, 198, 255, .20);
    --stage-fog-1: rgba(8, 125, 255, .22);
    --stage-fog-2: rgba(0, 201, 255, .12);
    --chrome-blur: saturate(140%) blur(18px);
    --glow-live: 0 0 0 1px rgba(0, 201, 255, .30), 0 22px 60px rgba(0, 4, 12, .55);
  }
}

/* ----------------------------------------------------------------------------
 * Reset / base
 * -------------------------------------------------------------------------- */
* { box-sizing: border-box; }

/* Author display rules (flex/grid/inline-flex) override the UA [hidden] rule, so
 * restore it explicitly for every element the client toggles via the attribute. */
[hidden] { display: none !important; }

.lk-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 85% -5%, var(--bg-grad-1), transparent 60%),
    radial-gradient(900px 500px at 5% 110%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* In a live call the page itself never scrolls — the stage owns the viewport.
 *
 * The shell is a flex column (topbar / banners / main) rather than a stack of
 * fixed overlays. The safety banners wrap to whatever height their text needs
 * — the remote-control line can run to three lines on a phone — and the call
 * below them simply gets the remaining height. No offset constant can track a
 * banner that changes height with its message, and guessing one is how the
 * "you are sharing your screen" title ends up hidden behind it. */
body[data-call="active"] {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
body[data-call="active"] > main { flex: 1 1 auto; min-height: 0; min-width: 0; }
body[data-call="active"] #lk-controller-banner,
body[data-call="active"] #lk-share-banner { position: static; flex: 0 0 auto; }

h1, h2, h3, h4 { margin: 0; line-height: 1.15; letter-spacing: -.01em; font-weight: 750; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent-hover); }

.eyebrow {
  margin: 0 0 var(--space-2);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: var(--fs-xs);
  font-weight: 800;
  color: var(--info);
}

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

/* Skip link */
.lk-skip {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-overlay);
  transform: translateY(-200%);
  background: var(--accent);
  color: var(--accent-contrast);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-decoration: none;
}
.lk-skip:focus { transform: translateY(0); }

/* Visible focus on every interactive element */
:where(a, button, input, select, textarea, [tabindex], summary, [role="button"], [role="option"], [role="tab"]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
.lk-tile:focus-visible,
.lk-iconbtn:focus-visible { box-shadow: var(--focus-ring); }

/* ----------------------------------------------------------------------------
 * Buttons
 * -------------------------------------------------------------------------- */
button {
  font: inherit;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 650;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), color var(--dur) var(--ease);
}
button:hover:not(:disabled) { border-color: var(--accent); transform: var(--hover-lift); }
button:active:not(:disabled) { transform: translateY(0) scale(.985); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary, .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent);
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 38%, transparent);
}
button.primary:disabled { box-shadow: none; }

button.secondary, .secondary {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text);
}
button.secondary:hover:not(:disabled) { background: var(--accent-soft); }

button.quiet, .quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  min-height: 40px;
  padding: 8px 12px;
}
button.quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--text); transform: none; border-color: transparent; }

button.danger, .danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-contrast);
}
button.danger:hover:not(:disabled) { filter: brightness(1.06); }

/* Icon buttons for the control bar */
.lk-iconbtn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 58px;
  min-height: 56px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  line-height: 1;
}
.lk-iconbtn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line);
  transform: none;
}
.lk-iconbtn .lk-ib-icon { width: 22px; height: 22px; display: block; }
.lk-iconbtn .lk-ib-label { font-size: 11px; font-weight: 700; letter-spacing: .01em; color: var(--text-muted); }
.lk-iconbtn:hover:not(:disabled) .lk-ib-label { color: var(--text); }
.lk-iconbtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.lk-iconbtn[aria-pressed="true"] .lk-ib-label { color: var(--accent); }
.lk-iconbtn.is-danger { color: var(--danger); }
.lk-iconbtn.is-danger .lk-ib-label { color: var(--danger); }
.lk-iconbtn.is-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.lk-iconbtn.is-active { background: var(--warm-soft); border-color: var(--warm); color: var(--warm); }
.lk-iconbtn.is-active .lk-ib-label { color: var(--warm); }

/* The two irreversible controls read as one destructive pill, not as text. */
#leave-room, #end-room {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-contrast);
}
#leave-room .lk-ib-label, #end-room .lk-ib-label { color: inherit; }
#leave-room:hover:not(:disabled), #end-room:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  filter: brightness(1.08);
}
#leave-room:hover:not(:disabled) .lk-ib-label, #end-room:hover:not(:disabled) .lk-ib-label { color: inherit; }

/* Mic on/off icon swap */
.lk-iconbtn .ic-off { display: none; }
.lk-iconbtn.is-muted .ic-on { display: none; }
.lk-iconbtn.is-muted .ic-off { display: block; }
.lk-iconbtn.is-muted { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.lk-iconbtn.is-muted .lk-ib-label { color: var(--danger); }

/* Live local microphone input meter beside the Mute control: shows at a glance
   that the mic is on and picking up the user's voice. A thin vertical bar whose
   fill rises from the bottom; JS drives it via scaleY on .lk-mic-meter-fill
   (0..1). When muted it collapses to a dim flat sliver (no false "live" signal). */
.lk-mic-meter { flex: 0 0 auto; align-self: center; width: 6px; min-height: 36px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; position: relative; }
.lk-mic-meter-fill { position: absolute; inset: 0; background: var(--accent); border-radius: 3px; transform: scaleY(0); transform-origin: bottom center; transition: transform .08s linear; }
.lk-mic-meter.is-muted { background: var(--danger-soft); }
.lk-mic-meter.is-muted .lk-mic-meter-fill { background: var(--danger); transform: scaleY(0.12); opacity: .5; }
@media (prefers-reduced-motion: reduce) { .lk-mic-meter-fill { transition: none; } }

.lk-iconbtn .lk-badge {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 18px; height: 18px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--warm);
  color: #fff;
  font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
}
.lk-iconbtn { position: relative; }

svg.lk-ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ----------------------------------------------------------------------------
 * Top bar
 * -------------------------------------------------------------------------- */
.lk-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-rail);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-h);
  padding: var(--space-2) clamp(var(--space-3), 4vw, var(--space-8));
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: var(--chrome-blur);
  border-bottom: 1px solid var(--line);
}
.lk-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  letter-spacing: -.02em;
  flex-shrink: 0;
}
.lk-brand .lk-logo { width: 34px; height: 34px; border-radius: 9px; display: block; }
.lk-brand .lk-wordmark { font-size: 1.12rem; white-space: nowrap; }
.lk-brand .lk-wordmark span { color: var(--info); }

.lk-room-context {
  flex: 1 1 auto;
  min-width: 0;
  display: none;
  flex-direction: column;
  gap: 0;
  justify-content: center;
}
body[data-call="active"] .lk-room-context { display: flex; }
/* One line each, always — a long transport string must never grow the bar. */
.lk-room-context .eyebrow,
.lk-room-context #room-title {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.lk-room-context .eyebrow { letter-spacing: .1em; }
.lk-room-context #room-title { font-size: 1rem; font-weight: 700; }

/* A live room gets a breathing cyan dot in front of its state line. */
.lk-room-context .eyebrow::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--info);
  vertical-align: middle;
  animation: lk-breathe 2.6s var(--ease) infinite;
}

.lk-account {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
#auth-state {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  white-space: nowrap;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lk-theme-toggle { min-height: 40px; min-width: 40px; padding: 8px; }

/* ----------------------------------------------------------------------------
 * App shell / layout
 * -------------------------------------------------------------------------- */
main { display: block; }

.lk-welcome-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(var(--space-8), 7vw, var(--space-16)) var(--space-4);
}
.welcome { position: relative; overflow: hidden; }
/* A soft brand aurora behind the first screen — the one decorative flourish. */
.welcome::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto -20%;
  height: 320px;
  background:
    radial-gradient(420px 220px at 22% 60%, var(--stage-fog-1), transparent 70%),
    radial-gradient(360px 200px at 78% 40%, var(--stage-fog-2), transparent 70%);
  pointer-events: none;
}
.welcome > * { position: relative; }
.welcome .actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-6) 0;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  padding: clamp(var(--space-5), 3vw, var(--space-8));
}
.welcome h1 { font-size: var(--fs-display); margin-bottom: var(--space-3); letter-spacing: -.025em; }
.status { color: var(--text-muted); font-size: var(--fs-sm); }
.security-note {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Call layout: main stage + collapsible rail */
.call-layout {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0;
  gap: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns var(--dur-slow) var(--ease-out);
}
.call-layout[data-rail="open"] { grid-template-columns: minmax(0, 1fr) min(380px, 40vw); }

/* Rows: waiting banner, verification, stage. Only the stage flexes, so the
 * shared screen keeps the height instead of being pushed below the fold. */
.call-main {
  display: grid;
  /* minmax(0,1fr), never auto: a wide child (the roster strip, a long
   * verification code) must scroll inside its own box, not stretch the column
   * and push the call off the side of a phone. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  align-content: start;
  padding: var(--stage-inset) var(--stage-inset) calc(var(--controlbar-h) + var(--space-4));
  overflow: auto;
  gap: var(--space-3);
}
/* Explicit rows, never positional: #waiting-banner is hidden most of the time,
 * and auto-placement would then slide the stage into an `auto` row where it can
 * never claim the free height. */
.call-main > #waiting-banner { grid-row: 1; }
.call-main > #verification { grid-row: 2; }
.call-main > .lk-stage-wrap { grid-row: 3; }

/* No banner offsets here: in a call the banners sit above this column in the
 * body's flex shell, so the column already starts below them. */

/* ----------------------------------------------------------------------------
 * Banners (fixed, viewport-level)
 * -------------------------------------------------------------------------- */
.lk-banner {
  position: fixed;
  left: 0; right: 0;
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) clamp(var(--space-4), 4vw, var(--space-8));
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
}
.lk-banner[data-visible="true"] { display: flex; animation: lk-drop var(--dur-slow) var(--ease-out); }
.lk-banner .lk-banner-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lk-banner .lk-banner-title { font-weight: 800; letter-spacing: .02em; }
.lk-banner .lk-banner-detail { color: inherit; opacity: .92; font-size: var(--fs-xs); word-break: break-word; }

#lk-controller-banner {
  top: var(--topbar-h);
  z-index: var(--z-banner);
  background: var(--banner-danger-bg);
  color: var(--banner-danger-fg);
  border-bottom: 2px solid rgba(0, 0, 0, .25);
}
#lk-controller-banner[data-state="paused"] { background: var(--banner-warn-bg); color: var(--banner-warn-fg); }
#lk-controller-banner[data-state="stopping"] { background: var(--banner-warn-bg); color: var(--banner-warn-fg); }
#lk-controller-banner[data-state="incomplete"] { background: var(--banner-danger-bg); color: var(--banner-danger-fg); }
#lk-controller-banner .lk-stop {
  background: #fff; color: var(--banner-danger-ink);
  border: none; font-weight: 800; flex-shrink: 0;
}
#lk-controller-banner .lk-stop:hover:not(:disabled) { background: #fff; filter: brightness(.94); }
#lk-controller-banner[data-state="paused"] .lk-stop,
#lk-controller-banner[data-state="stopping"] .lk-stop { color: var(--banner-warn-ink); }
#lk-controller-banner .lk-icon-shield { width: 24px; height: 24px; flex-shrink: 0; }

#lk-share-banner {
  top: var(--topbar-h);
  z-index: var(--z-reconnect);
  background: color-mix(in srgb, var(--surface-raised) 92%, transparent);
  backdrop-filter: var(--chrome-blur);
  color: var(--text);
  border-bottom: 1px solid var(--warn);
  box-shadow: inset 0 2px 0 0 var(--warn), var(--shadow-1);
}
/* Only applies outside a call: inside one both banners are position:static in
 * the flex shell, which stacks them exactly, and `top` is ignored. */
body[data-controlled="true"] #lk-share-banner { top: calc(var(--topbar-h) + 48px); }
#lk-share-banner .lk-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger); flex-shrink: 0;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent);
  animation: lk-rec 1.8s var(--ease) infinite;
}

#lk-reconnect-banner {
  bottom: calc(var(--controlbar-h) + var(--space-3));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(560px, calc(100% - 32px));
  z-index: var(--z-reconnect);
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
  backdrop-filter: var(--chrome-blur);
  color: var(--text);
  border: 1px solid var(--warn);
  border-radius: var(--radius-pill);
  justify-content: center;
  padding: var(--space-2) var(--space-5);
}
#lk-reconnect-banner .lk-banner-title { font-weight: 700; letter-spacing: 0; }
#lk-reconnect-banner .lk-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: lk-spin 900ms linear infinite; flex-shrink: 0;
}
@keyframes lk-spin { to { transform: rotate(360deg); } }
@keyframes lk-drop { from { opacity: 0; transform: translateY(-8px); } }
@keyframes lk-breathe { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes lk-rec {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent); }
  70%  { box-shadow: 0 0 0 7px color-mix(in srgb, var(--danger) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 0%, transparent); }
}

/* ----------------------------------------------------------------------------
 * Verification gate
 *
 * Security content is never hidden or truncated. It is loud while the gate is
 * unsatisfied, and recedes to a quiet strip once media is unlocked — which is
 * exactly when #mic-toggle stops being disabled. Browsers without :has() simply
 * keep the loud presentation, which is the safe direction to fail in.
 * -------------------------------------------------------------------------- */
.verification {
  background: var(--warm-soft);
  border: 1px solid var(--warm);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: padding var(--dur-slow) var(--ease), background var(--dur-slow) var(--ease);
}
.verification > strong { display: block; font-size: var(--fs-h3); margin-bottom: var(--space-2); }
.verification > p { margin-bottom: var(--space-3); }
#verification-code {
  display: grid;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}
#verification-code .lk-vcode-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
}
#verification-code .lk-vcode-name { font-weight: 650; color: var(--text-muted); font-size: var(--fs-sm); }
#verification-code .lk-vcode-value,
.lk-vcode {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(1.3rem, 3.5vw, 1.9rem);
  letter-spacing: .14em;
  color: var(--text);
}
#verify-warning { color: var(--warm); font-weight: 650; font-size: var(--fs-sm); min-height: 1.2em; }
#verify-warning:empty { display: none; }

/* Zero-ceremony default: the compare-codes block is not shown at all. The
 * signed pair verification and its codes are unchanged and run underneath;
 * only the person compare is gone. The page un-hides the block only when the
 * person opts into High-security verify (Advanced tab) or an AI endpoint's code
 * needs a human compare. The `hidden` rule must win over the status-strip grid
 * rules further down. */
#verification[hidden] { display: none !important; }
.lk-check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); color: var(--text-muted); }
.lk-check input { width: auto; flex: none; }
.verification[data-mode="auto"] {
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 42%, var(--line));
}
.verification[data-mode="auto"] > strong { font-size: var(--fs-sm); margin-bottom: 2px; color: var(--success); }
.verification[data-mode="auto"] > #verification-note,
.verification[data-mode="auto"] > #verification-code,
.verification[data-mode="auto"] > #verify-room { display: none; }
.verification[data-mode="auto"] > #verify-warning { color: var(--text-muted); font-weight: 500; }

/* Satisfied: a quiet status strip. The heading, the codes and the re-verify
 * button sit on one line; the full explanation stays underneath at small size.
 * Nothing is removed, collapsed behind a control, or clipped. */
body:has(.controls #mic-toggle:not(:disabled)) #verification {
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 42%, var(--line));
  font-size: var(--fs-sm);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: var(--space-3);
  row-gap: var(--space-1);
}
body:has(.controls #mic-toggle:not(:disabled)) #verification > strong { grid-row: 1; grid-column: 1; }
body:has(.controls #mic-toggle:not(:disabled)) #verification > #verification-code { grid-row: 1; grid-column: 2; }
body:has(.controls #mic-toggle:not(:disabled)) #verification > #verify-room { grid-row: 1; grid-column: 3; justify-self: end; }
body:has(.controls #mic-toggle:not(:disabled)) #verification > p { grid-column: 1 / -1; }
body:has(.controls #mic-toggle:not(:disabled)) #verification > strong { font-size: var(--fs-sm); margin-bottom: 2px; color: var(--success); }
body:has(.controls #mic-toggle:not(:disabled)) #verification > p { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: var(--space-2); }
body:has(.controls #mic-toggle:not(:disabled)) #verification #verification-code {
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  justify-content: start;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  overflow-x: auto;
}
body:has(.controls #mic-toggle:not(:disabled)) #verification .lk-vcode-row {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  gap: var(--space-2);
}
body:has(.controls #mic-toggle:not(:disabled)) #verification .lk-vcode-value { font-size: var(--fs-sm); letter-spacing: .1em; }
body:has(.controls #mic-toggle:not(:disabled)) #verification #verify-room { min-height: 36px; padding: 6px 14px; font-size: var(--fs-sm); }
body:has(.controls #mic-toggle:not(:disabled)) #verify-warning { font-size: var(--fs-xs); color: var(--success); }

/* ----------------------------------------------------------------------------
 * Stage + gallery
 * -------------------------------------------------------------------------- */
/* #stage and #local-preview share grid cell 1/1, so the self-view docks inside
 * the stage instead of escaping to the viewport corner. */
.lk-stage-wrap {
  position: relative;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* A floor, not 0: with minmax(0, 1fr) a tall roster compresses the stage to
   * nothing instead of scrolling itself. */
  grid-template-rows: minmax(var(--stage-min), 1fr);
  grid-auto-rows: auto;
  gap: var(--space-3);
}

.stage {
  grid-area: 1 / 1;
  position: relative;
  min-height: var(--stage-min);
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 420px at 50% -10%, var(--stage-fog-1), transparent 65%),
    radial-gradient(700px 380px at 15% 115%, var(--stage-fog-2), transparent 60%),
    var(--stage-bg);
  border: 1px solid var(--stage-edge);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transform-origin: center;
  box-shadow: var(--shadow-2);
}
/* Nothing is being shared yet: the stage shrinks to a hint and the people
 * below it take the room. */
.stage[data-has-share="false"] { min-height: 120px; }
.lk-stage-wrap:has(.stage[data-has-share="false"]) { grid-template-rows: auto; }
.stage[data-has-share="true"] { box-shadow: var(--glow-live); }
#stage-empty { color: #9fb6cf; font-size: var(--fs-sm); text-align: center; padding: var(--space-6); max-width: 40ch; }

.peer-media { width: 100%; height: 100%; display: grid; position: relative; }
/* The stage is a fixed window onto the share. Pinning the media card to the
 * stage box gives <video> a definite height, so object-fit letterboxes it —
 * before this it kept its 800px intrinsic height and was simply cropped.
 * link.js sets --zoom on #stage from the View zoom slider; scale the media,
 * not the frame, so the stage box and the roster below it never move. */
.stage > .peer-media {
  position: absolute;
  inset: 0;
  width: auto; height: auto;
  /* Definite tracks, or the auto row sizes to the video's intrinsic 800px and
   * height:100% on the <video> resolves against that instead of the stage. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  transform: scale(var(--zoom, 1));
  transform-origin: center;
}
.peer-media video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
  border-radius: var(--radius-md);
}
.peer-media audio { display: none; }
.peer-media h3 {
  position: absolute; left: var(--space-3); bottom: var(--space-3);
  z-index: 2;
  background: rgba(2, 9, 20, .68);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .01em;
  max-width: calc(100% - var(--space-6));
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.remote-live-indicator, #live-indicator {
  position: absolute; top: var(--space-3); left: var(--space-3);
  z-index: 2;
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(2, 9, 20, .68);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 5px 12px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: .08em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14);
}
.remote-live-indicator::before, #live-indicator::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: #ff5a5f;
  animation: lk-rec 1.8s var(--ease) infinite;
}

.local-preview {
  grid-area: 1 / 1;
  align-self: end;
  justify-self: end;
  position: relative;
  z-index: 3;
  margin: var(--space-3);
  width: min(240px, 34%);
  border: 1px solid var(--stage-edge);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-3);
  background: #000;
}
.local-preview video { width: 100%; display: block; }
.local-preview h3 {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(2, 9, 20, .72);
  display: inline-block; padding: 3px 9px;
  font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
}

/* Gallery of participant tiles (the roster, upgraded) */
#members {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
#members:empty { display: none; }
/* Two columns: the avatar is the anchor, everything link.js renders stacks in
 * the second column. Explicit placement keeps working whatever order the
 * client appends identity, activity and the presenter button in. */
#members > li {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-content: start;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
#members > li > * { grid-column: 2; min-width: 0; }
#members > li > .lk-tile-avatar { grid-column: 1; grid-row: 1 / span 2; align-self: start; }
#members > li > .lk-tile-badges { grid-row: 2; }
#members > li[data-kind="agent"] { border-style: dashed; border-color: var(--info); background: var(--surface-2); }
#members > li[data-speaking="true"] {
  border-color: var(--speaking);
  box-shadow: 0 0 0 2px var(--speaking), var(--shadow-2);
}
#members > li[data-self="true"]::after {
  content: "You";
  position: absolute; top: var(--space-3); right: var(--space-3);
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
}
/* The roster name span link.js renders carries no class of its own. */
#members > li > span:not(.roster-activity) {
  font-weight: 700;
  word-break: break-word;
  line-height: 1.3;
}
.lk-tile-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 1.1rem;
  letter-spacing: .02em;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 24%, transparent), color-mix(in srgb, var(--warm) 20%, transparent));
  color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: box-shadow var(--dur) var(--ease);
}
#members > li[data-kind="agent"] .lk-tile-avatar {
  background: color-mix(in srgb, var(--info) 18%, transparent);
  color: var(--info);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--info) 45%, transparent);
}
#members > li[data-speaking="true"] .lk-tile-avatar {
  box-shadow: 0 0 0 3px var(--speaking);
  animation: lk-speak 1.5s var(--ease) infinite;
}
@keyframes lk-speak {
  0%, 100% { box-shadow: 0 0 0 3px var(--speaking), 0 0 0 3px color-mix(in srgb, var(--speaking) 40%, transparent); }
  50%      { box-shadow: 0 0 0 3px var(--speaking), 0 0 0 10px color-mix(in srgb, var(--speaking) 0%, transparent); }
}
.lk-tile-name { font-weight: 700; word-break: break-word; }
.lk-tile-badges { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.lk-badge-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-xs); font-weight: 700;
  padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--line);
}
.lk-badge-chip.is-host { color: var(--accent); border-color: var(--accent); }
.lk-badge-chip.is-presenter { color: var(--warm); border-color: var(--warm); }
.lk-badge-chip.is-agent { color: var(--info); border-color: var(--info); }
.lk-badge-chip.is-muted { color: var(--danger); border-color: var(--danger); }
/* Local speaking read-out: the dot and colour make the state readable at a
 * glance without changing a word of the text link.js writes. */
.roster-activity { font-size: var(--fs-xs); color: var(--text-faint); }
#members > li[data-speaking="true"] .roster-activity { color: var(--speaking); font-weight: 700; }
.participant-identity { font-size: var(--fs-xs); color: var(--text-faint); }
.participant-identity p { margin: 2px 0; }
.participant-identity .endpoint-fingerprint { font-family: var(--font-mono); word-break: break-all; }
.roster-action { align-self: flex-start; }

/* Nothing shared yet: the people are the content, so the tiles get room. */
.lk-stage-wrap:has(.stage[data-has-share="false"]) #members > li { min-height: 124px; }

/* Sharing: people become a compact strip so the shared screen keeps the room.
 * Nothing is removed — tiles lay out horizontally and the row scrolls. */
.lk-stage-wrap:has(.stage[data-has-share="true"]) #members {
  grid-auto-flow: column;
  grid-auto-columns: minmax(230px, 1fr);
  grid-template-columns: none;
  /* Capped so the people strip can never out-grow the thing being shared.
   * Tiles stay complete; the strip scrolls. The floor matters as much as the
   * cap: a scroll container's automatic minimum in grid is 0, so without it
   * the row collapses and the tiles are sliced in half. */
  min-height: 108px;
  max-height: min(34vh, 260px);
  overflow: auto;
  padding-bottom: var(--space-1);
}
.lk-stage-wrap:has(.stage[data-has-share="true"]) #members > li {
  min-height: 0;
  padding: var(--space-3);
  gap: 2px var(--space-2);
  /* Never center: a tile stretched to the strip height whose content is
   * taller would center the overflow and slice the name off the top. */
  align-content: start;
}
.lk-stage-wrap:has(.stage[data-has-share="true"]) #members > li > .lk-tile-avatar { width: 36px; height: 36px; font-size: .86rem; }
.lk-stage-wrap:has(.stage[data-has-share="true"]) #members > li > span:not(.roster-activity) { font-size: .92rem; line-height: 1.25; }
/* The identity block stays rendered in full; it just stops shouting. */
.lk-stage-wrap:has(.stage[data-has-share="true"]) #members > li > .participant-identity { line-height: 1.35; }
.lk-stage-wrap:has(.stage[data-has-share="true"]) #members > li > .roster-action { margin-top: var(--space-1); min-height: 32px; padding: 4px 10px; font-size: var(--fs-xs); }

/* ----------------------------------------------------------------------------
 * Shared screen: presentation layout and full screen (link-stage.js)
 *
 * link-stage.js sets body[data-stage-layout] and .lk-stage-wrap[data-layout]
 * to "presentation" while somebody is really sharing (a card that decodes
 * frames), "gallery" otherwise. In presentation the shared screen is the call:
 * the stage takes every pixel the call area has, the picture is letterboxed
 * (object-fit: contain, never cropped, never stretched), and the people become
 * small glass tiles floating over it. Without the script none of this applies
 * and the gallery rules above stay correct.
 * -------------------------------------------------------------------------- */
/* A card that is not showing a share is not on the stage: link.js adds a card
 * for every peer, and the empty ones used to stack over the real one. */
.stage > .peer-media[data-live="false"] { display: none; }
/* link-stage.js owns the hint (it also knows when YOU are the one sharing). */
body[data-stage-layout] #stage-empty { display: none; }

.lk-stage-note {
  grid-area: 1 / 1;
  z-index: 1;
  align-self: center;
  justify-self: center;
  display: grid;
  gap: var(--space-1);
  max-width: min(54ch, calc(100% - var(--space-6)));
  padding: var(--space-4);
  text-align: center;
  pointer-events: none;
  color: #9fb6cf;
  font-size: var(--fs-sm);
}
.lk-stage-note strong { color: #e6eef9; font-size: var(--fs-body); font-weight: 700; }
.lk-stage-note[hidden] { display: none; }

/* Tidy gallery: the people are the content, so they sit centred at a readable width. */
.lk-stage-wrap:has(.stage[data-has-share="false"]) #members { max-width: 1040px; width: 100%; justify-self: center; }
.lk-stage-wrap:has(.stage[data-has-share="false"]) { align-content: start; }

/* Controls floating over the stage. */
.lk-stage-tools {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 6;
  display: flex;
  gap: var(--space-2);
  transition: opacity var(--dur-slow) var(--ease);
}
.lk-stage-tools[hidden] { display: none; }
.lk-stage-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(2, 9, 20, .72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .24);
  font-size: var(--fs-sm);
  font-weight: 700;
  box-shadow: none;
}
.lk-stage-btn:hover { background: rgba(8, 33, 59, .86); border-color: rgba(255, 255, 255, .4); }
.lk-stage-btn:disabled { opacity: .55; }
.lk-stage-btn .lk-ic { width: 20px; height: 20px; flex: 0 0 auto; }
/* The microphone only needs a copy here when the real control bar is out of sight. */
.lk-stage-btn-fs { display: none; }
.lk-stage-wrap[data-fullscreen="true"] .lk-stage-btn-fs { display: inline-flex; }
.lk-stage-wrap[data-fullscreen="true"] .lk-stage-btn-fs[hidden] { display: none; }

/* Presentation: one prefix, specific enough to beat the strip and mobile rules above. */
body[data-stage-layout="presentation"] .call-main {
  padding: var(--space-2) var(--space-2) calc(var(--controlbar-h) + var(--space-2));
  gap: var(--space-2);
}
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] {
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
}
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > .stage {
  min-height: 0;
  height: 100%;
  background: #000;
}
/* "What do I do next?" has nothing to add while you are watching: it stays for
 * screen readers (it is a live region) and gives its row to the picture. */
body[data-stage-layout="presentation"] #lk-guide[data-lk-phase="sharing-remote"] {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
/* Captions under the stage stay in the page for screen readers, out of the picture's way. */
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] > #presenter-state,
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] > .device-state {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* The people: small glass tiles over the corner of the screen. Hover or focus
 * opens a tile to its full detail (identity, activity, presenter request), so
 * nothing is removed — it is only folded away while you are watching. */
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members {
  position: absolute;
  z-index: 4;
  right: var(--space-3);
  bottom: var(--space-3);
  width: min(248px, 36%);
  max-height: 46%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow: auto;
  padding: 0;
  scrollbar-width: thin;
}
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members > li {
  flex: 0 0 auto;
  grid-template-columns: auto minmax(0, 1fr);
  align-content: start;
  gap: 0 var(--space-2);
  padding: 8px 10px;
  max-height: 66px;
  overflow: hidden;
  background: rgba(2, 9, 20, .76);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  color: #fff;
  transition: max-height var(--dur-slow) var(--ease-out), border-color var(--dur) var(--ease);
}
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members > li:hover,
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members > li:focus-within {
  max-height: 420px;
}
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members > li[data-speaking="true"] {
  border-color: var(--speaking);
  box-shadow: 0 0 0 2px var(--speaking), 0 6px 18px rgba(0, 0, 0, .35);
}
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members > li > .lk-tile-avatar { width: 32px; height: 32px; font-size: .78rem; color: #8ecbff; }
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members > li > span:not(.roster-activity) {
  font-size: var(--fs-xs);
  line-height: 1.3;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members > li:hover > span:not(.roster-activity),
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members > li:focus-within > span:not(.roster-activity) {
  white-space: normal;
  overflow: visible;
}
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members > li[data-self="true"]::after { display: none; }
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .roster-activity,
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .participant-identity { color: #c9d6e6; }
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .lk-badge-chip {
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .24);
  color: #e6eef9;
  padding: 1px 7px;
}
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .lk-badge-chip.is-host { color: #8ecbff; border-color: #8ecbff; }
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .lk-badge-chip.is-presenter { color: #ffd666; border-color: #ffd666; }
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .lk-badge-chip.is-agent { color: #c4c0ff; border-color: #c4c0ff; }
body[data-stage-layout="presentation"] .lk-stage-wrap[data-layout="presentation"] #members .lk-badge-chip.is-muted { color: #ffa7a2; border-color: #ffa7a2; }
/* Camera thumbnails ride along on the right edge, under the view controls. */
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > .lk-camera-strip {
  position: absolute;
  z-index: 4;
  top: calc(var(--space-3) + 52px);
  right: var(--space-3);
  width: min(200px, 30%);
  max-height: calc(54% - 52px);
  grid-template-columns: minmax(0, 1fr);
  overflow: auto;
}
body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > .lk-camera-strip[hidden] { display: none; }

/* Full screen: the stage container fills the display; people and controls ride on it. */
.lk-stage-wrap[data-fullscreen="true"] {
  background: #000;
  padding: 0;
  gap: 0;
  grid-template-rows: minmax(0, 1fr);
}
.lk-stage-wrap[data-fullscreen="true"] > .stage {
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.lk-stage-wrap[data-fullscreen="true"] .peer-media video { border-radius: 0; }
/* Watching, not interacting: the controls fade and the pointer goes. */
.lk-stage-wrap[data-fullscreen="true"][data-idle="true"] { cursor: none; }
.lk-stage-wrap[data-fullscreen="true"][data-idle="true"] > .lk-stage-tools { opacity: 0; pointer-events: none; }
.lk-stage-wrap[data-fullscreen="true"] > .lk-stage-tools {
  top: auto;
  bottom: var(--space-4);
  right: 50%;
  transform: translateX(50%);
}
.lk-stage-wrap[data-fullscreen="true"] > .lk-stage-note { display: none; }
.lk-stage-wrap[data-fullscreen="true"] > #members { bottom: calc(var(--space-4) + 56px); }

@media (max-width: 767px) {
  body[data-stage-layout="presentation"] .call-main { padding: 0 0 calc(var(--controlbar-h) + var(--space-1)); gap: 0; }
  body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > .stage { border-radius: 0; border-left: 0; border-right: 0; }
  /* Phones: the people ride along the bottom edge as a swipeable row. */
  body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members {
    left: var(--space-2);
    right: var(--space-2);
    bottom: var(--space-2);
    width: auto;
    max-height: none;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > #members > li { width: min(210px, 62vw); }
  body[data-stage-layout="presentation"] .call-main > .lk-stage-wrap[data-layout="presentation"] > .lk-camera-strip { width: min(150px, 40%); }
  .lk-stage-wrap[data-fullscreen="true"] > #members { bottom: calc(var(--space-2) + 56px); }
}
@media (max-width: 480px) {
  .lk-stage-btn { padding: 6px 10px; }
  .lk-stage-btn .lk-stage-btn-label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .lk-stage-tools,
  body[data-stage-layout="presentation"] .lk-stage-wrap #members > li { transition: none !important; }
}
@media (forced-colors: active) {
  .lk-stage-btn { border: 1px solid CanvasText; background: Canvas; color: CanvasText; }
  body[data-stage-layout="presentation"] .lk-stage-wrap #members > li { border: 1px solid CanvasText; background: Canvas; color: CanvasText; }
}

/* ----------------------------------------------------------------------------
 * Control bar
 * -------------------------------------------------------------------------- */
.controls {
  position: fixed;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-controlbar);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: color-mix(in srgb, var(--surface-raised) 88%, transparent);
  backdrop-filter: var(--chrome-blur);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-3);
  max-width: calc(100vw - 32px);
  flex-wrap: nowrap;
  justify-content: center;
  overflow-x: auto;
  scrollbar-width: none;
}
.controls::-webkit-scrollbar { display: none; }
.controls .lk-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding-right: var(--space-2);
  margin-right: var(--space-1);
  border-right: 1px solid var(--line);
  flex: 0 0 auto;
}
.controls .lk-group:last-child { border-right: none; padding-right: 0; margin-right: 0; }
/* A group whose every button is hidden must not leave a stray divider. */
.controls .lk-group:not(:has(button:not([hidden]))) { display: none; }

/* Elements that migrate into menus/panels are hidden from the bar itself */
.controls .lk-inbar-hidden { display: none; }

#mic-state, #speaking-state, #output-state, #presenter-state, .device-state { font-size: var(--fs-xs); color: var(--text-muted); }
#presenter-state { margin: 0; }

/* Overflow menu */
.lk-overflow-menu {
  position: fixed;
  z-index: var(--z-dialog);
  bottom: calc(var(--controlbar-h) + var(--space-3));
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  overflow: auto;
  background: color-mix(in srgb, var(--surface-raised) 96%, transparent);
  backdrop-filter: var(--chrome-blur);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  padding: var(--space-4);
  display: none;
  flex-direction: column;
  gap: var(--space-3);
}
.lk-overflow-menu[data-open="true"] { display: flex; animation: lk-rise var(--dur-slow) var(--ease-out); }
.lk-overflow-menu label { display: block; font-size: var(--fs-sm); font-weight: 650; margin-bottom: 4px; }
.lk-overflow-menu select,
.lk-overflow-menu input[type="range"] { width: 100%; }
@keyframes lk-rise { from { opacity: 0; transform: translate(-50%, 10px); } }

/* Call audio: the one-tap fallback when the browser blocks sound until a tap,
 * and touch-sized device pickers. Phone width first. */
.lk-audio-unlock {
  position: fixed;
  z-index: var(--z-banner);
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--controlbar-h) + var(--space-4));
  min-height: 52px;
  max-width: calc(100vw - 32px);
  padding: var(--space-3) var(--space-6);
  font-weight: 800;
  box-shadow: var(--shadow-3);
}
.lk-audio-unlock[hidden], #speaker-field[hidden], #speaker-picker[hidden],
#audio-check-speaker-field[hidden], #audio-check-choose-speaker[hidden] { display: none; }
.lk-overflow-menu select, .lk-overflow-menu #speaker-picker,
#audio-check-dialog select, #audio-check-dialog button { min-height: 44px; }
#audio-check-dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; }
#audio-check-dialog select, #audio-check-dialog progress { width: 100%; }
/* On phones the More button already carries device choice; the extra bar
 * button is for desktop widths where the bar has room. */
@media (max-width: 767px) { .lk-audio-settings { display: none; } }
@media (max-width: 480px) {
  #audio-check-dialog .actions > button { flex: 1 1 100%; }
  .lk-overflow-menu #output-state { overflow-wrap: anywhere; }
}

select, input[type="text"], input[type="email"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-height: 44px;
  max-width: 100%;
}
select:focus-visible, input:focus-visible, textarea:focus-visible { border-color: var(--accent); }
textarea { min-height: 88px; resize: vertical; }
.toggle { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); font-weight: 600; }
.toggle input { min-height: auto; width: auto; accent-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); }

/* ----------------------------------------------------------------------------
 * Side rail (participants / advanced / chat panels)
 * -------------------------------------------------------------------------- */
.lk-rail {
  min-width: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.call-layout:not([data-rail="open"]) .lk-rail { display: none; }
.lk-rail-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-3) 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.lk-rail-tab {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-weight: 650;
}
.lk-rail-tab:hover:not(:disabled) { color: var(--text); background: var(--surface-2); transform: none; border-color: transparent; border-bottom-color: transparent; }
.lk-rail-tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.lk-rail-close { margin-left: auto; flex: 0 0 auto; }
.lk-rail-panel { display: none; flex: 1 1 auto; overflow: auto; padding: var(--space-4); padding-bottom: calc(var(--controlbar-h) + var(--space-4)); }
.lk-rail-panel[data-active="true"] { display: block; animation: lk-fade var(--dur) var(--ease-out); }
@keyframes lk-fade { from { opacity: 0; } }

.lk-rail-panel h2 { margin-bottom: var(--space-3); display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.lk-rail-panel h3 { margin: var(--space-5) 0 var(--space-2); }
.lk-rail-panel .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }
.helper-note, .empty-state { font-size: var(--fs-xs); color: var(--text-muted); }
.empty-state { padding: var(--space-3) 0; }

#lk-seat-count { font-weight: 700; }

#waiting-members, #pending-control-requests { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
#waiting-members li, #pending-control-requests li {
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-md);
  display: grid;
  gap: var(--space-2);
}
.agent-capability-review {
  margin-top: var(--space-2);
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.capability-choice { display: flex; gap: var(--space-2); align-items: flex-start; margin: var(--space-2) 0; font-size: var(--fs-sm); }
.capability-list { margin: 4px 0; padding-left: var(--space-5); }

/* Advanced (AI / helper / remote-control) progressive disclosure */
.lk-advanced-section { margin-bottom: var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.lk-advanced-section:last-child { border-bottom: none; }
.lk-advanced-section label:not(.toggle) { display: block; font-size: var(--fs-sm); font-weight: 650; margin: var(--space-3) 0 var(--space-1); }
.lk-advanced-section select, .lk-advanced-section textarea { width: 100%; }

/* ----------------------------------------------------------------------------
 * Toasts
 * -------------------------------------------------------------------------- */
/* Toasts live at the bottom-right, above the control bar. The top of the
 * viewport belongs to the safety banners, and nothing transient should ever
 * cover the verification codes or the Admit button. */
#lk-toasts {
  position: fixed;
  top: auto;
  bottom: calc(var(--controlbar-h) + var(--space-3));
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--space-2);
  width: min(340px, calc(100vw - 32px));
  pointer-events: none;
}
/* Before the call starts there is no control bar to clear. */
body:not([data-call="active"]) #lk-toasts { bottom: var(--space-4); }
.lk-toast {
  pointer-events: auto;
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--surface-raised) 96%, transparent);
  backdrop-filter: var(--chrome-blur);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  font-size: var(--fs-sm);
  animation: lk-toast-in var(--dur-slow) var(--ease-out);
}
.lk-toast.is-warn { border-left-color: var(--warn); }
.lk-toast.is-danger { border-left-color: var(--danger); }
.lk-toast .lk-toast-close { margin-left: auto; min-height: auto; padding: 0 4px; background: none; border: none; color: var(--text-muted); font-size: 1.1rem; line-height: 1; }
.lk-toast .lk-toast-close:hover { color: var(--text); transform: none; }
@keyframes lk-toast-in { from { opacity: 0; transform: translateX(16px); } }

/* ----------------------------------------------------------------------------
 * Waiting-to-join banner (host only)
 *
 * This is the one moment where the product must interrupt: someone is at the
 * door. It reads as a notification card, and it is deliberately narrower than
 * the column so the Admit button never slides under the toast stack.
 * -------------------------------------------------------------------------- */
.lk-waiting-banner {
  display: grid;
  gap: var(--space-2);
  /* Sticky and above the toast layer. Load-bearing, not cosmetic: the toast
     announcing "X is waiting" is fixed at the top-right and used to land
     squarely on top of this banner's Admit button, so the pointer hit the
     toast instead and Admit silently did nothing. Pinning it also keeps a
     scrolled-down host aware that someone is waiting. */
  position: sticky;
  top: var(--space-2);
  z-index: calc(var(--z-toast) + 1);
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  width: min(560px, 100%);
  background: color-mix(in srgb, var(--surface-raised) 96%, transparent);
  backdrop-filter: var(--chrome-blur);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  animation: lk-knock var(--dur-slow) var(--ease-out);
}
.lk-waiting-banner[hidden] { display: none; }
.lk-waiting-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.lk-waiting-row span { font-weight: 600; flex: 1 1 14ch; min-width: 0; }
/* The knock: a yellow dot that pulses in front of each waiting person. */
.lk-waiting-row span::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 9px;
  border-radius: 50%;
  background: var(--warn);
  vertical-align: middle;
  animation: lk-breathe 1.8s var(--ease) infinite;
}
.lk-waiting-row button { flex: 0 0 auto; min-height: 40px; padding: 8px 20px; }
@keyframes lk-knock { from { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* ----------------------------------------------------------------------------
 * Dialogs
 * -------------------------------------------------------------------------- */
dialog {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-3);
  padding: clamp(var(--space-5), 3vw, var(--space-8));
  max-width: min(540px, calc(100vw - 32px));
  width: 100%;
}
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
dialog[open] { animation: lk-rise-dialog var(--dur-slow) var(--ease-out); }
@keyframes lk-rise-dialog { from { opacity: 0; transform: translateY(12px) scale(.985); } }
dialog h2 { margin-bottom: var(--space-3); }
dialog label { display: block; font-size: var(--fs-sm); font-weight: 650; }
dialog .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
dialog form { display: grid; gap: var(--space-3); }
#invite-url { font-family: var(--font-mono); font-size: var(--fs-sm); width: 100%; }
#mcp-pairing-summary { white-space: pre-wrap; font-family: var(--font-mono); font-size: var(--fs-xs); background: var(--surface-2); padding: var(--space-3); border-radius: var(--radius-sm); max-height: 40vh; overflow: auto; }
progress { width: 100%; height: 12px; }

/* Keyboard shortcut overlay */
#lk-shortcuts dl { display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-4); margin: 0; align-items: center; }
#lk-shortcuts dt { justify-self: start; }
#lk-shortcuts dd { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }
kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 7px;
}

/* ----------------------------------------------------------------------------
 * Responsive
 * -------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  .call-layout[data-rail="open"] { grid-template-columns: minmax(0, 1fr) 0; }
  /* Scoped to the call area, not the viewport, so the rail opens below
   * whatever safety banners are showing however tall they are. */
  .call-layout[data-rail="open"] .lk-rail {
    display: flex;
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 92vw);
    z-index: var(--z-dialog);
    box-shadow: var(--shadow-3);
    animation: lk-slide-in var(--dur-slow) var(--ease-out);
  }
  /* Stops short of the control bar: with the rail open, Mute, Share and End
   * must stay lit and clickable rather than sitting under the scrim. */
  .call-layout[data-rail="open"]::before {
    content: "";
    position: absolute; inset: 0 0 var(--controlbar-h) 0;
    background: var(--scrim);
    z-index: calc(var(--z-dialog) - 1);
  }
  @keyframes lk-slide-in { from { transform: translateX(16px); opacity: 0; } }
}

@media (max-width: 767px) {
  :root { --controlbar-h: 92px; --stage-inset: var(--space-3); }
  .call-main { padding-bottom: calc(var(--controlbar-h) + var(--space-3)); }
  /* The transport line is long prose; below tablet keep only the room name. */
  .lk-room-context .eyebrow { display: none; }
  #members { grid-template-columns: 1fr 1fr; }
  .lk-stage-wrap:has(.stage[data-has-share="true"]) #members { grid-auto-columns: minmax(210px, 76vw); min-height: 132px; }
  .controls {
    left: 0; right: 0;
    transform: none;
    bottom: 0;
    width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding: var(--space-2) var(--space-2) max(var(--space-2), env(safe-area-inset-bottom));
    max-width: none;
    justify-content: flex-start;
  }
  /* Every control — End most of all — has to be on screen without scrolling
   * the bar. `display: contents` dissolves the grouping boxes so all eight
   * buttons share the width evenly; grouping by threes would give the single
   * End button a quarter of the bar and squeeze the rest into overlap. */
  .controls { gap: 0; overflow-x: visible; }
  .controls .lk-group { display: contents; }
  .lk-iconbtn { min-width: 0; flex: 1 1 0; padding: 7px 1px; overflow: hidden; }
  .lk-iconbtn .lk-ib-label {
    font-size: 10px;
    letter-spacing: -.01em;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Stacked above the reconnect pill so the two never sit on each other. */
  #lk-toasts { bottom: calc(var(--controlbar-h) + 56px); left: 50%; right: auto; transform: translateX(-50%); }
  body:not([data-call="active"]) #lk-toasts { bottom: var(--space-4); }
  #lk-reconnect-banner { bottom: calc(var(--controlbar-h) + var(--space-2)); }
  .lk-overflow-menu { bottom: calc(var(--controlbar-h) + var(--space-2)); }
  .lk-topbar { padding: var(--space-2) var(--space-3); gap: var(--space-2); }
  .lk-brand .lk-wordmark { font-size: 1rem; }
  .lk-brand .lk-logo { width: 28px; height: 28px; }
  /* Stacked banner text instead of a clipped single line. Wrapped text makes
   * these banners taller, so the column below them starts lower. */
  .lk-banner { align-items: flex-start; padding: var(--space-2) var(--space-3); }
  /* A long remote-control message wraps to three lines here. The flex shell
   * absorbs that, so there is nothing to offset — and the banner is left
   * uncapped on purpose: "someone is controlling this computer" earning a
   * quarter of a phone screen is the correct outcome, and capping it would
   * put the Stop button behind a scroll. */
  #lk-controller-banner { flex-wrap: wrap; }
  #lk-controller-banner .lk-stop { width: 100%; }
  .local-preview { width: min(132px, 38%); margin: var(--space-2); }
  .verification { padding: var(--space-4); }
  /* On a phone the satisfied strip stacks; a three-column row only wraps the
   * button onto two lines and costs more height than it saves. */
  body:has(.controls #mic-toggle:not(:disabled)) #verification {
    grid-template-columns: minmax(0, 1fr);
    padding: var(--space-2) var(--space-3);
  }
  body:has(.controls #mic-toggle:not(:disabled)) #verification > strong,
  body:has(.controls #mic-toggle:not(:disabled)) #verification > #verification-code,
  body:has(.controls #mic-toggle:not(:disabled)) #verification > #verify-room { grid-row: auto; grid-column: 1; justify-self: start; }
  body:has(.controls #mic-toggle:not(:disabled)) #verification > p { font-size: var(--fs-xs); margin-bottom: 0; }
}

@media (max-width: 560px) {
  /* The account pill is redundant next to Sign out on a phone. */
  #auth-state { display: none; }
  /* Stacked: reset the row's horizontal flex basis, or `flex: 1 1 14ch`
   * becomes a 14ch-tall growing label with a hole under it. */
  .lk-waiting-row { flex-direction: column; align-items: stretch; }
  .lk-waiting-row span { flex: 0 0 auto; }
  .lk-waiting-row button { width: 100%; }
}

@media (max-width: 420px) {
  #members { grid-template-columns: 1fr; }
  .lk-brand .lk-wordmark span { display: inline; }
  #verification-code .lk-vcode-value, .lk-vcode { letter-spacing: .08em; }
}

/* Short viewports (a laptop with the browser chrome, or a phone in landscape):
 * give the stage the height back by trimming the shell. */
@media (max-height: 620px) {
  :root { --topbar-h: 56px; --controlbar-h: 72px; --stage-min: 140px; }
  .lk-iconbtn { min-height: 48px; }
  .lk-stage-wrap:has(.stage[data-has-share="true"]) #members { min-height: 92px; max-height: 30vh; }
}

/* ----------------------------------------------------------------------------
 * Preferences
 * -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  button:hover:not(:disabled) { transform: none; }
  .lk-spinner { animation: none; }
  /* State must still be legible without the pulse that normally carries it. */
  .lk-room-context .eyebrow::before,
  .lk-waiting-row span::before,
  .remote-live-indicator::before,
  #live-indicator::before,
  #lk-share-banner .lk-dot,
  #members > li[data-speaking="true"] .lk-tile-avatar { animation: none !important; }
  #members > li[data-speaking="true"] .lk-tile-avatar { box-shadow: 0 0 0 3px var(--speaking); }
}

@media (forced-colors: active) {
  button, .lk-iconbtn, .panel, #members > li, dialog, .lk-toast, .lk-banner {
    border: 1px solid CanvasText;
  }
  .lk-iconbtn[aria-pressed="true"],
  #members > li[data-speaking="true"] { outline: 2px solid Highlight; }
  :focus-visible { outline: 2px solid Highlight; box-shadow: none; }
  .stage, .lk-waiting-banner, .controls { border: 1px solid CanvasText; }
  .remote-live-indicator, #live-indicator, .peer-media h3 { border: 1px solid CanvasText; }
}

/* ----------------------------------------------------------------------------
 * Help, onboarding and guidance layer
 *
 * Everything below belongs to link-help.js and the matching markup in
 * index.html (.lk-guide, .lk-chip, .lk-steps, .lk-action-notes, the help
 * dialog). It is additive: it only adds new rules and a few presentational
 * overrides, and it keys off the data-lk-phase / data-tone attributes that
 * link-help.js maintains. If link-help.js does not run, the static markup is a
 * correct signed-out page and nothing here is load-bearing.
 * -------------------------------------------------------------------------- */
:root {
  --fs-lede: clamp(1.02rem, 1.4vw, 1.18rem);
  --tone-neutral: var(--accent);
  --tone-ok: var(--success);
  --tone-attention: var(--warn);
  --tone-warn: var(--warn);
  --tone-danger: var(--danger);
}

/* "What to do next" card. One element, always between the top bar and <main>:
 * a centred card on the start page, a full-width strip inside a call. */
.lk-guide {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--tone-neutral);
  box-shadow: var(--shadow-1);
}
.lk-guide[data-tone="ok"] { border-left-color: var(--tone-ok); }
.lk-guide[data-tone="attention"],
.lk-guide[data-tone="warn"] { border-left-color: var(--tone-warn); }
.lk-guide[data-tone="danger"] { border-left-color: var(--tone-danger); }
.lk-guide-icon {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
.lk-guide[data-tone="ok"] .lk-guide-icon { background: color-mix(in srgb, var(--tone-ok) 16%, transparent); color: var(--tone-ok); }
.lk-guide[data-tone="attention"] .lk-guide-icon,
.lk-guide[data-tone="warn"] .lk-guide-icon { background: var(--warn-soft); color: var(--warn); }
.lk-guide[data-tone="danger"] .lk-guide-icon { background: var(--danger-soft); color: var(--danger); }
.lk-guide-body { min-width: 0; }
.lk-guide-kicker {
  margin: 0 0 2px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.lk-guide-title { margin: 0; font-size: var(--fs-h3); font-weight: 750; letter-spacing: -.01em; line-height: 1.25; }
.lk-guide-text { margin: var(--space-1) 0 0; color: var(--text-muted); font-size: var(--fs-sm); max-width: 70ch; }
.lk-guide-action { flex-shrink: 0; }

/* Start page: the card sits above the welcome panel, aligned with it. */
body:not([data-call="active"]) .lk-guide {
  max-width: 728px;
  margin: var(--space-6) auto 0;
  width: calc(100% - 2 * var(--space-4));
  border-radius: var(--radius-lg);
}
body:not([data-call="active"]) .lk-welcome-wrap { padding-top: var(--space-4); }

/* In a call: a full-width strip under the banners. Same shell rule as the
 * banners: static, content-sized, never an offset constant. */
body[data-call="active"] .lk-guide {
  flex: 0 0 auto;
  padding: var(--space-2) clamp(var(--space-4), 4vw, var(--space-8));
  border-width: 0 0 1px 4px;
  border-radius: 0;
  box-shadow: none;
  gap: var(--space-3);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}
body[data-call="active"] .lk-guide-icon { width: 32px; height: 32px; }
body[data-call="active"] .lk-guide-icon .lk-ic { width: 18px; height: 18px; }
body[data-call="active"] .lk-guide-kicker { display: none; }
body[data-call="active"] .lk-guide-title { font-size: 1rem; }
body[data-call="active"] .lk-guide-text { margin-top: 0; font-size: var(--fs-sm); }
/* Once media is flowing the guide gets out of the way: one quiet line, and on a
 * phone it is dropped from view (it stays in the DOM and the accessibility tree
 * so a screen reader or agent can still read it). */
body[data-call="active"] .lk-guide[data-lk-phase="live"],
body[data-call="active"] .lk-guide[data-lk-phase="sharing-remote"],
body[data-call="active"] .lk-guide[data-lk-phase="sharing-local"] { padding-block: 6px; }
body[data-call="active"] .lk-guide[data-lk-phase="live"] .lk-guide-title,
body[data-call="active"] .lk-guide[data-lk-phase="sharing-remote"] .lk-guide-title,
body[data-call="active"] .lk-guide[data-lk-phase="sharing-local"] .lk-guide-title { font-size: var(--fs-sm); }
body[data-call="active"] .lk-guide[data-lk-phase="live"] .lk-guide-icon,
body[data-call="active"] .lk-guide[data-lk-phase="sharing-remote"] .lk-guide-icon,
body[data-call="active"] .lk-guide[data-lk-phase="sharing-local"] .lk-guide-icon { display: none; }
body[data-call="active"] .lk-guide[data-lk-phase="live"] .lk-guide-body,
body[data-call="active"] .lk-guide[data-lk-phase="sharing-remote"] .lk-guide-body,
body[data-call="active"] .lk-guide[data-lk-phase="sharing-local"] .lk-guide-body {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-3);
}
@keyframes lk-guide-in { from { opacity: 0; transform: translateY(-4px); } }
.lk-guide { animation: lk-guide-in var(--dur-slow) var(--ease-out); }

/* Plain-language status chip in the top bar (also visible on phones, where the
 * technical eyebrow line is dropped). */
.lk-chip {
  display: inline-flex; align-items: center; gap: 6px;
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 750;
  letter-spacing: .02em;
  white-space: nowrap;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--tone-neutral) 40%, transparent);
}
.lk-chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tone-neutral); }
.lk-chip[data-tone="ok"] { background: color-mix(in srgb, var(--tone-ok) 14%, transparent); border-color: color-mix(in srgb, var(--tone-ok) 45%, transparent); }
.lk-chip[data-tone="ok"]::before { background: var(--tone-ok); }
.lk-chip[data-tone="attention"], .lk-chip[data-tone="warn"] { background: var(--warn-soft); border-color: color-mix(in srgb, var(--tone-warn) 55%, transparent); }
.lk-chip[data-tone="attention"]::before, .lk-chip[data-tone="warn"]::before { background: var(--tone-warn); }
.lk-chip[data-tone="danger"] { background: var(--danger-soft); border-color: color-mix(in srgb, var(--tone-danger) 55%, transparent); }
.lk-chip[data-tone="danger"]::before { background: var(--tone-danger); }
.lk-chip[hidden] { display: none; }
/* The connecting/reconnecting status chip gently pulses so it is obvious the
   call is still establishing, even when muted or after an audio-device change
   (live-call feedback, Bobby 2026-10-14). */
body[data-lk-phase="connecting"] #lk-status-chip,
body[data-lk-phase="reconnecting"] #lk-status-chip { animation: lk-breathe 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  body[data-lk-phase="connecting"] #lk-status-chip,
  body[data-lk-phase="reconnecting"] #lk-status-chip { animation: none; }
}

/* Help button */
.lk-help-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; }
.lk-help-btn .lk-ic { width: 20px; height: 20px; }

/* Start page */
.welcome .eyebrow {
  display: inline-flex;
  padding: 4px 12px;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  letter-spacing: .08em;
}
.welcome h1 { max-width: 18ch; }
.lk-lede { font-size: var(--fs-lede); line-height: 1.5; color: var(--text-muted); max-width: 58ch; margin-bottom: 0; }
.welcome .actions { align-items: center; margin-bottom: var(--space-4); }
.welcome #create-room { min-height: 52px; padding: 12px 28px; font-size: 1.05rem; }
.welcome #join-room { min-height: 52px; padding: 12px 24px; }
.lk-action-notes {
  list-style: none; margin: 0 0 var(--space-5); padding: var(--space-3) var(--space-4);
  display: grid; gap: var(--space-1);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.lk-action-notes strong { color: var(--text); font-weight: 700; }

/* Four-step explainer; link-help.js marks done / current / todo. */
.lk-steps {
  list-style: none; margin: var(--space-6) 0 var(--space-4); padding: 0;
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.lk-steps > li {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.lk-step-num {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-weight: 800; font-size: var(--fs-sm);
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--line-strong);
}
.lk-step-copy { display: flex; flex-direction: column; gap: 2px; }
.lk-step-copy strong { font-size: var(--fs-sm); }
.lk-step-copy > span { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.45; }
.lk-steps > li[data-state="current"] { border-color: var(--accent); background: var(--accent-soft); }
.lk-steps > li[data-state="current"] .lk-step-num { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.lk-steps > li[data-state="done"] .lk-step-num { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); border-color: var(--success); }
.lk-steps > li[data-state="done"] .lk-step-copy > span { display: none; }

.security-note { display: flex; gap: var(--space-3); align-items: flex-start; }
.security-note .lk-ic { flex-shrink: 0; width: 20px; height: 20px; margin-top: 2px; color: var(--accent); }
.security-note strong { color: var(--text); }

/* Verification: plain gloss above the full, unabridged security text. */
.lk-verify-plain {
  display: flex; gap: var(--space-3); align-items: flex-start;
  font-weight: 600;
  color: var(--text);
}
.lk-verify-plain .lk-ic { flex-shrink: 0; width: 20px; height: 20px; margin-top: 2px; color: var(--warm); }
.verification > p:not(.lk-verify-plain) { font-size: var(--fs-sm); color: var(--text-muted); }
body:has(.controls #mic-toggle:not(:disabled)) #verification .lk-verify-plain { display: none; }

/* The page's default status line repeats the guide card; keep it for assistive
 * tech but stop drawing it twice. link-help.js sets the flag. */
#status[data-lk-dup="true"] {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.lk-advanced-intro { margin-bottom: var(--space-4); }
.lk-dialog-lede { color: var(--text-muted); margin: 0; }

/* Help dialog */
#lk-help-dialog { max-width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
.lk-help-steps { margin: 0; padding-left: var(--space-6); display: grid; gap: var(--space-2); }
.lk-help-steps li::marker { font-weight: 800; color: var(--accent); }
.lk-faq { display: grid; gap: var(--space-2); }
.lk-faq details {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.lk-faq summary { cursor: pointer; padding: var(--space-3) var(--space-4); font-weight: 650; border-radius: var(--radius-md); }
.lk-faq details[open] summary { border-bottom: 1px solid var(--line); border-radius: var(--radius-md) var(--radius-md) 0 0; }
.lk-faq details > p { margin: 0; padding: var(--space-3) var(--space-4); color: var(--text-muted); font-size: var(--fs-sm); }
.lk-faq code { font-family: var(--font-mono); font-size: .9em; background: var(--surface); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 767px) {
  .lk-guide { grid-template-columns: auto minmax(0, 1fr); }
  .lk-guide-action { grid-column: 1 / -1; width: 100%; }
  body[data-call="active"] .lk-guide { padding-block: var(--space-2); }
  /* In a live call on a phone the strip yields its height to the stage. */
  body[data-call="active"] .lk-guide[data-lk-phase="live"],
  body[data-call="active"] .lk-guide[data-lk-phase="sharing-remote"],
  body[data-call="active"] .lk-guide[data-lk-phase="sharing-local"] {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); border: 0; white-space: nowrap;
  }
  .lk-chip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
  .welcome h1 { max-width: none; }
}

@media (max-width: 560px) {
  .lk-help-btn { padding: 8px; min-width: 40px; justify-content: center; }
  .lk-help-btn span {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .lk-steps { grid-template-columns: 1fr 1fr; }
  .welcome #create-room, .welcome #join-room { flex: 1 1 100%; }
}

/* Phone top bar: logo, status chip, help, theme and sign-out must all fit in
 * 375px without widening the page (the fixed control bar is as wide as the
 * layout viewport). The wordmark stays available to assistive tech. */
@media (max-width: 480px) {
  .lk-brand .lk-wordmark {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .lk-topbar { gap: var(--space-2); }
  .lk-chip { max-width: 38vw; padding: 3px 10px; }
  .lk-account { gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .lk-guide { animation: none; }
}

@media (forced-colors: active) {
  .lk-guide, .lk-chip, .lk-steps > li, .lk-faq details { border: 1px solid CanvasText; }
  .lk-steps > li[data-state="current"] { outline: 2px solid Highlight; }
}

/* Browser capability notes (link-compat.js): an unavailable control stays
   visible, looks unavailable, and explains itself when pressed. */
.browser-notes { margin-top: var(--space-2, 0.5rem); }
[data-compat-unavailable] { opacity: 0.55; cursor: not-allowed; }

/* One-tap AI assistant: card, consent/control banners, always-visible Stop. */
.lk-ai-card { border: 1px solid var(--accent, #087dff); border-radius: 10px; padding: 12px 14px; }
.lk-ai-card .toggle { font-weight: 650; }
.lk-ai-manual > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.lk-ai-banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 10px 14px; margin: 0 0 8px; border: 1px solid var(--accent, #087dff); border-radius: 10px; }
.lk-ai-banner[hidden] { display: none; }
.lk-ai-banner-alert { border-width: 2px; border-color: #ff5964; }
.lk-iconbtn.lk-ai-stop { background: #ff5964; color: #fff; border-color: #ff5964; }
.lk-iconbtn.lk-ai-stop[hidden], #ai-enable-proxy[hidden] { display: none; }

/* Voice quality indicator (audio-quality.js). Scoped to .lk-aq*: a status dot
 * plus a five-segment microphone meter. Colour is never the only signal: the
 * label always spells the level out. */
.lk-aq {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line);
  font-size: var(--fs-xs); font-weight: 650; white-space: nowrap; color: var(--text);
}
.lk-aq[hidden] { display: none; }
.lk-aq-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--tone-neutral); }
.lk-aq[data-level="good"] .lk-aq-dot { background: var(--tone-ok); }
.lk-aq[data-level="fair"] .lk-aq-dot { background: var(--tone-warn); }
.lk-aq[data-level="poor"] .lk-aq-dot { background: var(--tone-danger); }
.lk-aq[data-level="poor"] { border-color: color-mix(in srgb, var(--tone-danger) 55%, transparent); }
.lk-aq-meter { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.lk-aq-meter i { display: block; width: 3px; border-radius: 1px; background: color-mix(in srgb, currentColor 22%, transparent); }
.lk-aq-meter i:nth-child(1) { height: 4px; }
.lk-aq-meter i:nth-child(2) { height: 6px; }
.lk-aq-meter i:nth-child(3) { height: 8px; }
.lk-aq-meter i:nth-child(4) { height: 10px; }
.lk-aq-meter i:nth-child(5) { height: 12px; }
.lk-aq-meter[data-level="1"] i:nth-child(-n+1),
.lk-aq-meter[data-level="2"] i:nth-child(-n+2),
.lk-aq-meter[data-level="3"] i:nth-child(-n+3),
.lk-aq-meter[data-level="4"] i:nth-child(-n+4),
.lk-aq-meter[data-level="5"] i:nth-child(-n+5) { background: var(--tone-ok); }
.lk-aq-meter[data-clip="true"] i { background: var(--tone-danger); }
@media (max-width: 480px) {
  .lk-aq-text { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
  .lk-aq { padding: 3px 8px; }
}
@media (forced-colors: active) {
  .lk-aq { border: 1px solid CanvasText; }
  .lk-aq-meter i { background: GrayText; }
  .lk-aq-meter[data-level="1"] i:nth-child(-n+1), .lk-aq-meter[data-level="2"] i:nth-child(-n+2), .lk-aq-meter[data-level="3"] i:nth-child(-n+3),
  .lk-aq-meter[data-level="4"] i:nth-child(-n+4), .lk-aq-meter[data-level="5"] i:nth-child(-n+5) { background: Highlight; }
}

/* ----------------------------------------------------------------------------
 * Optional camera: tiles, and the background / look panel (camera-ui.js)
 * Camera tiles live in their own strip, never inside #stage, so they are not
 * mistaken for a shared screen.
 * -------------------------------------------------------------------------- */
.lk-camera-strip {
  display: grid;
  /* Tiles are thumbnails, capped so a camera never out-grows a shared screen. */
  grid-template-columns: repeat(auto-fill, minmax(150px, 240px));
  justify-content: start;
  gap: var(--space-3);
  min-width: 0;
}
.lk-camera-strip[hidden] { display: none; }
.lk-cam-tile {
  position: relative;
  margin: 0;
  aspect-ratio: 16 / 9;
  min-width: 0;
  background: #000;
  border: 1px solid var(--stage-edge);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-2);
}
.lk-cam-video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
/* Only your own preview is mirrored; people see you the right way round. */
.lk-cam-tile.is-self .lk-cam-video { transform: scaleX(-1); }
.lk-cam-name {
  position: absolute; left: var(--space-2); bottom: var(--space-2);
  max-width: calc(100% - var(--space-4));
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(2, 9, 20, .68);
  color: #fff;
  font-size: var(--fs-xs); font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lk-cam-effects {
  position: absolute; top: var(--space-2); right: var(--space-2);
  min-height: 36px; padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: rgba(2, 9, 20, .68);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .24);
  font-size: var(--fs-xs); font-weight: 700;
}

.lk-camera-panel {
  position: fixed;
  z-index: var(--z-dialog);
  bottom: calc(var(--controlbar-h) + var(--space-3));
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px));
  max-height: min(72vh, 600px);
  overflow: auto;
  background: color-mix(in srgb, var(--surface-raised) 96%, transparent);
  backdrop-filter: var(--chrome-blur);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.lk-camera-panel[hidden] { display: none; }
.lk-camera-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.lk-camera-field { display: flex; flex-direction: column; gap: var(--space-2); }
.lk-camera-field[hidden] { display: none; }
.lk-camera-field label { font-size: var(--fs-sm); font-weight: 650; }
.lk-camera-field select { width: 100%; }
.lk-camera-legend { margin: 0; font-size: var(--fs-sm); font-weight: 700; }
.lk-bg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--space-2); }
.lk-bg-option {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  min-height: 44px; padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.lk-bg-option[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.lk-bg-option:disabled { opacity: .5; }
.lk-bg-label { font-size: var(--fs-xs); font-weight: 650; text-align: center; }
.lk-bg-swatch { display: block; height: 40px; border-radius: 6px; background: var(--surface-2); }
.lk-bg-swatch[data-bg="none"] { background: repeating-linear-gradient(135deg, var(--surface-2) 0 8px, var(--surface) 8px 16px); }
.lk-bg-swatch[data-bg="blur"] { background: radial-gradient(circle at 30% 40%, #6aa6ff 0, transparent 55%), radial-gradient(circle at 75% 60%, #00c9ff 0, transparent 50%), #26395a; filter: blur(1.5px); }
.lk-bg-swatch[data-bg="studio"] { background: linear-gradient(135deg, #1c2433, #4a5a78 55%, #8793ad); }
.lk-bg-swatch[data-bg="heapfile"] { background: linear-gradient(135deg, #020914, #08213b 55%, #087dff); }
.lk-bg-swatch[data-bg="loft"] { background: linear-gradient(135deg, #3a2a22, #8a5a3c 55%, #e8b878); }
.lk-bg-swatch[data-bg="ocean"] { background: linear-gradient(135deg, #06283d, #0b6e8a 55%, #7fd4d8); }
.lk-bg-swatch[data-bg="meadow"] { background: linear-gradient(135deg, #12301c, #3f7d4a 55%, #cfe8a8); }
.lk-bg-swatch[data-bg="custom"] { border: 1px dashed var(--line-strong); background: var(--surface); }
.lk-filter-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.lk-filter-option {
  min-height: 44px; padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: var(--fs-sm); font-weight: 650;
}
.lk-filter-option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.lk-filter-option:disabled { opacity: .5; }
.lk-camera-status { margin: 0; min-height: 1.2em; }
.lk-camera-status:empty { display: none; }
.lk-camera-privacy { margin: 0; }
@media (max-width: 767px) {
  .lk-camera-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lk-camera-panel {
    left: 0; right: 0; transform: none; width: auto;
    bottom: var(--controlbar-h);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 62vh;
  }
}

/* ----------------------------------------------------------------------------
 * In-call chat (link-chat.js). Same tokens as the rest of the rail, no inline styles.
 * The log scrolls; the composer stays at the bottom of the panel, above the control bar.
 * -------------------------------------------------------------------------- */
.lk-rail-panel.lk-chat-panel[data-active="true"] { display: flex; flex-direction: column; gap: var(--space-3); overflow: hidden; }
.lk-chat-panel > h2, .lk-chat-panel > .lk-chat-note, .lk-chat-panel > .lk-chat-status, .lk-chat-panel > .lk-chat-form, .lk-chat-panel > .lk-chat-actions { flex: 0 0 auto; margin: 0; }
.lk-chat-note summary { cursor: pointer; font-size: var(--fs-xs); color: var(--text-muted); }
.lk-chat-note p { margin: var(--space-2) 0 0; border-left: 3px solid var(--line-strong); padding: 0 var(--space-3); }
.lk-chat-status { font-size: var(--fs-sm); color: var(--warm); }
.lk-chat-log {
  flex: 1 1 auto; min-height: 120px; overflow-y: auto; margin: 0; padding: 0;
  list-style: none; display: flex; flex-direction: column; gap: var(--space-2);
  overscroll-behavior: contain;
}
.lk-chat-empty { color: var(--text-muted); font-size: var(--fs-sm); padding: var(--space-3) 0; }
.lk-chat-msg {
  max-width: 92%; align-self: flex-start;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-md);
}
.lk-chat-msg.is-mine { align-self: flex-end; background: var(--accent-soft); border-color: var(--accent); }
.lk-chat-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--space-2); font-size: var(--fs-xs); color: var(--text-muted); }
.lk-chat-meta strong { color: var(--text); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.lk-chat-state.is-failed { color: var(--danger); font-weight: 700; }
.lk-chat-state.is-delivered { color: var(--success); }
.lk-chat-text { margin: var(--space-1) 0 0; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; font-size: var(--fs-sm); color: var(--text); }
.lk-chat-form { display: flex; align-items: flex-end; gap: var(--space-2); }
.lk-chat-form textarea {
  flex: 1 1 auto; min-width: 0; resize: none; min-height: 44px; max-height: 120px;
  font: inherit; font-size: 16px; /* 16px stops iOS from zooming the page on focus */
  padding: var(--space-2) var(--space-3);
  color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-md);
}
.lk-chat-form textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lk-chat-form button { flex: 0 0 auto; min-height: 44px; }
.lk-chat-actions { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); }
.lk-chat-actions button { min-height: 32px; padding: 4px 8px; font-size: var(--fs-xs); }
.lk-chat-tab-badge { margin-left: var(--space-1); background: var(--warm); border-color: var(--warm); color: #fff; }
@media (max-width: 767px) {
  .lk-chat-msg { max-width: 100%; }
}

/* Pre-call setup card and the invited person's one-button join (welcome page). */
.lk-invite-card { margin: 18px 0 8px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-2); }
.lk-invite-card[hidden] { display: none; }
.lk-invite-card h2 { margin: 0 0 6px; font-size: 1.25rem; }
.lk-invite-card p { margin: 0 0 12px; }
.lk-invite-join { font-size: 1.05rem; padding: 12px 22px; }
.lk-prep { margin: 18px 0; padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); }
.lk-prep h2 { margin: 0 0 10px; font-size: 1.05rem; }
.lk-prep-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 22px; }
.lk-prep-col label { display: block; margin-top: 8px; }
.lk-prep-col select, .lk-prep-col progress { width: 100%; }
.lk-prep-col .actions { margin-top: 8px; }
.lk-prep-mic-on { display: block; margin-top: 14px; }
