/* =========================================================================
   Meta4Sec x Redlimit - dark CTF / terminal design system.

   Deliberately cheap to render: no web fonts, no images, no keyframe loops
   running while idle. The only continuously animated property is the timer
   bar's transform, which the compositor handles off the main thread.
   ========================================================================= */

:root {
  --bg: #06080c;
  --bg-grid: #0d121b;
  --surface: #0d1219;
  --surface-2: #131a24;
  --surface-3: #1a2330;
  --line: #1f2a3a;
  --line-bright: #2c3b50;

  --text: #e8eef7;
  --muted: #8794a8;
  --dim: #5c6879;

  --red: #ff2b4a;
  --red-dim: #7d1226;
  --green: #24f08a;
  --cyan: #35d7ff;
  --amber: #ffb020;
  --violet: #a86bff;

  /* Podium metals, shared by the podium and the leaderboard ranks. */
  --gold: #ffd25e;
  --silver: #cdd6e2;
  --bronze: #e08b4a;

  --a: #ff2b4a;
  --b: #35d7ff;
  --c: #ffb020;
  --d: #24f08a;

  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --pad: 12px;
  --tap: 50px;
}

@media (min-width: 600px) {
  :root {
    --pad: 18px;
    --tap: 54px;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background-color: var(--bg);
  /* Static grid: painted once, costs nothing to keep on screen. */
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 44px 44px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* A single soft glow instead of a particle field. */
body::before {
  content: "";
  position: fixed;
  inset: -30% -10% auto -10%;
  height: 60vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 43, 74, 0.14), transparent 65%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: var(--pad);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

[hidden] {
  display: none !important;
}

/* --- typography ---------------------------------------------------------- */

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.mono {
  font-family: var(--mono);
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 8px;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- brand --------------------------------------------------------------- */

.brand {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand b {
  color: var(--text);
  font-weight: 600;
}

.brand .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  flex: none;
}

.brand .dot.off {
  background: var(--dim);
  box-shadow: none;
}

.brand .dot.warn {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.topbar .brand {
  font-size: 11px;
  letter-spacing: 0.14em;
}

/* --- panels -------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

@media (min-width: 600px) {
  .panel {
    padding: 18px;
  }
}

.panel + .panel {
  margin-top: 14px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* --- buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 22px;
  width: 100%;
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.12s linear, border-color 0.12s linear, opacity 0.12s linear;
}

.btn:active {
  background: var(--surface-3);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn-primary:active {
  background: #d81f3b;
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  min-height: 40px;
  width: auto;
  padding: 0 14px;
  font-size: 12px;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-row .btn {
  width: auto;
  flex: 1 1 auto;
}

/* --- inputs -------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px; /* 16px avoids the iOS zoom-on-focus jump */
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

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

.hint {
  font-size: 12px;
  color: var(--dim);
}

.error-text {
  font-size: 13px;
  color: var(--red);
  font-family: var(--mono);
  min-height: 18px;
}

/* --- landing ------------------------------------------------------------- */

.landing-brand {
  font-family: var(--mono);
  font-size: clamp(20px, 6.4vw, 30px);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.2;
}

.landing-brand .x {
  color: var(--red);
}

.landing-title {
  font-family: var(--mono);
  font-size: clamp(30px, 10vw, 52px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 14px 0 20px;
}

.tagline {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--muted);
  line-height: 2;
}

.tagline span {
  display: block;
}

.tagline span::before {
  content: "> ";
  color: var(--green);
}

.rule {
  height: 1px;
  background: linear-gradient(90deg, var(--red), transparent);
  margin: 22px 0;
}

/* --- avatar -------------------------------------------------------------- */

.avatar {
  display: block;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  image-rendering: pixelated;
  flex: none;
}

.avatar-lg {
  width: 112px;
  height: 112px;
}

.avatar-md {
  width: 56px;
  height: 56px;
}

.avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 7px;
}

.avatar-xs {
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

.identity {
  display: flex;
  align-items: center;
  gap: 14px;
}

.identity .name {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  word-break: break-word;
}

/* --- lobby --------------------------------------------------------------- */

.counter {
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
  color: var(--green);
}

.player-grid {
  display: grid;
  /* Narrower cells + the space the rules panel used to take = roughly twice
     as many players visible without scrolling. */
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 6px;
  max-height: 56vh;
  overflow-y: auto;
  padding-right: 4px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  min-width: 0;
}

.player-chip .nick {
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-chip.me {
  border-color: var(--red);
}

/* --- question ------------------------------------------------------------ */

.q-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
}

.timer-wrap {
  margin: 8px 0 12px;
}

.timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.timer-num {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.timer-num.low {
  color: var(--red);
}

.timer-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--amber));
  transform-origin: left center;
  /* Driven by a single transform so it stays on the compositor. */
  transform: scaleX(1);
}

.q-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 6px;
}

.q-prompt {
  font-size: 16px;
  line-height: 1.4;
  font-weight: 600;
  margin: 0 0 14px;
  white-space: pre-wrap;
}

@media (min-width: 600px) {
  .q-prompt {
    font-size: 19px;
    line-height: 1.45;
    margin-bottom: 18px;
  }
}

.q-prompt code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-3);
  border: 1px solid var(--line-bright);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--cyan);
  word-break: break-word;
}

