/* ============================================================ */
/* SYNTHWAVE RUNNER - CSS */
/* Runner infini synthwave rétro-futuriste */
/* ============================================================ */

/* ============================================================ */
/* 1. VARIABLES CSS - Synthwave Palette */
/* ============================================================ */

:root {
  /* 2. Couleurs néon */
  --color-primary: #ff3d9d; /* Rose/magenta vif */
  --color-secondary: #37f6ff; /* Cyan brillant */
  --color-accent: #ffd84d; /* Jaune électrique */

  /* 3. Couleurs de fond */
  --color-bg-dark: #1b1452;
  --color-bg-darker: #0d0a2b;

  /* 4. Texte */
  --color-text-light: #ffffff;
  --color-text-dim: #aaaaaa;

  /* 5. Timing */
  --trans-fast: 100ms;
  --trans-normal: 200ms;
  --trans-slow: 400ms;
}

/* ============================================================ */
/* 6. IMPORT POLICE */
/* ============================================================ */
/* ============================================================ */
/* 7. RESET & BASE */
/* ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  /* 8. Fond sombre */
  background: var(--color-bg-darker);
  color: var(--color-text-light);
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 16px;

  /* 9. Anti-aliasing */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* 10. Désactiver selections */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;

  /* 11. Texture scanlines */
  background-image:
    radial-gradient(
      circle at 20% 10%,
      rgba(55, 246, 255, 0.18),
      transparent 34%
    ),
    radial-gradient(
      circle at 80% 90%,
      rgba(255, 61, 157, 0.2),
      transparent 38%
    ),
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.05) 0px,
      rgba(0, 0, 0, 0.05) 1px,
      transparent 1px,
      transparent 2px
    );
}

/* ============================================================ */
/* 12. SYSTÈME DE SCREENS (SPA) */
/* ============================================================ */

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  /* 13. Hidden par défaut */
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans-slow);
}

.screen-active {
  /* 14. Visible */
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================ */
/* 15. ÉCRAN DE MENU */
/* ============================================================ */

#menuScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(
      circle at 50% 78%,
      rgba(255, 113, 72, 0.78) 0 7%,
      rgba(255, 61, 157, 0.35) 8% 20%,
      transparent 42%
    ),
    linear-gradient(150deg, #181059 0%, #4f187c 48%, #14104a 100%);
}

#menuScreen::before {
  content: "";
  position: absolute;
  inset: 55% -20% -45%;
  transform: perspective(360px) rotateX(58deg);
  transform-origin: top;
  background-image:
    linear-gradient(rgba(55, 246, 255, 0.46) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255, 61, 157, 0.52) 2px, transparent 2px);
  background-size: 58px 40px;
  box-shadow: 0 -12px 40px rgba(255, 61, 157, 0.45);
  opacity: 0.9;
}

#menuScreen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.08),
    transparent
  );
  mix-blend-mode: screen;
}

