:root {
  --bg: #0f1f17;
  --bg-2: #14281d;
  --panel: #1b3427;
  --panel-2: #23402f;
  --line: #2f5240;
  --text: #eef5ef;
  --muted: #9fb8a8;
  --ball: #d4ec3c;
  --ball-ink: #1d2a05;
  --clay: #d0683f;
  --danger: #e04b4b;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--ball); outline-offset: 1px; border-color: transparent; }
button:focus-visible { outline: 2px solid var(--ball); outline-offset: 2px; }

.primary {
  background: var(--ball); color: var(--ball-ink); font-weight: 700;
  padding: 12px 18px; border-radius: 10px; transition: filter .15s;
}
.primary:hover { filter: brightness(1.07); }
.primary:disabled { opacity: .6; cursor: wait; }
.primary.small { padding: 8px 14px; }
.ghost { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); }
.ghost:hover { color: var(--text); border-color: var(--muted); }
.error { color: #ff9a9a; margin: 0; font-size: .92rem; }

/* ---------- Lobby ---------- */
.lobby {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #24563a 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #5a2c1a 0%, transparent 60%),
    var(--bg);
}
.lobby-card {
  width: min(960px, 100%); background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line); border-radius: 20px; padding: 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); }
.lobby-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px; align-items: start; }
.preview-video {
  position: relative; aspect-ratio: 16/9; background: #08120d; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line);
}
.preview-video video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.preview-controls {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px;
}
.round {
  width: 46px; height: 46px; border-radius: 50%; background: rgba(20,40,29,.85);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 1.15rem;
  backdrop-filter: blur(6px);
}
.round[aria-pressed="false"] { background: var(--danger); border-color: var(--danger); }
.devices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.devices label, .join-form label { display: grid; gap: 6px; font-size: .88rem; color: var(--muted); }
.join-form { display: grid; gap: 14px; }
.hint { margin: -6px 0 4px; color: var(--muted); font-size: .85rem; }

.room-line { margin: 0; color: var(--muted); }
.room-line strong { color: var(--text); word-break: break-all; }
.invite-view { display: grid; gap: 18px; max-width: 560px; }
.notice h2 { margin: 0 0 6px; font-size: 1.25rem; }
.notice p { margin: 0; color: var(--muted); line-height: 1.5; }
.host-panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--bg-2); }
.host-panel summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.host-panel[open] summary { margin-bottom: 14px; color: var(--text); }
.optional { color: var(--muted); font-weight: 400; }
.host-result { display: grid; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.host-result p { margin: 0; }
.host-result .row { display: flex; gap: 10px; flex-wrap: wrap; }
a.ghost { text-decoration: none; display: inline-flex; align-items: center; }
.legal-page { max-width: 760px; line-height: 1.6; }
.legal-page h1 { margin-top: 0; font-size: 1.5rem; }
.legal-page h2 { font-size: 1.1rem; margin: 24px 0 6px; }
.legal-page a { color: var(--ball); }
.legal-page li { margin-bottom: 6px; }
.legal { display: flex; gap: 18px; margin-top: 24px; font-size: .85rem; }
.legal a { color: var(--muted); }
.legal a:hover { color: var(--text); }

@media (max-width: 760px) {
  .lobby-card { padding: 18px; }
  .lobby-grid { grid-template-columns: 1fr; gap: 18px; }
  .devices { grid-template-columns: 1fr; }
}

/* ---------- Call ---------- */
.call { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; background: var(--bg); }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.room-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.room-info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.chip {
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  white-space: nowrap;
}
.chip:hover { border-color: var(--ball); }

.stage { display: flex; min-height: 0; position: relative; }
.grid {
  flex: 1; min-width: 0; display: grid; gap: 10px; padding: 12px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr); align-content: stretch;
}
.tile {
  position: relative; margin: 0; background: #0a1610; border-radius: var(--radius);
  overflow: hidden; border: 2px solid transparent; min-height: 0; transition: border-color .15s;
}
.tile.speaking { border-color: var(--ball); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #0a1610; }
.tile.self video { transform: scaleX(-1); }
.tile.screen video { object-fit: contain; transform: none; }
.tile .avatar {
  position: absolute; inset: 0; display: none; place-items: center; background: var(--panel);
}
.tile.cam-off .avatar { display: grid; }
.tile.cam-off video { visibility: hidden; }
.avatar span {
  width: clamp(56px, 22%, 120px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  font-size: clamp(1.4rem, 4vw, 2.6rem); font-weight: 700; background: var(--clay); color: #fff;
}
.tile figcaption {
  position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; align-items: center;
  padding: 4px 10px; border-radius: 8px; background: rgba(0,0,0,.55); font-size: .88rem;
  max-width: calc(100% - 16px);
}
.tile figcaption .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.focused { grid-column: 1 / -1; grid-row: span 2; }
.tile .reaction {
  position: absolute; left: 50%; bottom: 20%; font-size: 3rem; pointer-events: none;
  animation: floatUp 1.8s ease-out forwards;
}
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(.6); opacity: 0; }
  15% { opacity: 1; transform: translate(-50%, -10px) scale(1.1); }
  100% { transform: translate(-50%, -140px) scale(1); opacity: 0; }
}

.controls {
  display: flex; justify-content: center; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg-2); border-top: 1px solid var(--line); flex-wrap: wrap;
}
.ctrl {
  position: relative; min-width: 52px; height: 52px; padding: 0 16px; border-radius: 26px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 1.2rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.ctrl:hover { border-color: var(--muted); }
.ctrl.off { background: var(--danger); border-color: var(--danger); }
.ctrl.active { background: var(--ball); color: var(--ball-ink); border-color: var(--ball); }
.ctrl.leave { background: var(--danger); border-color: var(--danger); font-size: 1rem; font-weight: 700; }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--clay); color: #fff; font-size: .75rem; font-weight: 700;
  display: grid; place-items: center;
}
.reactions-wrap { position: relative; }
.react-menu {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px;
  padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.react-menu button { font-size: 1.5rem; width: 44px; height: 44px; border-radius: 50%; }
.react-menu button:hover { background: var(--panel-2); }

.chat {
  width: 320px; border-left: 1px solid var(--line); background: var(--bg-2);
  display: grid; grid-template-rows: auto 1fr auto; min-height: 0;
}
.chat header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.chat-log { list-style: none; margin: 0; padding: 12px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.chat-log li { display: grid; gap: 2px; }
.chat-log .meta { font-size: .78rem; color: var(--muted); }
.chat-log .meta b { color: var(--ball); font-weight: 600; }
.chat-log .text { white-space: pre-wrap; word-wrap: break-word; line-height: 1.35; }
.chat-log .sys { color: var(--muted); font-size: .82rem; font-style: italic; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

@media (max-width: 760px) {
  .chat { position: absolute; inset: 0; width: auto; z-index: 5; border-left: 0; }
  .ctrl { min-width: 48px; height: 48px; padding: 0 12px; }
  .controls { gap: 8px; flex-wrap: nowrap; }
  .ctrl.leave { padding: 0 14px; }
  .leave-label { display: none; }
  .grid { gap: 6px; padding: 6px; }
}

.banner {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--clay); color: #fff; padding: 8px 16px; border-radius: 10px; font-size: .92rem;
}
.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--panel); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
