:root {
  --bg: #0e0f12;
  --panel: #17191e;
  --panel-2: #1f2228;
  --line: #2a2e36;
  --text: #eceae4;
  --muted: #9a9ca3;
  --accent: #f2b544;
  --accent-ink: #1b1405;
  --danger: #e5484d;
  --ok: #3dd68c;
  --radius: 16px;
  --gap: 12px;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.sprite { display: none; }
svg { width: 22px; height: 22px; fill: currentColor; }

/* ------------------------------------------------------------ lobby */

.lobby {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 1fr);
  gap: clamp(24px, 5vw, 72px);
  align-items: center;
  padding: clamp(20px, 6vw, 80px);
  max-width: 1280px;
  margin: 0 auto;
  overflow-y: auto;
  height: 100%;
}

.lobby-preview .tile { aspect-ratio: 16 / 9; width: 100%; }

.preview-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  translate: -50% 0;
  display: flex;
  gap: 12px;
}

.meter {
  position: absolute;
  left: 16px;
  bottom: 24px;
  width: 6px;
  height: 48px;
  border-radius: 3px;
  background: rgb(255 255 255 / 0.15);
  overflow: hidden;
}
.meter i {
  position: absolute;
  inset: auto 0 0 0;
  height: 100%;
  background: var(--ok);
  transform-origin: bottom;
  transform: scaleY(var(--level, 0));
  transition: transform 80ms linear;
}

.media-hint { color: var(--accent); font-size: 14px; margin: 12px 4px 0; }

.brand {
  font-size: clamp(40px, 6vw, 64px);
  letter-spacing: -0.04em;
  margin: 0 0 8px;
  font-weight: 750;
}
.brand .brand-dot { color: var(--accent); }
.notice { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 18px; }
.invite-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 18px; }
.invite-box p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.invite-row { display: flex; gap: 8px; }
.invite-row input { font-size: 13px; padding: 10px 12px; }
.btn-secondary { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 0 16px; font-weight: 600; }
.btn-secondary:hover { background: #2a2e36; }
.tagline { color: var(--muted); margin: 0 0 28px; line-height: 1.5; max-width: 38ch; }

form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
form small { color: #6c6f77; font-size: 12px; }

input, select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
input:focus-visible, select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(242 181 68 / 0.18); }

.devices { margin: 4px 0 18px; }
.devices summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 12px; }

.form-error { color: #ff8589; font-size: 14px; margin: 0 0 12px; }

.btn-primary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  font-weight: 650;
  font-size: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform 120ms, filter 120ms;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

/* ------------------------------------------------------------ tiles */

.tile {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--panel);
  isolation: isolate;
  outline: 2px solid transparent;
  outline-offset: -2px;
  transition: outline-color 150ms;
}
.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.tile--self video { transform: scaleX(-1); }
.tile--self.screen video, .tile.screen video { object-fit: contain; transform: none; }

.tile-avatar {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, var(--panel-2), var(--panel));
}
.tile-avatar span {
  width: clamp(56px, 22%, 120px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(20px, 4vw, 40px);
  font-weight: 650;
  background: #2c2417;
  color: var(--accent);
}
.tile.no-video .tile-avatar { display: grid; }
.tile.no-video video { visibility: hidden; }

.tile.speaking { outline-color: var(--ok); }

.tile-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 20px);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 13px;
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(6px);
}
.tile-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted-icon { display: none; width: 16px; height: 16px; color: var(--danger); flex: none; }
.tile.mic-off .muted-icon { display: block; }

.tile-hand {
  position: absolute;
  top: 10px;
  left: 10px;
  display: none;
  padding: 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  animation: wave 1.2s ease-in-out infinite;
}
.tile-hand svg { width: 20px; height: 20px; display: block; }
.tile.hand .tile-hand { display: block; }
@keyframes wave { 50% { rotate: 14deg; } }

.tile-status {
  position: absolute;
  top: 10px;
  right: 10px;
  display: none;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  background: rgb(0 0 0 / 0.6);
  color: var(--muted);
}
.tile.has-status .tile-status { display: block; }

/* ------------------------------------------------------------ call */

.call {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "stage" "controls";
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  gap: 12px;
}
.call.chat-open {
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "bar bar" "stage chat" "controls chat";
}

