:root {
  --amber: #ffb545;
  --cyan: #59f2ff;
  --red: #ff5240;
  --ink: #1a0f08;
  --panel: rgba(26, 15, 8, 0.62);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #2a170c; }
body {
  font-family: "Lucida Console", "Courier New", ui-monospace, monospace;
  color: var(--amber);
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

#flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 30;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255,60,20,0.75) 100%);
  opacity: 0;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.hud-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 181, 69, 0.45);
  box-shadow: 0 0 0 2px rgba(26,15,8,0.35), inset 0 0 18px rgba(255,140,40,0.08);
  padding: 8px 12px;
}
#h-top {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
#h-speedbox { min-width: 132px; }
#h-speed { font-size: 44px; font-weight: bold; line-height: 0.9; text-shadow: 0 0 12px rgba(255,181,69,0.6); }
.hud-label { font-size: 10px; letter-spacing: 3px; opacity: 0.8; margin-top: 4px; }
#h-speedbar, .bar { height: 7px; background: rgba(255,181,69,0.16); margin-top: 6px; overflow: hidden; }
#h-speedbar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--amber), #ffe29a); }
#h-mid { text-align: center; }
#h-lap { font-size: 18px; letter-spacing: 2px; }
#h-time { font-size: 22px; color: #ffe9c4; }
#h-cpname { font-size: 11px; color: var(--cyan); letter-spacing: 2px; min-height: 14px; }
#h-posbox { min-width: 96px; text-align: right; }
#h-pos { font-size: 40px; font-weight: bold; color: #ffe9c4; line-height: 0.95; }
#h-pos.p1 { color: var(--cyan); text-shadow: 0 0 14px rgba(89,242,255,0.7); }
#h-gap { font-size: 12px; opacity: 0.85; min-height: 15px; }

#h-bottom {
  position: absolute; bottom: 34px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
}
#h-heat { width: 200px; }
#h-heat .bar { height: 10px; }
#h-heat-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7ce07c, #ffb545 60%, #ff5240); transition: width 0.1s linear; }
#h-heat-fill.hot { animation: pulse 0.4s infinite alternate; }
#h-heat.overheat { border-color: var(--red); animation: pulse 0.25s infinite alternate; }
#h-boost {
  margin-top: 6px; font-size: 11px; letter-spacing: 3px; text-align: center;
  padding: 3px 0; border: 1px solid rgba(255,181,69,0.4); opacity: 0.5;
}
#h-boost.on { opacity: 1; background: var(--amber); color: var(--ink); box-shadow: 0 0 16px rgba(255,181,69,0.8); }
#h-boost.dead { border-color: var(--red); color: var(--red); opacity: 0.9; }
#h-dmgbox { width: 200px; text-align: right; }
#h-dmg-fill { height: 100%; width: 100%; background: #7ce07c; transition: width 0.15s; }
#h-dmg-fill.warn { background: var(--amber); }
#h-dmg-fill.crit { background: var(--red); animation: pulse 0.3s infinite alternate; }
#h-engines { margin-top: 6px; font-size: 11px; letter-spacing: 2px; }
.eng { display: inline-block; padding: 2px 8px; margin-left: 6px; border: 1px solid rgba(255,255,255,0.3); }
.eng.ok { color: #7ce07c; }
.eng.hit { color: var(--amber); }
.eng.crit { color: var(--red); border-color: var(--red); animation: pulse 0.3s infinite alternate; }

#h-progress {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: min(560px, 74vw); height: 6px; background: rgba(26,15,8,0.6);
  border: 1px solid rgba(255,181,69,0.4);
}
.prog-dot {
  position: absolute; top: -3px; width: 8px; height: 10px; margin-left: -4px;
  background: #888; transition: left 0.2s linear;
}
.prog-dot.me { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.prog-tick { position: absolute; top: -4px; width: 2px; height: 14px; background: rgba(255,181,69,0.65); }

#h-zone {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%);
  font-size: 15px; letter-spacing: 6px; color: #ffe9c4; opacity: 0;
  text-shadow: 0 2px 0 var(--ink), 0 0 14px rgba(255,181,69,0.6);
  transition: opacity 0.4s;
}
#h-zone.show { opacity: 1; }
#h-wrongway {
  position: absolute; top: 128px; left: 50%; transform: translateX(-50%);
  color: var(--red); font-size: 18px; letter-spacing: 3px; animation: pulse 0.3s infinite alternate;
}
#h-hint {
  position: absolute; bottom: 76px; left: 50%; transform: translateX(-50%);
  font-size: 12px; letter-spacing: 1px; color: #ffe9c4; opacity: 0.9;
  background: var(--panel); padding: 6px 14px; border: 1px solid rgba(255,181,69,0.3);
  white-space: nowrap;
}

#h-msg, #h-sub {
  position: fixed; left: 50%; transform: translateX(-50%);
  z-index: 25; text-align: center; pointer-events: none;
  font-weight: bold; letter-spacing: 4px;
  opacity: 0; transition: opacity 0.12s;
}
#h-msg { top: 30%; font-size: 52px; color: var(--amber); text-shadow: 0 3px 0 var(--ink), 0 0 24px rgba(255,160,50,0.7); }
#h-sub { top: 30%; margin-top: 62px; font-size: 18px; color: #ffe9c4; text-shadow: 0 2px 0 var(--ink); }
#h-msg.show, #h-sub.show { opacity: 1; }
#h-msg.count { font-size: 96px; color: var(--red); }
#h-msg.go { color: #5eff8a; text-shadow: 0 3px 0 var(--ink), 0 0 30px rgba(94,255,138,0.8); }
#h-msg.bad { color: var(--red); }
#h-msg.good { color: var(--cyan); }

