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

html, body {
  height: 100%;
  background: #000000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 540px;
  height: 960px;
  /* near-black neon-void fallback so the frame reads dark before the canvas paints. */
  background: radial-gradient(120% 90% at 50% 38%, #060912 0%, #02040a 55%, #000000 100%);
  border: 1px solid #112233;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.75), inset 0 0 70px rgba(0,0,0,0.45),
              0 0 40px rgba(60, 200, 255, 0.10);
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* ---------- HUD overlay ---------- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 14px 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(180deg, rgba(4,8,18,0.72), rgba(4,8,18,0));
}
.t-title {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 7px;
  color: #eafaff;
  text-shadow: 0 0 18px rgba(80,210,255,0.65), 0 0 4px rgba(255,60,180,0.5);
}
.t-sub {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  letter-spacing: 3px;
  opacity: 0.85;
}
#race-info { color: #9fd6ff; }
.lap-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  padding: 2px 10px;
  border-radius: 14px;
  background: rgba(10,18,40,0.6);
  border: 1px solid rgba(120,200,255,0.32);
}
.lap-label { font-size: 9px; letter-spacing: 2px; color: #b9d6ff; margin-right: 4px; }
.lap-num { font-family: "SF Mono", Menlo, monospace; font-size: 17px; font-weight: 900; color: #fff; }
.lap-sep { opacity: 0.5; }
.lap-tot { font-family: "SF Mono", Menlo, monospace; font-size: 13px; font-weight: 800; opacity: 0.7; }

/* ---------- Leaderboard ---------- */
#leaderboard {
  position: absolute;
  top: 92px; left: 12px;
  width: 196px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(8,12,26,0.55);
  border: 1px solid rgba(255,255,255,0.07);
  transition: transform 0.35s cubic-bezier(.2,1,.3,1), background 0.3s ease, border-color 0.3s ease;
}
.lb-row.leader {
  background: rgba(20,28,50,0.7);
  border-color: rgba(255,255,255,0.22);
}
.lb-pos {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
  font-weight: 900;
  width: 26px;
  text-align: center;
  opacity: 0.92;
}
.lb-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 10px currentColor;
}
.lb-name {
  flex: 1;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-lap {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  opacity: 0.6;
}

/* ---------- Lead gap ---------- */
#gap-readout {
  position: absolute;
  top: 92px; right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 5px 11px;
  border-radius: 10px;
  background: rgba(8,12,26,0.55);
  border: 1px solid rgba(120,200,255,0.22);
}
.gap-label { font-size: 8px; letter-spacing: 3px; color: #acd0ff; opacity: 0.8; }
.gap-val {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 18px;
  font-weight: 900;
  color: #d8f3ff;
  text-shadow: 0 0 12px rgba(90,210,255,0.6);
}
#gap-readout.tight .gap-val { color: #ffd36b; text-shadow: 0 0 14px rgba(255,200,80,0.8); }

/* ---------- Photo-finish flash ---------- */
#finish-flash {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 7px;
  color: #fff;
  text-shadow: 0 0 24px rgba(255,80,180,0.9), 0 0 10px rgba(90,220,255,0.8);
}
#finish-flash.show { animation: pfPulse 0.45s ease-in-out infinite; }
#finish-flash.hidden { display: none !important; }
@keyframes pfPulse {
  0%,100% { opacity: 0.55; transform: translate(-50%,-50%) scale(0.97); }
  50% { opacity: 1; transform: translate(-50%,-50%) scale(1.06); }
}

/* ---------- Victory banner ---------- */
#victory-banner {
  position: absolute;
  top: 44%; left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(.2,1.3,.4,1);
}
#victory-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#victory-banner.hidden { display: none !important; }
.vb-sub {
  font-size: 12px;
  letter-spacing: 6px;
  font-weight: 700;
  opacity: 0.85;
}
.vb-name {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 3px;
  line-height: 1;
  margin: 8px 0;
  color: #fff;
  text-shadow: 0 0 34px currentColor;
}
.vb-tag {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 14px;
  opacity: 0.95;
}

/* ---------- Watermark / ticker ---------- */
#watermark {
  position: absolute;
  bottom: 30px; right: 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.55);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.ticker {
  position: absolute;
  left: 0; right: 0;
  bottom: 8px;
  text-align: center;
  font-family: "SF Mono", "Menlo", "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.6;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

#boot-error {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  font-size: 14px;
  line-height: 1.6;
  color: #ff8a8a;
  background: rgba(8,10,20,0.95);
}

/* CRITICAL: an ID selector (#boot-error{display:flex}) would otherwise outrank
   a plain .hidden{display:none}, leaving the full-screen dark overlay visible
   on top of the WebGL canvas. !important keeps it hidden unless we explicitly
   un-hide it on an actual context-creation failure. */
.hidden { display: none !important; }

#stage.shaking { animation: quake 0.3s linear infinite; }
@keyframes quake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -2px); }
}
