:root {
  color-scheme: dark;
  --bg: #070b18;
  --bg-2: #0d1530;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eef2ff;
  --muted: #8b98b8;
  --accent: #22d3ee;
  --quiz-from: #22d3ee;
  --quiz-to: #34d399;
  --bonus: #a78bfa;
  --negative: #f87171;
  --gold: #fbbf24;
  --silver: #d6dde8;
  --bronze: #e08a4b;
  --track: rgba(255, 255, 255, 0.08);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body.board-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse at top, var(--bg-2), var(--bg) 70%);
  color: var(--text);
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: clamp(12px, 2.4vh, 36px) clamp(16px, 3vw, 64px);
}

/* ---------- Backdrop ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.glow {
  position: absolute;
  width: 55vmax;
  height: 55vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.22;
  animation: drift 38s ease-in-out infinite alternate;
}

.glow-1 {
  background: #0ea5e9;
  top: -25vmax;
  left: -15vmax;
}

.glow-2 {
  background: #10b981;
  bottom: -30vmax;
  right: -20vmax;
  animation-delay: -12s;
  opacity: 0.16;
}

.glow-3 {
  background: #8b5cf6;
  top: 30%;
  left: 55%;
  width: 35vmax;
  height: 35vmax;
  animation-delay: -24s;
  opacity: 0.12;
}

@keyframes drift {
  to {
    transform: translate(8vmax, 6vmax) scale(1.1);
  }
}

/* ---------- Header ---------- */

.board-header {
  text-align: center;
  margin-bottom: clamp(10px, 2.2vh, 32px);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-weight: 700;
  font-size: clamp(0.7rem, 1.5vh, 1.05rem);
}

