:root {
  --bg: #0a0c10;
  --bg-raised: #12161d;
  --line: #232a35;
  --text: #e7ecf3;
  --muted: #8c97a8;
  --accent: #4f8cff;
  --ok: #3ecf8e;
  --warn: #f2b544;
  --bad: #ef5f5f;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 50% -10%, #162031 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100%;
  display: flex;
}

.screen {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

[hidden] {
  display: none !important;
}

/* Landing ---------------------------------------------------------- */

.gate {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: min(460px, 100%);
  background: linear-gradient(180deg, #141924, #0f131a);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.brand {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(79, 140, 255, 0.12);
  color: var(--accent);
}

h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}

.lead {
  margin: 0 0 24px;
  color: var(--muted);
}

.invite-preview {
  margin: 0 0 18px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

.primary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #06101f;
  background: var(--accent);
  cursor: pointer;
  transition: filter 120ms ease, transform 120ms ease;
}

.primary:hover {
  filter: brightness(1.08);
}

.primary:active {
  transform: translateY(1px);
}

.primary:focus-visible,
.ctl:focus-visible,
.ghost:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.hint {
  margin: 18px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.unlock {
  display: grid;
  gap: 10px;
  text-align: left;
}

.field-label {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b0f15;
  color: var(--text);
  font: inherit;
}

.field:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.form-error {
  margin: 0;
  color: var(--bad);
  font-size: 0.82rem;
  text-align: center;
}

.linklike {
  margin-top: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
}

.linklike:hover {
  color: var(--text);
}

/* Call ------------------------------------------------------------- */

.call {
  padding: 14px clamp(12px, 3vw, 28px) 20px;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  row-gap: 10px;
  min-height: 32px;
}

/* On one line the spacer above absorbs the free space; once the bar wraps
   (host widths around 900-1000px, or narrow phones) the codec and quality
   groups take the whole next row and right-align themselves. */
.codec,
.quality {
  margin-left: auto;
}

.spacer {
  flex: 1;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  font-size: 0.82rem;
  color: var(--muted);
}

.pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.pill[data-state="ok"] {
  color: var(--ok);
  border-color: rgba(62, 207, 142, 0.35);
}

.pill[data-state="busy"],
.pill[data-state="wait"] {
  color: var(--warn);
  border-color: rgba(242, 181, 68, 0.3);
}

.pill[data-state="warn"] {
  color: var(--warn);
}

.pill[data-state="bad"] {
  color: var(--bad);
  border-color: rgba(239, 95, 95, 0.35);
}

.ghost {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}

.ghost:hover {
  border-color: #33405a;
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}

.tile {
  position: relative;
  background: #05070a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 220px;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #05070a;
}

.tile-label {
  position: absolute;
  left: 12px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.72rem;
  color: #cfd8e6;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: rgba(5, 7, 10, 0.72);
  color: var(--muted);
}

.placeholder-sub {
  font-size: 0.82rem;
  opacity: 0.75;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ctl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.ctl:hover {
  background: #171c25;
}

.ctl[aria-pressed="true"] {
  border-color: rgba(242, 181, 68, 0.5);
  color: var(--warn);
}

.ctl.danger {
  border-color: rgba(239, 95, 95, 0.35);
  color: var(--bad);
}

.ctl.danger:hover {
  background: rgba(239, 95, 95, 0.12);
}

.ctl-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.devices {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.devices label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.devices select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 220px;
}

/* Codec ------------------------------------------------------------ */

.codec {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.8rem;
}

.codec-label {
  flex: 0 0 auto;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.codec select {
  flex: 0 0 auto;
  width: 132px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.codec select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: transparent;
}

.codec-actual {
  flex: 0 0 auto;
  min-width: 3.6em;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Quality ---------------------------------------------------------- */

.quality {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.8rem;
}

.quality-label {
  flex: 0 0 auto;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.quality select {
  flex: 0 0 auto;
  width: 112px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.quality-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.quality-role {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--muted);
}

.quality select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: transparent;
}

.quality-hint,
.quality-note {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.quality-note {
  font-size: 0.76rem;
}

/* Notice ----------------------------------------------------------- */

.notice {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.notice-card {
  width: min(440px, 100%);
  text-align: center;
  background: linear-gradient(180deg, #141924, #0f131a);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 36px 30px;
  box-shadow: var(--shadow);
}

.notice-card h2 {
  margin: 0 0 10px;
  font-size: 1.3rem;
}

.notice-card p {
  margin: 0 0 24px;
  color: var(--muted);
}

/* Toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 10px;
  background: #1b2230;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* Small screens ---------------------------------------------------- */

@media (max-width: 860px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: 1.35fr 1fr;
  }

  .tile {
    min-height: 0;
  }

  .ctl-text {
    display: none;
  }

  .ctl {
    padding: 12px 14px;
  }

  /* The topbar wraps on its own now (see .topbar); on a phone the codec and
     quality labels are dropped and only the compact selects remain. */
  .codec {
    gap: 6px;
  }

  .codec-label {
    display: none;
  }

  .codec select {
    width: 120px;
  }

  .codec-actual {
    min-width: 2.8em;
  }

  /* The quality control follows the codec onto the wrapped row. The group
     label is dropped on a phone; the per-side labels and the hint stay, since
     they are the only explanation of which select caps whom. */
  .quality {
    gap: 6px;
  }

  .quality-label {
    display: none;
  }

  .quality select {
    width: 104px;
  }

  .quality-note {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

/* Background ------------------------------------------------------- */

/* Same compact inline group as Codec/Quality, placed right after the codec
   group: codec's own auto margin already pushes the pair to the right edge, so
   this group deliberately has none (two auto margins would spread the row). */
.bg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.8rem;
}

.bg-label {
  flex: 0 0 auto;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.bg select {
  flex: 0 0 auto;
  width: 92px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 120ms ease, opacity 120ms ease;
}

.bg select:hover:not(:disabled) {
  border-color: #33405a;
}

.bg select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: transparent;
}

/* Busy: the model is loading or a mode switch is in flight. Locked, but still
   legible, with the status line carrying the explanation. */
.bg select:disabled {
  opacity: 0.55;
  cursor: progress;
}

.bg[data-state="loading"] select {
  border-color: rgba(242, 181, 68, 0.35);
}

/* A failed switch only needs the red edge: the select stays usable so the
   user can pick "Off" again. Missing/unsupported engines are truly locked. */
.bg[data-state="error"] select {
  border-color: rgba(239, 95, 95, 0.35);
}

.bg[data-state="unavailable"] select {
  border-color: rgba(239, 95, 95, 0.35);
  cursor: not-allowed;
}

.bg[data-state="unsupported"] select {
  cursor: not-allowed;
}

.bg-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 4.4em;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.bg-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.bg-status[data-state="active"] {
  color: var(--ok);
}

.bg-status[data-state="loading"] {
  color: var(--warn);
}

.bg-status[data-state="loading"]::before {
  opacity: 1;
  animation: bg-pulse 1.1s ease-in-out infinite;
}

.bg-status[data-state="error"],
.bg-status[data-state="unavailable"] {
  color: var(--bad);
}

@keyframes bg-pulse {
  50% {
    opacity: 0.2;
  }
}

/* Small screens: drop the group label like Codec/Quality do and let the select
   shrink. The status line stays: it is the only feedback while the model loads
   or when the effect fails. */
@media (max-width: 860px) {
  .bg {
    /* On a phone the group can end up alone on its row (long status text), so
       right-align it like the codec and quality groups. */
    margin-left: auto;
    gap: 6px;
  }

  .bg-label {
    display: none;
  }

  .bg select {
    width: 88px;
  }

  .bg-status {
    min-width: 0;
    font-size: 0.7rem;
  }
}

/* Very narrow screens: the call bar already wraps here; make sure the status
   text can use the row instead of forcing the select off-screen. */
@media (max-width: 420px) {
  .bg-status {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bg-status[data-state="loading"]::before {
    animation: none;
  }
}
