:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #262b36;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #4f8cff;
  --danger: #e5484d;
  --ok: #30a46c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

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

input {
  background: var(--panel);
  border: 1px solid var(--panel-2);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  background: var(--panel-2);
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.15); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.big { padding: 14px 26px; font-size: 1.05rem; }

/* ---------- landing page ---------- */

.landing { display: grid; place-items: center; padding: 24px; }
.hero { max-width: 560px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 32px; }
.notice { background: #3a1d1f; border-radius: 10px; padding: 10px 14px; margin-bottom: 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: center; }
.actions form { display: flex; gap: 8px; }
.join-form input { width: 240px; }

/* ---------- pre-join screen ---------- */

.prejoin {
  min-height: 100dvh;
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pj-card { width: min(560px, 100%); }

.pj-video {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
}
.pj-video video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.pj-off {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: var(--panel); color: var(--muted);
}

.pj-controls { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

.pj-side { width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px; }
.pj-side h1 { margin: 0; font-size: 1.6rem; }
.code { margin: 0; color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; }
.note { margin: 0; color: var(--muted); font-size: .9rem; min-height: 1.4em; }

/* ---------- meeting ---------- */

.meeting { display: flex; flex-direction: column; height: 100dvh; }

.top {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  color: var(--muted);
}
.room-code { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text); }
.count { margin-right: auto; }
.link-btn { background: none; color: var(--accent); padding: 6px 10px; }

.stage { flex: 1; display: flex; min-height: 0; }

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  min-width: 0;
}

.tile {
  position: relative;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
  min-height: 0;
}
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile video.mirror { transform: scaleX(-1); }
.tile.presenting video { object-fit: contain; }
.tile.novideo video { visibility: hidden; }

.avatar {
  display: none;
  position: absolute; inset: 0;
  align-items: center; justify-content: center;
  background: var(--panel-2);
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 600;
  color: #fff;
}
.tile.novideo .avatar { display: flex; }

.label {
  position: absolute; left: 8px; bottom: 8px;
  display: flex; gap: 8px; align-items: center;
  background: rgba(0, 0, 0, .6);
  border-radius: 8px;
  padding: 2px 10px;
  font-size: .9rem;
  max-width: calc(100% - 16px);
}
.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge:not(:empty) { color: #ffb4b6; font-size: .8rem; }
.tile.presenting .badge:not(:empty) { color: #9ec3ff; }

.tile.speaking { outline: 3px solid var(--ok); outline-offset: -3px; }
.tile.connecting::after {
  content: "Connecting…";
  position: absolute; top: 8px; right: 8px;
  background: rgba(0, 0, 0, .6);
  border-radius: 8px; padding: 2px 10px; font-size: .8rem;
}

/* ---------- control bar ---------- */

.bar {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  padding: 12px;
  background: var(--panel);
}

.ctl { border-radius: 999px; padding: 10px 20px; }
.ctl.off { background: var(--danger); color: #fff; }
.ctl.active { background: var(--accent); color: #fff; }
.ctl.leave { background: var(--danger); color: #fff; }
.unread {
  display: inline-block; min-width: 1.3em;
  background: var(--danger); color: #fff;
  border-radius: 999px; font-size: .75rem; padding: 0 6px; margin-left: 4px;
}

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

.chat {
  width: 320px;
  display: flex; flex-direction: column;
  background: var(--panel);
  margin: 8px 8px 8px 0;
  border-radius: 12px;
  min-height: 0;
}
.chat-head { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--panel-2); }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg .meta { color: var(--muted); font-size: .78rem; }
.msg .text { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.me .meta { color: #9ec3ff; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--panel-2); }
.chat-form input { flex: 1; }

@media (max-width: 720px) {
  .chat {
    position: fixed; inset: 0 0 64px 0;
    width: auto; margin: 0; border-radius: 0;
    z-index: 5;
  }
  .grid { --cols: 1 !important; grid-auto-rows: minmax(140px, 1fr); overflow-y: auto; }
  .ctl { padding: 10px 14px; }
}

/* ---------- toast ---------- */

.banner {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%);
  background: #2b3140; border-radius: 10px;
  padding: 10px 16px; max-width: min(90vw, 520px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  z-index: 10;
}
