:root {
  --bg: #12111f;
  --bg-panel: #1c1930;
  --bg-panel-strong: #25213e;
  --text: #f4f0ff;
  --text-muted: #b9b1d6;
  --line: #3a315f;
  --cyan: #29d9ff;
  --pink: #ff4fd8;
  --yellow: #ffd447;
  --green: #4dff88;
  --orange: #ff8a3d;
  --red: #ff4f6d;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

html, body { min-width: 320px; }

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(41, 217, 255, 0.14), transparent 34rem),
    linear-gradient(135deg, rgba(255, 79, 216, 0.08), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.app-question {
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image:
    linear-gradient(rgba(244, 240, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 240, 255, 0.05) 1px, transparent 1px);
  background-size: 2rem 2rem;
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: 0.55; }

:focus-visible {
  outline: 3px solid rgba(41, 217, 255, 0.85);
  outline-offset: 3px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 25, 48, 0.92);
  box-shadow: 0 16px 40px var(--shadow);
}

.admin-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(22rem, 1.15fr) minmax(20rem, 0.85fr);
  gap: 1rem;
  padding: 1rem;
}

.admin-left, .admin-right {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 3px solid var(--cyan);
}

.eyebrow, h1, h2, p { margin: 0; }

.eyebrow, h2 {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 { font-size: clamp(1.5rem, 3vw, 2rem); }

.header-badges, .panel-title-row, .control-actions, .topbar-main, .viewer-strip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-badges { flex-wrap: wrap; justify-content: flex-end; }

.room-code, .status-badge, .player-chip {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-panel-strong);
  color: var(--text);
  font-weight: 800;
}

.room-code {
  padding: 0.35rem 0.75rem;
  border-color: rgba(255, 212, 71, 0.75);
  color: var(--yellow);
  font-size: 1.25rem;
}

.status-badge { padding: 0.35rem 0.65rem; color: var(--cyan); }

.player-chip {
  --chip-colour: var(--cyan);
  gap: 0.45rem;
  padding: 0.35rem 0.55rem;
  text-transform: capitalize;
}

.player-chip::before {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  flex: 0 0 auto;
  border-radius: 99px;
  background: var(--chip-colour);
  box-shadow: 0 0 14px var(--chip-colour);
}

.editor-panel, .link-panel, .control-panel, .players-panel, .results-panel {
  padding: 1rem;
}

.editor-panel {
  flex: 1;
  display: flex;
  min-height: 25rem;
  flex-direction: column;
  gap: 0.75rem;
}

.panel-title-row { justify-content: space-between; }

textarea {
  flex: 1;
  width: 100%;
  min-height: 20rem;
  resize: vertical;
}

.tagline-field, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #100e1d;
  color: var(--text);
  padding: 1rem;
}

.tagline-field {
  width: 100%;
  min-height: 3rem;
  font-weight: 800;
}

textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  line-height: 1.55;
}

textarea:focus, .tagline-field:focus, .link-field:focus { border-color: var(--cyan); }

.url-meter { color: var(--cyan); font-weight: 800; }
.url-meter.is-warning { color: var(--yellow); }
.url-meter.is-error, .field-note.error { color: var(--red); }

.field-note { color: var(--text-muted); font-size: 0.95rem; }

.link-field {
  width: 100%;
  margin: 0.75rem 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #100e1d;
  color: var(--text);
  padding: 0.8rem;
}

.button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.8rem 1rem;
  font-weight: 900;
  color: #11101c;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.button:hover:not(:disabled), .buzz-button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.button:active:not(:disabled), .buzz-button:active:not(:disabled) { transform: translateY(1px); }

.start-button {
  flex: 1;
  min-height: 4rem;
  background: linear-gradient(135deg, var(--green), var(--yellow));
  box-shadow: 0 0 22px rgba(77, 255, 136, 0.25);
}

.reset-button {
  min-height: 4rem;
  background: linear-gradient(135deg, var(--orange), var(--red));
  color: var(--text);
}

.accent-button { background: var(--cyan); }
.small-button { padding: 0.45rem 0.75rem; }

.round-state {
  margin: 0.75rem 0 1rem;
  color: var(--yellow);
  font-size: 1.3rem;
  font-weight: 900;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chip-list.compact { margin-top: 0; }
.empty-state { color: var(--text-muted); }

.player-editor {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(6rem, 0.75fr) auto;
  gap: 0.5rem;
  align-items: center;
}

.player-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #100e1d;
  color: var(--text);
  padding: 0.55rem 0.65rem;
}

