/* KartMoule — Web3 × Synthwave HUD + rendu pixélisé */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@500;700;900&family=Space+Grotesk:wght@400;600&display=swap');

:root {
  --bg: #09090f;
  --magenta: #ff2bd6;
  --violet: #7b2cbf;
  --cyan: #00f0ff;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(0, 240, 255, 0.4);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Space Grotesk', system-ui, sans-serif;
  touch-action: none;
  color: #e8e6f2;
}

/* Avant sélection de circuit : HUD / contrôles masqués */
body.pre-race #hud,
body.pre-race #hint,
body.pre-race #mobileControls,
body.pre-race #scoreFloats,
body.pre-race #finishPanel,
body.pre-race #overlay,
body.pre-race #topLinks {
  visibility: hidden !important;
  pointer-events: none !important;
}

body.pre-race #loadingOverlay {
  display: none !important;
}

/* ===== MENU ===== */
.track-menu {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background:
    radial-gradient(ellipse at 50% 15%, rgba(255, 43, 214, 0.18), transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(0, 240, 255, 0.12), transparent 45%),
    linear-gradient(160deg, #08060f 0%, #141022 50%, #0a0812 100%);
}

.track-menu.is-hidden {
  display: none;
}

.track-menu-card {
  position: relative;
  width: min(640px, 100%);
  padding: 1.75rem 1.5rem 1.5rem;
  background:
    linear-gradient(180deg, rgba(28, 24, 48, 0.95), rgba(12, 10, 22, 0.96)),
    repeating-linear-gradient(-14deg, transparent 0 12px, rgba(255, 255, 255, 0.02) 12px 13px);
  border: 1px solid rgba(0, 240, 255, 0.35);
  box-shadow: 0 0 0 1px rgba(255, 43, 214, 0.15), 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.menu-hub-link {
  display: block;
  width: fit-content;
  margin: 0 0 0.85rem;
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-decoration: none;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.55);
}

.menu-hub-link:hover {
  color: #fff;
}

.track-eyebrow {
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  color: var(--magenta);
  margin-bottom: 0.65rem;
}

.track-menu-card h1 {
  font-family: 'Orbitron', monospace, sans-serif;
  font-weight: 900;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: 0.06em;
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.35);
  margin-bottom: 0.45rem;
}