.q-prompt strong {
  color: var(--amber);
}

.q-prompt .quote {
  display: block;
  border-left: 3px solid var(--line-bright);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--muted);
  font-style: italic;
  font-weight: 500;
}

/* --- answer options ------------------------------------------------------ */

/* Two columns, two rows: the whole answer set stays above the fold on a
   375px phone without scrolling. */
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.opt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  min-height: 108px;
  padding: 10px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line-bright);
  border-top: 3px solid var(--key);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.3;
  cursor: pointer;
  transition: background-color 0.12s linear, border-color 0.12s linear;
}

@media (min-width: 600px) {
  .options {
    gap: 12px;
  }

  .opt {
    min-height: 118px;
    padding: 14px;
    font-size: 15.5px;
    gap: 10px;
  }
}

.opt[data-key="A"] { --key: var(--a); }
.opt[data-key="B"] { --key: var(--b); }
.opt[data-key="C"] { --key: var(--c); }
.opt[data-key="D"] { --key: var(--d); }
.opt[data-key="E"] { --key: var(--violet); }
.opt[data-key="F"] { --key: var(--green); }

.opt .badge {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: color-mix(in srgb, var(--key) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--key) 55%, transparent);
  color: var(--key);
  font-family: var(--mono);
  font-weight: 800;
  font-size: 13px;
}

@media (min-width: 600px) {
  .opt .badge {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }
}

.opt:active {
  background: var(--surface-2);
}

.opt.selected {
  background: color-mix(in srgb, var(--key) 14%, var(--surface));
  border-color: var(--key);
}

.opt.locked {
  cursor: default;
}

.opt.dimmed {
  opacity: 0.4;
}

.opt.correct {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 14%, var(--surface));
}

.opt.wrong {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 12%, var(--surface));
}

.opt .mark {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--mono);
  font-weight: 800;
}

.opt {
  position: relative;
}

.lock-note {
  margin-top: 12px;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--green);
}

/* --- boost --------------------------------------------------------------- */

.boost {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px dashed var(--line-bright);
  border-radius: var(--radius-sm);
}

.boost.ready {
  border-color: var(--amber);
  border-style: solid;
}

.boost.on {
  border-color: var(--amber);
  border-style: solid;
  background: color-mix(in srgb, var(--amber) 12%, var(--surface));
}

.boost-info {
  flex: 1;
  min-width: 0;
}

.boost-title {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--amber);
}

.boost-sub {
  font-size: 12px;
  color: var(--muted);
}

/* --- result -------------------------------------------------------------- */