.winner-block, .winner-row {
  border: 1px solid rgba(255, 212, 71, 0.7);
  border-radius: 8px;
  background: rgba(255, 212, 71, 0.12);
  color: var(--yellow);
  font-weight: 900;
}

.winner-block {
  margin: 0.75rem 0;
  padding: 1rem;
  font-size: 1.25rem;
}

.results-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.results-list li {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  border-left: 0.3rem solid var(--chip-colour, var(--cyan));
  border-radius: 8px;
  background: var(--bg-panel-strong);
  padding: 0.75rem;
}

.results-list em { color: var(--text-muted); font-style: normal; }

.question-shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.question-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
  padding: 0.75rem 1rem;
  border-bottom: 3px solid var(--pink);
  background: rgba(18, 17, 31, 0.86);
}

.question-topbar .topbar-main { min-width: 0; flex-wrap: wrap; }

.viewer-strip { flex-wrap: wrap; color: var(--text-muted); justify-content: flex-end; }

.question-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  min-height: 0;
  overflow: hidden;
  padding: clamp(0.75rem, 2vh, 2rem) 1rem;
}

.stage-message {
  max-width: min(42rem, 90vw);
  text-align: center;
}

.stage-message h1 {
  font-size: clamp(2rem, 5vw, 4.5rem);
  margin-bottom: 0.5rem;
}

.stage-message p { color: var(--text-muted); font-size: 1.2rem; }

.loading-bar {
  display: block;
  width: min(24rem, 70vw);
  height: 0.35rem;
  margin: 1.5rem auto 0;
  overflow: hidden;
  border-radius: 99px;
  background: var(--bg-panel-strong);
}

.loading-bar span {
  display: block;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--pink), var(--yellow));
  animation: loadingSlide 1.2s ease-in-out infinite;
}

.question-content {
  display: none;
  width: min(76rem, 92vw);
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  text-align: center;
}

.question-stage.is-revealed .question-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.5rem, 1.5vh, 1rem);
  animation: questionReveal 560ms ease-out both;
}
.question-stage.is-revealed .stage-message { display: none; }

.question-stage.is-revealed::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 212, 71, 0.28), transparent);
  transform: translateX(-120%);
  animation: stageSweep 680ms ease-out both;
}

.question-content h1 { font-size: clamp(2rem, 5vw, 4.5rem); }
.question-content h2 { color: var(--text); font-size: clamp(1.4rem, 3vw, 2.5rem); letter-spacing: 0; text-transform: none; }
.question-content p, .question-content li { font-size: clamp(1.2rem, 2.5vw, 2rem); line-height: 1.35; }
.question-content a { color: var(--cyan); }
.question-content ul { display: inline-grid; text-align: left; }

.question-content > * {
  flex: 0 1 auto;
  min-height: 0;
  overflow-wrap: anywhere;
}

.question-content img, .question-content iframe, .question-content video {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  max-width: min(100%, 64rem);
  max-height: 100%;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090812;
  object-fit: contain;
}

.question-content img, .question-content video {
  width: auto;
  height: auto;
}

.question-content video {
  width: 100%;
  height: 100%;
}

.question-content iframe {
  width: min(64rem, 92vw);
  height: auto;
  aspect-ratio: 16 / 9;
}

.joined-buzzers {
  --buzzer-count: 1;
  --buzzer-columns: var(--buzzer-count);
  --buzzer-scale: 1;
  width: 100%;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(var(--buzzer-columns), max-content);
  justify-content: center;
  align-content: center;
  align-items: center;
  gap: clamp(0.35rem, calc(1rem * var(--buzzer-scale)), 1rem);
  min-height: 0;
  overflow: hidden;
  padding: 0.25rem 0;
}

.joined-buzzers.is-empty {
  min-height: 0;
  color: var(--text-muted);
  font-weight: 800;
}

.stage-buzzer {
  --buzzer-colour: var(--cyan);
  position: relative;
  display: flex;
  flex: 0 0 auto;
  width: 9.75em;
  min-height: 12.875em;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: calc(1rem * var(--buzzer-scale));
  line-height: 1.15;
  padding: 0;
  user-select: none;
}

.stage-buzzer:disabled { opacity: 1; }

.stage-buzzer.is-mine:not(:disabled) .buzzer-content {
  animation: buzzerPulse 1.35s ease-in-out infinite;
}

.stage-buzzer:not(:disabled):active .b-dome {
  transform: translateY(14px) scaleY(0.88);
}

.buzzer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  filter: drop-shadow(0 0.625em 0.4375em rgba(0, 0, 0, 0.35));
  transition: transform 120ms ease;
}

