:root {
  --blue: #3d8bff;
  --orange: #ff8a2a;
  --bg: #070b18;
  --panel: rgba(10, 16, 34, 0.88);
  --text: #eef3ff;
  --muted: #93a0bf;
  --display: 'Russo One', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, sans-serif; user-select: none; -webkit-user-select: none;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#scoreboard {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; font-family: var(--display); filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.5));
}
.score { min-width: 62px; padding: 6px 14px; font-size: 30px; text-align: center; }
.score.blue { background: linear-gradient(180deg, #4b95ff, #1d56c9); border-radius: 10px 0 0 10px; }
.score.orange { background: linear-gradient(180deg, #ff9f45, #d9620f); border-radius: 0 10px 10px 0; }
#clock { background: rgba(8, 12, 26, 0.92); padding: 6px 16px; font-size: 30px; min-width: 112px; text-align: center; }
#clock.ot { color: #ffd34d; }

#bigmsg {
  position: absolute; top: 30%; left: 0; right: 0; text-align: center; font-family: var(--display);
  font-size: clamp(48px, 12vw, 140px); opacity: 0; transform: scale(0.85);
  transition: opacity 0.2s, transform 0.2s; text-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
}
#bigmsg.on { opacity: 1; transform: scale(1); }

#feed { position: absolute; top: 72px; right: 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.feed-item {
  background: rgba(8, 12, 26, 0.82); padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 14px;
  border-left: 4px solid; animation: feed 4s forwards;
}
@keyframes feed { 0% { opacity: 0; transform: translateX(20px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

#boost { position: absolute; right: 22px; bottom: 22px; width: 132px; height: 132px; }
#boost svg { width: 100%; height: 100%; transform: rotate(135deg); }
#boost .track { fill: rgba(8, 12, 26, 0.75); stroke: rgba(255, 255, 255, 0.12); stroke-width: 8; stroke-dasharray: 197.9 999; stroke-linecap: round; }
#boost .arc { fill: none; stroke: #ffb02e; stroke-width: 8; stroke-linecap: round; stroke-dasharray: 0 999; transition: stroke-dasharray 0.1s; }
#boost.supersonic .arc { stroke: #9fdcff; }
#boostNum { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--display); font-size: 40px; }
#speed { position: absolute; bottom: 10px; width: 100%; text-align: center; font-size: 12px; color: var(--muted); }
#camlabel {
  position: absolute; left: 14px; bottom: 14px; font-size: 12px; font-weight: 800; letter-spacing: 0.1em;
  color: var(--muted); background: rgba(8, 12, 26, 0.6); padding: 4px 8px; border-radius: 6px;
}
#pauseBtn {
  pointer-events: auto; position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px;
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(8, 12, 26, 0.7); font-size: 13px;
}

/* touch controls */
#touch { position: fixed; inset: 0; pointer-events: none; }
body:not(.touch) #touch { display: none; }
#joyZone { position: absolute; left: 0; bottom: 0; width: 50%; height: 70%; pointer-events: auto; touch-action: none; }
#joyBase {
  position: absolute; left: 110px; top: calc(100% - 120px); width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.2);
}
#joyBase.on { background: rgba(255, 255, 255, 0.14); }
#joyKnob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
}
.tbtn {
  position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35); background: rgba(8, 12, 26, 0.45);
  font-weight: 800; letter-spacing: 0.04em; font-size: 13px;
}
.tbtn.down { background: rgba(255, 255, 255, 0.35); }
.tbtn.jump { width: 92px; height: 92px; right: max(22px, env(safe-area-inset-right)); bottom: 28px; }
.tbtn.boost { width: 78px; height: 78px; right: calc(max(22px, env(safe-area-inset-right)) + 104px); bottom: 22px; border-color: #ffb02e; color: #ffd27a; }
.tbtn.small { width: 56px; height: 56px; font-size: 11px; }
#tSlide { right: calc(max(22px, env(safe-area-inset-right)) + 18px); bottom: 136px; }
#tCam { right: calc(max(22px, env(safe-area-inset-right)) + 92px); bottom: 118px; }
body.touch #boost { right: auto; left: 50%; transform: translateX(-50%) scale(0.62); bottom: auto; top: 44px; transform-origin: top center; }
body.touch #camlabel { display: none; }
body.touch #feed { top: 60px; }

/* screens */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(7, 11, 24, 0.35), rgba(7, 11, 24, 0.8));
  overflow-y: auto; touch-action: pan-y;
}
.panel {
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 18px;
  padding: 26px 26px 18px; width: min(460px, 100%); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px); max-height: 100%; overflow-y: auto;
}
.panel.small { width: min(400px, 100%); text-align: center; }
h1 { font-family: var(--display); font-size: clamp(34px, 9vw, 52px); margin: 0; line-height: 1; letter-spacing: 0.02em;
  background: linear-gradient(90deg, #5aa2ff, #ffffff 50%, #ff9a3d); -webkit-background-clip: text; background-clip: text; color: transparent; }
h1 span { display: inline-block; }
h2 { font-family: var(--display); font-size: 40px; margin: 0 0 12px; }
h2.win { color: #7dd3a8; }
h2.lose { color: #ff7a7a; }
.tag { color: var(--muted); margin: 6px 0 20px; font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.row label { width: 50px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.seg { display: flex; flex: 1; background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: linear-gradient(180deg, #3d8bff, #2563d6); color: #fff; }
.cta {
  display: block; width: 100%; margin: 18px 0 8px; padding: 14px; border: 0; border-radius: 12px;
  font-family: var(--display); font-size: 22px; letter-spacing: 0.06em;
  background: linear-gradient(180deg, #ffa646, #f0700f); color: #1a0d02; box-shadow: 0 8px 24px rgba(255, 130, 30, 0.35);
}
.cta:hover { filter: brightness(1.08); }
.ghost { display: block; width: 100%; padding: 11px; border-radius: 12px; background: transparent; border: 1px solid rgba(255, 255, 255, 0.18); }
.controls { margin-top: 10px; font-size: 13px; color: var(--muted); }
.controls summary { cursor: pointer; padding: 6px 0; }
.controls table { width: 100%; border-collapse: collapse; }
.controls td { padding: 4px 6px; border-top: 1px solid rgba(255, 255, 255, 0.06); vertical-align: top; }
.controls td:first-child { color: var(--text); font-weight: 600; white-space: nowrap; }
.fine { font-size: 11px; color: #5d6886; margin: 12px 0 0; text-align: center; }
#endScore { font-family: var(--display); font-size: 44px; margin-bottom: 10px; }
#endScore .b { color: #5aa2ff; }
#endScore .o { color: #ff9a3d; }
#endTable { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0 4px; }
#endTable th { color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px; }
#endTable td { padding: 6px 4px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
#endTable tr.b td:first-child { border-left: 3px solid #3d8bff; }
#endTable tr.o td:first-child { border-left: 3px solid #ff8a2a; }

@media (max-width: 600px) {
  .score, #clock { font-size: 22px; }
  #clock { min-width: 84px; }
}
