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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1220;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 10, 20, 0.55);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.panel {
  background: linear-gradient(160deg, #1a2744 0%, #0f172a 100%);
  border: 3px solid #f5c542;
  border-radius: 24px;
  padding: 36px 44px;
  min-width: 380px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(245, 197, 66, 0.15);
  text-align: center;
}

.title {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(90deg, #ff4d4d, #f5c542, #4ade80, #38bdf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
  text-shadow: 0 0 30px rgba(245, 197, 66, 0.2);
}

.title.small {
  font-size: 36px;
  margin-bottom: 18px;
}

.subtitle {
  color: #94a3b8;
  font-size: 16px;
  letter-spacing: 6px;
  margin-bottom: 28px;
  text-transform: uppercase;
}

.char-select {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.char-btn {
  background: #16213e;
  border: 2px solid #334155;
  border-radius: 14px;
  color: #e2e8f0;
  padding: 12px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.char-btn:hover {
  border-color: #f5c542;
  transform: translateY(-2px);
}

.char-btn.selected {
  border-color: #f5c542;
  background: #1e293b;
  box-shadow: 0 0 0 3px rgba(245, 197, 66, 0.25);
}

.char-face {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 20px;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.char-face.mario { background: #e74c3c; }
.char-face.luigi { background: #2ecc71; }
.char-face.peach { background: #ff8fab; }
.char-face.bowser { background: #f39c12; }

.big-btn {
  background: linear-gradient(180deg, #fbbf24, #d97706);
  border: none;
  border-radius: 999px;
  color: #1c1400;
  font-size: 20px;
  font-weight: 800;
  padding: 14px 42px;
  cursor: pointer;
  letter-spacing: 2px;
  box-shadow: 0 6px 0 #92400e, 0 12px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.big-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #92400e, 0 14px 28px rgba(0, 0, 0, 0.4);
}

.big-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #92400e, 0 6px 12px rgba(0, 0, 0, 0.3);
}

.big-btn.secondary {
  background: linear-gradient(180deg, #64748b, #475569);
  color: #f8fafc;
  box-shadow: 0 6px 0 #334155, 0 12px 24px rgba(0, 0, 0, 0.35);
}

.controls-hint {
  margin-top: 24px;
  color: #94a3b8;
  font-size: 13px;
  line-height: 1.7;
}

.controls-hint b {
  color: #e2e8f0;
}

.btn-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 8px;
}

/* Countdown */
#countdown {
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}

#countdown-text {
  font-size: 140px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px #f5c542, 0 8px 0 #d97706;
  animation: pop 0.35s ease-out;
}

@keyframes pop {
  0% { transform: scale(2.2); opacity: 0; }
  60% { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

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

.hud-top {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
}

.hud-box {
  background: rgba(10, 16, 32, 0.72);
  border: 2px solid rgba(245, 197, 66, 0.55);
  border-radius: 14px;
  padding: 8px 18px;
  min-width: 100px;
  text-align: center;
  backdrop-filter: blur(4px);
}

.hud-box .label {
  font-size: 11px;
  color: #94a3b8;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.hud-box .value {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 24px;
}

.speedo {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(10, 16, 32, 0.75);
  border: 4px solid #334155;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.speed-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(180deg, #38bdf8, #22c55e);
  opacity: 0.35;
  transition: height 0.08s linear;
}

.speed-text {
  position: relative;
  font-size: 42px;
  font-weight: 900;
  color: #fff;
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.speed-unit {
  position: relative;
  font-size: 12px;
  color: #94a3b8;
  letter-spacing: 2px;
}

.item-slot {
  position: relative;
  width: 110px;
  height: 110px;
  border-radius: 18px;
  background: rgba(10, 16, 32, 0.78);
  border: 3px solid rgba(245, 197, 66, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.item-label {
  font-size: 11px;
  color: #94a3b8;
  letter-spacing: 2px;
}

.item-icon {
  font-size: 42px;
  font-weight: 900;
  color: #f5c542;
  text-shadow: 0 0 16px rgba(245, 197, 66, 0.5);
}

#minimap {
  width: 160px;
  height: 160px;
  border-radius: 16px;
  background: rgba(10, 16, 32, 0.75);
  border: 2px solid rgba(51, 65, 85, 0.9);
}

.drift-indicator,
.boost-indicator {
  position: absolute;
  left: 50%;
  bottom: 200px;
  transform: translateX(-50%);
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 6px;
  pointer-events: none;
  animation: pulse 0.3s ease infinite alternate;
}

.drift-indicator {
  color: #38bdf8;
  text-shadow: 0 0 20px #38bdf8;
}

.boost-indicator {
  color: #fbbf24;
  text-shadow: 0 0 20px #fbbf24;
  bottom: 250px;
}

@keyframes pulse {
  from { transform: translateX(-50%) scale(1); opacity: 0.85; }
  to { transform: translateX(-50%) scale(1.08); opacity: 1; }
}

.message-toast {
  position: absolute;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid #f5c542;
  color: #fff;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.results-list {
  text-align: left;
  margin-bottom: 24px;
}

.results-list .row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #334155;
  color: #e2e8f0;
  font-size: 16px;
  font-weight: 600;
}

.results-list .row.player {
  border-color: #f5c542;
  background: rgba(245, 197, 66, 0.12);
}

.results-list .rank {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: #f5c542;
}

.results-list .name {
  flex: 1;
}

.results-list .time {
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 190px;
  display: none;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
  z-index: 15;
}

.touch-left,
.touch-right {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.tbtn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 23, 42, 0.7);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tbtn.gas { background: rgba(34, 197, 94, 0.75); width: 78px; height: 78px; }
.tbtn.drift { background: rgba(56, 189, 248, 0.7); }
.tbtn.item { background: rgba(251, 191, 36, 0.75); }

@media (hover: none) and (pointer: coarse) {
  .touch-controls { display: flex; }
  .hud-bottom { bottom: 12px; }
}

@media (max-width: 640px) {
  .panel { padding: 24px 18px; min-width: 0; }
  .title { font-size: 32px; }
  .char-select { grid-template-columns: repeat(2, 1fr); }
  .hud-bottom { padding: 0 12px; }
  .speedo { width: 110px; height: 110px; }
  .speed-text { font-size: 28px; }
  .item-slot { width: 80px; height: 80px; }
  .item-icon { font-size: 28px; }
  #minimap { width: 110px; height: 110px; }
}