.board-header h1 {
  margin: 0.15em 0 0.25em;
  font-size: clamp(1.8rem, min(6vh, 7vw), 4.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  background: linear-gradient(90deg, #fff, #c7d2fe 60%, #a5f3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.legend {
  display: inline-flex;
  gap: 1.6em;
  color: var(--muted);
  font-size: clamp(0.72rem, 1.4vh, 1rem);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
}

.swatch {
  width: 1.8em;
  height: 0.55em;
  border-radius: 999px;
  display: inline-block;
}

.swatch.quiz,
.seg.quiz {
  background: linear-gradient(90deg, var(--quiz-from), var(--quiz-to));
}

.swatch.bonus,
.seg.bonus {
  background: repeating-linear-gradient(-45deg, var(--bonus) 0 6px, #c4b5fd 6px 12px);
}

/* ---------- Board ---------- */

.board-main {
  flex: 1;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}

.board {
  --fs: clamp(0.95rem, min(3.3vh, 4.4vw), 2.5rem);
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45em;
  font-size: var(--fs);
}

/* Up to 20 teams must fit on a 16:9 screen without scrolling. */
.board.compact {
  --fs: clamp(0.8rem, min(1.85vh, 3.4vw), 1.45rem);
  gap: 0.25em;
}

body:has(.board.compact) .board-header {
  margin-bottom: 1.2vh;
}

body:has(.board.compact) .board-header h1 {
  font-size: clamp(1.6rem, min(4.2vh, 6vw), 3rem);
  margin: 0.05em 0 0.15em;
}

.row {
  position: relative;
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.8em;
  padding: 0.5em 0.9em;
  border-radius: 0.55em;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  will-change: transform;
}

.compact .row {
  padding: 0.22em 0.8em;
  gap: 0.7em;
}

.compact .rank {
  width: 1.5em;
  height: 1.5em;
}

.rank {
  width: 1.8em;
  height: 1.8em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  font-weight: 800;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
}

.info {
  min-width: 0;
  display: grid;
  gap: 0.3em;
}

.compact .info {
  grid-template-columns: minmax(0, 34%) minmax(0, 1fr);
  align-items: center;
  gap: 0.9em;
}

.name {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.bar {
  height: 0.5em;
  border-radius: 999px;
  background: var(--track);
  display: flex;
  overflow: hidden;
}

.compact .bar {
  height: 0.55em;
}

.seg {
  display: block;
  height: 100%;
  width: 0;
  transition: width 1.1s var(--ease-out);
}

.seg.quiz {
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.45);
}

.score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 3.2em;
  line-height: 1.05;
}

.compact .score {
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.6em;
  /* Fixed width keeps the bars aligned whether or not a bonus label is shown. */
  min-width: 7em;
}

.total {
  font-size: 1.45em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.compact .total {
  font-size: 1.2em;
}

.total.negative {
  color: var(--negative);
}

.manual {
  color: var(--bonus);
  font-size: 0.55em;
  font-weight: 700;
  white-space: nowrap;
}

.compact .manual {
  font-size: 0.7em;
}

.manual:empty {
  display: none;
}

/* ---------- Podium ---------- */

.podium {
  border-color: color-mix(in srgb, var(--medal) 45%, transparent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--medal) 14%, transparent), var(--panel) 45%);
}

.podium-1 {
  --medal: var(--gold);
  box-shadow: 0 0 28px color-mix(in srgb, var(--gold) 22%, transparent);
}

.podium-2 {
  --medal: var(--silver);
}

.podium-3 {
  --medal: var(--bronze);
}

.podium .rank {
  background: radial-gradient(circle at 30% 30%, #fff8, transparent 60%), var(--medal);
  color: #1b1405;
}

.podium-1 .name {
  font-weight: 800;
}

/* ---------- Deltas ---------- */

.deltas {
  position: absolute;
  right: 0.8em;
  top: 0;
  transform: translateY(-68%);
  display: flex;
  gap: 0.35em;
  pointer-events: none;
  z-index: 2;
}

.delta {
  padding: 0.12em 0.55em;
  border-radius: 999px;
  font-size: 0.7em;
  font-weight: 800;
  color: #04151a;
  background: linear-gradient(90deg, var(--quiz-from), var(--quiz-to));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  animation: delta 3.2s var(--ease-out) forwards;
  white-space: nowrap;
}

.delta.bonus {
  background: var(--bonus);
  color: #1a0f3a;
}

.delta.negative {
  background: var(--negative);
  color: #2a0707;
}

@keyframes delta {
  0% {
    opacity: 0;
    transform: translateY(0.6em) scale(0.6);
  }
  10% {
    opacity: 1;
    transform: translateY(0) scale(1.12);
  }
  18% {
    transform: scale(1);
  }
  80% {
    opacity: 1;
    transform: translateY(-0.2em);
  }
  100% {
    opacity: 0;
    transform: translateY(-0.9em);
  }
}

.row.flash {
  animation: flash 1.6s ease-out;
}

@keyframes flash {
  0% {
    background-color: rgba(34, 211, 238, 0.22);
  }
  100% {
    background-color: transparent;
  }
}

/* ---------- Empty state ---------- */

.empty {
  display: grid;
  place-items: center;
  gap: 1.2rem;
  padding: 12vh 0;
  color: var(--muted);
  font-size: clamp(1.1rem, 3vh, 2rem);
  text-align: center;
}

.empty p {
  margin: 0;
}

.pulse {
  width: 3.5em;
  height: 3.5em;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.8;
  animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.6);
    box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.6);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 1.4em rgba(34, 211, 238, 0);
  }
  100% {
    transform: scale(0.6);
  }
}

/* ---------- Connection status ---------- */

.status {
  position: fixed;
  right: 14px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.35em 0.8em;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 0.75rem;
  transition: opacity 0.4s;
}

.status .dot {
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: #f59e0b;
}

.status[data-state='live'] {
  opacity: 0.45;
}

.status[data-state='live'] .dot {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
}

.status[data-state='offline'] .dot {
  background: var(--negative);
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .board,
  .board.compact {
    --fs: 0.95rem;
  }

  .compact .info {
    grid-template-columns: 1fr;
    gap: 0.25em;
  }

  .compact .score {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    min-width: 4.5em;
  }

  .row {
    padding: 0.5em 0.7em;
    gap: 0.6em;
  }

  .manual,
  .compact .manual {
    font-size: 0.72em;
  }

  .legend {
    gap: 1em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .glow,
  .pulse,
  .row.flash {
    animation: none;
  }

  .seg {
    transition: none;
  }
}