@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.7); } }

/* ---------- touch ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 22; display: none; }
.tpad {
  position: absolute; bottom: 90px; width: 88px; height: 88px;
  border: 2px solid rgba(255,181,69,0.55); border-radius: 10px;
  background: rgba(26,15,8,0.45); color: var(--amber);
  font-size: 30px; display: flex; align-items: center; justify-content: center;
  pointer-events: auto; touch-action: none;
}
.tpad.on { background: rgba(255,181,69,0.5); color: var(--ink); }
#t-left { left: 18px; }
#t-right { left: 122px; }
#t-boost { right: 18px; width: 108px; font-size: 15px; letter-spacing: 2px; border-color: rgba(89,242,255,0.6); color: var(--cyan); }
#t-boost.on { background: rgba(89,242,255,0.45); color: var(--ink); }
#t-pause { right: 18px; bottom: 196px; width: 56px; height: 44px; font-size: 14px; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, rgba(26,15,8,0.25), rgba(26,15,8,0.72));
}
.title-inner { text-align: center; padding: 20px; }
.logo-kicker { font-size: 14px; letter-spacing: 10px; color: var(--cyan); text-shadow: 0 0 10px rgba(89,242,255,0.6); }
h1 {
  font-size: clamp(44px, 11vw, 108px); letter-spacing: 4px; color: var(--amber);
  text-shadow: 0 4px 0 #4d2a14, 0 0 34px rgba(255,150,50,0.65);
  line-height: 1; margin: 6px 0 4px;
}
h1 span { color: #ffe9c4; }
.tagline { font-size: 13px; letter-spacing: 3px; opacity: 0.85; margin-bottom: 26px; }
button {
  font: inherit; letter-spacing: 2px; cursor: pointer;
  background: var(--amber); color: var(--ink); border: none;
  padding: 12px 26px; font-size: 16px; font-weight: bold;
  box-shadow: 0 4px 0 #7a4416, 0 0 20px rgba(255,160,50,0.35);
}
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #7a4416; }
button.big { font-size: 20px; padding: 16px 40px; }
button.dim { background: #5d4630; color: #ffe9c4; box-shadow: 0 4px 0 #2c1d10; }
.best { margin: 18px 0 10px; font-size: 13px; letter-spacing: 2px; color: var(--cyan); }
.controls {
  display: grid; grid-template-columns: repeat(3, auto); gap: 8px 26px;
  justify-content: center; font-size: 12px; margin: 14px 0; color: #ffd9a0;
}
.controls b { color: var(--cyan); }
.footnote { font-size: 11px; letter-spacing: 2px; opacity: 0.65; }

.panel {
  background: var(--panel); border: 1px solid rgba(255,181,69,0.5);
  padding: 34px 44px; text-align: center; backdrop-filter: blur(3px);
}
.panel h2 { font-size: 34px; letter-spacing: 6px; margin-bottom: 22px; }
.panel button { display: block; width: 100%; margin: 10px 0; }
.panel.wide { min-width: min(520px, 92vw); }
.record { color: #5eff8a; font-size: 14px; letter-spacing: 3px; margin-bottom: 8px; min-height: 18px; }
#res-body { width: 100%; border-collapse: collapse; margin: 8px 0 18px; font-size: 14px; }
#res-body th { color: var(--cyan); font-size: 11px; letter-spacing: 2px; text-align: left; padding: 4px 8px; border-bottom: 1px solid rgba(89,242,255,0.3); }
#res-body td { padding: 6px 8px; text-align: left; color: #ffe9c4; }
#res-body tr.me td { color: var(--amber); font-weight: bold; }
.panel .row { display: flex; gap: 10px; }
.panel .row button { flex: 1; }
kbd { background: rgba(0,0,0,0.4); padding: 1px 6px; border: 1px solid rgba(255,255,255,0.25); font-size: 11px; }

#screen-crash {
  position: fixed; inset: 0; z-index: 35; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s;
  background: radial-gradient(ellipse at center, rgba(120,10,0,0.12), rgba(60,5,0,0.55));
}
#screen-crash.show { opacity: 1; }
#screen-crash div {
  font-size: clamp(40px, 9vw, 84px); font-weight: bold; letter-spacing: 10px;
  color: var(--red); text-shadow: 0 4px 0 #300a05, 0 0 30px rgba(255,60,30,0.8);
}
#fade { position: fixed; inset: 0; background: #1a0f08; z-index: 60; pointer-events: none; opacity: 0; transition: opacity 0.4s; }

@media (max-width: 720px) {
  #h-speed { font-size: 30px; }
  #h-speedbox { min-width: 92px; }
  #h-pos { font-size: 28px; }
  #h-heat, #h-dmgbox { width: 130px; }
  #h-time { font-size: 15px; }
  #h-lap { font-size: 13px; }
  #h-msg { font-size: 34px; }
  #h-msg.count { font-size: 64px; }
  #h-hint { display: none; }
  .controls { grid-template-columns: repeat(2, auto); }
  #h-bottom { bottom: 190px; }
}
