:root {
  --bg: #08080c;
  --bg-2: #101018;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eceaf5;
  --muted: #8e8ba6;
  --accent: #ff5f7e;
  --accent-2: #7a5cff;
  --good: #3ddc97;
  --warn: #ffbf5f;
  --bad: #ff5f5f;
  --radius: 14px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 15% -10%, #1a1430 0%, transparent 60%),
    radial-gradient(1000px 700px at 110% 10%, #2a1030 0%, transparent 55%), var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.screen {
  height: 100dvh;
}
.screen[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.02em;
}
h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1rem;
}
h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.82rem;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.85em;
}

/* ─── buttons & fields ─────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease, border-color 0.15s ease;
}
.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.11);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}
.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn.ghost {
  background: transparent;
}
.btn.small {
  padding: 6px 11px;
  font-size: 0.82rem;
}
.btn.wide {
  width: 100%;
  padding: 13px;
  font-size: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.field.inline {
  flex: 1;
}
.field em {
  font-style: normal;
  color: var(--text);
  float: right;
  font-variant-numeric: tabular-nums;
}
input[type='password'],
input[type='text'],
select {
  appearance: none;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% + 1px), calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
input:focus-visible,
select:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

.error {
  color: var(--bad);
  font-size: 0.86rem;
  margin: 10px 0 0;
}
.warn {
  color: var(--warn);
  font-size: 0.83rem;
  background: rgba(255, 191, 95, 0.08);
  border: 1px solid rgba(255, 191, 95, 0.25);
  padding: 10px 12px;
  border-radius: 10px;
  margin: 12px 0 0;
  line-height: 1.55;
}
.warn p {
  margin: 0;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  cursor: pointer;
  color: var(--text);
}
.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--warn);
  flex: none;
}
.status-line {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 10px 0 0;
  min-height: 1.2em;
}
.status-line.ok {
  color: var(--good);
}
.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 14px 0 0;
  line-height: 1.5;
}

/* ─── login ────────────────────────────────────────────────────────── */
.login {
  display: grid;
  place-items: center;
  padding: 24px;
}
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}
.login-card {
  width: min(400px, 100%);
  padding: 34px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.login-card .field {
  text-align: left;
  margin-top: 6px;
}
.login-mark {
  font-size: 2.4rem;
  line-height: 1;
}

/* ─── setup ────────────────────────────────────────────────────────── */
.setup {
  overflow-y: auto;
  padding: 32px 20px 60px;
  display: flex;
  justify-content: center;
}
.setup-card {
  width: min(720px, 100%);
  padding: 28px;
  height: max-content;
}
.setup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.block {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.block:first-of-type {
  border-top: 0;
}
.block-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.block-head p {
  margin: 3px 0 0;
}
.step {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

/* ─── app shell ────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
}
.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
  flex: none;
}
.brand {
  font-weight: 650;
  letter-spacing: -0.02em;
}
.brand span {
  opacity: 0.85;
}
.pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: 6px;
}
.bar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.pill {
  font-size: 0.74rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill.ok {
  color: var(--good);
  border-color: rgba(61, 220, 151, 0.35);
  background: rgba(61, 220, 151, 0.1);
}
.pill.warn {
  color: var(--warn);
  border-color: rgba(255, 191, 95, 0.35);
  background: rgba(255, 191, 95, 0.1);
}
.pill.bad {
  color: var(--bad);
  border-color: rgba(255, 95, 95, 0.35);
  background: rgba(255, 95, 95, 0.1);
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px;
}

/* ─── stage ────────────────────────────────────────────────────────── */
.stage-wrap {
  position: relative;
  min-width: 0;
  display: grid;
  place-items: center;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
/* The frame is sized to the *content* aspect ratio; the video inside is scaled
   slightly taller so the beacon strip at its bottom edge falls outside. */
.stage-frame {
  position: relative;
  overflow: hidden;
  background: #000;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--content-aspect, 16 / 9);
  width: 100%;
}
.stage-frame video {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  height: calc(100% * var(--overscan, 1));
  width: auto;
  display: block;
}
/* The fallback compositor path reads frames out of this element, and a browser
   only hands out frames for something it is actually painting — so it has to
   stay in the document *and* inside the viewport. Parked off-screen (or
   display:none) it silently stops the cast. Out of sight, just barely. */
.offscreen-source {
  position: fixed;
  top: 0;
  left: 0;
  width: 2px;
  height: 2px;
  opacity: 0.01;
  pointer-events: none;
  z-index: -1;
}
.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
  background: #000;
  text-align: center;
  padding: 20px;
}
.placeholder[hidden] {
  display: none;
}
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.audio-gate {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  z-index: 5;
}
.audio-gate[hidden] {
  display: none;
}

/* ─── rail ─────────────────────────────────────────────────────────── */
.rail {
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}
.cam-tile {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  flex: none;
}
.cam-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1); /* mirror — how people expect to see faces on a call */
}
.cam-tile.self {
  aspect-ratio: 16 / 10;
  opacity: 0.92;
}
.cam-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
}
.cam-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  background: #0b0b12;
}
.cam-empty[hidden] {
  display: none;
}
.cam-tile.muted::after {
  content: '🔇';
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 0.9rem;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}
.ctl {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 4px;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  display: grid;
  gap: 4px;
  justify-items: center;
  transition: background 0.15s ease;
}
.ctl span {
  font-size: 1.1rem;
  line-height: 1;
}
.ctl:hover {
  background: rgba(255, 255, 255, 0.11);
}
.ctl[aria-pressed='false'] {
  background: rgba(255, 95, 95, 0.16);
  border-color: rgba(255, 95, 95, 0.4);
  color: #ffc9c9;
}
.ctl.danger:hover {
  background: rgba(255, 95, 95, 0.2);
  border-color: rgba(255, 95, 95, 0.4);
}

.reactor {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  flex: none;
}
.emoji {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 7px 0;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.15s ease;
}
.emoji:hover {
  transform: translateY(-2px) scale(1.08);
  background: var(--panel-strong);
}

.reactions {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
}
.float-emoji {
  position: absolute;
  bottom: 8%;
  font-size: 2.4rem;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
  animation: floatUp 2.6s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}
@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.6);
  }
  12% {
    opacity: 1;
    transform: translateY(0) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translateY(-260px) scale(1);
  }
}

.sync-panel,
.volume {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  flex: none;
}
.sync-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tag {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  border: 1px solid var(--line);
}
.tag.ok {
  color: var(--good);
  border-color: rgba(61, 220, 151, 0.35);
  background: rgba(61, 220, 151, 0.1);
}
.tag.warn {
  color: var(--warn);
  border-color: rgba(255, 191, 95, 0.35);
  background: rgba(255, 191, 95, 0.1);
}
.sync-rows {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.82rem;
}
.sync-rows div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.sync-rows span {
  color: var(--muted);
}
.sync-rows b {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.diag {
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius);
  padding: 11px;
  font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  white-space: pre-wrap;
  margin: 0;
  flex: none;
}
.diag[hidden] {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: rgba(20, 20, 30, 0.95);
  border: 1px solid var(--line);
  padding: 11px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: min(520px, 90vw);
  font-size: 0.88rem;
}
.toast[hidden] {
  display: none;
}

/* role visibility, driven by <body data-role> */
body:not([data-role='host']) .host-only {
  display: none !important;
}
body:not([data-role='guest']) .guest-only {
  display: none !important;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .rail {
    flex-direction: row;
    overflow-x: auto;
    align-items: flex-start;
  }
  .rail > * {
    min-width: 190px;
  }
  .cam-tile {
    width: 150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
