/* ==================================================================
   Space Scoreboard - deep space theme
   ================================================================== */

:root {
  --void:        #03040d;
  --void-2:      #070a1c;
  --panel:       rgba(14, 20, 46, 0.55);
  --panel-edge:  rgba(120, 160, 255, 0.16);
  --ink:         #e8edff;
  --ink-dim:     #8d99c4;
  --ink-faint:   #5a648c;

  --cyan:        #5cf2ff;
  --violet:      #a06cff;
  --magenta:     #ff5ce0;
  --gold:        #ffd24a;
  --silver:      #cfd9f5;
  --bronze:      #ff9a52;
  --up:          #3dffa8;
  --down:        #ff5f7e;

  --glow-cyan:   0 0 24px rgba(92, 242, 255, 0.45);
  --glow-gold:   0 0 32px rgba(255, 210, 74, 0.45);

  --row-h: 58px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

/* An id or class that sets `display` outranks the UA rule for the `hidden`
   attribute, so state it explicitly - #gate and the empty state rely on it. */
[hidden] { display: none !important; }

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

body {
  background: var(--void);
  color: var(--ink);
  font-family: "Space Grotesk", "Chakra Petch", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- background layers ---------- */

#starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
}

.nebula {
  position: fixed;
  z-index: 1;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  animation: drift 40s ease-in-out infinite alternate;
}
.nebula.a {
  width: 60vw; height: 60vw;
  top: -22vw; left: -14vw;
  background: radial-gradient(circle, rgba(160, 108, 255, 0.55), transparent 65%);
}
.nebula.b {
  width: 52vw; height: 52vw;
  bottom: -20vw; right: -12vw;
  background: radial-gradient(circle, rgba(92, 242, 255, 0.4), transparent 65%);
  animation-delay: -14s;
}
.nebula.c {
  width: 38vw; height: 38vw;
  top: 40%; left: 55%;
  background: radial-gradient(circle, rgba(255, 92, 224, 0.28), transparent 65%);
  animation-delay: -26s;
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(4vw, 6vh, 0) scale(1.18); }
}

/* horizon glow along the bottom, like a planet limb */
.horizon {
  position: fixed;
  z-index: 1;
  left: -10%;
  right: -10%;
  bottom: -32vh;
  height: 46vh;
  border-radius: 50% 50% 0 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(92, 242, 255, 0.16), transparent 62%);
  border-top: 1px solid rgba(92, 242, 255, 0.28);
  pointer-events: none;
}

/* ---------- earth, moon and astronaut ----------
   They live in the free space either side of the centred .shell column.
   --gutter is the width of that space and --size is fitted inside it with
   a margin, so they can never overlap the board. Too narrow: hidden. */

.deco {
  --gutter: calc((100vw - 1180px) / 2);
  --size: min(calc(var(--gutter) - 64px), 300px);
  position: fixed;
  z-index: 1;
  display: none;
  height: auto;
  pointer-events: none;
  user-select: none;
}
@media (min-width: 1500px) {
  .deco { display: block; }
}

.deco-earth {
  --earth: calc(var(--size) * 0.72);
  width: var(--earth);
  left: calc((var(--gutter) - var(--earth)) / 2);
  bottom: 12vh;
  filter: drop-shadow(0 0 40px rgba(92, 200, 255, 0.25));
  animation: deco-bob 20s ease-in-out infinite alternate;
}

.deco-moon {
  --moon: calc(var(--size) * 0.34);
  width: var(--moon);
  right: calc((var(--gutter) - var(--moon)) / 2);
  top: 13vh;
  animation: deco-bob 16s ease-in-out infinite alternate-reverse;
}

.deco-astronaut {
  --astro: calc(var(--size) * 0.72);
  width: var(--astro);
  right: calc((var(--gutter) - var(--astro)) / 2);
  top: 48vh;
  animation: deco-float 14s ease-in-out infinite;
}

@keyframes deco-bob {
  from { transform: translateY(0); }
  to   { transform: translateY(-14px); }
}
@keyframes deco-float {
  0%   { transform: translate(0, 0) rotate(-6deg); }
  50%  { transform: translate(-4px, -22px) rotate(7deg); }
  100% { transform: translate(0, 0) rotate(-6deg); }
}

/* ---------- shell ---------- */

