* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
html, body {
  position: fixed; inset: 0; width: 100%; height: 100%; background: #0c183d;
  display: flex; justify-content: center; align-items: center;
  overflow: hidden; touch-action: none; font-family: 'Arial Black', sans-serif;
}
#wrap { position: relative; width: 100%; height: 100%; overflow: hidden; }
canvas { display: block; width: 100% !important; height: 100% !important; }
#hud { position: absolute; inset: 0; pointer-events: none; color: #fff; }
.top-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 5px 8px; background: linear-gradient(90deg, #e61c0e 0 11%, #1746d1 11% 89%, #e61c0e 89% 100%);
  border-bottom: 3px solid #08112e; pointer-events: auto;
}
.top-btn { display: flex; flex-direction: column; align-items: center; font-size: 9px; text-shadow: 0 1px 2px #000; }
.top-btn .ico { font-size: 18px; line-height: 1; }
.curr-pill {
  display: flex; align-items: center; gap: 4px; background: #0c2266;
  border: 2px solid #07133b; border-radius: 8px; padding: 2px 4px 2px 6px; font-size: 12px;
}
.curr-pill .plus {
  background: #28c745; color: #fff; font-style: normal; font-weight: 900;
  border-radius: 4px; padding: 0 5px; font-size: 13px; border: 1px solid #0b4f1b;
}
.gear-btn { background: none; border: none; font-size: 24px; cursor: pointer; filter: drop-shadow(0 2px 2px #000); }
.track-bar {
  background: repeating-linear-gradient(90deg, #111b3b 0 28px, #0b1229 28px 32px);
  padding: 6px 10px 4px; border-bottom: 4px solid #1746d1;
}
.track-items { display: flex; justify-content: space-between; align-items: flex-end; padding: 0 8px; }
.racer { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: #ffe033; text-shadow: 0 1px 2px #000; }
.av-box { width: 30px; height: 30px; border: 2px solid #fff; border-radius: 5px; background: #1e357a; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.racer.active .av-box { width: 36px; height: 36px; border: 3px solid #39ff14; background: rgba(15,28,70,0.6); }
.racer.active span { color: #fff; }
.gift-box { font-size: 26px; line-height: 1.1; }
.stripe-line {
  height: 6px; margin-top: 3px; border-radius: 3px;
  background: repeating-linear-gradient(-45deg, #ffe033 0 6px, #1746d1 6px 12px);
}

.lives-row {
  position: absolute; top: 108px; right: 12px; display: flex; gap: 4px; font-size: 18px;
  filter: drop-shadow(0 2px 3px #000);
}
.lives-row .life { transition: transform 0.25s, opacity 0.25s; }
.lives-row .life.off { opacity: 0.22; transform: scale(0.75); filter: grayscale(1); }

.combo-bar-wrap {
  position: relative; width: min(86%, 340px); height: 38px;
  margin: 34px auto 0; display: flex; align-items: center;
}
.combo-track {
  position: absolute; left: 16px; right: 16px; height: 18px;
  background: #070b1a; border: 3px solid #fff; border-radius: 9px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.7); overflow: hidden;
}
.combo-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #ff6a00, #ffd500, #39ff14);
  transition: width 0.25s ease-out;
}
.hex-node {
  position: absolute; width: 36px; height: 38px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: translateX(-50%); filter: drop-shadow(0 2px 3px rgba(0,0,0,0.8));
}
.hex-node::before {
  content: ''; position: absolute; inset: 3px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  background: #ff6200; z-index: 0;
}
.hex-node.start { left: 6%; width: 42px; height: 44px; }
.hex-node.start::before { background: radial-gradient(circle, #ff9900, #e63900); }
.hex-node.n1 { left: 37%; }
.hex-node.n2 { left: 68%; }
.hex-node.n3 { left: 95%; }
.hex-node span { position: relative; z-index: 1; font-size: 13px; color: #fff; text-shadow: 0 1px 2px #000; line-height: 1; }
.hex-node.start span { font-size: 20px; }
.hex-node b { position: relative; z-index: 1; font-size: 9px; color: #ffe033; line-height: 1; margin-top: 1px; }
.hex-node.active::before { background: linear-gradient(180deg, #39ff14, #149e00); }
.hex-node.active { transform: translateX(-50%) scale(1.12); }

#msgBox { margin-top: 10px; text-align: center; font-size: 28px; color: #5eff82; text-shadow: 0 2px 8px #000; }
#hint { position: absolute; bottom: 26%; width: 100%; text-align: center; font-size: 19px; opacity: 0.92; text-shadow: 0 2px 6px #000; }

#gameOverModal {
  position: absolute; inset: 0; background: rgba(6,12,32,0.82); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; pointer-events: auto; z-index: 20;
}
#gameOverModal.hidden { display: none; }
.go-card {
  background: #132563; border: 3px solid #4d79ff; border-radius: 16px;
  padding: 22px 28px; text-align: center; box-shadow: 0 10px 30px #000;
}
.go-card h2 { font-size: 28px; color: #ffe033; margin-bottom: 12px; }
.go-card p { font-size: 16px; margin-bottom: 8px; }
#restartBtn {
  margin-top: 14px; padding: 10px 22px; font-size: 16px; font-family: inherit;
  background: #28c745; color: #fff; border: 2px solid #fff; border-radius: 10px; cursor: pointer;
}

#tunePanel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25; height: 46dvh;
  overflow-y: auto; background: rgba(10,18,42,0.88); backdrop-filter: blur(6px); color: #fff;
  border-top: 2px solid #4d79ff; border-radius: 14px 14px 0 0; padding: 12px 16px 24px;
  font-family: sans-serif; font-size: 13px; touch-action: auto;
}
#tunePanel.hidden { display: none; }
.tune-row { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
.tune-row label { display: flex; justify-content: space-between; margin-bottom: 2px; }
.tune-desc { font-size: 10px; color: #9db4ff; margin-bottom: 3px; }
.tune-row input[type="range"] {
  -webkit-appearance: none; appearance: none; width: calc(100% - 28px);
  height: 26px; background: transparent; pointer-events: none; touch-action: pan-y;
}
.tune-row input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; background: rgba(255,255,255,0.25); border-radius: 3px; pointer-events: none;
}
.tune-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: #4d79ff; border: 2px solid #fff; margin-top: -8px; pointer-events: auto; cursor: grab;
}

#comboTimerBadge {
  position: absolute; right: 10px; top: 42px; background: #0c2266;
  border: 2px solid #ffe033; border-radius: 10px; padding: 2px 8px;
  font-size: 12px; color: #ffe033; text-shadow: 0 1px 2px #000;
}
#comboTimerBadge.hidden { display: none; }

#roundSplash {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%) scale(1);
  background: linear-gradient(180deg, #ff9900, #e61c0e); border: 4px solid #fff;
  border-radius: 18px; padding: 10px 26px; font-size: 28px; color: #fff;
  text-shadow: 0 3px 0 #000; box-shadow: 0 10px 25px rgba(0,0,0,0.75);
  z-index: 15; white-space: nowrap; animation: splashPop 0.35s cubic-bezier(.2,1.5,.4,1);
}
#roundSplash.hidden { display: none; }

@keyframes splashPop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes textPop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.pop-msg { animation: textPop 0.3s ease-out; -webkit-text-stroke: 1.5px #000; }

.tune-tabs { display: flex; gap: 4px; margin-bottom: 10px; position: sticky; top: 0; background: #0d1738; padding: 4px 0 6px; z-index: 5; }
.tune-tab { flex: 1; padding: 6px 4px; font-size: 11px; font-weight: bold; background: #182963; color: #b8c8ff; border: 1px solid #3554b8; border-radius: 7px; cursor: pointer; }
.tune-tab.active { background: #4d79ff; color: #fff; border-color: #fff; }
.preset-box { background: rgba(77,121,255,0.16); border: 1px solid rgba(120,160,255,0.35); border-radius: 9px; padding: 8px; margin-bottom: 10px; }
.preset-grid { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.preset-btn { padding: 5px 8px; font-size: 11px; background: #1a2d6e; color: #fff; border: 1px solid #4d79ff; border-radius: 6px; cursor: pointer; }
.preset-btn.active { background: #28c745; border-color: #fff; }
