/* ==========================================================================
   RUN & CLICK — synthwave runner
   Layout portrait, une main, zone du pouce en bas.
   ========================================================================== */

:root {
  --violet:   #7b2cff;
  --violet-d: #2a0a4a;
  --rose:     #ff2fb9;
  --cyan:     #21e6ff;
  --jaune:    #ffd166;
  --bg:       #150029;
  --ink:      #f4e9ff;

  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ==========================================================================
   HUD
   ========================================================================== */

/* bouton son : toujours visible, au-dessus des écrans */
.sound-btn {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 12px;
  width: 38px; height: 38px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 50%;
  background: rgba(42, 10, 74, .82);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 20;
  transition: transform .1s, opacity .15s;
}
.sound-btn:active { transform: scale(.9); }
.sound-btn.muted  { opacity: .5; }

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 0 60px;
  pointer-events: none;
  z-index: 5;
}

.hud-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hud-row--sub { margin-top: 8px; }

.hearts {
  display: flex;
  gap: 5px;
  font-size: 24px;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(255, 47, 185, .9));
}
.hearts span { transition: transform .18s, opacity .18s; }
.hearts span.dead { opacity: .22; filter: grayscale(1); transform: scale(.8); }

.score-box {
  text-align: right;
  line-height: 1;
}
.score-box #score {
  display: block;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 10px var(--cyan), 0 0 22px rgba(33, 230, 255, .6);
  font-variant-numeric: tabular-nums;
}
.score-box small {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--rose);
  text-shadow: 0 0 8px rgba(255, 47, 185, .8);
}

.next-level {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.next-level i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--rose), var(--cyan));
  box-shadow: 0 0 10px var(--rose);
  transition: width .15s linear;
}

.boost {
  margin: 10px auto 0;
  width: max-content;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(90deg, #ff6a00, #ff2fb9);
  box-shadow: 0 0 18px rgba(255, 106, 0, .8);
  animation: pulse .6s ease-in-out infinite alternate;
}
.boost b { font-variant-numeric: tabular-nums; }

@keyframes pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.06); }
}

/* ==========================================================================
   Bannière « niveau supérieur »
   ========================================================================== */

.banner {
  position: absolute;
  top: 30%;
  left: 0; right: 0;
  padding: 0 16px;
  text-align: center;
  font-size: clamp(20px, 7.5vw, 42px);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 3px;
  color: #fff;
  text-shadow: 0 0 12px var(--rose), 0 0 34px var(--violet);
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}
.banner small {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: 6px;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
}
.banner.show { animation: banner 1.5s ease-out; }

@keyframes banner {
  0%   { opacity: 0; transform: scale(.6) translateY(20px); }
  18%  { opacity: 1; transform: scale(1.08) translateY(0); }
  30%  { transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.1); }
}

/* ==========================================================================
   Contrôles tactiles
   ========================================================================== */

#controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(14px + var(--safe-b));
  display: flex;
  gap: 10px;
  padding: 0 12px;
  z-index: 7;
}

.pad {
  position: relative;
  flex: 1;
  height: 84px;
  border: 2px solid rgba(255, 255, 255, .28);
  border-radius: 18px;
  /* Fond OPAQUE, pas de `backdrop-filter`. Un flou d'arrière-plan posé sur un
     canvas qui s'anime oblige le navigateur à re-flouter la zone à CHAQUE
     image — sur mobile, ces trois boutons coûtaient plus cher que le jeu
     lui-même. Une teinte dense donne la même lisibilité pour rien. */
  background: rgba(38, 9, 68, .86);
  color: var(--ink);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  touch-action: none;
  transition: transform .06s, background .12s, box-shadow .12s;
  overflow: hidden;
}
.pad-ico { font-size: 22px; line-height: 1; }
.pad-lbl { font-size: 10px; letter-spacing: 2px; font-weight: 700; opacity: .85; }

