:root {
  --bg: #0A0A0B;
  --card: #141418;
  --red: #E10600;
  --gold: #C9A84C;
  --gold-hi: #E8C96A;
  --electric: #27C4E8;
  --white: #FFFFFF;
  --muted: #8A8A90;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--white);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 800px at 50% -10%, rgba(225, 6, 0, 0.10), transparent 60%),
    radial-gradient(900px 700px at 80% 120%, rgba(39, 196, 232, 0.06), transparent 60%),
    var(--bg);
  z-index: -1;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 22px 36px 6px;
}
.wordmark {
  font-family: 'Bebas Neue', Impact, sans-serif;
  font-size: clamp(28px, 4vw, 52px);
  letter-spacing: 2px;
  line-height: 1;
}
.wordmark span { color: var(--red); margin-left: 0.35ch; }
.tagline { color: var(--gold); font-weight: 600; font-size: clamp(11px, 1.2vw, 15px); letter-spacing: 1px; }

/* ---- Stage ---- */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 5vh, 64px);
  padding: 12px;
}

/* ---- Gantry ---- */
.gantry {
  display: flex;
  gap: clamp(12px, 2.4vw, 34px);
  padding: clamp(14px, 2vw, 28px) clamp(18px, 2.6vw, 40px);
  background: linear-gradient(#0c0c0e, #060607);
  border: 1px solid #222;
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.04);
}
.light {
  width: clamp(58px, 9vw, 130px);
  height: clamp(78px, 12vw, 176px);
  border-radius: 14px;
  background: #0a0a0a;
  border: 1px solid #1c1c1f;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.light span {
  width: 74%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #1a0202;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.03);
  transition: background 60ms linear, box-shadow 60ms linear;
}
.light.on span {
  background: radial-gradient(circle at 38% 32%, #ff5a4a, var(--red) 58%, #8e0400 100%);
  box-shadow: 0 0 38px 6px rgba(225,6,0,0.75), inset 0 0 10px rgba(255,180,170,0.6);
}

/* ---- Centerline messaging ---- */
.centerline { text-align: center; min-height: 1px; }
.headline {
  font-family: 'Bebas Neue', Impact, sans-serif;
  font-size: clamp(40px, 8vw, 120px);
  letter-spacing: 2px;
  line-height: 0.95;
}
.subhead { color: var(--muted); font-size: clamp(14px, 1.8vw, 22px); margin-top: 8px; letter-spacing: 1px; }

.countdown {
  font-family: 'Bebas Neue', Impact, sans-serif;
  font-size: clamp(120px, 30vh, 340px);
  line-height: 1;
  color: var(--white);
  display: none;
}
.result { display: none; }
.result .big {
  font-family: 'Bebas Neue', Impact, sans-serif;
  font-size: clamp(90px, 22vh, 280px);
  line-height: 0.9;
  letter-spacing: 2px;
}
.result .big.false { color: var(--red); font-size: clamp(56px, 12vh, 150px); }
.result .compare { color: var(--gold); font-size: clamp(18px, 2.4vw, 34px); letter-spacing: 1px; margin-top: 10px; }
.result .h2h { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.result .h2h .row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center;
  font-size: clamp(20px, 3vw, 40px); padding: 8px 18px; border-radius: 12px; background: var(--card);
}
.result .h2h .row.win { outline: 2px solid var(--gold); color: var(--gold-hi); }
.result .h2h .row .rk { font-family: 'Bebas Neue', sans-serif; color: var(--muted); }
.result .h2h .row .gap { color: var(--muted); font-size: 0.6em; }

/* ---- Bottom panel ---- */
.panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  padding: 16px 36px 28px;
}
.join { display: flex; align-items: center; gap: 18px; }
.qrbox {
  background: #fff; padding: 10px; border-radius: 12px; line-height: 0;
  width: 168px; height: 168px; display: flex; align-items: center; justify-content: center;
}
.qrbox img, .qrbox canvas { width: 148px !important; height: 148px !important; }
.qrbox .qr-fallback { color: #000; font-size: 11px; word-break: break-all; padding: 6px; line-height: 1.3; }
.joinmeta .scan { font-family: 'Bebas Neue', sans-serif; font-size: 26px; letter-spacing: 2px; }
.joinmeta .roomcode { color: var(--muted); margin-top: 4px; letter-spacing: 1px; }
.joinmeta .roomcode b { color: var(--gold); font-family: 'Bebas Neue', sans-serif; font-size: 22px; letter-spacing: 3px; }
.joinmeta .joinurl { color: #4a4a50; font-size: 11px; margin-top: 6px; }

.board { justify-self: center; min-width: 240px; }
.board-title { font-family: 'Bebas Neue', sans-serif; letter-spacing: 2px; color: var(--gold); font-size: 18px; margin-bottom: 6px; }
.board-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.board-list li { display: flex; justify-content: space-between; gap: 18px; font-variant-numeric: tabular-nums; color: #cfcfd4; font-size: 15px; }
.board-list li b { color: var(--white); font-weight: 600; }
.board-list .board-empty { color: var(--muted); justify-content: center; }

.status { justify-self: end; color: var(--muted); font-size: 15px; max-width: 280px; text-align: right; }

/* ---- State visibility ---- */
body[data-state="COUNTDOWN"] .countdown,
body[data-state="RACE"] .gantry,
body[data-state="OUT"] .gantry { }

body[data-state="CONNECTING"] .headline,
body[data-state="LOBBY"] .headline { }

/* hide headline/sub during active play + result */
body[data-state="COUNTDOWN"] .headline, body[data-state="COUNTDOWN"] .subhead,
body[data-state="RACE"] .headline, body[data-state="RACE"] .subhead,
body[data-state="OUT"] .headline, body[data-state="OUT"] .subhead,
body[data-state="RESULT"] .headline, body[data-state="RESULT"] .subhead { display: none; }

body[data-state="COUNTDOWN"] .countdown { display: block; }
body[data-state="RESULT"] .result { display: block; }

/* hide the join/board panel while a round is live */
body[data-state="COUNTDOWN"] .join, body[data-state="COUNTDOWN"] .board,
body[data-state="RACE"] .join, body[data-state="RACE"] .board,
body[data-state="OUT"] .join, body[data-state="OUT"] .board,
body[data-state="RESULT"] .join, body[data-state="RESULT"] .board { visibility: hidden; }

/* dim the gantry pre-round; bright once active */
body[data-state="LOBBY"] .gantry { opacity: 0.9; }

/* lights-out flash */
body[data-state="OUT"] .stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  animation: flash 320ms ease-out;
}
@keyframes flash { from { background: rgba(255,255,255,0.10); } to { background: transparent; } }

/* ---- Sound enable / mute toggle ---- */
.sfx-toggle {
  position: fixed; bottom: 14px; left: 14px; z-index: 40;
  font-family: 'Inter', system-ui, sans-serif; font-size: 13px; font-weight: 600;
  letter-spacing: 0.5px; color: var(--muted);
  background: rgba(20,20,24,0.82); border: 1px solid #2a2a30; border-radius: 999px;
  padding: 8px 14px; cursor: pointer; backdrop-filter: blur(6px);
  transition: color 120ms ease, border-color 120ms ease;
}
.sfx-toggle:hover { color: var(--white); border-color: #3a3a42; }
.sfx-toggle.on { color: var(--gold); border-color: rgba(201,168,76,0.5); }

/* ---- Debug overlay ---- */
.debug {
  position: fixed; top: 10px; right: 10px; z-index: 50;
  background: rgba(0,0,0,0.82); border: 1px solid #2a2a30; border-radius: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; color: #9fe;
  padding: 8px 10px; white-space: pre; line-height: 1.5; pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .light span { transition: none; }
  body[data-state="OUT"] .stage::after { animation: none; }
}

@media (max-width: 820px) {
  .panel { grid-template-columns: 1fr; justify-items: center; gap: 14px; }
  .status { text-align: center; justify-self: center; }
}
