* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 0%, #1c2333, #05060a 70%);
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  color: #eaeef7;
}

#wrap {
  position: relative;
  width: min(960px, 100vw, calc((100vh - 20px) * 16 / 9));
}

#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag {
  font-size: 11px;
  font-weight: 700;
  width: 24px;
  text-align: center;
  padding: 2px 0;
  border-radius: 4px;
  background: rgba(0,0,0,0.5);
}

.tag.me { color: #4fd0ff; }
.tag.ai { color: #ff6b6b; }

.bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  overflow: hidden;
}

.fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.15s linear;
}

.fill.me { background: linear-gradient(90deg, #2fa7ff, #7fe0ff); }
.fill.ai { background: linear-gradient(90deg, #ff4d4d, #ffa66b); }

.dist {
  font-size: 11px;
  width: 46px;
  text-align: right;
  opacity: 0.8;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #2b2b33;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

#speedo {
  position: absolute;
  bottom: 14px;
  right: 14px;
  z-index: 5;
  background: rgba(0,0,0,0.55);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  letter-spacing: 0.5px;
}

#speedVal {
  font-size: 20px;
  font-weight: 700;
  color: #ffd24f;
}

.boost-bar {
  margin-top: 4px;
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}

.boost-fill {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #7fe0ff, #4fd0ff);
  transition: width 0.1s linear;
}

.drift-bar { margin-top: 5px; }

.drift-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: rgba(255,255,255,0.6);
  transition: width 0.05s linear, background 0.15s linear;
}

.drift-fill.tier1 { background: linear-gradient(90deg, #ffffff, #cfe6ff); }
.drift-fill.tier2 { background: linear-gradient(90deg, #ffd24f, #ff9a3a); }
.drift-fill.tier3 {
  background: linear-gradient(90deg, #d76bff, #ff5fd6);
  box-shadow: 0 0 8px rgba(255,95,214,0.9);
  animation: driftPulse 0.35s infinite alternate;
}

@keyframes driftPulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.6); }
}

#itemBox {
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 5;
  width: 64px;
  height: 64px;
  background: rgba(0,0,0,0.55);
  border: 2px dashed rgba(255,255,255,0.35);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

#itemBox.filled {
  border-style: solid;
  border-color: #ffd24f;
  box-shadow: 0 0 14px rgba(255,210,79,0.6);
}

.item-icon {
  font-size: 26px;
  line-height: 1;
}

.item-key {
  font-size: 10px;
  opacity: 0.7;
  letter-spacing: 1px;
}

#countdown {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 88px;
  font-weight: 800;
  color: #ffd24f;
  text-shadow: 0 4px 20px rgba(0,0,0,0.6);
  pointer-events: none;
}

#countdown.show { display: flex; }

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 10, 0.86);
  border-radius: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  text-align: center;
}

#overlay.show { display: flex; }

#overlayBox h1 {
  margin: 0 0 8px;
  font-size: 28px;
  background: linear-gradient(90deg, #4fd0ff, #ffd24f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#overlayBox p {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.6;
  color: #cfd6e6;
}

#overlayBox button {
  border: none;
  padding: 10px 26px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 999px;
  background: linear-gradient(90deg, #2fa7ff, #4fd0ff);
  color: #0a0f1a;
  cursor: pointer;
}

#overlayBox button:hover { filter: brightness(1.08); }

#overlayBox .result {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
}

#overlayBox .result.win { color: #6bffb0; }
#overlayBox .result.lose { color: #ff6b6b; }

#touchControls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 6;
  align-items: flex-end;
  justify-content: space-between;
  padding: 14px;
  pointer-events: none;
}

.touch-group {
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.touch-steer { align-items: flex-end; }

.touch-actions {
  flex-wrap: wrap;
  width: 148px;
  justify-content: flex-end;
}

.touch-btn {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  border: none;
  border-radius: 50%;
  background: rgba(35, 42, 61, 0.75);
  color: #eaeef7;
  font-weight: 700;
  font-size: 20px;
  width: 64px;
  height: 64px;
  line-height: 1.1;
  backdrop-filter: blur(2px);
}

.touch-btn.small {
  width: 52px;
  height: 52px;
  font-size: 18px;
}

.touch-btn.boost {
  width: 68px;
  height: 68px;
  font-size: 15px;
  background: rgba(47, 167, 255, 0.55);
}

.touch-btn:active { background: rgba(54, 66, 102, 0.9); }
.touch-btn.boost:active { background: rgba(79, 208, 255, 0.75); }

@media (pointer: coarse) {
  #touchControls { display: flex; }
  /* Lift the item box and speedo above the on-screen touch buttons so they don't overlap. */
  #itemBox { bottom: 92px; }
  #speedo { bottom: 158px; }
}
