:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1d242d;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b97a5;
  --accent: #4c9aff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; }

a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0.5rem 0; }
.hint { color: var(--muted); font-size: 13px; margin: 0.25rem 0 0.75rem; min-height: 1.2em; }

input {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}
input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

label { display: block; font-size: 13px; color: var(--muted); }

button {
  padding: 0.4rem 0.8rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { width: 100%; margin-top: 0.75rem; padding: 0.65rem; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { padding: 0.15rem 0.5rem; font-size: 12px; background: none; }

.card {
  width: min(440px, 100%);
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.card h1 { margin: 0 0 0.5rem; font-size: 1.4rem; }

/* ---- landing + join overlay ---- */
body.landing main, .overlay {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1rem;
  padding: 1rem;
}

/* ---- room ---- */
body.room main#app {
  --side-w: 320px;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  transition: grid-template-columns 0.2s ease;
}
body.room main#app.collapsed { --side-w: 48px; }

.stage { position: relative; display: grid; place-items: center; background: #000; min-width: 0; }
.ratio { position: relative; width: min(100%, calc(100vh * 16 / 9)); aspect-ratio: 16 / 9; }
.ratio iframe, .ratio #player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.fake-screen { display: grid; place-items: center; background: repeating-linear-gradient(45deg, #111, #111 20px, #181818 20px, #181818 40px); color: var(--muted); }
.stage-hint {
  position: absolute; left: 50%; bottom: 4.5rem; transform: translateX(-50%);
  padding: 0.4rem 0.9rem;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none; /* clicks must reach the player underneath */
}
.stage-msg {
  position: absolute; inset: auto 1rem 1rem 1rem;
  padding: 0.75rem 1rem;
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
}

.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem;
  gap: 0.75rem;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}
.side header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.side h2 { margin: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
button.icon { padding: 0.2rem 0.6rem; font-size: 1.1rem; line-height: 1; }
#collapse { transition: rotate 0.2s ease; }

/* Collapsed: just a thin strip holding the expand button. */
.collapsed .side { padding: 0.5rem; align-items: center; overflow: hidden; }
.collapsed .side > :not(header) { display: none !important; } /* beats #roster's display:flex */
.collapsed .side header > :not(#collapse) { display: none !important; }
.collapsed #collapse { rotate: 180deg; }

.conn { font-size: 13px; }
.conn.open { color: var(--ok); }
.conn.connecting, .conn.reconnecting { color: var(--warn); }
.conn.closed { color: var(--bad); }

.banner { padding: 0.5rem 0.7rem; background: rgba(210, 153, 34, 0.15); border: 1px solid var(--warn); border-radius: var(--radius); font-size: 13px; }

#roster { list-style: none; margin: 0; padding: 0; flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }
.member {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.member.me { border-color: var(--line); }
.member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member.leader .member-name { font-weight: 600; }

.pill {
  min-width: 4.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  background: var(--line);
  color: var(--muted);
}
.pill.ok { background: rgba(63, 185, 80, 0.18); color: var(--ok); }
.pill.warn { background: rgba(210, 153, 34, 0.18); color: var(--warn); }
.pill.bad { background: rgba(248, 81, 73, 0.18); color: var(--bad); }

.side footer { display: flex; flex-direction: column; gap: 0.75rem; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
#debug-list { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.75rem; margin: 0.5rem 0 0; font-size: 12px; font-variant-numeric: tabular-nums; }
#debug-list dt { color: var(--muted); }
#debug-list dd { margin: 0; text-align: right; }
.fake-controls { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.fake-controls button { padding: 0.2rem 0.5rem; font-size: 12px; }

@media (max-width: 900px) {
  body.room main#app, body.room main#app.collapsed { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .ratio { width: 100%; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
}