.verdict {
  font-family: var(--mono);
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.verdict.ok {
  color: var(--green);
}

.verdict.no {
  color: var(--red);
}

.points {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  background: var(--surface-2);
  color: var(--muted);
}

.chip.hot {
  border-color: var(--amber);
  color: var(--amber);
}

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

.chip.bad {
  border-color: var(--red);
  color: var(--red);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.stat .k {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

.stat .v {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.explain {
  margin-top: 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--cyan);
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

/* --- leaderboard --------------------------------------------------------- */

.lb {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.lb-row.me {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 10%, var(--surface-2));
}

.lb-rank {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 800;
  width: 30px;
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lb-row:nth-child(1) .lb-rank { color: var(--gold); }
.lb-row:nth-child(2) .lb-rank { color: var(--silver); }
.lb-row:nth-child(3) .lb-rank { color: var(--bronze); }

.lb-name {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-score {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* --- podium -------------------------------------------------------------- */

.podium {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  align-items: end;
  gap: 8px;
  margin: 8px 0 20px;
}

.pod {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  min-width: 0;
}

.pod .crown {
  font-size: 24px;
  line-height: 1;
}

/* Each place carries its own metal: gold, silver, bronze. */
.pod.p1 { --metal: var(--gold); }
.pod.p2 { --metal: var(--silver); }
.pod.p3 { --metal: var(--bronze); }

.pod .nick {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--metal);
}

.pod .score {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.pod .avatar {
  border-color: var(--metal);
}

.pod .plinth {
  width: 100%;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--metal);
  border-bottom: none;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--metal) 26%, var(--surface-3)),
    var(--surface)
  );
}

.pod.p1 .plinth { height: 88px; }
.pod.p2 .plinth { height: 62px; }
.pod.p3 .plinth { height: 46px; }

.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  background: var(--surface-2);
}

.level-badge[data-tone="green"] { border-color: var(--green); color: var(--green); }
.level-badge[data-tone="blue"] { border-color: var(--cyan); color: var(--cyan); }
.level-badge[data-tone="yellow"] { border-color: #f5e06a; color: #f5e06a; }
.level-badge[data-tone="orange"] { border-color: var(--amber); color: var(--amber); }
.level-badge[data-tone="red"] { border-color: var(--red); color: var(--red); }

/* --- connection banner --------------------------------------------------- */

.banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 16px;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: var(--amber);
  color: #101010;
  font-weight: 700;
}

.banner.err {
  background: var(--red);
  color: #fff;
}

/* --- admin --------------------------------------------------------------- */

.admin .app {
  max-width: 1080px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 900px) {
  .grid-2 {
    grid-template-columns: 1.15fr 1fr;
    align-items: start;
  }
}

.kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 620px) {
  .kpis {
    grid-template-columns: repeat(4, 1fr);
  }
}

.state-pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  background: var(--surface-2);
}

.state-pill[data-state="QUESTION_ACTIVE"] { border-color: var(--green); color: var(--green); }
.state-pill[data-state="QUESTION_RESULT"] { border-color: var(--cyan); color: var(--cyan); }
.state-pill[data-state="LEADERBOARD"] { border-color: var(--violet); color: var(--violet); }
.state-pill[data-state="PAUSED"] { border-color: var(--amber); color: var(--amber); }
.state-pill[data-state="FINISHED"] { border-color: var(--red); color: var(--red); }

.q-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 62vh;
  overflow-y: auto;
}

.q-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.q-item.live {
  border-color: var(--green);
}

.q-item .num {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
  color: var(--dim);
  width: 26px;
  flex: none;
  padding-top: 2px;
}

.q-item .body {
  flex: 1;
  min-width: 0;
}

.q-item .txt {
  font-size: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.q-item .meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  margin-top: 4px;
}

.q-item .key {
  color: var(--green);
  font-weight: 700;
}

.q-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid var(--line-bright);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--surface-3);
}

.icon-btn.danger {
  color: var(--red);
  border-color: var(--red-dim);
}

.bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}

.bar > i {
  display: block;
  height: 100%;
  background: var(--cyan);
}

.bar.ok > i {
  background: var(--green);
}

.dist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dist-row {
  font-family: var(--mono);
  font-size: 12px;
}

.dist-row .top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.dist-row .lbl {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dist-row.is-correct .lbl {
  color: var(--green);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 5, 8, 0.8);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 20px 16px;
}

.modal {
  width: 100%;
  max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  padding: 20px;
}

.opt-edit {
  display: flex;
  align-items: center;
  gap: 10px;
}

.opt-edit .lbl {
  font-family: var(--mono);
  font-weight: 800;
  width: 18px;
  flex: none;
}

.opt-edit input[type="radio"] {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--green);
}

.row-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: 90vw;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--line-bright);
  font-family: var(--mono);
  font-size: 13px;
}

.toast.err {
  border-color: var(--red);
  color: var(--red);
}

.toast.ok {
  border-color: var(--green);
  color: var(--green);
}

/* --- accessibility ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Nothing depends on hover: every affordance is visible on touch. */
@media (hover: hover) {
  .btn:hover:not(:disabled) {
    border-color: var(--line-bright);
    background: var(--surface-3);
  }

  .btn-primary:hover:not(:disabled) {
    background: #ff4460;
  }

  .opt:hover:not(.locked) {
    border-color: var(--key);
  }

  .icon-btn:hover {
    color: var(--text);
  }
}

