:root {
  --accent: #ff5c33;
  --accent2: #ffd23f;
  --panel: rgba(10, 14, 24, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #eef2ff;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b0e18;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  user-select: none;
}

#scene { display: block; width: 100%; height: 100%; }

.hidden { display: none !important; }

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

#top-left {
  position: absolute; top: 18px; left: 18px;
  display: flex; flex-direction: column; gap: 6px;
}
#position {
  font-size: 56px; font-weight: 800; line-height: 1;
  color: var(--accent2);
  text-shadow: 0 3px 10px rgba(0,0,0,.6);
  letter-spacing: 1px;
}
#position .ord { font-size: 26px; vertical-align: super; color: var(--text); }
#lap {
  font-size: 18px; font-weight: 700; letter-spacing: 2px;
  background: var(--panel); border: 1px solid var(--panel-border);
  padding: 4px 12px; border-radius: 8px; width: fit-content;
}

#center-msg {
  position: absolute; top: 14%; left: 50%; transform: translateX(-50%);
  font-size: 64px; font-weight: 900; letter-spacing: 4px;
  text-shadow: 0 4px 16px rgba(0,0,0,.7);
  text-align: center; white-space: nowrap;
}
#center-msg.go { color: var(--accent2); }
#center-msg.count { color: #fff; }

#minimap-wrap {
  position: absolute; top: 18px; right: 18px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 6px;
}
#minimap { display: block; border-radius: 8px; }

#item-box {
  position: absolute; bottom: 24px; left: 24px;
  width: 84px; height: 84px;
  background: var(--panel); border: 2px solid var(--panel-border);
  border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
}
#item-slot { font-size: 40px; line-height: 1; }
#item-label { font-size: 11px; letter-spacing: 2px; opacity: .7; }
#item-box.has-item { border-color: var(--accent2); box-shadow: 0 0 18px rgba(255,210,63,.35); }

#speedo-wrap {
  position: absolute; bottom: 18px; right: 22px;
  width: 150px; height: 150px;
}
#speedo { display: block; }
#speed-num {
  position: absolute; bottom: 34px; left: 0; width: 100%;
  text-align: center; font-size: 30px; font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,.7);
}

#boost-bar {
  position: absolute; bottom: 150px; right: 22px;
  width: 150px; height: 10px;
  background: rgba(255,255,255,.12); border-radius: 6px; overflow: hidden;
}
#boost-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #ff5c33, #ffd23f);
  transition: width .05s linear;
}

/* ---------- Overlay ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(12,16,30,.82), rgba(6,8,16,.95));
}
#overlay-card {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 36px 48px;
  max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
#overlay-card h1 {
  font-size: 46px; font-weight: 900; letter-spacing: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 8px;
}
#overlay-card .sub { opacity: .8; margin-bottom: 22px; font-size: 15px; }
#controls {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px;
  margin: 0 auto 26px; max-width: 380px;
  font-size: 14px; text-align: left;
}
#controls b { color: var(--accent2); }

#start-btn {
  pointer-events: auto; cursor: pointer;
  font-size: 20px; font-weight: 800; letter-spacing: 2px;
  color: #1a1206;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border: none; border-radius: 12px;
  padding: 14px 44px;
  transition: transform .1s, box-shadow .1s;
}
#start-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(255,92,51,.4); }

#results { margin-top: 22px; }
#results table { width: 100%; border-collapse: collapse; font-size: 15px; }
#results td { padding: 6px 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
#results .rank { font-weight: 800; color: var(--accent2); width: 40px; }
#results .you { color: var(--accent2); font-weight: 700; }
#results .best { margin-top: 14px; font-size: 14px; opacity: .85; }

#loading {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; letter-spacing: 2px; background: #0b0e18;
}