.call-bar { grid-area: bar; display: flex; align-items: center; gap: 12px; min-height: 36px; }
.room-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 14px;
  font-weight: 600;
}
.room-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgb(61 214 140 / 0.15); }
.room-pill .count { color: var(--muted); font-weight: 400; }
.banner { padding: 8px 14px; border-radius: 999px; background: #3a2a0d; color: var(--accent); font-size: 14px; }

.stage {
  grid-area: stage;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: var(--gap);
  overflow: auto;
}
.stage > .tile { width: var(--tile-w, 100%); aspect-ratio: 16 / 9; }

.stage.has-featured {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  grid-template-rows: repeat(var(--rail-rows, 4), minmax(0, 1fr));
  align-content: stretch;
}
.stage.has-featured > .tile { width: auto; aspect-ratio: auto; grid-column: 2; }
.stage.has-featured > .tile.featured { grid-column: 1; grid-row: 1 / -1; }
.stage.has-featured > .tile.featured video { object-fit: contain; }

.e2ee-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 0;
  border-radius: 999px;
  background: #13261c;
  color: var(--ok);
  font-size: 13px;
}
.e2ee-pill svg { width: 15px; height: 15px; }
.e2ee-pill code { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--text); letter-spacing: 0.02em; }
.e2ee-pill:hover { background: #183325; }
.e2ee-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 820px) { .e2ee-pill .label { display: none; } }

/* ------------------------------------------------------------ controls */

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

.ctl {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  transition: background 120ms, transform 120ms;
}
.ctl:hover { background: #2a2e36; }
.ctl:active { transform: scale(0.94); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctl.off { background: var(--danger); color: #fff; }
.ctl.active { background: var(--accent); color: var(--accent-ink); }
.ctl--leave { width: 68px; border-radius: 26px; background: var(--danger); color: #fff; }
.ctl--leave:hover { background: #f25c61; }
.lobby .ctl { background: rgb(0 0 0 / 0.5); backdrop-filter: blur(8px); }
.lobby .ctl.off { background: var(--danger); }

.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  line-height: 18px;
  background: var(--accent);
  color: var(--accent-ink);
}

/* ------------------------------------------------------------ chat */

.chat {
  grid-area: chat;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.chat h2 { font-size: 15px; margin: 0; }
.chat-note { margin: 0; padding: 8px 18px; font-size: 12px; color: var(--ok); border-bottom: 1px solid var(--line); }
.messages li.undecryptable .body { color: var(--muted); font-style: italic; }
.icon-btn { border: 0; background: transparent; padding: 8px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

.messages { list-style: none; margin: 0; padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.messages li { max-width: 88%; }
.messages li.mine { align-self: flex-end; text-align: right; }
.messages .meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.messages .body {
  display: inline-block;
  text-align: left;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.4;
}
.messages li.mine .body { background: #3a2c10; }

.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { padding: 10px 12px; }

/* ------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  top: 16px;
  left: 50%;
  translate: -50% 0;
  display: grid;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
  justify-items: center;
}
.toast {
  padding: 10px 16px;
  border-radius: 12px;
  background: rgb(31 34 40 / 0.95);
  border: 1px solid var(--line);
  font-size: 14px;
  max-width: min(90vw, 420px);
  overflow-wrap: anywhere;
  animation: toast-in 180ms ease-out;
  transition: opacity 300ms, translate 300ms;
}
.toast.out { opacity: 0; translate: 0 -6px; }
@keyframes toast-in { from { opacity: 0; translate: 0 -6px; } }

/* ------------------------------------------------------------ small screens */

@media (max-width: 820px) {
  .lobby { grid-template-columns: 1fr; align-content: start; }
  .call.chat-open { grid-template-columns: 1fr; grid-template-areas: "bar" "chat" "controls"; }
  .call.chat-open .stage { display: none; }
  .stage.has-featured { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr) auto; }
  .stage.has-featured > .tile { grid-column: auto; grid-row: 2; aspect-ratio: 1; }
  .stage.has-featured > .tile.featured { grid-column: 1 / -1; grid-row: 1; aspect-ratio: auto; }
  .ctl { width: 46px; height: 46px; }
  .ctl--leave { width: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------ /check */

.check-page { overflow-y: auto; }
.check { max-width: 760px; margin: 0 auto; padding: clamp(20px, 5vw, 56px) 20px 80px; }
.check .brand { font-size: 40px; }
.check-preview .tile { aspect-ratio: 16 / 9; max-width: 360px; margin-bottom: 20px; }
.checks { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.check-row {
  display: grid;
  grid-template-columns: 28px 190px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 14px;
}
.check-row::before { content: "…"; font-weight: 700; color: var(--muted); text-align: center; }
.check-row.ok::before { content: "✓"; color: var(--ok); }
.check-row.warn::before { content: "!"; color: var(--accent); }
.check-row.fail::before { content: "✕"; color: var(--danger); }
.check-name { font-weight: 600; }
.check-detail { color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.check-summary { font-weight: 600; margin: 0 0 16px; }
.check-summary.ok { color: var(--ok); }
.check-summary.warn { color: var(--accent); }
.check-summary.fail { color: #ff8589; }
.check-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.check-actions .btn-primary { width: auto; padding: 12px 22px; }
.check-actions .btn-secondary { padding: 12px 18px; }
.link-btn { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; }
.lobby-links { margin: 14px 2px 0; font-size: 13px; }
.lobby-links a { color: var(--muted); }
@media (max-width: 600px) {
  .check-row { grid-template-columns: 24px minmax(0, 1fr); }
  .check-detail { grid-column: 2; }
}
