:root {
  --ink: #1b1f3b;
  --paper: #fff8e8;
  --accent: #ff3b3b;
  --accent-2: #ffcc00;
  --blue: #2b6bff;
  --green: #3ecf5a;
  --shadow: 0 10px 0 rgba(27, 31, 59, 0.18);
  --font: "Fredoka", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #6ec6ff;
  font-family: var(--font);
  color: var(--ink);
}

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

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

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: radial-gradient(ellipse at center, rgba(30, 60, 120, 0.15), rgba(10, 20, 50, 0.45));
  pointer-events: none;
}

.overlay.active {
  display: flex;
  pointer-events: auto;
}

.menu-card {
  position: relative;
  width: min(520px, 92vw);
  padding: 36px 32px 28px;
  background: linear-gradient(180deg, #fffdf5 0%, var(--paper) 100%);
  border: 5px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 14px 0 rgba(27, 31, 59, 0.25), 0 30px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.logo-ribbon {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  background: var(--accent);
  color: #fff;
  border: 4px solid var(--ink);
  border-radius: 999px;
  padding: 6px 18px;
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 13px;
  box-shadow: 0 4px 0 rgba(27, 31, 59, 0.2);
}

.title {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 0.95;
  margin-bottom: 8px;
}

.title-m {
  font-size: clamp(42px, 8vw, 64px);
  font-weight: 900;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--accent-2), 5px 5px 0 var(--ink);
  letter-spacing: 0.04em;
}

.title-k {
  font-size: clamp(36px, 7vw, 54px);
  font-weight: 900;
  color: var(--blue);
  text-shadow: 3px 3px 0 #9fd0ff, 5px 5px 0 var(--ink);
  letter-spacing: 0.2em;
}

.subtitle {
  margin: 10px 0 18px;
  font-weight: 700;
  opacity: 0.7;
  letter-spacing: 0.08em;
}

.controls-hint {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  margin-bottom: 22px;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
}

.controls-hint div {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

kbd {
  display: inline-block;
  min-width: 28px;
  padding: 3px 8px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--ink);
  font-family: var(--font);
  font-weight: 700;
  font-size: 12px;
  text-align: center;
}

.btn-main {
  appearance: none;
  border: 4px solid var(--ink);
  background: linear-gradient(180deg, #ff6b6b, var(--accent));
  color: #fff;
  font-family: var(--font);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.18em;
  padding: 14px 36px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn-main:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--ink);
}

.btn-main:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--ink);
}

.tip {
  margin-top: 16px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.65;
}

/* ---------- Countdown ---------- */
.count-text {
  font-size: clamp(100px, 22vw, 180px);
  font-weight: 900;
  color: var(--accent-2);
  text-shadow:
    4px 4px 0 var(--accent),
    8px 8px 0 var(--ink);
  animation: pop 0.45s ease;
}

.count-text.go {
  color: var(--green);
  text-shadow:
    4px 4px 0 #9ef0b0,
    8px 8px 0 var(--ink);
}

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

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  font-family: var(--font);
}

.hud.hidden {
  display: none;
}

.badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 110px;
  padding: 8px 14px;
  background: rgba(255, 253, 245, 0.92);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 5px 0 rgba(27, 31, 59, 0.25);
}

.badge-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  opacity: 0.6;
}

.badge-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.hud-top-left,
.hud-top-right {
  position: absolute;
  top: 16px;
  display: flex;
  gap: 12px;
}

.hud-top-left { left: 16px; }
.hud-top-right { right: 16px; }

.pos-badge .badge-value { color: var(--accent); font-size: 26px; }
.lap-badge .badge-value { color: var(--blue); }

.hud-bottom-left {
  position: absolute;
  left: 20px;
  bottom: 20px;
}

.speedo {
  width: 140px;
  padding: 12px 14px 14px;
  background: rgba(255, 253, 245, 0.92);
  border: 4px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 5px 0 rgba(27, 31, 59, 0.25);
  text-align: center;
}

.speed-num {
  font-size: 40px;
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
}

.speed-unit {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.15em;
  opacity: 0.55;
  margin-bottom: 10px;
}

.drift-meter {
  position: relative;
  height: 14px;
  background: #e8e4d8;
  border: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.drift-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--accent-2), var(--accent));
  transition: width 0.05s linear;
}

.drift-label {
  position: absolute;
  inset: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
  line-height: 14px;
  opacity: 0.7;
}

.hud-bottom-right {
  position: absolute;
  right: 20px;
  bottom: 20px;
}

.item-slot {
  width: 110px;
  height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 253, 245, 0.95);
  border: 5px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 6px 0 rgba(27, 31, 59, 0.25);
}

.item-slot.has-item {
  animation: itemPulse 1.2s ease infinite;
}

@keyframes itemPulse {
  0%, 100% { box-shadow: 0 6px 0 rgba(27, 31, 59, 0.25); }
  50% { box-shadow: 0 6px 0 rgba(27, 31, 59, 0.25), 0 0 0 8px rgba(255, 204, 0, 0.35); }
}

.item-icon {
  font-size: 42px;
  line-height: 1;
  font-weight: 900;
}

.item-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-top: 4px;
  min-height: 1em;
}

.minimap-wrap {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 180px;
  height: 180px;
  background: rgba(255, 253, 245, 0.88);
  border: 4px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 5px 0 rgba(27, 31, 59, 0.25);
  overflow: hidden;
}

#minimap {
  width: 100%;
  height: 100%;
  display: block;
}

.toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  padding: 12px 28px;
  background: rgba(255, 253, 245, 0.95);
  border: 4px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(27, 31, 59, 0.25);
  font-size: 22px;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

/* ---------- Finish ---------- */
.finish-title {
  font-size: 42px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--accent-2);
  margin-bottom: 8px;
}

.finish-rank {
  font-size: 28px;
  font-weight: 800;
  color: var(--blue);
  margin-bottom: 18px;
}

.results {
  text-align: left;
  margin: 0 auto 24px;
  max-width: 360px;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid var(--ink);
  border-radius: 16px;
  overflow: hidden;
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  font-weight: 700;
  border-bottom: 2px solid rgba(27, 31, 59, 0.08);
}

.result-row:last-child {
  border-bottom: none;
}

.result-row.player {
  background: rgba(255, 204, 0, 0.35);
}

.result-row .who {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}

@media (max-width: 720px) {
  .controls-hint {
    grid-template-columns: 1fr;
  }

  .minimap-wrap {
    width: 120px;
    height: 120px;
    top: auto;
    bottom: 150px;
    transform: none;
  }

  .badge {
    min-width: 88px;
    padding: 6px 10px;
  }

  .badge-value {
    font-size: 16px;
  }

  .pos-badge .badge-value {
    font-size: 18px;
  }

  .item-slot {
    width: 84px;
    height: 84px;
  }

  .item-icon {
    font-size: 30px;
  }
}
