/* ===================== RESET & BASE ===================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #05060a;
  --bg2: #0b1020;
  --accent: #ffe81f;       /* jaune Star Wars */
  --accent2: #4fd6ff;       /* bleu laser */
  --danger: #ff3b3b;
  --green: #57ff7a;
  --text: #e8ecff;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  overflow: hidden;
  -webkit-font-smoothing: none;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ===================== ÉCRANS ===================== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* ===================== STARFIELD ===================== */
.starfield {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(1px 1px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 70% 60%, #fff, transparent),
    radial-gradient(2px 2px at 40% 80%, #cfe3ff, transparent),
    radial-gradient(1px 1px at 85% 20%, #fff, transparent),
    radial-gradient(1px 1px at 55% 45%, #fff, transparent),
    radial-gradient(2px 2px at 10% 70%, #aab8ff, transparent),
    radial-gradient(1px 1px at 90% 90%, #fff, transparent),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  background-size: 100% 100%;
  animation: drift 60s linear infinite;
}
@keyframes drift {
  from { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: -200px 0, -150px 0, -300px 0, -100px 0, -250px 0, -180px 0, -220px 0, 0 0; }
}

/* ===================== ACCUEIL FULL SCREEN ===================== */
#screen-home { padding: 0; justify-content: center; }
.hero-full {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;   /* image entière, jamais rognée ni étirée */
  z-index: 0;
}
.hero-fallback-full { position: absolute; inset: 0; z-index: 0; }
.home-overlay {
  position: relative;
  z-index: 2;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0 20px;
}
.home-overlay .btn { font-size: 13px; padding: 18px 26px; }

/* ===================== (ancien layout accueil, conservé) ===================== */
.home-inner {
  position: relative;
  z-index: 2;
  text-align: center;
  max-width: 760px;
  width: 100%;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.hero-frame {
  width: min(70vw, 280px);
  aspect-ratio: 1 / 1;
  border: 4px solid var(--accent);
  box-shadow: 0 0 0 4px #000, 0 0 32px rgba(255,232,31,.35);
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hero-frame img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }

/* Fallback hero (casque mando dessiné en CSS) */
.hero-fallback { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, #1a2540, #05060a); }
.hero-helmet {
  width: 52%; height: 64%;
  background: linear-gradient(180deg, #d8dde6 0%, #aab0bd 60%, #7c8392 100%);
  border-radius: 48% 48% 42% 42% / 56% 56% 44% 44%;
  position: relative;
  box-shadow: inset 0 -10px 14px rgba(0,0,0,.4), 0 0 18px rgba(255,255,255,.15);
}
.hero-helmet .visor {
  position: absolute; left: 50%; top: 42%; transform: translateX(-50%);
  width: 26%; height: 34%;
  background: linear-gradient(180deg, #2b3550, #0a0f1d);
  border-radius: 40% 40% 50% 50%;
}

.title { display: flex; flex-direction: column; gap: 10px; line-height: 1.5; }
.title-small { font-size: 8px; color: var(--accent2); opacity: .85; }
.title-main { font-size: clamp(18px, 6vw, 40px); color: var(--accent); text-shadow: 0 0 12px rgba(255,232,31,.5); letter-spacing: 1px; }
.title-sub { font-size: 10px; color: var(--text); opacity: .8; }

.home-text { font-size: 9px; line-height: 1.9; color: var(--text); opacity: .92; }
.accent { color: var(--accent); }

.controls-hint { font-size: 7px; opacity: .6; margin-top: 4px; line-height: 1.8; }

/* ===================== BOUTONS ===================== */
.btn {
  font-family: inherit;
  font-size: 11px;
  padding: 16px 22px;
  border: 3px solid var(--accent);
  background: #11152a;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  box-shadow: 0 4px 0 #000, 0 0 16px rgba(255,232,31,.25);
  transition: transform .05s, box-shadow .05s, background .15s;
  line-height: 1.6;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 #000, 0 0 16px rgba(255,232,31,.25); }
.btn-primary:hover { background: #1a2040; }
.btn-victory { border-color: var(--green); color: var(--green); box-shadow: 0 4px 0 #000, 0 0 22px rgba(87,255,122,.5); }
.btn-victory:hover { background: #0f2418; }

/* ===================== BOUTON SON ===================== */
.btn-sound {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  right: calc(env(safe-area-inset-right) + 10px);
  z-index: 20;
  font-family: inherit;
  font-size: 7px;
  padding: 8px 10px;
  border: 2px solid var(--accent2);
  background: rgba(8,12,24,.8);
  color: var(--accent2);
  cursor: pointer;
  line-height: 1.4;
}
.btn-sound.muted { border-color: #555; color: #777; }
/* masqué pendant le jeu pour ne pas gêner le HUD */
body.in-game .btn-sound { display: none; }

/* ===================== HUD ===================== */
#screen-game { justify-content: flex-start; padding: 0; background: var(--bg); }
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  font-size: 9px;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(0,0,0,.9);
}
.hud-item span { color: var(--accent); }
.hud-center { color: var(--accent2); }
.hud-right { text-align: right; }

.boss-bar {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 38px);
  left: 50%; transform: translateX(-50%);
  z-index: 5;
  width: min(80%, 420px);
  text-align: center;
  pointer-events: none;
}
.boss-label { font-size: 7px; color: var(--danger); display: block; margin-bottom: 4px; text-shadow: 0 0 6px rgba(0,0,0,.9); }
.boss-bar-track { width: 100%; height: 12px; border: 2px solid var(--danger); background: #1a0808; }
.boss-bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff3b3b, #ff8a3b); transition: width .15s; }

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

/* ===================== CONTRÔLES TACTILES ===================== */
.touch-controls { display: none; }
.joystick {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 24px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,.05);
  border: 2px solid rgba(255,232,31,.35);
  z-index: 6;
  touch-action: none;
}
.joystick-knob {
  position: absolute;
  top: 50%; left: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255,232,31,.25);
  border: 2px solid var(--accent);
  pointer-events: none;
}
.btn-fire {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 36px);
  right: 28px;
  width: 96px; height: 96px;
  border-radius: 50%;
  border: 3px solid var(--accent2);
  background: rgba(79,214,255,.15);
  color: var(--accent2);
  font-family: inherit;
  font-size: 12px;
  z-index: 6;
  box-shadow: 0 0 18px rgba(79,214,255,.3);
  touch-action: none;
}
.btn-fire:active { background: rgba(79,214,255,.35); }

/* Affiche les contrôles tactiles sur appareils tactiles */
body.touch .touch-controls { display: block; }
body.touch .desktop-only { display: none; }
body:not(.touch) .mobile-only { display: none; }

/* ===================== FINS (game over / victoire) ===================== */
.center-inner {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}
.end-title { font-size: clamp(24px, 9vw, 56px); letter-spacing: 2px; }
.end-title.danger { color: var(--danger); text-shadow: 0 0 18px rgba(255,59,59,.6); animation: blink 1s steps(2) infinite; }
.end-title.victory { color: var(--green); text-shadow: 0 0 22px rgba(87,255,122,.7); }
@keyframes blink { 50% { opacity: .35; } }
.end-text { font-size: 10px; line-height: 1.9; }
.end-text span { color: var(--accent); }
.victory-sub { font-size: 8px; color: var(--accent2); opacity: .85; line-height: 1.8; }

.victory-burst {
  position: absolute;
  top: -40px; left: 50%; transform: translateX(-50%);
  width: 240px; height: 240px;
  background: radial-gradient(circle, rgba(87,255,122,.25), transparent 70%);
  animation: pulse 2.4s ease-in-out infinite;
  z-index: -1;
}
@keyframes pulse { 0%,100% { transform: translateX(-50%) scale(1); opacity:.6 } 50% { transform: translateX(-50%) scale(1.25); opacity:1 } }

/* ===================== RESPONSIVE ===================== */
@media (max-height: 560px) {
  .hero-frame { width: min(40vh, 160px); }
  .title-main { font-size: 22px; }
}
