:root {
  --bg: #0e1124;
  --panel: #171b36;
  --panel-2: #1f2448;
  --line: #2b3164;
  --text: #f2f3ff;
  --muted: #a2a7cc;
  --accent: #ffc83d;
  --accent-ink: #231a00;
  --good: #3ddc84;
  --bad: #ff5c6c;
  --radius: 14px;
  color-scheme: dark;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

h1,
h2,
h3 {
  margin: 0 0 0.5em;
  line-height: 1.2;
}

h2 {
  font-size: 1.05rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

a {
  color: var(--accent);
}

[hidden] {
  display: none !important;
}

/* ---- Controls ---- */

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55em 1em;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button:hover {
  border-color: var(--muted);
}

button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.danger {
  color: var(--bad);
}

button.small,
.button.small {
  padding: 0.25em 0.6em;
  font-size: 0.85rem;
}

button.big,
.button.big {
  width: 100%;
  font-size: 1.2rem;
  padding: 0.8em 1em;
}

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

input,
textarea,
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65em 0.8em;
  width: 100%;
}

select {
  width: auto;
  padding: 0.45em 0.6em;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

input[type='checkbox'] {
  width: auto;
  accent-color: var(--accent);
}

input[type='range'] {
  width: auto;
  flex: 1;
  padding: 0;
  accent-color: var(--accent);
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label {
  display: grid;
  gap: 0.35em;
  font-weight: 600;
  margin-bottom: 1em;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 1.5rem;
  text-align: center;
}

.error {
  color: var(--bad);
  margin: 0 0 1em;
}

.muted {
  color: var(--muted);
}

/* ---- Layout ---- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.narrow {
  max-width: 440px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: grid;
  gap: 1.25rem;
}

.title {
  text-align: center;
  font-size: 2.2rem;
  margin: 1rem 0 0;
}

.title span {
  color: var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar .spacer {
  flex: 1;
}

.room-code strong {
  font-size: 1.35rem;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.status {
  font-size: 0.85rem;
  padding: 0.2em 0.7em;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.status[data-status='online'] {
  color: var(--good);
  border-color: var(--good);
}

.status[data-status='offline'],
.status[data-status='closed'] {
  color: var(--bad);
  border-color: var(--bad);
}

/* ---- Players ---- */

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

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  background: var(--panel-2);
  border-radius: 10px;
}

.player-list .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-list .score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 3ch;
  text-align: right;
}

.dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.dot.online {
  background: var(--good);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.chips li {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 0.25em 0.8em;
}

.chips li.me {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.chips li.offline {
  opacity: 0.5;
}

/* ---- Host console ---- */

.host-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}

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

.join-banner {
  text-align: center;
  padding: 2rem 1rem;
}

.join-banner .big-code {
  font-size: clamp(3rem, 10vw, 5.5rem);
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent);
  line-height: 1.1;
}

.join-banner .url {
  font-size: 1.1rem;
  word-break: break-all;
}

/* ---- Player page ---- */

.player-main {
  max-width: 520px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.lobby-hello {
  text-align: center;
  padding: 2rem 1rem;
}

.lobby-hello .big {
  font-size: 1.6rem;
  font-weight: 700;
}

/* ---- Shared game pieces ---- */

h3 {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
}

.stack {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.row h2 {
  margin: 0;
}

.row .spacer {
  flex: 1;
}

label.inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin: 0;
  font-weight: 500;
}

input[type='number'] {
  width: 5.5em;
  padding: 0.45em 0.6em;
}

kbd {
  font: inherit;
  font-size: 0.75em;
  padding: 0.05em 0.4em;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: 0.7;
}

.shortcuts {
  font-size: 0.85rem;
  margin: 0;
}

button.good {
  color: var(--good);
  border-color: var(--good);
}

button.active {
  border-color: var(--accent);
  color: var(--accent);
}

.pill {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.2em 0.8em;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}

.pill.live {
  background: var(--accent);
  color: var(--accent-ink);
}

.pill.good {
  background: var(--good);
  color: #062b16;
}

.question-text {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0.75rem 0 1rem;
}

.question-card .question-text {
  font-size: 1.3rem;
  margin-bottom: 0;
}

.buzz-queue {
  list-style: none;
  counter-reset: queue;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.buzz-queue li {
  counter-increment: queue;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: var(--panel-2);
}

.buzz-queue li::before {
  content: counter(queue);
  font-weight: 800;
  color: var(--muted);
  min-width: 1.2em;
}

.buzz-queue li.active {
  outline: 2px solid var(--accent);
}

.buzz-queue li.winner {
  outline: 2px solid var(--good);
}

.buzz-queue .name {
  font-weight: 700;
  font-size: 1.15rem;
  flex: 1;
}

/* The big round BUZZ button on the player page. */
.buzz-button {
  display: block;
  width: min(80vw, 320px);
  aspect-ratio: 1;
  margin: 0.5rem auto;
  border-radius: 50%;
  border: 6px solid #ff8a95;
  background: radial-gradient(circle at 35% 30%, #ff7b88, #d81b36 70%);
  color: #fff;
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  box-shadow: 0 10px 0 #8c0c20;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.05s, box-shadow 0.05s;
}

.buzz-button:active:not([aria-disabled]) {
  transform: translateY(8px);
  box-shadow: 0 2px 0 #8c0c20;
}

.buzz-button[aria-disabled] {
  background: var(--panel-2);
  border-color: var(--line);
  box-shadow: none;
  color: var(--muted);
  font-size: 1.3rem;
  cursor: default;
}

.buzz-button.waiting {
  border-color: var(--accent);
  color: var(--accent);
}

.buzz-button.good {
  border-color: var(--good);
  color: var(--good);
}

.buzz-button.bad {
  border-color: var(--bad);
  color: var(--bad);
}

.leaderboard,
.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: var(--panel-2);
}

.leaderboard li.me {
  outline: 2px solid var(--accent);
}

.leaderboard .rank {
  font-weight: 800;
  color: var(--accent);
  min-width: 1.5em;
}

.leaderboard .name {
  flex: 1;
}

.leaderboard .score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.log-list {
  max-height: 22rem;
  overflow-y: auto;
}

.log-list li {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr) auto auto;
  grid-template-areas:
    'points name time del'
    'points reason reason reason';
  column-gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line);
}

.log-list .points {
  grid-area: points;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.log-list .points.plus {
  color: var(--good);
}

.log-list .points.minus {
  color: var(--bad);
}

.log-list .name {
  grid-area: name;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-list .reason {
  grid-area: reason;
  font-size: 0.85rem;
}

.log-list time {
  grid-area: time;
  font-size: 0.8rem;
}

.log-list button {
  grid-area: del;
}

.adjust-row {
  margin-bottom: 0.75rem;
}

.adjust-row input:not([type='number']) {
  flex: 1;
  min-width: 8rem;
  width: auto;
}

/* ---- Overlays ---- */

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(14 17 36 / 0.92);
  z-index: 10;
  text-align: center;
}

.fatal .card {
  max-width: 420px;
  font-size: 1.1rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 1rem);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6em 1.1em;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- Editor ---- */

.brand {
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
}

.brand span {
  color: var(--accent);
}

.crumbs {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumbs a {
  color: var(--text);
}

.editor-main {
  padding: 1rem;
  max-width: 1500px;
  margin: 0 auto;
}

.editor-main > .card {
  max-width: 900px;
  margin: 0 auto;
}

.editor-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 40%);
  gap: 1rem;
  align-items: start;
}

.side {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 1rem;
}

@media (max-width: 980px) {
  .editor-cols {
    grid-template-columns: 1fr;
  }

  .side {
    position: static;
  }
}

.small {
  font-size: 0.85rem;
}

.stack.tight {
  gap: 0.4rem;
}

.row.tight {
  gap: 0.25rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 10rem minmax(0, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.grid-2 label {
  margin: 0;
}

.settings {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  gap: 1.25rem;
}

.banner {
  margin: 1rem auto 0;
  max-width: 1500px;
  padding: 1rem 1.25rem;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  background: rgb(255 92 108 / 0.12);
}

.banner p {
  margin: 0 0 0.75rem;
}

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

.quiz-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: var(--panel-2);
}

.quiz-title {
  flex: 1;
  min-width: 10rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.problems {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  color: var(--accent);
  font-size: 0.9rem;
}

.problems:empty {
  display: none;
}

.problems li.none {
  list-style: none;
  margin-left: -1.2rem;
  color: var(--good);
}

.problems a {
  color: var(--text);
}

.narrow-card {
  max-width: 640px;
}

.type-choices {
  display: grid;
  gap: 0.6rem;
}

.type-choice {
  display: grid;
  justify-content: stretch;
  justify-items: start;
  gap: 0.2rem;
  text-align: left;
  padding: 0.9rem 1rem;
  font-weight: 400;
}

.type-choice strong {
  font-size: 1.1rem;
}

/* The board grid in the editor: a points column, then one column per category. */
.be-scroll {
  overflow-x: auto;
  margin: 0.5rem 0;
}

.board-editor {
  display: grid;
  grid-template-columns: 6.5rem repeat(var(--columns), minmax(8.5rem, 1fr));
  gap: 0.4rem;
  min-width: min-content;
}

.be-corner {
  align-self: end;
  font-size: 0.85rem;
  padding-bottom: 0.6rem;
}

.be-head {
  display: grid;
  gap: 0.3rem;
  align-content: end;
  border-radius: 10px;
}

.be-head input {
  font-weight: 700;
  padding: 0.5em 0.6em;
}

.be-tier {
  grid-column: 1;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.be-tier input[type='number'] {
  width: 100%;
  min-width: 0;
}

.be-square {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 0.15rem;
  min-height: 5.2rem;
  padding: 0.55rem 0.65rem;
  text-align: left;
  font-weight: 400;
  background: #1e2a6e;
  border-color: #2f3c8c;
}

.be-square.empty {
  place-content: center;
  justify-items: center;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

.be-type {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.be-snippet {
  font-size: 0.85rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}

.be-points {
  margin-top: auto;
  font-weight: 800;
  color: var(--accent);
}

.be-square.flagged::after {
  content: '';
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  padding: 0 0.3rem;
  user-select: none;
  font-size: 1.1rem;
  line-height: 1;
}

.drag-handle.inline {
  cursor: default;
  padding: 0;
}

.dragging {
  opacity: 0.4;
}

.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* Content Flow editor */
.flow-rows {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.flow-row {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  border-left: 4px solid var(--accent);
}

.flow-row.joins {
  border-left-color: var(--line);
}

/* Items that join a step indent under the item that starts it. */
.flow-row.joins:not([data-step='0']) {
  margin-left: 1rem;
}

.flow-row-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.flow-row-head .spacer {
  flex: 1;
}

.step-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1em 0.6em;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
}

.flow-row.joins .step-badge {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.flow-fields {
  display: grid;
  gap: 0.5rem;
}

.flow-fields label.inline {
  justify-self: start;
}

.image-fields {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
}

.thumb {
  width: 5.5rem;
  height: 4rem;
  object-fit: contain;
  background: var(--bg);
  border-radius: 6px;
}

/* Previews: a view drawn at full size, scaled down to fit its frame. */
.preview-pane {
  display: grid;
  gap: 0.5rem;
}

.preview-label {
  margin: 0.4rem 0 0;
}

.preview-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.preview-frame[data-size='phone'] {
  width: min(100%, 260px);
  justify-self: center;
  border-radius: 18px;
}

.preview-frame > .view {
  position: absolute;
  top: 0;
  left: 0;
  transform: scale(var(--scale, 0.3));
  transform-origin: 0 0;
  pointer-events: none;
}

/* ---- Shared views: the big screen and the player's phone ---- */

.view {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.view-screen {
  width: 1280px;
  height: 720px;
  padding: 36px 56px;
  background: radial-gradient(ellipse at top, #1d2456, var(--bg) 70%);
}

.view-phone {
  width: 390px;
  height: 720px;
  padding: 16px;
}

.view-title {
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.view-screen .view-title {
  font-size: 30px;
  margin-bottom: 20px;
}

.view-phone .view-title {
  font-size: 15px;
  margin-bottom: 12px;
}

.view-phase {
  margin: 0 0 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--good);
}

.view-screen .view-phase {
  font-size: 24px;
}

.view-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-wait {
  margin: auto;
  text-align: center;
}

.view-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
  font-size: 22px;
}

.view-footer .pill {
  font-size: 28px;
  padding: 0.25em 1em;
}

/* Content items, stacked top to bottom. Images share the space left by text. */
.flow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6em;
  text-align: center;
}

.flow-text {
  margin: 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.view-screen .flow-text.size-small {
  font-size: 30px;
}

.view-screen .flow-text.size-normal {
  font-size: 44px;
}

.view-screen .flow-text.size-large {
  font-size: 68px;
  font-weight: 800;
}

.view-phone .flow-text.size-small {
  font-size: 15px;
}

.view-phone .flow-text.size-normal {
  font-size: 19px;
}

.view-phone .flow-text.size-large {
  font-size: 26px;
  font-weight: 800;
}

.flow-image {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flow-image img {
  flex: 1;
  min-height: 0;
  max-width: 100%;
  object-fit: contain;
}

.view-screen .flow {
  justify-content: center;
}

.view-phone .flow {
  flex: none;
}

.view-phone .flow-image {
  flex: none;
}

.view-phone .flow-image img {
  max-height: 260px;
}

.flow-image.missing div {
  flex: 1;
  width: 60%;
  min-height: 3em;
  display: grid;
  place-items: center;
  border: 2px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
}

.flow-image figcaption {
  font-weight: 700;
  margin-top: 0.3em;
}

.view-phone .buzz-button {
  flex: none;
  width: 220px;
  margin-top: auto;
}

/* The Jeopardy board. */
.board-body {
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: 8px;
}

.view-screen .board {
  flex: 1;
  grid-template-rows: auto;
  grid-auto-rows: 1fr;
}

.board-head {
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 800;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  padding: 0.3em;
  border-bottom: 3px solid var(--accent);
}

.view-screen .board-head {
  font-size: 24px;
}

.view-phone .board {
  gap: 4px;
}

.view-phone .board-head {
  font-size: 10px;
  min-height: 40px;
  border-bottom-width: 2px;
}

.square {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1e2a6e;
  border: 1px solid #2f3c8c;
  color: var(--accent);
  font-weight: 900;
  padding: 0;
}

.view-screen .square {
  font-size: 44px;
}

.view-phone .square {
  font-size: 16px;
  min-height: 52px;
}

.square.empty {
  background: transparent;
  border-color: transparent;
}

.square.used {
  opacity: 0.25;
  color: transparent;
}

.square.highlight {
  animation: square-flash 0.4s ease-in-out 4 alternate;
}

@keyframes square-flash {
  to {
    background: var(--accent);
    color: var(--accent-ink);
  }
}