.track-tagline {
  color: #a8a0c0;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.track-resume-btn {
  appearance: none;
  display: block;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0.9rem 1rem;
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: #061018;
  background: linear-gradient(180deg, #7ef9ff, #00d4e8);
  border: 1px solid rgba(0, 240, 255, 0.7);
  box-shadow: 0 0 22px rgba(0, 240, 255, 0.28);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.track-resume-btn:hover,
.track-resume-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 0 28px rgba(0, 240, 255, 0.4);
  outline: none;
}

.track-resume-btn.is-hidden {
  display: none;
}

.track-grid {
  display: grid;
  gap: 0.65rem;
}

.track-btn {
  appearance: none;
  display: grid;
  gap: 0.2rem;
  text-align: left;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(0, 240, 255, 0.28);
  background: rgba(8, 10, 20, 0.75);
  color: #e8e6f2;
  cursor: pointer;
  font-family: 'Orbitron', monospace, sans-serif;
  transition: border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.track-btn:hover,
.track-btn:focus-visible {
  border-color: var(--cyan);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.2);
  transform: translateY(-1px);
  outline: none;
}

.track-btn-random {
  border-color: rgba(255, 43, 214, 0.4);
}

.track-btn-random:hover,
.track-btn-random:focus-visible {
  border-color: var(--magenta);
  box-shadow: 0 0 18px rgba(255, 43, 214, 0.22);
}

.track-btn--locked,
.track-btn-soon {
  opacity: 0.45;
  filter: grayscale(0.55);
  cursor: not-allowed;
}

.track-btn--locked:hover,
.track-btn-soon:hover {
  transform: none;
  border-color: rgba(0, 240, 255, 0.2);
  box-shadow: none;
}

.track-btn--locked .track-meta,
.track-btn-soon .track-meta {
  color: #c48a9e;
}

.track-music-toggle {
  margin-top: 1rem;
  width: 100%;
  pointer-events: auto;
  cursor: pointer;
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 0.65rem 0.8rem;
  color: #e8ffff;
  background: rgba(20, 20, 30, 0.75);
  border: 1px solid rgba(0, 255, 255, 0.35);
  border-radius: 8px;
}

.track-music-toggle.is-muted {
  color: #ff8ab8;
  border-color: rgba(255, 43, 214, 0.45);
}

.track-name {
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: #fff;
}

.track-meta {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 0.8rem;
  color: #9a92b0;
  letter-spacing: 0.02em;
}

/* Fond synthwave derrière le canvas (visible aux bords / chargement) */
.synth-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.synth-sky {
  position: absolute;
  inset: 0 0 40% 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(123, 44, 191, 0.4), transparent 70%),
    linear-gradient(180deg, #09090f, #1a0a2e 60%, #2d0b4e);
}

.synth-sun {
  position: absolute;
  left: 50%;
  top: 34%;
  width: min(30vw, 180px);
  height: min(30vw, 180px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: linear-gradient(180deg, #ff9a3c, #ff2bd6 60%, #7b2cbf);
  opacity: 0.55;
  mask-image: linear-gradient(180deg, #000 45%, transparent 80%);
  -webkit-mask-image: linear-gradient(180deg, #000 45%, transparent 80%);
}

.synth-grid {
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: -8%;
  height: 58%;
  background-image:
    linear-gradient(rgba(255, 43, 214, 0.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123, 44, 191, 0.4) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(420px) rotateX(58deg);
  transform-origin: center top;
  animation: grid-rush 12s linear infinite;
  opacity: 0.7;
}

@keyframes grid-rush {
  from { background-position: 0 0; }
  to { background-position: 0 48px; }
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100vw !important;
  height: 100vh !important;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#loadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  transition: opacity 0.65s ease;
}

#loadingOverlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

#loadingText {
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: clamp(14px, 3vw, 22px);
  letter-spacing: 0.12em;
  color: #bffbff;
  text-align: center;
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.6), 0 0 22px rgba(255, 43, 214, 0.35);
  animation: loading-blink 1s step-end infinite;
}

@keyframes loading-blink {
  50% { opacity: 0.45; }
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#beerBlur {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: rgba(40, 25, 10, 0.12);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition: opacity 0.15s ease;
}

#beerBlur.is-active {
  opacity: 1;
}

#weedEyes {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#weedEyes.is-active {
  opacity: 1;
}

.weed-lid {
  position: absolute;
  left: 0;
  right: 0;
  background: #050308;
  transition: height 0.35s ease;
  height: 0%;
  box-shadow: inset 0 0 40px rgba(40, 120, 40, 0.35);
}

.weed-lid-top { top: 0; }
.weed-lid-bot { bottom: 0; }

#weedEyes.is-active .weed-lid-top,
#weedEyes.is-active .weed-lid-bot {
  height: var(--weed-close, 18%);
}

.hud-glass {
  font-family: 'Orbitron', monospace, sans-serif;
  letter-spacing: 0.1em;
  background: rgba(20, 20, 30, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 8px;
  box-shadow:
    0 0 12px rgba(0, 255, 255, 0.25),
    0 0 28px rgba(255, 43, 214, 0.15),
    inset 0 0 12px rgba(0, 255, 255, 0.06);
  padding: 10px 14px;
  color: #e8ffff;
  text-shadow:
    0 0 6px rgba(0, 255, 255, 0.9),
    0 0 14px rgba(0, 255, 255, 0.55),
    0 0 24px rgba(255, 43, 214, 0.35);
}

.lap-pill {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: clamp(14px, 3.2vw, 22px);
  font-weight: 700;
  color: #ffffff;
}

.score-pill {
  position: absolute;
  top: 62px;
  left: 16px;
  font-size: clamp(12px, 2.6vw, 16px);
  font-weight: 700;
  color: #ffe566;
}

.time-pill {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(12px, 2.5vw, 15px);
  font-weight: 700;
  color: #b8ffff;
  font-variant-numeric: tabular-nums;
}

.best-pill {
  position: absolute;
  top: 102px;
  left: 16px;
  font-size: clamp(10px, 2.2vw, 13px);
  font-weight: 600;
  color: #ff9ad8;
  font-variant-numeric: tabular-nums;
}

.best-score-pill {
  position: absolute;
  top: 134px;
  left: 16px;
  font-size: clamp(10px, 2.2vw, 13px);
  font-weight: 600;
  color: #ffe566;
  font-variant-numeric: tabular-nums;
}

.damage-pill {
  position: absolute;
  top: 62px;
  right: 16px;
  min-width: 132px;
  padding: 8px 12px;
  display: grid;
  gap: 6px;
}

.damage-label {
  font-size: clamp(9px, 2vw, 11px);
  letter-spacing: 0.14em;
  color: #ffb0a0;
}

#damageBar {
  height: 10px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 120, 90, 0.45);
  overflow: hidden;
}

#damageFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #3ecf6a, #ffe566 55%, #ff3b3b);
  box-shadow: 0 0 10px rgba(255, 80, 60, 0.45);
  transition: width 0.08s linear;
}

.speed-pill {
  position: absolute;
  bottom: 18px;
  right: 18px;
  font-size: clamp(14px, 3vw, 20px);
  font-weight: 700;
  color: #00ffff;
}

.music-pill {
  position: absolute;
  bottom: 18px;
  left: 18px;
  pointer-events: auto;
  cursor: pointer;
  font-size: clamp(11px, 2.4vw, 14px);
  font-weight: 700;
  color: #9ef7ff;
  letter-spacing: 0.12em;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.music-pill.is-muted {
  color: #ff8ab8;
  border-color: rgba(255, 43, 214, 0.45);
  text-shadow:
    0 0 6px rgba(255, 43, 214, 0.7),
    0 0 14px rgba(255, 43, 214, 0.35);
}

.music-pill:hover,
.music-pill:focus-visible {
  outline: none;
  border-color: rgba(0, 255, 255, 0.7);
}

.status-pill {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #ffffff;
  background: rgba(20, 20, 30, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 255, 0.25);
  border-radius: 8px;
  box-shadow: 0 0 12px rgba(0, 255, 255, 0.18);
  padding: 5px 10px;
  min-height: 1.2em;
  max-width: min(70vw, 320px);
  text-align: center;
  text-shadow:
    0 0 6px rgba(0, 255, 255, 0.9),
    0 0 14px rgba(255, 43, 214, 0.5);
}

.status-pill:empty {
  display: none;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

#scoreFloats {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 25;
  overflow: hidden;
}

.score-float {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, 0);
  font-family: 'Orbitron', monospace, sans-serif;
  font-weight: 900;
  font-size: clamp(18px, 4vw, 28px);
  color: #ffe566;
  text-shadow: 0 0 12px rgba(255, 43, 214, 0.7);
  animation: score-float-up 1.1s ease-out forwards;
  white-space: nowrap;
}

.score-float.neg { color: #ff6b8a; }

@keyframes score-float-up {
  0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1.15); }
}

#finishPanel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 3, 12, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 20px;
}

#finishPanel.hidden { display: none; }

.finish-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  padding: 28px 24px;
  border-radius: 16px;
  background: rgba(20, 20, 30, 0.85);
  border: 1px solid rgba(0, 255, 255, 0.4);
  box-shadow: 0 0 40px rgba(255, 43, 214, 0.25);
  font-family: 'Orbitron', monospace, sans-serif;
}

.finish-card h2 {
  color: var(--magenta);
  font-size: clamp(22px, 5vw, 32px);
  margin-bottom: 14px;
  text-shadow: 0 0 16px rgba(255, 43, 214, 0.6);
}

#finishStats {
  color: #dfffff;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 20px;
  letter-spacing: 0.04em;
}