.menu-container {
  position: relative;
  z-index: 1;
  text-align: center;
  width: min(92%, 620px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: clamp(22px, 4vh, 42px) clamp(20px, 5vw, 56px);
  border: 2px solid rgba(55, 246, 255, 0.68);
  border-radius: 22px;
  background: linear-gradient(
    145deg,
    rgba(35, 18, 91, 0.78),
    rgba(91, 18, 115, 0.62)
  );
  box-shadow:
    0 0 0 6px rgba(255, 61, 157, 0.12),
    0 0 45px rgba(55, 246, 255, 0.22),
    inset 0 0 38px rgba(255, 61, 157, 0.15);
  backdrop-filter: blur(10px);
  animation: menuFadeIn 0.8s ease-out;
}

/* 16. Titre du jeu */
.game-title {
  font-size: clamp(34px, 6vw, 64px);
  color: #fff4fb;
  text-shadow:
    0 0 10px var(--color-primary),
    0 0 20px var(--color-primary),
    0 0 30px rgba(255, 0, 110, 0.6);
  margin-bottom: 18px;
  letter-spacing: 3px;
  animation: titlePulse 2s ease-in-out infinite;
  line-height: 1.2;
}

.game-subtitle {
  font-size: clamp(13px, 2vw, 18px);
  color: #bcfbff;
  text-shadow: 0 0 12px var(--color-secondary);
  margin-bottom: 18px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

/* ============================================================ */
/* 17. BOUTONS */
/* ============================================================ */

.btn {
  padding: 14px 22px;
  border: 2px solid currentColor;
  background: linear-gradient(
    135deg,
    rgba(255, 61, 157, 0.28),
    rgba(55, 246, 255, 0.18)
  );
  color: #ffffff;
  font-family: "Press Start 2P", monospace;
  font-size: 12px;
  cursor: pointer;
  border-radius: 10px;
  text-shadow: 0 0 9px currentColor;
  transition: all var(--trans-normal);

  appearance: none;
  -webkit-appearance: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  color: #101039;
  background: var(--color-secondary);
  box-shadow: 0 0 28px var(--color-secondary);
  transform: scale(1.05);
}

.btn:active {
  transform: scale(0.95);
}

/* 18. Variant Start */
.btn-start {
  margin: 16px 0 20px;
  padding: 18px 40px;
  font-size: 16px;
  color: #ffffff;
  border-color: #ff86c3;
  background: linear-gradient(135deg, #e91882, #7c31d8);
  text-shadow: 0 0 10px var(--color-primary);
  animation: startBtnPulse 1s ease-in-out infinite;
}

/* 19. Variant Restart & Menu */
.btn-restart,
.btn-menu {
  margin: 8px;
  min-width: 150px;
}

/* ============================================================ */
/* 20. HIGH SCORE DISPLAY */
/* ============================================================ */

.high-score-display {
  margin: 10px 0 18px;
  padding: 17px;
  border: 2px solid var(--color-secondary);
  background: rgba(17, 15, 61, 0.7);
  border-radius: 12px;
  box-shadow:
    inset 0 0 24px rgba(55, 246, 255, 0.1),
    0 0 18px rgba(55, 246, 255, 0.2);
}

.hs-label {
  font-size: 12px;
  color: var(--color-secondary);
  text-shadow: 0 0 10px var(--color-secondary);
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.hs-value {
  font-size: 25px;
  color: var(--color-accent);
  text-shadow: 0 0 10px var(--color-accent);
  font-family: "Courier New", monospace;
  font-weight: bold;
}

.settings-card {
  margin: 0 0 14px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  background: rgba(13, 10, 43, 0.48);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  cursor: pointer;
}

.setting-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.setting-title {
  color: #ffffff;
  font-size: clamp(11px, 1.6vw, 14px);
  letter-spacing: 1px;
}

.setting-status {
  color: var(--color-secondary);
  font-family: "Courier New", monospace;
  font-size: 13px;
  font-weight: 700;
  text-shadow: 0 0 8px var(--color-secondary);
}

.setting-checkbox {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.setting-switch {
  position: relative;
  flex: 0 0 62px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  background: rgba(9, 8, 40, 0.9);
  transition: 180ms ease;
}

.setting-switch span {
  position: absolute;
  top: 4px;
  left: 5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #b8afcb;
  transition: 180ms ease;
}

.setting-checkbox:checked + .setting-switch {
  border-color: var(--color-secondary);
  background: rgba(55, 246, 255, 0.22);
  box-shadow: 0 0 16px rgba(55, 246, 255, 0.42);
}

.setting-checkbox:checked + .setting-switch span {
  left: 33px;
  background: var(--color-secondary);
  box-shadow: 0 0 10px var(--color-secondary);
}

.setting-checkbox:focus-visible + .setting-switch {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

/* ============================================================ */
/* 21. INSTRUCTIONS */
/* ============================================================ */

.instructions {
  margin-top: 8px;
  padding: 16px 12px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.35);
}

.instruction-text {
  font-size: clamp(10px, 1.6vw, 13px);
  color: #f7edff;
  line-height: 1.55;
  margin: 7px 0;
  text-shadow: 0 2px 8px rgba(12, 8, 43, 0.9);
}

/* ============================================================ */
/* 22. ÉCRAN DE JEU */
/* ============================================================ */

#gameScreen {
  top: 64px;
  height: calc(100% - 64px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background:
    radial-gradient(
      circle at 50% 0%,
      rgba(55, 246, 255, 0.22),
      transparent 42%
    ),
    linear-gradient(145deg, #15104b, #4a146d 52%, #15104b);
  padding: 12px;
  gap: 12px;
}

/* ============================================================ */
/* 23. HUD IN-GAME */
/* ============================================================ */

.game-hud {
  width: min(100%, 960px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  background: linear-gradient(
    90deg,
    rgba(255, 61, 157, 0.3),
    rgba(24, 18, 79, 0.8),
    rgba(55, 246, 255, 0.25)
  );
  border: 2px solid rgba(55, 246, 255, 0.75);
  border-radius: 12px;
  box-shadow:
    0 0 24px rgba(55, 246, 255, 0.28),
    inset 0 0 24px rgba(255, 61, 157, 0.12);
  font-size: clamp(14px, 2vw, 19px);
  color: #ffffff;
  text-shadow: 0 0 10px var(--color-secondary);
  letter-spacing: 2px;
  font-family: "Press Start 2P", "Courier New", monospace;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
}

.hud-score,
.hud-level {
  flex: 1;
}

.hud-score {
  text-align: left;
}

.hud-level {
  text-align: right;
}

.btn-pause {
  flex: 0 0 auto;
  margin-left: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 14px;
  border-color: rgba(255, 255, 255, 0.7);
  font-size: clamp(9px, 1.2vw, 12px);
}

/* ============================================================ */
/* 24. CANVAS - Zone de jeu */
/* ============================================================ */

#gameCanvas {
  /* 25. Responsive : 800x400 virtuel, scaling sans déformation */
  width: min(100%, 960px, calc((100dvh - 175px) * 2));
  height: auto;
  max-width: 960px;
  max-height: calc(100dvh - 175px);

  aspect-ratio: 2 / 1;
  object-fit: contain;
  background: linear-gradient(180deg, #1a0a3a 0%, #0a0e27 100%);

  image-rendering: pixelated;
  image-rendering: crisp-edges;

  flex: 0 1 auto;
  align-self: center;
  border: 2px solid rgba(255, 118, 192, 0.7);
  border-radius: 16px;
  box-shadow:
    0 0 30px rgba(255, 61, 157, 0.32),
    0 0 65px rgba(55, 246, 255, 0.16);
}

.pause-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(9, 7, 36, 0.72);
  backdrop-filter: blur(8px);
}

.pause-overlay[hidden] {
  display: none;
}

.pause-panel {
  width: min(92%, 520px);
  padding: clamp(26px, 5vw, 44px);
  text-align: center;
  border: 2px solid var(--color-secondary);
  border-radius: 20px;
  background: linear-gradient(
    145deg,
    rgba(43, 22, 104, 0.97),
    rgba(102, 22, 117, 0.95)
  );
  box-shadow:
    0 0 46px rgba(55, 246, 255, 0.3),
    inset 0 0 36px rgba(255, 61, 157, 0.18);
}

.pause-kicker {
  margin-bottom: 12px;
  color: var(--color-secondary);
  font-size: 11px;
  letter-spacing: 2px;
}

.pause-title {
  margin-bottom: 18px;
  color: #ffffff;
  font-size: clamp(38px, 8vw, 64px);
  text-shadow:
    0 0 14px var(--color-primary),
    0 0 30px var(--color-primary);
}

.pause-copy {
  margin: 0 auto 24px;
  color: #f7edff;
  font-family: "Courier New", monospace;
  font-size: 17px;
  line-height: 1.45;
}

.btn-resume,
.btn-quit {
  display: block;
  width: 100%;
  margin-top: 12px;
}

.btn-resume {
  border-color: var(--color-secondary);
  background: rgba(55, 246, 255, 0.2);
}

.btn-quit {
  border-color: #ff92c9;
}

.pause-warning {
  margin-top: 18px;
  color: #ffe58a;
  font-family: "Courier New", monospace;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

/* ============================================================ */
/* 26. ÉCRAN GAME OVER */
/* ============================================================ */

#gameOverScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    135deg,
    #ff006e 0%,
    var(--color-bg-darker) 50%,
    #ff006e 100%
  );
}

.game-over-container {
  text-align: center;
  width: min(90%, 560px);
  padding: 36px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 20px;
  background: rgba(34, 12, 72, 0.78);
  box-shadow: 0 0 45px rgba(255, 61, 157, 0.42);
  backdrop-filter: blur(10px);
  animation: gameOverSlideIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 27. Titre Game Over */
.game-over-title {
  font-size: clamp(34px, 6vw, 54px);
  color: var(--color-accent);
  text-shadow:
    0 0 20px var(--color-accent),
    0 0 40px rgba(255, 190, 11, 0.5);
  margin-bottom: 12px;
  letter-spacing: 2px;
}

.game-over-subtitle {
  font-size: 14px;
  color: var(--color-secondary);
  margin-bottom: 24px;
  animation: warningBlink 0.5s infinite;
}

/* 28. Stats */
.game-over-stats {
  margin: 24px 0;
}

.stat-line {
  font-size: 17px;
  line-height: 1.5;
  color: var(--color-text-light);
  margin: 6px 0;
  font-family: "Courier New", monospace;
}

/* 29. New Record Banner */
.new-record-banner {
  padding: 16px;
  background: rgba(0, 255, 0, 0.1);
  border: 2px solid #00ff00;
  border-radius: 4px;
  margin: 24px 0;
}

.new-record-text {
  font-size: 12px;
  color: #00ff00;
  text-shadow: 0 0 15px #00ff00;
  animation: recordPulse 0.6s ease-in-out infinite;
}

/* 30. Boutons Game Over */
.game-over-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

.game-over-buttons .btn {
  min-width: 180px;
  margin: 0 auto;
}

/* ============================================================ */
/* 31. ANIMATIONS */
/* ============================================================ */

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes titlePulse {
  0%,
  100% {
    text-shadow:
      0 0 10px var(--color-primary),
      0 0 20px var(--color-primary),
      0 0 30px rgba(255, 0, 110, 0.6);
    transform: scale(1);
  }
  50% {
    text-shadow:
      0 0 20px var(--color-primary),
      0 0 40px var(--color-primary),
      0 0 60px rgba(255, 0, 110, 0.8);
    transform: scale(1.05);
  }
}

@keyframes startBtnPulse {
  0%,
  100% {
    box-shadow: 0 0 10px var(--color-primary);
  }
  50% {
    box-shadow:
      0 0 30px var(--color-primary),
      0 0 50px rgba(255, 0, 110, 0.6);
  }
}

@keyframes gameOverSlideIn {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(-50px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes warningBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

@keyframes recordPulse {
  0%,
  100% {
    transform: scale(1);
    text-shadow: 0 0 10px #00ff00;
  }
  50% {
    transform: scale(1.05);
    text-shadow: 0 0 20px #00ff00;
  }
}

/* ============================================================ */
/* 32. RESPONSIVE */
/* ============================================================ */

@media (max-width: 360px) {
  .menu-container {
    width: 96%;
    padding: 20px 12px;
  }

  .game-title {
    font-size: 29px;
  }

  .game-over-title {
    font-size: 24px;
  }

  .btn-start {
    font-size: 12px;
    padding: 14px 24px;
  }
}

@media (min-width: 361px) {
  body {
    font-size: 16px;
  }
}

@media (min-width: 769px), (orientation: landscape) {
  .game-title {
    font-size: clamp(42px, 5.2vw, 64px);
  }

  #gameCanvas {
    max-width: 100%;
    max-height: calc(100dvh - 92px);
  }
}

/* ============================================================ */
/* 33. SAFE AREA (iPhone avec encoche) */
/* ============================================================ */

@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}
