:root {
  --bg: #0a0a0f;
  --panel: #14141d;
  --panel2: #1c1c28;
  --line: #2a2a3a;
  --fg: #f2f2f7;
  --dim: #9a9ab0;
  --accent: #5eead4;
  --accent2: #38bdf8;
  --danger: #f43f5e;
  --ok: #34d399;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(900px 500px at 12% -10%, rgba(94,234,212,.10), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(56,189,248,.10), transparent 55%);
}

.hidden { display: none !important; }

button, input, select { font: inherit; color: inherit; }

/* ---------------- lobby ---------------- */
.lobby {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, var(--panel), #0f0f16);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 30px 70px rgba(0,0,0,.55);
}

.card h1 {
  font-size: 28px;
  letter-spacing: -.02em;
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub { color: var(--dim); font-size: 14px; margin: 8px 0 26px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--dim);
  margin-bottom: 7px;
}

input, select {
  width: 100%;
  padding: 12px 14px;
  background: #0b0b12;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(94,234,212,.14); }
#code { text-transform: uppercase; letter-spacing: .22em; font-weight: 700; text-align: center; }

.row { display: flex; align-items: center; gap: 12px; }
.or { color: var(--dim); font-size: 13px; }

.btn {
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
  cursor: pointer;
  font-weight: 600;
  transition: transform .1s, background .15s, border-color .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { flex: 1; background: linear-gradient(100deg, var(--accent), var(--accent2)); color: #06231f; border-color: transparent; }
.btn.ghost { flex: 1; }
.btn.wide { width: 100%; margin-top: 4px; }
.btn:hover { border-color: var(--accent); }

#joinBox { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }

.status { margin-top: 16px; font-size: 13px; color: var(--dim); min-height: 20px; }
.status.err { color: var(--danger); }
.status.ok { color: var(--ok); }

/* ---------------- room ---------------- */
.room { height: 100dvh; display: flex; flex-direction: column; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(10,10,15,.8);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.bar .left, .bar .right { display: flex; align-items: center; gap: 9px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 3px rgba(244,63,94,.18); }
#roomCode { font-weight: 700; letter-spacing: .16em; }

.pill {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--dim);
}
.pill.up { color: var(--ok); border-color: rgba(52,211,153,.4); }
.pill.down { color: var(--danger); border-color: rgba(244,63,94,.4); }

.mini {
  padding: 6px 11px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  cursor: pointer;
}
.mini:hover { border-color: var(--accent); }
.mini.danger:hover { border-color: var(--danger); color: var(--danger); }
.mini b { background: var(--accent); color: #06231f; border-radius: 999px; padding: 0 5px; font-size: 10px; margin-left: 3px; }

/* ---------------- grid ---------------- */
.grid {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: start;
}

.tile {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #08080d;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.tile.speaking { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(94,234,212,.28); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #08080d; }
.tile .avatar {
  width: 68px; height: 68px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 700; color: #06231f;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.tile .tag {
  position: absolute; left: 9px; bottom: 9px;
  background: rgba(0,0,0,.62); backdrop-filter: blur(6px);
  padding: 3px 9px; border-radius: 8px; font-size: 12px;
  max-width: calc(100% - 18px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .mute { position: absolute; right: 9px; top: 9px; font-size: 14px; }
.tile .state {
  position: absolute; inset: auto 0 0 0; height: 3px; background: var(--line);
}
.tile .state i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s; }
.tile .pending { position: absolute; top: 9px; left: 9px; font-size: 11px; color: var(--dim); }

/* ---------------- dock ---------------- */
.dock {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 9px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(10,10,15,.85);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.spacer { flex: 1; }
.dock-btn {
  width: 46px; height: 46px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--panel2);
  font-size: 19px; cursor: pointer; transition: .15s;
}
.dock-btn.on { background: rgba(94,234,212,.14); border-color: var(--accent); }
.dock-btn.off { opacity: .45; }
.dock-btn.rec { color: var(--danger); border-color: var(--danger); }
.dock-btn.rec.active { animation: blink 1.1s infinite; }
@keyframes blink { 50% { background: rgba(244,63,94,.2); } }
.rec-timer { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--danger); font-weight: 700; }
.dock-note { font-size: 11px; color: var(--dim); max-width: 130px; line-height: 1.25; }
.sel { width: auto; max-width: 150px; font-size: 12px; padding: 9px 10px; }

/* ---------------- chat ---------------- */
.chat {
  position: fixed; right: 16px; bottom: 84px;
  width: min(330px, calc(100vw - 32px));
  height: min(430px, 58dvh);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  z-index: 20;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 13px; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 13px; display: flex; flex-direction: column; gap: 9px; }
.msg { max-width: 85%; }
.msg.me { align-self: flex-end; }
.msg.sys { align-self: center; color: var(--dim); font-size: 12px; text-align: center; }
.msg .who { font-size: 11px; color: var(--dim); margin-bottom: 2px; }
.msg .txt { padding: 8px 11px; border-radius: 11px; background: var(--panel2); word-break: break-word; white-space: pre-wrap; }
.msg.me .txt { background: linear-gradient(100deg, var(--accent), var(--accent2)); color: #06231f; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { padding: 9px 11px; }

/* ---------------- toasts ---------------- */
.toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 11px; font-size: 13px;
  box-shadow: 0 12px 34px rgba(0,0,0,.5);
  animation: drop .25s ease;
}
.toast.err { border-color: var(--danger); color: #ffd9df; }
@keyframes drop { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .sel { display: none; }
  .chat { right: 8px; left: 8px; width: auto; }
}