.shell {
  position: relative;
  z-index: 2;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* ---------- header ---------- */

header.hud {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--panel-edge);
}

.brand { min-width: 0; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 8px;
}

.brand-mark {
  display: block;
  height: 36px;
  width: auto;
  filter: drop-shadow(0 0 10px rgba(92, 242, 255, 0.35));
}
.eyebrow-sep { opacity: 0.45; }

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.05;
  background: linear-gradient(100deg, #ffffff 10%, var(--cyan) 45%, var(--violet) 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-wrap: balance;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  backdrop-filter: blur(10px);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  white-space: nowrap;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 10px var(--up);
  animation: beat 1.6s ease-in-out infinite;
}
.pill.offline .dot { background: var(--down); box-shadow: 0 0 10px var(--down); }
.pill.offline { color: var(--down); border-color: rgba(255, 95, 126, 0.35); }
@keyframes beat {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.8); }
}

button.pill {
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.12s;
}
button.pill:hover {
  border-color: rgba(92, 242, 255, 0.5);
  box-shadow: var(--glow-cyan);
}
button.pill:active { transform: translateY(1px); }
button.pill[aria-pressed="false"] { color: var(--ink-faint); }

/* ---------- alert ---------- */

.alert {
  margin: 18px 0 0;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 95, 126, 0.35);
  background: rgba(255, 95, 126, 0.08);
  color: #ffc3ce;
  font-size: 13px;
  line-height: 1.5;
}

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

.podium {
  display: grid;
  grid-template-columns: 1fr 1.18fr 1fr;
  align-items: end;
  gap: 16px;
  margin: 34px 0 30px;
}

.pod {
  position: relative;
  border-radius: 18px;
  border: 1px solid var(--panel-edge);
  background:
    linear-gradient(180deg, rgba(20, 28, 64, 0.72), rgba(8, 12, 32, 0.72));
  backdrop-filter: blur(14px);
  padding: 20px 18px 18px;
  overflow: hidden;
  transition: transform 0.6s var(--ease-out), box-shadow 0.6s, border-color 0.6s;
}

/* the accent bar and halo per medal */
.pod::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--accent, var(--cyan));
  box-shadow: 0 0 18px var(--accent, var(--cyan));
}
.pod::after {
  content: "";
  position: absolute;
  inset: 0;
  /* Anchored below the card so the falloff stays inside it - a gradient that
     ends mid-card leaves a visible seam. */
  background: radial-gradient(ellipse 130% 90% at 50% 118%, var(--halo, transparent), transparent 72%);
  pointer-events: none;
}

.pod.p1 { --accent: var(--gold);   --halo: rgba(255, 210, 74, 0.2);  order: 2; padding-top: 26px; padding-bottom: 24px; }
.pod.p2 { --accent: var(--silver); --halo: rgba(207, 217, 245, 0.14); order: 1; }
.pod.p3 { --accent: var(--bronze); --halo: rgba(255, 154, 82, 0.14);  order: 3; }

.pod.p1 { box-shadow: var(--glow-gold), 0 20px 60px rgba(0, 0, 0, 0.5); }

.pod-medal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

/* Medals belong to the podium slot, not to whoever is standing on it:
   gold centre, silver left, bronze right, whatever the standings do. */
.pod-medal-icon::before {
  content: "\2B50";           /* fallback if PODIUM_SIZE ever exceeds 3 */
  font-size: 21px;
  line-height: 1;
}
.pod.p1 .pod-medal-icon::before { content: "\1F947"; font-size: 26px; }
.pod.p2 .pod-medal-icon::before { content: "\1F948"; }
.pod.p3 .pod-medal-icon::before { content: "\1F949"; }

.rank-badge {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--void);
  background: var(--accent, var(--cyan));
  box-shadow: 0 0 20px var(--accent, var(--cyan));
}
.pod.p1 /* Medals belong to the podium slot, not to whoever is standing on it:
   gold centre, silver left, bronze right, whatever the standings do. */
.pod-medal-icon::before {
  content: "\2B50";           /* fallback if PODIUM_SIZE ever exceeds 3 */
  font-size: 21px;
  line-height: 1;
}
.pod.p1 .pod-medal-icon::before { content: "\1F947"; font-size: 26px; }
.pod.p2 .pod-medal-icon::before { content: "\1F948"; }
.pod.p3 .pod-medal-icon::before { content: "\1F949"; }