.pad--jump     { flex: 1.5; border-color: var(--cyan);   box-shadow: 0 0 16px rgba(33, 230, 255, .35) inset, 0 0 12px rgba(33, 230, 255, .25); color: #d9fbff; }
.pad--duck     { border-color: var(--violet); box-shadow: 0 0 16px rgba(123, 44, 255, .35) inset; }
.pad--shoulder { border-color: var(--rose);   box-shadow: 0 0 16px rgba(255, 47, 185, .35) inset; }

.pad.active {
  transform: scale(.95);
  background: rgba(255, 255, 255, .16);
}
.pad--jump.active     { box-shadow: 0 0 26px var(--cyan); }
.pad--duck.active     { box-shadow: 0 0 26px var(--violet); }
.pad--shoulder.active { box-shadow: 0 0 26px var(--rose); }

/* jauge de cooldown de l'épaule */
.pad-cd {
  position: absolute;
  left: 0; bottom: 0;
  height: 4px;
  width: 0%;
  background: var(--rose);
  box-shadow: 0 0 8px var(--rose);
}
.pad.cooling { opacity: .55; }

/* ==========================================================================
   Écrans (menu / game over)
   ========================================================================== */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + var(--safe-b));
  text-align: center;
  /* Fond OPAQUE : en translucide, le décor animé du canvas transparaissait
     derrière le texte et donnait une impression de bug d'affichage. */
  background: #0b0016 radial-gradient(ellipse at 50% 35%, #34106b, #0b0016 72%);
  overflow-y: auto;
}

/* --- écran de chargement --- */

.loader { z-index: 30; gap: 14px; }

.load-bar {
  width: min(280px, 70vw);
  height: 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.load-bar i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--rose), var(--cyan));
  box-shadow: 0 0 10px var(--rose);
  transition: width .2s linear;
}
.load-pct {
  font-size: 11px;
  letter-spacing: 3px;
  color: rgba(244, 233, 255, .6);
  font-variant-numeric: tabular-nums;
}

/* Le tutoriel et les scores se posent PAR-DESSUS le menu et le game over.
   À z-index égal c'est l'ordre du DOM qui tranche, or #scores est déclaré
   avant #gameover : le tableau s'ouvrait donc *derrière* lui, complètement
   masqué depuis que les écrans sont opaques. */
#tutorial,
#scores {
  z-index: 12;
}

.title {
  font-size: clamp(30px, 11vw, 56px);
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1.05;
  color: #fff;
  text-shadow: 0 0 14px var(--rose), 0 0 40px var(--violet);
}
.title span:first-child { color: var(--cyan); text-shadow: 0 0 14px var(--cyan), 0 0 40px rgba(33, 230, 255, .5); }
.title span:last-child  { color: var(--rose); text-shadow: 0 0 14px var(--rose), 0 0 40px rgba(255, 47, 185, .5); }

.tagline {
  margin-top: -10px;
  font-size: clamp(11px, 3.4vw, 15px);
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--jaune);
  text-shadow: 0 0 12px rgba(255, 209, 102, .8);
}

.subtitle {
  font-size: 12px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: rgba(244, 233, 255, .7);
}

/* --- sélection de perso --- */

.char-list {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  justify-content: center;
}

.char {
  flex: 1;
  min-width: 0;
  padding: 10px 6px 12px;
  border: 2px solid rgba(255, 255, 255, .2);
  border-radius: 16px;
  background: #2a0a4a;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.char canvas {
  display: block;
  width: 100%;
  height: 82px;
  image-rendering: pixelated;
}
.char-name {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char.selected {
  border-color: var(--cyan);
  box-shadow: 0 0 20px rgba(33, 230, 255, .5);
  transform: translateY(-3px);
}

/* --- boutons --- */

.neon-btn {
  margin-top: 4px;
  padding: 15px 44px;
  border: 2px solid var(--rose);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 47, 185, .28), rgba(123, 44, 255, .28));
  color: #fff;
  font-family: inherit;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 4px;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(255, 47, 185, .55);
  transition: transform .1s, box-shadow .15s;
}
.neon-btn:active { transform: scale(.96); box-shadow: 0 0 34px rgba(255, 47, 185, .9); }

.ghost-btn {
  padding: 10px 22px;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  background: transparent;
  color: rgba(244, 233, 255, .75);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 2px;
  cursor: pointer;
}
.ghost-btn:active { background: rgba(255, 255, 255, .1); }

.menu-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, .26);
  border-radius: 999px;
  background: #2a0a4a;
  color: rgba(244, 233, 255, .85);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  transition: transform .1s, border-color .12s;
}
.icon-btn span { font-size: 14px; }
.icon-btn:active { transform: scale(.95); border-color: var(--cyan); }

