/* =========================================================================
   NEON SNAKE — feuille de style arcade / rétro néon
   Palette sombre + accents néon, police Orbitron, HUD lisible.
   Cohérent avec le portail arcade (fond sombre, glow cyan/magenta).
   ========================================================================= */

:root {
  /* Palette néon */
  --bg:        #05060f;
  --bg-2:      #0a0d1f;
  --panel:     rgba(14, 18, 40, 0.72);
  --panel-brd: rgba(0, 240, 255, 0.28);
  --grid:      rgba(120, 160, 255, 0.06);

  --neon-cyan:    #00f0ff;
  --neon-magenta: #ff2fd0;
  --neon-green:   #39ff14;
  --neon-yellow:  #ffe600;
  --neon-orange:  #ff8a00;
  --neon-purple:  #b14bff;

  --text:      #eaf6ff;
  --text-dim:  #8fa6c8;
  --danger:    #ff5470;

  --font: 'Orbitron', 'Segoe UI', system-ui, sans-serif;

  --radius: 14px;
  --glow-cyan: 0 0 8px rgba(0,240,255,.6), 0 0 22px rgba(0,240,255,.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 50% -10%, #131a3a 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 110%, #1a0f2e 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Scanlines discrètes façon écran CRT */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.16) 3px,
    rgba(0,0,0,0) 4px
  );
  mix-blend-mode: multiply;
  opacity: .5;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}

/* ---------- Barre de titre ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.logo {
  font-weight: 900;
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  letter-spacing: .12em;
  margin: 0;
  color: var(--neon-cyan);
  text-shadow: var(--glow-cyan);
}
.logo span {
  color: var(--neon-magenta);
  text-shadow: 0 0 8px rgba(255,47,208,.6), 0 0 22px rgba(255,47,208,.4);
}

.portal-link {
  font-size: .8rem;
  letter-spacing: .1em;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--panel-brd);
  border-radius: 999px;
  padding: 6px 12px;
  transition: color .2s, border-color .2s, box-shadow .2s;
  white-space: nowrap;
}
.portal-link:hover, .portal-link:focus-visible {
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan);
}

/* ---------- Écrans (start / game / over) ---------- */
.screen { display: none; }
.screen.active { display: block; animation: fade-in .28s ease; }

@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-title {
  text-align: center;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  font-weight: 900;
  letter-spacing: .14em;
  margin: 8px 0 4px;
  color: var(--neon-cyan);
  text-shadow: var(--glow-cyan);
}
#over-title { color: var(--danger); text-shadow: 0 0 10px rgba(255,84,112,.7), 0 0 26px rgba(255,84,112,.4); }

.screen-sub {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 18px;
  font-size: .95rem;
}

/* ---------- Formulaire pseudo ---------- */
#pseudo-form {
  display: flex;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto 6px;
}
#pseudo-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 1.05rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius);
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#pseudo-input::placeholder { color: rgba(143,166,200,.5); letter-spacing: .12em; }
#pseudo-input:focus {
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan);
}

.form-error {
  text-align: center;
  color: var(--danger);
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: .85rem;
}

/* ---------- Boutons ---------- */
.btn {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: .1em;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 12px 22px;
  border: 1px solid transparent;
  transition: transform .1s, box-shadow .2s, background .2s, color .2s, border-color .2s;
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }

.btn-primary {
  display: block;
  margin: 18px auto 0;
  color: #04121a;
  background: linear-gradient(180deg, var(--neon-cyan), #06b6c9);
  box-shadow: var(--glow-cyan);
}
.btn-primary:hover, .btn-primary:focus-visible {
  box-shadow: 0 0 14px rgba(0,240,255,.9), 0 0 34px rgba(0,240,255,.5);
}

.btn-ghost {
  color: var(--text);
  background: var(--panel);
  border-color: var(--panel-brd);
}
.btn-ghost:hover, .btn-ghost:focus-visible {
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: var(--glow-cyan);
}

/* ---------- HUD ---------- */
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.hud-item {
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  min-width: 0;
}
.hud-label {
  display: block;
  font-size: .58rem;
  letter-spacing: .16em;
  color: var(--text-dim);
}
.hud-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px rgba(0,240,255,.5);
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-best .hud-value { color: var(--neon-yellow); text-shadow: 0 0 6px rgba(255,230,0,.5); }

/* ---------- Canvas ---------- */
.canvas-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  border: 1px solid var(--panel-brd);
  overflow: hidden;
  background: #04050d;
  box-shadow: 0 0 0 1px rgba(0,240,255,.06), 0 12px 40px rgba(0,0,0,.6),
              inset 0 0 60px rgba(0,240,255,.05);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* évite le scroll pendant les swipes */
}

