:root {
  --bg: #1b1130;
  --panel: #2a1c4a;
  --ink: #ffffff;
  --muted: #b9a9dd;
  --accent: #7c4dff;
  --error: #ff6b6b;

  /* Fixed answer-tile palette (slot order: red, blue, yellow, green). See CONTEXT.md. */
  --tile-red: #e21b3c;
  --tile-blue: #1368ce;
  --tile-yellow: #d89e00;
  --tile-green: #26890c;

  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over any element that also sets `display` (.center,
   .console, .lobby-grid all do), otherwise hidden views still render. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

.center {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
}

.brand {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

.muted { color: var(--muted); }
.error { color: var(--error); font-weight: 600; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(90vw, 340px);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(90vw, 640px);
}

input {
  font: inherit;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 2px solid transparent;
  background: var(--panel);
  color: var(--ink);
}
input:focus { outline: none; border-color: var(--accent); }

.btn {
  font: inherit;
  font-weight: 700;
  padding: 0.85rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost {
  background: transparent;
  border: 2px solid var(--accent);
}
.btn.small { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.btn.danger { background: var(--tile-red); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.link {
  background: none;
  border: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  padding: 0;
}
.link:hover { color: var(--accent); }

/* --- Admin console layout --- */
.console {
  min-height: 100vh;
  display: block;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 5vw, 4rem);
  text-align: left;
}
.console .row { width: 100%; }
.gap { display: flex; gap: 0.6rem; align-items: center; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
}

.list { list-style: none; padding: 0; margin: 1rem 0 0; }
.list-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  margin-bottom: 0.5rem;
}

.title-input {
  font-size: 1.5rem;
  font-weight: 700;
  width: 100%;
  margin: 1rem 0;
  background: transparent;
  border: 2px solid transparent;
  border-bottom-color: rgba(255, 255, 255, 0.15);
  border-radius: 0;
}

.question-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.q-num { font-weight: 800; color: var(--muted); }
.q-prompt { width: 100%; margin: 0.75rem 0; font-weight: 600; }

.choices { display: flex; flex-direction: column; gap: 0.5rem; }
.choice-row { display: flex; align-items: center; gap: 0.6rem; }
.choice-row input[type="text"] { flex: 1; }

.tile-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.tile-0 { background: var(--tile-red); }
.tile-1 { background: var(--tile-blue); }
.tile-2 { background: var(--tile-yellow); }
.tile-3 { background: var(--tile-green); }

.time-label { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); }
.time-input { width: 5rem; }

.console h2 { margin: 0; }

/* --- Presenter lobby --- */
#presenter { min-height: 100vh; }
.lobby-grid {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 1.2fr;
  gap: 2rem;
  padding: 3vh 3vw;
  align-items: center;
}
.lobby-qr { text-align: center; }
.lobby-qr h2 { font-size: clamp(1.5rem, 3vw, 2.5rem); margin-bottom: 1rem; }
#qr-img {
  width: min(40vw, 420px);
  height: auto;
  background: #fff;
  border-radius: var(--radius);
  padding: 0.75rem;
}
.join-url { color: var(--muted); margin-top: 0.75rem; font-size: 1.1rem; word-break: break-all; }

.lobby-guests h2 { font-size: clamp(1.5rem, 3vw, 2.5rem); }
.name-cloud {
  list-style: none;
  padding: 0;
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-content: flex-start;
}
.name-chip {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: clamp(1rem, 2vw, 1.5rem);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  animation: pop 0.25s ease-out;
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (max-width: 700px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

/* --- Question stage (presenter) --- */
.stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 3vh 3vw;
  gap: 2vh;
}
.q-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  font-size: 1.25rem;
}
/* In the reveal header the prompt shares the row with the Next button. Let the prompt take
   the remaining width and wrap (min-width:0 lets a flex item shrink below its content's
   intrinsic single-line width), and keep the button from being pushed off-screen or
   squashed by a long prompt. */
.q-top .q-big {
  flex: 1;
  min-width: 0;
  text-align: left;
  margin: 0;
  overflow-wrap: anywhere;
}
.q-top .btn {
  flex-shrink: 0;
}
.timer {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 800;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  min-width: 2.4em;
  text-align: center;
  padding: 0.1em 0.3em;
}
.q-big {
  font-size: clamp(1.75rem, 4.5vw, 3.5rem);
  text-align: center;
  margin: 2vh 0;
  flex-shrink: 0;
  overflow-wrap: anywhere;
}

/* Answer tiles: fixed color per slot; the grid is 1 or 2 columns. */
.tile-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  flex: 1;
}
.tile-grid li { display: flex; }
.tile {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: clamp(1.25rem, 2.5vw, 2rem);
  font-weight: 700;
  cursor: pointer;
  min-height: 5rem;
  width: 100%;
  text-align: left;
}
.tile-shape { font-size: 1.4em; }
.tile-0 { background: var(--tile-red); }
.tile-1 { background: var(--tile-blue); }
.tile-2 { background: var(--tile-yellow); }
.tile-3 { background: var(--tile-green); }
.tile-correct { outline: 6px solid #fff; }
.tile-dim { opacity: 0.35; }
.tile:disabled { cursor: default; }

/* Guest answer view fills the whole phone screen; tiles are big and thumb-friendly. */
#answer-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
}
.guest-tiles { flex: 1; }
.guest-tiles .tile { justify-content: center; font-size: 2rem; }
.guest-tiles .tile-shape { font-size: 2.5em; }
.answer-status { text-align: center; font-size: 1.1rem; }

/* --- Leaderboard --- */
.leaderboard { margin-top: 2vh; }
.lb-list { list-style: none; padding: 0; margin: 1rem 0 0; counter-reset: rank; }
.lb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  margin-bottom: 0.5rem;
  font-size: clamp(1.1rem, 2vw, 1.6rem);
}
.lb-name { font-weight: 700; flex: 1; }
.lb-name::before { counter-increment: rank; content: counter(rank) ". "; color: var(--muted); }
.lb-score { font-weight: 800; color: var(--accent); }

/* Kick affordance on lobby chips and leaderboard rows. */
.name-chip { display: inline-flex; align-items: center; gap: 0.5rem; }
/* A guest whose connection dropped (mid-game) is dimmed until they reconnect. */
.name-chip.is-disconnected { opacity: 0.45; }
.kick-btn {
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 1.6em;
  height: 1.6em;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}
.kick-btn:hover { background: var(--tile-red); }

/* Final podium: emphasise the top three. */
.podium .lb-row:nth-child(1) { background: #b8860b; font-size: 1.3em; }
.podium .lb-row:nth-child(2) { background: #6b7280; }
.podium .lb-row:nth-child(3) { background: #7c4a1e; }
#final-view { align-items: center; }
#final-view .lb-list { width: min(90vw, 640px); }