/* --- tutoriel --- */

.scr-title {
  font-size: clamp(22px, 7vw, 34px);
  font-weight: 900;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 12px var(--cyan), 0 0 34px var(--violet);
}

.tuto-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.tuto-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-left-width: 3px;
  border-radius: 12px;
  background: #241043;
  text-align: left;
}
.tuto-row canvas {
  flex: 0 0 68px;
  width: 68px;
  height: 46px;
}
.tuto-txt { flex: 1; min-width: 0; }
.tuto-name {
  display: block;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
}
.tuto-desc {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.4;
  color: rgba(244, 233, 255, .6);
}
.tuto-act {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  text-align: center;
}

.tuto-note {
  max-width: 420px;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(244, 233, 255, .68);
}
.tuto-note b { color: var(--cyan); }

/* --- tableau des scores --- */

.score-list {
  width: 100%;
  max-width: 400px;
  list-style: none;
  counter-reset: rank;
}
.score-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  font-size: 14px;
  counter-increment: rank;
}
.score-list li::before {
  content: counter(rank);
  flex: 0 0 24px;
  font-size: 12px;
  font-weight: 800;
  color: var(--rose);
  text-align: right;
}
.score-list li:nth-child(1)::before { color: var(--jaune); }
.score-list .sc-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: 1px;
}
.score-list .sc-lvl { font-size: 10px; color: rgba(244, 233, 255, .45); }
.score-list .sc-pts {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--cyan);
}
.score-list li.me { background: rgba(255, 47, 185, .16); border-radius: 8px; }
.score-src {
  max-width: 400px;
  font-size: 10px;
  line-height: 1.5;
  letter-spacing: 1px;
  color: rgba(244, 233, 255, .45);
}
.score-src.offline { color: var(--jaune); }

.score-empty {
  font-size: 12px;
  color: rgba(244, 233, 255, .5);
  list-style: none;
}
.score-empty::before { content: none !important; }

/* --- saisie du pseudo --- */

.save-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.save-form label {
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(244, 233, 255, .6);
}
.save-row { display: flex; gap: 8px; }
.save-row input {
  /* le body coupe sélection et gestes tactiles : il faut les rendre au champ */
  user-select: text;
  -webkit-user-select: text;
  touch-action: manipulation;
  width: 150px;
  padding: 10px 12px;
  border: 2px solid rgba(33, 230, 255, .5);
  border-radius: 10px;
  background: #0b0016;
  color: #fff;
  font-family: inherit;
  font-size: 16px;          /* < 16px ferait zoomer iOS au focus */
  font-weight: 700;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
}
.save-row input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(33, 230, 255, .5);
}
.save-btn {
  padding: 10px 18px;
  border: 2px solid var(--cyan);
  border-radius: 10px;
  background: rgba(33, 230, 255, .18);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 2px;
  cursor: pointer;
}
.save-btn:active { transform: scale(.95); }
.save-btn:disabled { opacity: .4; }
.save-msg {
  min-height: 14px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--jaune);
}

/* --- aide --- */

.help {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.9;
  color: rgba(244, 233, 255, .62);
}
.help b { color: var(--cyan); letter-spacing: 1px; }
.help-kb { margin-top: 6px; opacity: .55; font-size: 10px; }

/* --- game over --- */

.go-title {
  font-size: clamp(28px, 10vw, 48px);
  font-weight: 900;
  letter-spacing: 6px;
  color: #fff;
  text-shadow: 0 0 14px var(--rose), 0 0 40px #ff0055;
}
.go-score { line-height: 1.1; }
.go-score small { font-size: 11px; letter-spacing: 4px; color: rgba(244, 233, 255, .6); }
.go-score strong {
  display: block;
  font-size: clamp(44px, 16vw, 76px);
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 16px var(--cyan), 0 0 44px rgba(33, 230, 255, .5);
  font-variant-numeric: tabular-nums;
}
.go-score .best {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--jaune);
}
.go-stats {
  display: flex;
  gap: 18px;
  font-size: 12px;
  letter-spacing: 1px;
  color: rgba(244, 233, 255, .7);
}
.go-stats b { color: #fff; }

/* --- paysage / grand écran : on garde une colonne portrait centrée --- */

@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  #app {
    width: min(56vh, 100vw);
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 80px rgba(123, 44, 255, .35);
  }
}