.b-dome {
  position: relative;
  z-index: 5;
  width: 7.5em;
  height: 4.3em;
  overflow: hidden;
  border: 0.1875em solid #090812;
  border-bottom: 0;
  border-radius: 4em 4em 0 0;
  background: var(--buzzer-colour);
  box-shadow: inset -1.2em -0.7em 0 rgba(0, 0, 0, 0.18), 0 0 1.375em rgba(244, 240, 255, 0.22);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.b-dome::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  background: rgba(0, 0, 0, 0.14);
}

.b-highlight {
  position: absolute;
  top: 0.9em;
  right: 1.25em;
  width: 1.1em;
  height: 1.1em;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.36);
}

.b-highlight::after {
  content: "";
  position: absolute;
  right: -0.35em;
  bottom: -0.5em;
  width: 0.55em;
  height: 0.55em;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.3);
}

.b-neck {
  z-index: 4;
  width: 6em;
  height: 1em;
  margin-top: -2px;
  border-right: 0.1875em solid #090812;
  border-left: 0.1875em solid #090812;
  background: #34495e;
}

.b-base {
  position: relative;
  z-index: 3;
  width: 8.7em;
  height: 2.1em;
  margin-top: -2px;
  border: 0.1875em solid #090812;
  border-radius: 1em 1em 0 0;
  background: #95a5a6;
}

.b-base::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  border-radius: 0.8em 0 0 0;
  background: rgba(0, 0, 0, 0.1);
}

.b-base::after {
  content: "";
  position: absolute;
  right: -0.6em;
  bottom: -0.8em;
  left: -0.6em;
  height: 0.9em;
  border: 0.1875em solid #090812;
  border-radius: 999px;
  background: #7f8c8d;
}

.b-label {
  max-width: 9.5em;
  margin-top: 1.4em;
  color: var(--text);
  font-size: 1em;
  font-weight: 900;
  text-align: center;
  text-transform: capitalize;
  overflow-wrap: anywhere;
}

.b-delta {
  display: inline-flex;
  margin-top: 0.35em;
  border: 1px solid rgba(255, 212, 71, 0.5);
  border-radius: 999px;
  background: rgba(255, 212, 71, 0.12);
  color: var(--yellow);
  padding: 0.2em 0.55em;
  font-size: 0.82em;
  font-weight: 900;
}

.stage-buzzer.locked .b-dome {
  transform: translateY(14px) scaleY(0.88);
  filter: brightness(1.25) saturate(1.45);
  box-shadow: inset -1.2em -0.7em 0 rgba(0, 0, 0, 0.16), 0 0 1.5em var(--buzzer-colour);
}

.stage-buzzer.locked .buzzer-content {
  transform: translateY(0.35em);
}

.rank-badge {
  position: absolute;
  top: 0;
  right: 0.15rem;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 2.3em;
  height: 2.3em;
  border: 0.125em solid #090812;
  border-radius: 50%;
  background: var(--yellow);
  color: #120f1f;
  font-weight: 1000;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  animation: popIn 260ms cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.buzzer-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-height: 0;
  max-height: min(38vh, 18rem);
  overflow: hidden;
  padding: 1rem;
  border-top: 1px solid var(--line);
  background: rgba(18, 17, 31, 0.9);
}

.player-result {
  color: var(--yellow);
  font-size: 1rem;
  font-weight: 900;
}

.dev-buzz-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  color: var(--text-muted);
}

.dev-buzz-panel[hidden] { display: none; }

.dev-buzz-panel select {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-panel-strong);
  color: var(--text);
  padding: 0.35rem 0.6rem;
}

@keyframes loadingSlide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(260%); }
}

@keyframes questionReveal {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  60% { opacity: 1; transform: translateY(-2px) scale(1.01); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes stageSweep { to { transform: translateX(120%); } }

@keyframes buzzerPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.18rem); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .question-stage.is-revealed::after { display: none; }
}

@media (max-width: 760px) {
  .admin-shell { grid-template-columns: 1fr; padding: 0.75rem; }
  .admin-header, .question-topbar, .buzzer-dock { align-items: stretch; flex-direction: column; }
  .control-actions { flex-direction: column; }
  .button { width: 100%; }
  .question-topbar { display: flex; }
  .buzzer-dock { display: flex; max-height: min(38vh, 19rem); padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
  .joined-buzzers { gap: clamp(0.3rem, calc(0.8rem * var(--buzzer-scale)), 0.8rem); }
  .dev-buzz-panel { flex-wrap: wrap; }
}
