:root {
  --bg:      #0a0a0b;
  --surface: #121214;
  --raised:  #18181c;
  --line:    #232329;
  --text:    #f4f4f5;
  --muted:   #8b8b96;
  --faint:   #5c5c66;
  --gold:    #d4af6a;
  --good:    #4ade80;
  --maxw:    620px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:      #fbfaf8;
    --surface: #ffffff;
    --raised:  #ffffff;
    --line:    #e9e7e2;
    --text:    #15151a;
    --muted:   #6b6b76;
    --faint:   #9a9aa4;
    --gold:    #9a7636;
  }
}
:root[data-theme="light"] {
  --bg:#fbfaf8; --surface:#fff; --raised:#fff; --line:#e9e7e2;
  --text:#15151a; --muted:#6b6b76; --faint:#9a9aa4; --gold:#9a7636;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* --------------------------------------------------------------- motion -- */

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes pop {
  0%   { opacity: 0; transform: scale(.82); }
  60%  { transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes ring {
  from { box-shadow: 0 0 0 1px var(--line), 0 0 0 5px var(--bg), 0 0 0 6px var(--gold),
                     0 0 0 6px color-mix(in srgb, var(--gold) 55%, transparent); }
  to   { box-shadow: 0 0 0 1px var(--line), 0 0 0 5px var(--bg), 0 0 0 6px var(--gold),
                     0 0 0 26px transparent; }
}

/* Each piece animates on entrance; --d staggers them down the page. */
.anim { animation: rise .55s cubic-bezier(.22,.61,.36,1) both; animation-delay: var(--d, 0s); }
.anim-pop { animation: pop .6s cubic-bezier(.22,.61,.36,1) both; animation-delay: var(--d, 0s); }

/* Someone who just took the lead gets one halo pulse, not a loop. */
.spot .av.celebrate { animation: pop .6s cubic-bezier(.22,.61,.36,1) both, ring 1.5s ease-out .5s 2; }

@media (prefers-reduced-motion: reduce) {
  .anim, .anim-pop, .spot .av.celebrate { animation: none !important; }
  #confetti { display: none; }
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 56px 20px 64px;
}

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

.head {
  text-align: center;
  padding-bottom: 34px;
  margin-bottom: 30px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-family: 'Instrument Serif', Georgia, serif;
  font-weight: 400;
  font-size: clamp(42px, 11vw, 60px);
  line-height: 1;
  letter-spacing: -.015em;
}

.lede {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 18px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
}
.live .pulse {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--good);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

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

.panel {
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
}
.panel h2 {
  margin: 0 0 10px;
  font-family: 'Instrument Serif', Georgia, serif;
  font-weight: 400;
  font-size: 26px;
  color: var(--text);
}
.panel p { margin: 0 auto; max-width: 38ch; font-size: 14.5px; }

.spinner {
  width: 22px; height: 22px; margin: 0 auto 18px;
  border: 1.5px solid var(--line);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  margin-top: 22px;
  padding: 9px 22px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }

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

.podium {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  align-items: end;
  gap: 8px;
  padding: 16px 0 34px;
}
/* DOM order stays 1,2,3 for screen readers; the eye wants 2 · 1 · 3. */
.podium .spot[data-rank="1"] { order: 2; }
.podium .spot[data-rank="2"] { order: 1; }
.podium .spot[data-rank="3"] { order: 3; }

/* With fewer than three, a three-column podium looks broken. */
.podium.only-1 { grid-template-columns: 1fr; max-width: 260px; margin-inline: auto; }
.podium.only-2 { grid-template-columns: 1fr 1fr; max-width: 420px; margin-inline: auto; }

.spot { text-align: center; min-width: 0; }

.spot .medal {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  margin-bottom: 12px;
  color: var(--faint);
}
.spot[data-rank="1"] .medal { color: var(--gold); }

.spot .av {
  border-radius: 50%;
  object-fit: cover;
  background: var(--raised);
  width: 60px; height: 60px;
  box-shadow: 0 0 0 1px var(--line), 0 0 0 4px var(--bg), 0 0 0 5px var(--line);
}
/* The winner is simply bigger, and the only one ringed in gold. */
.spot[data-rank="1"] .av {
  width: 92px; height: 92px;
  box-shadow: 0 0 0 1px var(--line), 0 0 0 5px var(--bg), 0 0 0 6px var(--gold);
}

.spot .name {
  margin-top: 14px;
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 19px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spot[data-rank="1"] .name {
  margin-top: 20px;
  font-size: clamp(26px, 7vw, 34px);
  letter-spacing: -.01em;
}

.spot .line {
  margin-top: 7px;
  font-size: 12px;
  color: var(--faint);
}
.spot[data-rank="1"] .line { margin-top: 10px; font-size: 14px; color: var(--muted); }
.spot .line b { color: var(--text); font-weight: 600; }
/* An order placed is the outcome that matters, so it carries the one accent. */
.spot .line .ordered, .spot .line .ordered b { color: var(--good); }

/* The step each name stands on — a hairline, tallest under first place. */
.spot .step {
  margin-top: 16px;
  border-top: 2px solid var(--line);
  height: 14px;
}
.spot[data-rank="1"] .step { height: 30px; border-top-color: var(--gold); }
.spot[data-rank="2"] .step { height: 20px; }

/* ----------------------------------------------------------------- board -- */

.board { list-style: none; margin: 0; padding: 0; }

.board li {
  display: grid;
  grid-template-columns: 30px 40px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 16px 2px;
  border-top: 1px solid var(--line);
}
.board li:last-child { border-bottom: 1px solid var(--line); }

.board .rank {
  font-size: 13px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.board .av {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--raised);
  box-shadow: 0 0 0 1px var(--line);
}

.board .name {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board .score {
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.board .score b { color: var(--text); font-weight: 600; }
.board .score .ordered { color: var(--good); }
.board .score .ordered b { color: var(--good); }

/* ---------------------------------------------------------------- totals -- */

.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 38px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
  text-align: center;
}
.totals b {
  display: block;
  font-family: 'Instrument Serif', Georgia, serif;
  font-weight: 400;
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.totals span {
  display: block;
  margin-top: 7px;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
}

.legend {
  margin: 26px 0 0;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--faint);
}
.legend b { color: var(--muted); font-weight: 600; }

/* ----------------------------------------------------------------- debug -- */

.debug {
  margin-top: 40px;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 13px;
}
.debug h2 {
  margin: 0 0 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.debug dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; }
.debug dt { color: var(--faint); white-space: nowrap; }
.debug dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}
.debug dd.yes { color: var(--good); }
.debug dd.no  { color: var(--faint); }
.debug-note { margin: 16px 0 0; font-size: 12px; color: var(--faint); }
.debug code {
  font-size: 11.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--raised);
}

.foot {
  margin-top: 44px;
  text-align: center;
  font-size: 12px;
}
.foot a { color: var(--faint); text-decoration: none; }
.foot a:hover { color: var(--muted); }

/* ------------------------------------------------------------------ 420px -- */

@media (max-width: 420px) {
  .wrap { padding: 40px 18px 52px; }
  .podium { gap: 4px; }
  .spot .av { width: 46px; height: 46px; }
  .spot[data-rank="1"] .av { width: 74px; height: 74px; }
  .spot .name { font-size: 15px; margin-top: 11px; }
  .spot[data-rank="1"] .name { font-size: 24px; margin-top: 15px; }
  .spot .line { font-size: 11px; }
  .spot[data-rank="1"] .line { font-size: 12.5px; }
  /* Narrow columns: stack the two stats rather than orphan a word. */
  .spot .line > span { display: block; }
  .spot .line .sep { display: none; }
  .spot .medal { font-size: 10px; letter-spacing: .12em; }
  .board li { grid-template-columns: 22px 36px 1fr auto; gap: 11px; }
  .board .av { width: 36px; height: 36px; }
  .totals b { font-size: 26px; }
  .debug dl { grid-template-columns: 1fr; gap: 3px 0; }
  .debug dt { margin-top: 8px; }
}