/* --- layout utilities ----------------------------------------------------
   The CSP is `style-src 'self'` with no 'unsafe-inline', so inline style
   attributes would be blocked. Everything positional lives in a class.
   ------------------------------------------------------------------------ */

.m0 { margin: 0; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 10px; }
.mt-3 { margin-top: 14px; }
.mt-4 { margin-top: 18px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 10px; }
.mb-3 { margin-bottom: 14px; }
.mb-4 { margin-bottom: 18px; }
.minw0 { min-width: 0; }
.tc { text-align: center; }
.grow { flex: 1; }

.title-md { font-size: clamp(24px, 7vw, 34px); }
.title-sm { font-size: clamp(26px, 8vw, 38px); }
.h-sm { font-size: 15px; }
.t-lg { font-size: 18px; font-weight: 700; }
.t-md { font-size: 17px; font-weight: 700; }

/* --- sound toggle -------------------------------------------------------- */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sound-btn {
  width: 38px;
  height: 38px;
  font-size: 15px;
  color: var(--green);
  border-color: var(--line-bright);
}

.sound-btn[aria-pressed="false"] {
  color: var(--dim);
}

/* --- podium reveal -------------------------------------------------------
   Each place fades and rises once, on a slow ease-out. Nothing loops, so the
   compositor goes idle again as soon as the third reveal lands.
   ------------------------------------------------------------------------ */

.pod {
  opacity: 0;
  transform: translateY(26px);
}

.pod.revealed {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 900ms ease-out, transform 900ms cubic-bezier(0.16, 1, 0.3, 1);
}

.podium-caption {
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  min-height: 18px;
  margin-bottom: 10px;
}

@media (prefers-reduced-motion: reduce) {
  .pod {
    opacity: 1;
    transform: none;
  }
}

/* --- avatar picker -------------------------------------------------------- */

.avatar-pick {
  position: relative;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex: none;
  line-height: 0;
  border-radius: 10px;
}

.avatar-pick .avatar {
  display: block;
}

.avatar-pick-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 0;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-align: center;
  color: var(--text);
  background: rgba(6, 8, 12, 0.82);
  border-radius: 0 0 10px 10px;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 2px;
}

.avatar-option {
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  line-height: 0;
  overflow: hidden;
  aspect-ratio: 1;
}

.avatar-option img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.avatar-option[aria-pressed="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--red) 40%, transparent);
}

/* --- auto-advance countdown ---------------------------------------------- */

.next-in {
  margin-top: 14px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  min-height: 16px;
}

/* --- leaderboard movement ------------------------------------------------- */

.lb-delta {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  width: 34px;
  flex: none;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}

.lb-delta.up {
  color: var(--green);
}

.lb-delta.down {
  color: var(--red);
}

/* The slide itself is driven from JS (see animateRankShift): rows are placed
   at their previous position and then transformed to the new one. Only
   `transform` animates, so it stays on the compositor and runs exactly once
   per leaderboard. */
.lb-row {
  will-change: auto;
}

.lb-row.moved-up {
  border-color: color-mix(in srgb, var(--green) 55%, var(--line));
}

.lb-row.moved-down {
  border-color: color-mix(in srgb, var(--red) 45%, var(--line));
}

/* --- answer distribution on the result screen ---------------------------- */

.dist-row.mine {
  position: relative;
  padding-left: 8px;
  border-left: 2px solid var(--cyan);
}

.dist-count {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.dist-mine {
  display: inline-block;
  margin-top: 4px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cyan);
}

.dist-row .lbl {
  /* On a phone the options run long; let them wrap rather than truncate, so
     nobody has to guess which option the bar belongs to. */
  white-space: normal;
  overflow: visible;
  line-height: 1.35;
}

/* --- final: the personal panel waits for the podium ----------------------- */

.final-stats {
  opacity: 0;
  transform: translateY(18px);
}

.final-stats.revealed {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 700ms ease-out, transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
  .final-stats {
    opacity: 1;
    transform: none;
  }
}

/* --- waiting-room ticker --------------------------------------------------
   The rules used to sit in a panel that ate a third of the screen. As a strip
   along the bottom the player list gets that space back. One transform-only
   keyframe on a single element: compositor work, no layout, no paint.
   ------------------------------------------------------------------------ */