.rank-badge { width: 44px; height: 44px; font-size: 19px; }

.pod-name {
  font-size: clamp(15px, 2vw, 21px);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}
.pod.p1 .pod-name { font-size: clamp(18px, 2.6vw, 27px); }

.pod-score {
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--accent, var(--cyan));
  line-height: 1;
  margin-top: 10px;
}
.pod-score small {
  font-size: 0.42em;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  margin-left: 7px;
  text-transform: uppercase;
}

.pod-meta {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 15px;
}

/* rocket that rides the 1st place card */
.pod .rocket { display: none; }
.pod.p1 .rocket { display: block; }

.rocket {
  position: absolute;
  right: 14px;
  bottom: 12px;
  font-size: 26px;
  filter: drop-shadow(0 0 10px rgba(255, 210, 74, 0.7));
  animation: hover 3.4s ease-in-out infinite;
}
@keyframes hover {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50%      { transform: translateY(-7px) rotate(-2deg); }
}

/* ---------- table ---------- */

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}
.board-head h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
}
.board-head .count {
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.col-head {
  display: grid;
  grid-template-columns: 52px 1fr 88px 84px 108px;
  gap: 14px;
  padding: 0 16px 8px;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.col-head span:first-child { text-align: center; }
.col-head span:nth-child(4),
.col-head span:last-child { text-align: right; }

@media (max-width: 560px) {
  .col-head {
    grid-template-columns: 34px 1fr auto auto;
    gap: 9px;
    padding: 0 13px 8px;
  }
  .col-head span:nth-child(3) { display: none; }
}

#rows {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: grid;
  grid-template-columns: 52px 1fr 88px 84px 108px;
  align-items: center;
  gap: 14px;
  min-height: var(--row-h);
  padding: 10px 16px;
  border-radius: 13px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  backdrop-filter: blur(10px);
  will-change: transform;
}

.row .r-pos {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  text-align: center;
}
.row.top3 .r-pos { color: var(--gold); }

.row .r-name {
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .r-name .sub {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.row .r-score {
  text-align: right;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
}

.row .r-time {
  text-align: right;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
}
.row .r-time .muted { color: var(--ink-faint); }

.row .r-trend { height: 26px; }
.row .r-trend svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* rank delta chip */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
  margin-left: 8px;
}
.delta.up   { color: var(--up);   background: rgba(61, 255, 168, 0.12); }
.delta.down { color: var(--down); background: rgba(255, 95, 126, 0.12); }

/* ---------- movement effects ---------- */

.row.flash-up,
.pod.flash-up {
  animation: flashUp 1.5s var(--ease-out);
}
.row.flash-down {
  animation: flashDown 1.5s var(--ease-out);
}
@keyframes flashUp {
  0%   { border-color: var(--up); box-shadow: 0 0 0 1px var(--up), 0 0 34px rgba(61, 255, 168, 0.5); }
  100% { border-color: var(--panel-edge); box-shadow: none; }
}
@keyframes flashDown {
  0%   { border-color: var(--down); box-shadow: 0 0 0 1px var(--down), 0 0 34px rgba(255, 95, 126, 0.45); }
  100% { border-color: var(--panel-edge); box-shadow: none; }
}

.pod.takeover {
  animation: takeover 1.5s var(--ease-out);
}
@keyframes takeover {
  0%   { transform: scale(1.06); box-shadow: 0 0 0 2px var(--accent), 0 0 70px var(--accent); }
  100% { transform: scale(1); }
}

/* score count-up pop */
.bumped { animation: bump 0.7s var(--ease-out); }
@keyframes bump {
  0%   { transform: scale(1); }
  32%  { transform: scale(1.16); filter: brightness(1.5); }
  100% { transform: scale(1); }
}

/* +N floater */
.floater {
  position: absolute;
  right: 0;
  top: -2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--up);
  text-shadow: 0 0 12px rgba(61, 255, 168, 0.8);
  pointer-events: none;
  white-space: nowrap;
  animation: rise 1.4s var(--ease-out) forwards;
  font-variant-numeric: tabular-nums;
}
/* Rises only as far as the row is tall, and is fully faded by the time it
   reaches the top, so it never reads as part of the row above. */
@keyframes rise {
  0%   { opacity: 0; transform: translateY(4px); }
  18%  { opacity: 1; transform: translateY(0); }
  70%  { opacity: 0.55; }
  100% { opacity: 0; transform: translateY(-19px); }
}

/* ---------- rocket flight deck ---------- */

#flightdeck {
  position: fixed;
  inset: 0;
  z-index: 35;          /* over the board, under the toasts */
  pointer-events: none;
  overflow: hidden;
}

