:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e8eaef;
  --muted: #8c93a3;
  --green: #22c55e;
  --green-dim: #15803d;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Must come with !important: .join and .play set `display: flex`, which would
   otherwise beat the user-agent [hidden] rule and leave both views stacked. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

.status {
  position: fixed; top: 8px; right: 10px;
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
  z-index: 10;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.online { background: var(--green); }
.dot.offline { background: var(--red); }
.dot.connecting { background: var(--amber); }

/* The puzzle images are black-on-white line art; a white card keeps them
   legible on the dark UI instead of inverting them into mush. */
.card {
  background: #fff;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ---------- player ---------- */
.join {
  min-height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; padding: 24px;
}
.join h1 { font-size: 22px; margin: 0 0 4px; }
.join p { color: var(--muted); margin: 0 0 8px; text-align: center; font-size: 14px; max-width: 320px; }
.join input {
  width: 100%; max-width: 320px; padding: 14px 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 17px;
}
.join button {
  width: 100%; max-width: 320px; padding: 14px;
  border: 0; border-radius: 12px; background: var(--green);
  color: #06230f; font-weight: 700; font-size: 17px;
}

.play {
  height: 100%;
  display: flex; flex-direction: column;
  padding: 12px; gap: 12px;
}
.play .meta {
  display: flex; gap: 10px; align-items: baseline;
  color: var(--muted); font-size: 13px;
  padding-right: 80px; /* keep clear of the fixed connection badge */
}
.play .card { flex: 1; min-height: 0; padding: 10px; }
#rename {
  margin-left: auto; background: none; border: 0; color: var(--muted);
  font-size: 12px; text-decoration: underline; padding: 0;
}

#buzzer {
  flex: 0 0 auto; height: 24vh; min-height: 120px;
  border: 0; border-radius: 20px;
  font-size: 26px; font-weight: 800; letter-spacing: 0.5px;
  background: var(--green); color: #06230f;
  transition: transform .06s ease, background .15s ease;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#buzzer:active { transform: scale(0.97); }
#buzzer.locked { background: #2a2f3a; color: var(--muted); }
#buzzer.done { background: var(--green-dim); color: #d7ffe5; }

/* ---------- host ---------- */
.host {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: 1fr auto;
  gap: 14px; padding: 14px;
}
.stage { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.stage .card { flex: 1; min-height: 0; padding: 16px; }
.stage .label { color: var(--muted); font-size: 14px; display: flex; gap: 12px; align-items: center; }

#answer {
  font-size: 22px; font-weight: 700; text-align: center;
  padding: 10px; border-radius: 10px; background: var(--panel);
  border: 1px solid var(--line); min-height: 48px;
}
#answer.hidden { color: var(--muted); font-weight: 400; font-size: 15px; }

/* Right-hand rail holds the buzz order above the player roster. */
.rail { display: flex; flex-direction: column; gap: 14px; min-height: 0; }

.side {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  display: flex; flex-direction: column; min-height: 0;
}
.rail .side:first-child { flex: 1 1 55%; }
.rail .side:last-child  { flex: 1 1 45%; }
.side h2 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; letter-spacing: .4px; }
#buzzlist, #playerlist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#buzzlist li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px; margin-bottom: 6px;
  background: #1e2230; animation: slide .18s ease;
}
#buzzlist li.first { background: #1b7a42; color: #f2fff7; }
/* Deliberately animates transform only, never opacity: a browser freezes
   animations in a backgrounded tab, and a row stuck at opacity 0 would make
   a buzz invisible to the host. Movement is cosmetic; visibility is not. */
@keyframes slide { from { transform: translateY(-6px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { #buzzlist li { animation: none; } }
.place { font-weight: 800; width: 24px; text-align: center; }
.who { flex: 1; font-weight: 600; }
.sub { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
#buzzlist li.first .sub { color: #c9f7db; }
.empty { color: var(--muted); font-size: 13px; padding: 8px; }

/* ---- player roster ---- */
#playerlist li {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 9px; margin-bottom: 5px;
  background: #1e2230; font-size: 14px;
}
#playerlist li.away { opacity: .55; }
.pdot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); flex: 0 0 auto;
}
#playerlist li.away .pdot { background: var(--muted); }
.kick {
  background: none; border: 0; color: var(--muted);
  font-size: 17px; line-height: 1; padding: 0 2px; flex: 0 0 auto;
}
.kick:hover { color: var(--red); }
#pcount { color: var(--muted); font-weight: 400; }

.controls {
  grid-column: 1 / -1;
  display: flex; gap: 10px; align-items: center;
}
.controls button {
  padding: 14px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-weight: 600;
}
.controls button:hover:not(:disabled) { border-color: #3a4152; }
.controls button:disabled { opacity: .4; }
#toggle { background: var(--green); color: #06230f; border-color: transparent; min-width: 150px; }
#toggle.open { background: var(--amber); color: #2a1a00; }
.controls .spacer { flex: 1; }
.controls .count { color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .host { grid-template-columns: 1fr; grid-template-rows: 1fr auto auto; }
  .rail { flex-direction: row; max-height: 220px; }
  .rail .side { flex: 1 1 50%; }
  .controls { flex-wrap: wrap; }
}