.finish-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-finish {
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid rgba(0, 255, 255, 0.4);
  background: rgba(0, 240, 255, 0.08);
  color: #bffbff;
  cursor: pointer;
}

.btn-finish-main {
  background: rgba(255, 43, 214, 0.2);
  border-color: rgba(255, 43, 214, 0.55);
  color: #ffd6f2;
}

.btn-finish:hover {
  background: rgba(0, 255, 255, 0.18);
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(64px, 8vh) 16px 0;
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}

#overlay.hidden { display: none; }

#overlayText {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(16px, 4vw, 28px);
  font-weight: 900;
  color: var(--magenta);
  text-align: center;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(20, 20, 30, 0.72);
  border: 1px solid var(--glass-border);
  box-shadow: 0 0 24px rgba(255, 43, 214, 0.3);
  text-shadow: 0 0 14px rgba(255, 43, 214, 0.55);
  animation: flash 0.45s step-end infinite;
  max-width: min(92vw, 420px);
}

@keyframes flash {
  50% { opacity: 0.45; }
}

#hint {
  position: fixed;
  bottom: 14px;
  left: 18px;
  z-index: 10;
  font-family: 'Orbitron', sans-serif;
  font-size: 9px;
  letter-spacing: 0.06em;
  color: rgba(232, 230, 242, 0.55);
  pointer-events: none;
  max-width: min(42vw, 280px);
  line-height: 1.35;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

#topLinks {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 15;
  display: flex;
  gap: 8px;
  align-items: center;
}

.top-link,
#backHub {
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  color: #00ffff;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(20, 20, 30, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 255, 0.3);
  box-shadow:
    0 0 12px rgba(0, 255, 255, 0.25),
    0 0 28px rgba(255, 43, 214, 0.15);
  text-shadow:
    0 0 6px rgba(0, 255, 255, 0.9),
    0 0 14px rgba(0, 255, 255, 0.45);
  transition: background 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

button.top-link {
  appearance: none;
}

.top-link:hover,
#backHub:hover {
  background: rgba(0, 255, 255, 0.12);
  box-shadow:
    0 0 18px rgba(0, 255, 255, 0.4),
    0 0 32px rgba(255, 43, 214, 0.25);
}

#mobileControls {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 30;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  gap: 16px;
}

.mobile-left {
  display: flex;
  flex-direction: row;
  gap: 12px;
  pointer-events: auto;
  align-items: center;
}

.mobile-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: auto;
  margin-bottom: 8px;
}

.mobile-right {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
  max-width: none;
  flex-wrap: nowrap;
}

.mobile-drive {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.touch-btn {
  width: 62px;
  height: 62px;
  border: 1px solid rgba(0, 255, 255, 0.35);
  border-radius: 14px;
  background: rgba(20, 20, 30, 0.75);
  color: #dfffff;
  font-family: 'Orbitron', monospace, sans-serif;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.7);
  box-shadow: 0 0 12px rgba(0, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active,
.touch-btn.is-active {
  transform: scale(0.96);
  background: rgba(0, 255, 255, 0.18);
  box-shadow: 0 0 16px rgba(0, 255, 255, 0.45);
}

.touch-btn-main {
  width: 72px;
  height: 72px;
  font-size: 28px;
}

.touch-btn-small {
  width: 44px;
  height: 44px;
  font-size: 15px;
}

@media (hover: none), (pointer: coarse), (max-width: 900px) {
  #mobileControls {
    display: flex;
  }

  #hint {
    display: none !important;
  }

  #topLinks {
    top: 10px;
    right: 10px;
  }

  .time-pill {
    top: 12px;
  }

  .damage-pill {
    top: 52px;
    right: 10px;
    min-width: 110px;
  }

  .status-pill {
    top: 48px;
    font-size: 10px;
  }

  .speed-pill {
    bottom: auto;
    right: auto;
    top: 102px;
    left: 16px;
    font-size: clamp(12px, 2.6vw, 15px);
  }
}