.flight {
  position: absolute;
  inset: 0;
}

.flight svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.flight-rocket {
  position: absolute;
  top: 0;
  left: 0;
  line-height: 1;
  will-change: transform;
}

/* ---------- toast feed ---------- */

#toasts {
  position: fixed;
  z-index: 40;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 15px;
  border-radius: 13px;
  border: 1px solid var(--accent, var(--cyan));
  background: linear-gradient(120deg, rgba(14, 20, 46, 0.94), rgba(8, 12, 32, 0.94));
  backdrop-filter: blur(14px);
  box-shadow: 0 0 30px -6px var(--accent, var(--cyan)), 0 14px 40px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  line-height: 1.4;
  animation: toastIn 0.5s var(--ease-out);
}
.toast.out { animation: toastOut 0.45s var(--ease-out) forwards; }
.toast .icon { font-size: 19px; line-height: 1; }
.toast strong { color: var(--accent, var(--cyan)); }
.toast .who { font-weight: 600; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(26px) scale(0.94); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(26px) scale(0.94); }
}

/* ---------- empty state ---------- */

.empty {
  margin: 40px 0;
  padding: 48px 24px;
  text-align: center;
  border-radius: 18px;
  border: 1px dashed var(--panel-edge);
  background: rgba(10, 14, 36, 0.4);
  color: var(--ink-dim);
}
.empty .big { font-size: 40px; margin-bottom: 14px; }
.empty h3 { margin: 0 0 8px; color: var(--ink); font-size: 17px; font-weight: 600; }
.empty p { margin: 0; font-size: 13px; line-height: 1.6; }
.empty code {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(92, 242, 255, 0.1);
  color: var(--cyan);
  font-size: 12px;
}

/* ---------- sound opt-in overlay ---------- */

#gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 4, 13, 0.82);
  backdrop-filter: blur(8px);
}
#gate .card {
  text-align: center;
  max-width: 420px;
  padding: 36px 30px;
  border-radius: 20px;
  border: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, rgba(20, 28, 64, 0.9), rgba(8, 12, 32, 0.9));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}
#gate .big { font-size: 46px; margin-bottom: 14px; }
#gate h2 { margin: 0 0 10px; font-size: 21px; font-weight: 600; }
#gate p { margin: 0 0 24px; color: var(--ink-dim); font-size: 13px; line-height: 1.6; }
#gate .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#gate button {
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: transform 0.12s, box-shadow 0.2s;
}
#gate button:active { transform: translateY(1px); }
#gate .primary {
  color: var(--void);
  background: linear-gradient(100deg, var(--cyan), var(--violet));
  box-shadow: var(--glow-cyan);
}
#gate .ghost {
  color: var(--ink-dim);
  background: transparent;
  border-color: var(--panel-edge);
}
#gate .ghost:hover { color: var(--ink); border-color: rgba(92, 242, 255, 0.4); }

/* ---------- footer credit ---------- */

.credit {
  margin: 44px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--panel-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: center;
}

.credit-mark {
  display: block;
  height: 42px;
  width: auto;
}

/* ---------- responsive ---------- */

@media (max-width: 820px) {
  .podium { grid-template-columns: 1fr; }
  .pod.p1, .pod.p2, .pod.p3 { order: unset; }
  .pod.p1 { order: -1; }
}

@media (max-width: 560px) {
  .shell { padding: 20px 14px 56px; }
  .eyebrow { flex-wrap: wrap; row-gap: 4px; }
  .credit { flex-direction: column; gap: 6px; }
  .row {
    grid-template-columns: 34px 1fr auto auto;
    gap: 9px;
    padding: 10px 13px;
  }
  .row .r-trend { display: none; }
  .row .r-time { font-size: 12px; }
  header.hud { align-items: flex-start; }
  #toasts { left: 14px; right: 14px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
