:root {
  --ink: #1c1412;
  --burgundy: #6d1526;
  --deep: #3c0d16;
  --gold: #c6a15a;
  --gold-bright: #e6c98a;
  --green: #1b6b38;
  --cream: #f6f1e8;
  --paper: #fbf8f3;
  --serif: "Fraunces", Palatino, serif;
  --sans: "Outfit", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}
button, input { font: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

.lobby {
  min-height: 100dvh;
  padding: 1.5rem 6vw 3rem;
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(230, 201, 138, 0.28), transparent 55%),
    linear-gradient(165deg, #4a101a, #2a0a10 70%);
  color: var(--cream);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.4rem;
}
.brand img { height: 46px; width: auto; }
.lobby-card {
  max-width: 640px;
  margin: 8vh auto 0;
}
.kicker {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-bright);
  font-size: 0.78rem;
}
h1 {
  font-family: var(--serif);
  font-weight: 520;
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  line-height: 1.05;
  margin: 0.4rem 0 1rem;
}
.lede { max-width: 38rem; color: rgba(246, 241, 232, 0.86); font-size: 1.08rem; }
form { display: grid; gap: 0.9rem; margin-top: 1.6rem; }
label { display: grid; gap: 0.35rem; font-size: 0.9rem; }
input {
  width: 100%;
  border: 1px solid rgba(230, 201, 138, 0.35);
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  border-radius: 0.8rem;
  padding: 0.85rem 0.9rem;
}
input:focus { outline: 2px solid var(--gold); }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; }
.btn {
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  padding: 0.75rem 1.15rem;
}
.btn.gold { background: linear-gradient(180deg, #f0d7a2, #c49645); color: #2a1608; }
.btn.line { background: transparent; color: var(--cream); border: 1px solid rgba(246, 241, 232, 0.45); }
.btn.tiny { min-height: 36px; padding: 0.35rem 0.75rem; background: transparent; color: inherit; border: 1px solid rgba(230, 201, 138, 0.45); }
.form-error { min-height: 1.2rem; margin: 0; color: #ffd0d0; }

.room {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: #14080b;
  color: var(--cream);
}
.room[hidden], .lobby[hidden] { display: none; }
.topbar, .controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
}
.topbar { padding-bottom: 0.75rem; border-bottom: 1px solid rgba(230, 201, 138, 0.18); }
.top-title { display: flex; flex-direction: column; gap: 0.15rem; }
.top-title strong { font-family: var(--serif); font-weight: 520; }
.top-title span, #people-count, #voice-status { color: var(--gold-bright); font-size: 0.88rem; }
.top-actions { display: flex; align-items: center; gap: 0.6rem; }
.stage { display: grid; grid-template-columns: 1fr; min-height: 0; }
.stage.chat-open { grid-template-columns: 1fr minmax(260px, 340px); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.7rem;
  padding: 0.7rem;
  align-content: start;
  overflow: auto;
}
.tile {
  position: relative;
  background: #241014;
  border-radius: 1rem;
  overflow: hidden;
  min-height: 180px;
  aspect-ratio: 16 / 10;
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #1a0c10;
}
.tile .meta {
  position: absolute;
  left: 0.6rem;
  bottom: 0.55rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  background: rgba(20, 8, 11, 0.72);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}
.tile .avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 2.4rem;
  color: var(--gold-bright);
}
.tile.video-off video { opacity: 0; }
.tile.speaking {
  box-shadow: inset 0 0 0 4px var(--gold-bright);
}
.tile.speaking .flags::after {
  content: "Speaking";
  color: var(--gold-bright);
  margin-left: 0.35rem;
}
.controls {
  justify-content: center;
  flex-wrap: wrap;
  border-top: 1px solid rgba(230, 201, 138, 0.18);
  background: #1b0b0e;
}
.ctrl {
  min-height: 48px;
  border-radius: 999px;
  border: 1px solid rgba(230, 201, 138, 0.4);
  background: transparent;
  color: var(--cream);
  padding: 0.65rem 0.95rem;
}
.ctrl[aria-pressed="false"] { background: var(--burgundy); }
.ctrl.end { border-color: var(--gold-bright); }
.ctrl.leave { background: #8d2436; border-color: transparent; }
.chat {
  display: none;
  grid-template-rows: auto 1fr auto;
  border-left: 1px solid rgba(230, 201, 138, 0.18);
  background: #1b0b0e;
  min-height: 0;
}
.stage.chat-open .chat { display: grid; }
.chat-head, .chat-form { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.7rem; }
.chat-log { overflow: auto; padding: 0 0.8rem 0.6rem; display: flex; flex-direction: column; gap: 0.55rem; }
.bubble { background: rgba(255, 255, 255, 0.05); border-radius: 0.8rem; padding: 0.45rem 0.6rem; }
.bubble strong { display: block; color: var(--gold-bright); font-size: 0.78rem; font-weight: 500; }
.bubble p { margin: 0.15rem 0 0; white-space: pre-wrap; word-break: break-word; }
.chat-form input { background: #14080b; color: var(--cream); border-color: rgba(230, 201, 138, 0.3); }
.status { margin: 0; padding: 0 1rem 0.7rem; text-align: center; color: var(--gold-bright); min-height: 1.2rem; font-size: 0.88rem; }

@media (max-width: 800px) {
  .stage.chat-open { grid-template-columns: 1fr; }
  .stage.chat-open .grid { display: none; }
  .chat { border-left: 0; min-height: 50dvh; }
  .tile { min-height: 220px; }
}