.ticker {
  margin-top: 12px;
  padding: 8px 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  /* Fade the text out at both ends instead of clipping it hard. */
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}

.ticker-track {
  display: flex;
  width: max-content;
  animation: ticker-scroll 34s linear infinite;
}

.ticker-item {
  padding-right: 2.5rem;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  white-space: nowrap;
}

.ticker-item::before {
  content: "> ";
  color: var(--green);
}

@keyframes ticker-scroll {
  from {
    transform: translateX(0);
  }
  to {
    /* The item list is rendered twice, so half a track is one full loop. */
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ticker {
    overflow-x: auto;
    mask-image: none;
    -webkit-mask-image: none;
  }
}

/* --- room display (/monitor) ----------------------------------------------
   Same components, sized for a projector at the back of a room. Everything
   scales from one breakpoint so a 1080p screen and a laptop both work.
   ------------------------------------------------------------------------ */

.monitor .app {
  max-width: 1280px;
}

.monitor .q-prompt {
  font-size: clamp(20px, 2.6vw, 40px);
  line-height: 1.3;
  margin-bottom: 20px;
}

.monitor .opt {
  min-height: clamp(110px, 13vh, 190px);
  font-size: clamp(15px, 1.5vw, 26px);
  cursor: default;
}

.monitor .opt .badge {
  width: clamp(32px, 3vw, 52px);
  height: clamp(32px, 3vw, 52px);
  font-size: clamp(15px, 1.5vw, 26px);
}

.monitor .options {
  gap: clamp(10px, 1.2vw, 18px);
}

.monitor .timer-num {
  font-size: clamp(32px, 5vw, 84px);
}

.monitor .timer-bar {
  height: 10px;
}

.monitor .q-meta {
  font-size: clamp(12px, 1.2vw, 20px);
}

.monitor .q-title {
  font-size: clamp(12px, 1.1vw, 18px);
}

.monitor .lb-row {
  padding: clamp(10px, 1.1vh, 18px) 14px;
}

.monitor .lb-name,
.monitor .lb-score {
  font-size: clamp(14px, 1.5vw, 26px);
}

.monitor .lb-rank {
  font-size: clamp(15px, 1.6vw, 28px);
  width: clamp(30px, 3vw, 52px);
}

.monitor .avatar-sm {
  width: clamp(34px, 3.2vw, 56px);
  height: clamp(34px, 3.2vw, 56px);
}

.monitor .dist-row {
  font-size: clamp(12px, 1.2vw, 20px);
}

.monitor .explain {
  font-size: clamp(14px, 1.3vw, 22px);
}

.monitor .pod .nick {
  font-size: clamp(14px, 1.6vw, 28px);
}

.monitor .pod .score {
  font-size: clamp(14px, 1.5vw, 26px);
}

.monitor .pod.p1 .plinth { height: clamp(88px, 12vh, 170px); }
.monitor .pod.p2 .plinth { height: clamp(62px, 8vh, 120px); }
.monitor .pod.p3 .plinth { height: clamp(46px, 6vh, 92px); }

/* --- monitor: join panel --------------------------------------------------- */

.m-join {
  text-align: center;
  padding: clamp(14px, 3vh, 40px) 0 clamp(10px, 2vh, 26px);
}

.m-url {
  font-size: clamp(30px, 6vw, 92px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--text);
  word-break: break-word;
}

.m-count {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  margin-top: clamp(10px, 2vh, 24px);
}

.monitor .counter {
  font-size: clamp(40px, 6vw, 96px);
}

.m-grid {
  grid-template-columns: repeat(auto-fill, minmax(clamp(120px, 12vw, 190px), 1fr));
  max-height: 46vh;
}

.monitor .player-chip .nick {
  font-size: clamp(12px, 1.1vw, 18px);
}

.monitor .avatar-xs {
  width: clamp(26px, 2.4vw, 42px);
  height: clamp(26px, 2.4vw, 42px);
}

.m-correct {
  font-size: clamp(18px, 2.2vw, 38px);
  font-weight: 800;
  line-height: 1.25;
  color: var(--green);
  margin-top: 4px;
}

.monitor .next-in {
  font-size: clamp(11px, 1.1vw, 17px);
}

.monitor .landing-title {
  font-size: clamp(30px, 6vw, 84px);
}