/* Overlay (pause) */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 15, .72);
  backdrop-filter: blur(2px);
  z-index: 3;
}
.overlay[hidden] { display: none; }
.overlay-inner { text-align: center; }
.overlay-title {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: .2em;
  color: var(--neon-yellow);
  text-shadow: 0 0 10px rgba(255,230,0,.6);
  margin: 0;
}
.overlay-sub { color: var(--text-dim); margin: 6px 0 0; font-size: .85rem; }

/* Compte à rebours de lancement */
.countdown-number {
  margin: 0;
  font-size: clamp(4rem, 22vw, 8rem);
  font-weight: 900;
  line-height: 1;
  color: var(--neon-cyan);
  text-shadow: 0 0 14px rgba(0,240,255,.7), 0 0 40px rgba(0,240,255,.45);
}
/* Petite animation « pop » à chaque changement de chiffre */
.countdown-number.tick { animation: countdown-pop .5s ease-out; }
@keyframes countdown-pop {
  0%   { transform: scale(1.6); opacity: 0; }
  40%  { transform: scale(1);   opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}
/* Le « GO! » final passe en vert néon */
.countdown-number.go {
  color: var(--neon-green);
  text-shadow: 0 0 14px rgba(57,255,20,.7), 0 0 40px rgba(57,255,20,.45);
}
@media (prefers-reduced-motion: reduce) {
  .countdown-number.tick { animation: none; }
}

/* ---------- Barre de power-up ---------- */
.powerup-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--neon-purple);
  border-radius: 12px;
  box-shadow: 0 0 12px rgba(177,75,255,.35);
}
.powerup-bar[hidden] { display: none; }
.pu-icon { font-size: 1.2rem; }
.pu-name {
  font-size: .72rem;
  letter-spacing: .12em;
  color: var(--text);
  white-space: nowrap;
}
.pu-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.pu-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--neon-purple), var(--neon-magenta));
  transform-origin: left;
  transition: width .1s linear;
}

.game-controls {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

/* ---------- Classement ---------- */
.mini-board {
  max-width: 480px;
  margin: 22px auto 0;
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.mini-board h3 {
  margin: 0 0 10px;
  font-size: .8rem;
  letter-spacing: .16em;
  color: var(--text-dim);
  text-align: center;
}
.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rank;
}
.lb-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px dashed rgba(120,160,255,.12);
  font-size: .92rem;
}
.lb-list li:last-child { border-bottom: none; }
.lb-list li.lb-row::before {
  counter-increment: rank;
  content: counter(rank);
  flex: 0 0 1.6em;
  text-align: right;
  color: var(--text-dim);
  font-weight: 700;
}
.lb-list li.lb-row:nth-child(1)::before { color: var(--neon-yellow); }
.lb-list li.lb-row:nth-child(2)::before { color: #cfe3ff; }
.lb-list li.lb-row:nth-child(3)::before { color: var(--neon-orange); }
.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.lb-score {
  font-weight: 900;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px rgba(0,240,255,.4);
}
.lb-date { color: var(--text-dim); font-size: .72rem; flex: 0 0 auto; }
.lb-empty, .lb-error { color: var(--text-dim); text-align: center; justify-content: center; }
.lb-error { color: var(--danger); }
.lb-list li.lb-me { background: rgba(0,240,255,.08); border-radius: 8px; }

/* ---------- Game over ---------- */
.final { text-align: center; margin-bottom: 6px; }
.final-score { display: inline-flex; flex-direction: column; gap: 2px; }
.final-label { font-size: .7rem; letter-spacing: .18em; color: var(--text-dim); }
.final-value {
  font-size: 3rem;
  font-weight: 900;
  color: var(--neon-cyan);
  text-shadow: var(--glow-cyan);
  line-height: 1;
}
.rank-line { margin: 12px 0 2px; font-size: 1rem; color: var(--neon-yellow); }
.save-state { margin: 0; font-size: .8rem; color: var(--text-dim); min-height: 1em; }

/* ---------- Aide ---------- */
.help {
  max-width: 480px;
  margin: 20px auto 0;
  color: var(--text-dim);
  font-size: .85rem;
}
.help summary {
  cursor: pointer;
  text-align: center;
  letter-spacing: .08em;
  color: var(--neon-cyan);
}
.help ul { margin: 10px 0 0; padding-left: 20px; line-height: 1.7; }
.help kbd {
  background: var(--bg-2);
  border: 1px solid var(--panel-brd);
  border-radius: 6px;
  padding: 1px 7px;
  font-family: var(--font);
  font-size: .8em;
  color: var(--neon-cyan);
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: rgba(143,166,200,.5);
  font-size: .7rem;
  letter-spacing: .18em;
  padding: 18px 0 24px;
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .hud-value { font-size: 1rem; }
  .hud-label { font-size: .5rem; }
  #pseudo-form { flex-direction: column; }
  .btn-primary { width: 100%; }
}

/* ---------- Accessibilité : mouvement réduit ---------- */
@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
  .scanlines { display: none; }
  * { transition-duration: .01ms !important; }
}
