:root {
  --ink: #07090c;
  --paper: #f5f7f4;
  --dim: rgba(245, 247, 244, 0.68);
  --glass: rgba(7, 9, 12, 0.58);
  --glass-line: rgba(245, 247, 244, 0.14);
  --six: #e9b949;
  --end: #d23b3b;
  --live: #39c47a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font: 16px/1.4 "Bricolage Grotesque", system-ui, sans-serif;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
:focus-visible { outline: 2px solid var(--six); outline-offset: 2px; }

/* One call fills the screen; two vendors split it. */
.panels { display: grid; height: 100dvh; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.panels.single { grid-template-columns: minmax(0, 1fr); }
.call { position: relative; min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.call:has(.drawer:not([hidden])) { grid-template-columns: 1fr 340px; }

.stage { position: relative; min-height: 0; min-width: 0; background: var(--ink); overflow: hidden; }
.stage > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* The face is trained landscape (16:9). On a portrait screen it is cropped to fit, so pull the
   zoom back a little and favour the right side of the frame. Tweak these two numbers to taste. */
@media (orientation: portrait) {
  .stage > video[data-el="video"] {
    --zoom: 0.9;       /* 1 = fill the full height, smaller = less zoomed in (thin bars top and bottom) */
    --crop-x: 47%;     /* 50% = centre of the frame, lower moves the player right on screen */
    height: calc(100% * var(--zoom)); top: calc((100% - 100% * var(--zoom)) / 2);
    object-position: var(--crop-x) 50%;
  }
  /* The space above and below the pulled-back video is filled with a blurred copy of the same
     stream, so the status pills and control bar sit over picture rather than black bands. */
  .stage > video.backdrop { display: block; }
}
/* Base rules for the two stage videos (the portrait block above only switches the backdrop on). */
/* The trained clips carry a black band of 16 rows (1.5%) along the top edge (compositing). A 3.2%
   overscan keeps it off screen in both orientations. */
.stage > video[data-el="video"] { z-index: 1; transform: scale(1.032); }
.stage > video.backdrop {
  display: none; z-index: 0; pointer-events: none;
  filter: blur(28px) brightness(0.55); transform: scale(1.3);
}
@media (orientation: portrait) { .stage > video.backdrop { display: block; } }

.stage video.self {
  inset: auto 12px calc(16px + var(--safe-b)) auto; z-index: 2;
  width: 18vw; min-width: 72px; max-width: 112px; aspect-ratio: 3 / 4; height: auto;
  transition: bottom 0.25s ease;
  border-radius: 14px; border: 1px solid var(--glass-line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55); transform: scaleX(-1);
}
.stage video.self[hidden] { display: none; }

/* Lobby */
.lobby { position: absolute; inset: 0; display: grid; grid-template-rows: 1fr auto; place-items: center; text-align: center; }
.lobby[hidden] { display: none; }
.poster {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  filter: blur(26px) saturate(0.8) brightness(0.45); transform: scale(1.12); z-index: 0;
}
.lobby-body { position: relative; z-index: 1; padding: 24px; width: 100%; max-width: 440px; justify-self: center; }
.lobby h1 {
  margin: 0 0 8px; font-size: clamp(38px, 7vw, 64px); font-weight: 700; line-height: 1;
  letter-spacing: -0.03em; font-variation-settings: "opsz" 96;
}
.lede { margin: 0 0 28px; color: var(--dim); font-size: 17px; }
.lobby-form { display: grid; gap: 14px; justify-items: center; }
.lobby-form input {
  width: 240px; text-align: center; font-size: 22px; padding: 6px 4px;
  background: none; border: 0; border-bottom: 1.5px solid var(--glass-line); border-radius: 0;
}
.lobby-form input::placeholder { color: var(--dim); }
.lobby-form input:focus { outline: none; border-bottom-color: var(--six); }
.lobby-form select {
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: 10px; padding: 8px 12px; font-size: 14px;
}
.lobby-form select[hidden] { display: none; }
.go {
  margin-top: 6px; width: 240px; padding: 14px 20px; border: 0; border-radius: 999px;
  background: var(--six); color: #1b1300; font-weight: 700; font-size: 17px;
}
.go:not(:disabled):hover { filter: brightness(1.06); }
.note { margin: 18px 0 0; min-height: 1.4em; color: var(--dim); font-size: 14px; }
.note.warn { color: #ffb4b4; }
.lobby .diag {
  position: relative; z-index: 1; margin: 0; padding: 0 16px calc(14px + var(--safe-b));
  color: rgba(245, 247, 244, 0.4); font-size: 12px;
}

/* Tap-to-play gate for mobile autoplay rules */
.tap {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; z-index: 3;
  background: rgba(7, 9, 12, 0.6); color: var(--six); font-size: 20px; font-weight: 700;
}
.tap[hidden] { display: none; }

/* In-call chrome: everything is glass over the video */
.hud { position: absolute; top: calc(12px + var(--safe-t)); left: 12px; display: flex; gap: 6px; z-index: 2; }
.pill {
  background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(10px);
  font-size: 13px; font-variant-numeric: tabular-nums; padding: 4px 11px; border-radius: 999px;
}
.pill:empty { display: none; }
.pill.live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--live); margin-right: 7px; vertical-align: 1px; }
.pill.warn { background: rgba(210, 59, 59, 0.75); border-color: transparent; }
.ai-badge {
  position: absolute; top: calc(12px + var(--safe-t)); right: 12px; z-index: 2;
  background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(10px);
  font-size: 13px; padding: 4px 11px; border-radius: 999px; color: var(--dim);
}

.captions {
  position: absolute; bottom: calc(96px + var(--safe-b)); z-index: 2; pointer-events: none;
  /* Centred in the space left of the self tile, so the two never overlap */
  left: 16px; right: calc(clamp(72px, 18vw, 112px) + 36px); margin: 0 auto; max-width: 640px; text-align: center;
  font-size: 17px; line-height: 1.35; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  color: var(--paper);
}
.captions:empty { display: none; }

.bar {
  position: absolute; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 10px; padding: 8px; border-radius: 999px; z-index: 2;
  background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(14px);
}
.bar[hidden] { display: none; }
/* Idle call: chrome fades out, self tile and captions drop to the edge. A tap brings it back. */
.bar, .hud, .ai-badge, .text-row, .captions { transition: opacity 0.3s ease, bottom 0.25s ease; }
.stage.chrome-hidden :is(.bar, .hud, .ai-badge, .text-row) { opacity: 0; pointer-events: none; }
.stage:not(.chrome-hidden) video.self { bottom: calc(92px + var(--safe-b)); }
.stage.chrome-hidden .captions { bottom: calc(24px + var(--safe-b)); }
@media (prefers-reduced-motion: reduce) { .bar, .hud, .ai-badge, .text-row, .captions, video.self { transition: none; } }
.bar button {
  width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(245, 247, 244, 0.1);
}
.bar button:not(:disabled):hover { background: rgba(245, 247, 244, 0.2); }
.bar button.on { background: var(--paper); color: var(--ink); }
.bar button.muted { background: var(--end); color: #fff; }
.bar .slash { display: none; }
.bar button.muted .slash { display: block; stroke-width: 2.2; }
.bar button.end { background: var(--end); width: 64px; }
.bar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bar button.end svg { fill: currentColor; stroke: none; }

.text-row {
  position: absolute; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%);
  width: min(92%, 560px); display: flex; gap: 8px; z-index: 2;
}
.text-row[hidden] { display: none; }
.text-row input {
  flex: 1; min-width: 0; padding: 12px 16px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(10px);
}
.text-row button { padding: 0 18px; border-radius: 999px; border: 0; background: var(--paper); color: var(--ink); font-weight: 500; }

/* Transcript and timings drawer */
.drawer {
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px; min-height: 0;
  padding: calc(14px + var(--safe-t)) 16px calc(14px + var(--safe-b));
  background: #0d1115; border-left: 1px solid var(--glass-line);
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; color: var(--dim); font-size: 14px; }
.drawer-head button { background: none; border: 1px solid var(--glass-line); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.transcript { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: grid; gap: 6px; align-content: start; }
.transcript li { padding: 8px 12px; border-radius: 14px; max-width: 90%; font-size: 15px; }
.transcript .fan { background: rgba(233, 185, 73, 0.18); justify-self: end; border-bottom-right-radius: 4px; }
.transcript .twin { background: rgba(245, 247, 244, 0.08); border-bottom-left-radius: 4px; }
.transcript .sys { color: var(--dim); font-size: 12px; justify-self: center; background: none; padding: 2px 0; }
.metrics { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 0; font-size: 14px; border-top: 1px solid var(--glass-line); padding-top: 12px; }
.metrics dt { color: var(--dim); }
.metrics dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

@media (max-width: 860px) {
  .panels { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
  .call:has(.drawer:not([hidden])) { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .drawer { border-left: 0; border-top: 1px solid var(--glass-line); max-height: 45dvh; }
}

@media (prefers-reduced-motion: no-preference) {
  .lobby-body { animation: rise 0.5s ease-out both; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}
