/* ============================================================ */
/* ELNE REEL : STREET CROWN — ARCADE FIGHTER STYLES             */
/* Palette: Night #101529, Gold #FFBD53, Red #DE2448, Cream     */
/* ============================================================ */

:root {
  --bg-night: #0b0d18;
  --bg-darker: #06070d;
  --panel-bg: rgba(16, 21, 41, 0.88);
  --gold: #ffbd53;
  --gold-glow: rgba(255, 189, 83, 0.45);
  --red: #de2448;
  --red-glow: rgba(222, 36, 72, 0.5);
  --cream: #fff0cf;
  --blue: #577a9a;
  --cyan: #38bdf8;
  --violet: #3d285f;
  --font-arcade: 'Syne', sans-serif;
  --font-body: 'Montserrat', sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-darker);
  color: var(--cream);
  font-family: var(--font-body);
}

/* Pseudo Fullscreen Immersif pour iOS Safari et tous navigateurs */
html.pseudo-fullscreen, body.pseudo-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  z-index: 999999 !important;
  background: #000 !important;
}

/* Master Game Container */
#game-wrapper {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #171d36 0%, #06070d 100%);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Canvas Viewport */
#viewport-box {
  position: absolute;
  inset: 0;
  width: 100% !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  display: block;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: none !important;
  border: none !important;
  border-radius: 0 !important;
}


/* CRT Scanline Overlay Effect (Toggleable) */
.crt-overlay {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%,
    rgba(0, 0, 0, 0.25) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.03),
    rgba(0, 255, 0, 0.01),
    rgba(0, 0, 255, 0.03)
  );
  background-size: 100% 3px, 6px 100%;
  z-index: 10;
  opacity: 0.7;
}

/* ============================================================ */
/* ARCADE HUD OVERLAY (TOP BARS, COMBO, SUPER METER)            */
/* ============================================================ */
#arcade-hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 20px;
}

/* Top Fighters Health Bar Container */
.hud-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

/* Player 1 (Elne Reel) Health Box */
.hud-fighter-side {
  display: flex;
  flex-direction: column;
  width: 40%;
}

.hud-fighter-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.hud-avatar-frame {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 2px solid var(--gold);
  background: #141a2e;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.hud-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.hud-fighter-name {
  font-family: var(--font-arcade);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fff;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.9), 1px 1px 0 #000;
}

.hud-health-track {
  position: relative;
  width: 100%;
  height: 20px;
  background: #1e2438;
  border: 2px solid #333d5a;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0,0,0,0.8);
}

.hud-health-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffbd53 0%, #de2448 100%);
  transition: width 0.15s ease-out;
  box-shadow: 0 0 12px var(--gold-glow);
}

.hud-health-damage {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
  transition: width 0.4s ease-out;
  z-index: 1;
}

/* P2 / Boss Side Flip */
.hud-fighter-side.right-side {
  align-items: flex-end;
}

.hud-fighter-side.right-side .hud-fighter-info {
  flex-direction: row-reverse;
}

.hud-fighter-side.right-side .hud-health-fill {
  margin-left: auto;
  background: linear-gradient(270deg, #de2448 0%, #ff5277 100%);
}

/* Center Timer & Round Pills */
.hud-center-timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 14px;
}

.hud-timer-num {
  font-family: var(--font-arcade);
  font-size: 38px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 189, 83, 0.8), 2px 2px 0 #000;
  line-height: 1;
}

.hud-stage-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--cyan);
  text-transform: uppercase;
  margin-top: 4px;
  text-shadow: 1px 1px 0 #000;
}

/* Super Meter (Bottom HUD) */
.hud-bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.super-meter-box {
  display: flex;
  flex-direction: column;
  width: 260px;
}

.super-meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: var(--gold);
  margin-bottom: 3px;
  text-shadow: 1px 1px 0 #000;
}

.super-meter-track {
  width: 100%;
  height: 14px;
  background: #111524;
  border: 1px solid var(--gold);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 8px rgba(255, 189, 83, 0.3);
}

.super-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8 0%, #ffbd53 100%);
  transition: width 0.1s linear;
}

.super-meter-fill.ready {
  animation: superPulse 0.4s infinite alternate;
}

@keyframes superPulse {
  from { background: #ffbd53; box-shadow: 0 0 15px #ffbd53; }
  to { background: #de2448; box-shadow: 0 0 20px #de2448; }
}

/* Street Run Pickups Bar */
.hud-pickups-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  font-family: var(--font-arcade);
  font-size: 16px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

.pickup-stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Combo Popup Badge */
.combo-popup {
  position: absolute;
  top: 130px;
  left: 80px;
  font-family: var(--font-arcade);
  transform: skew(-10deg);
  opacity: 0;
  transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.2s ease;
  pointer-events: none;
}

.combo-popup.active {
  opacity: 1;
  transform: skew(-10deg) scale(1.15);
}

.combo-hits-count {
  font-size: 42px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 15px rgba(255, 189, 83, 0.8), 3px 3px 0 #000;
}

.combo-hits-label {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--red);
  text-shadow: 2px 2px 0 #000;
}

/* Center Dramatic Announcer Banners */
.announcer-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  font-family: var(--font-arcade);
  font-size: clamp(38px, 7vw, 68px);
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 25px rgba(255, 189, 83, 0.9), 4px 4px 0 #de2448, 6px 6px 0 #000;
  pointer-events: none;
  opacity: 0;
  z-index: 50;
  white-space: nowrap;
  transition: transform 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.25s ease;
}

.announcer-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.1);
}

/* ============================================================ */
/* MANETTE SEGA MEGADRIVE 6 BOUTONS (MOBILE & TABLETTE)         */
/* ============================================================ */
.md-controller {
  display: flex;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px 24px max(18px, env(safe-area-inset-bottom, 18px));
  background: linear-gradient(180deg, rgba(8, 11, 20, 0.25) 0%, rgba(6, 8, 16, 0.85) 40%, rgba(4, 5, 10, 0.98) 100%);
  border-top: 2px solid rgba(255, 189, 83, 0.35);
  box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 45;
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
}

/* Poignée Gauche : D-Pad Mega Drive Circulaire Flottant */
.md-left-side {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.md-dpad-socket {
  width: 184px;
  height: 184px;
  border-radius: 50%;
  background: radial-gradient(circle, #090c14 55%, #182032 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 4px 14px rgba(0, 0, 0, 0.95), 0 3px 8px rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 189, 83, 0.2);
}

.md-dpad-disc {
  position: relative;
  width: 156px;
  height: 156px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #2d3852 0%, #171e2e 65%, #0b0f1a 100%);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.9), inset 0 2px 3px rgba(255, 255, 255, 0.4);
  cursor: pointer;
  touch-action: none;
}

.md-dpad-cross {
  position: relative;
  width: 100%;
  height: 100%;
}

.md-dir-btn {
  position: absolute;
  background: transparent;
  border: none;
  color: #ffbd53;
  font-size: 22px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  text-shadow: 0 0 8px rgba(255, 189, 83, 0.7);
  touch-action: none;
}

.md-dir-btn.dir-up {
  top: 6px; left: 52px; width: 52px; height: 46px;
}
.md-dir-btn.dir-down {
  bottom: 6px; left: 52px; width: 52px; height: 46px;
}
.md-dir-btn.dir-left {
  top: 52px; left: 6px; width: 46px; height: 52px;
}
.md-dir-btn.dir-right {
  top: 52px; right: 6px; width: 46px; height: 52px;
}

/* ============================================================ */
/* NOUVEAU JOYSTICK VIRTUEL FLOTTANT 2.5D                      */
/* ============================================================ */
.v-joystick-zone {
  width: 170px;
  height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

.v-joystick-base {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.95) 70%, rgba(8, 11, 20, 0.98) 100%);
  border: 2.5px solid rgba(192, 132, 252, 0.5);
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.25), inset 0 0 15px rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.v-joystick-indicator {
  position: absolute;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  font-weight: 900;
  transition: color 0.1s ease, transform 0.1s ease;
}
.v-ind-up { top: 6px; }
.v-ind-down { bottom: 6px; }
.v-ind-left { left: 8px; }
.v-ind-right { right: 8px; }

.v-joystick-base.active-up .v-ind-up,
.v-joystick-base.active-down .v-ind-down,
.v-joystick-base.active-left .v-ind-left,
.v-joystick-base.active-right .v-ind-right {
  color: #ffbd53;
  text-shadow: 0 0 8px #ffbd53;
  transform: scale(1.3);
}

.v-joystick-knob {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffbd53 0%, #d97706 50%, #78350f 100%);
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.9), 0 0 14px rgba(255, 189, 83, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.7);
  pointer-events: none;
  position: absolute;
  transform: translate(0, 0);
  transition: transform 0.04s ease-out;
}

/* Zone Centrale : PAUSE & DASH */
.md-center-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-bottom: 6px;
}

.md-btn-start {
  background: linear-gradient(180deg, #de2448 0%, #881337 100%);
  border: 1.5px solid #ff8095;
  border-radius: 16px;
  color: #fff;
  font-family: var(--font-arcade);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 1.5px;
  padding: 8px 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.7);
  cursor: pointer;
  touch-action: none;
}

.md-btn-dash-quick {
  background: #1e1b4b;
  border: 1.5px solid #818cf8;
  border-radius: 14px;
  color: #c7d2fe;
  font-family: var(--font-arcade);
  font-weight: 900;
  font-size: 10px;
  letter-spacing: 1px;
  padding: 6px 12px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  touch-action: none;
}

.md-btn-start:active, .md-btn-dash-quick:active, .md-btn-dash-quick.pressed {
  transform: scale(0.94);
  filter: brightness(1.3);
}

/* ============================================================ */
/* NOUVEAU CLUSTER 3 BOUTONS DE COMBAT ERGONOMIQUES           */
/* ============================================================ */
.combat-3buttons-cluster {
  display: grid;
  grid-template-areas:
    "context jump"
    "strike strike";
  gap: 12px;
  align-items: center;
  justify-items: center;
}

.combat-touch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.85), inset 0 2px 3px rgba(255, 255, 255, 0.4);
  transition: transform 0.05s ease, filter 0.05s ease, box-shadow 0.05s ease;
}

.combat-touch-btn:active, .combat-touch-btn.pressed {
  transform: scale(0.92) translateY(2px);
  filter: brightness(1.35);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.95), inset 0 3px 6px rgba(0, 0, 0, 0.6);
}

/* Bouton 1 : FRAPPER (Gros Bouton Géant Principal) */
.btn-strike {
  grid-area: strike;
  width: 92px;
  height: 92px;
  background: radial-gradient(circle at 35% 35%, #e11d48 0%, #be123c 60%, #4c0519 100%);
  border-color: #fda4af;
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.5);
}
.btn-strike .btn-icon { font-size: 26px; line-height: 1; }
.btn-strike .btn-title {
  font-family: var(--font-arcade);
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 1px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}
.btn-strike .btn-sub {
  font-size: 8px;
  font-weight: 800;
  color: #fecdd3;
  letter-spacing: 0.5px;
}

/* Bouton 2 : SAUTER */
.btn-jump {
  grid-area: jump;
  width: 72px;
  height: 72px;
  background: radial-gradient(circle at 35% 35%, #0284c7 0%, #0369a1 60%, #082f49 100%);
  border-color: #7dd3fc;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.45), inset 0 2px 3px rgba(255, 255, 255, 0.4);
}
.btn-jump .btn-icon { font-size: 18px; line-height: 1; }
.btn-jump .btn-title {
  font-family: var(--font-arcade);
  font-size: 11px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.5px;
}
.btn-jump .btn-sub {
  font-size: 8px;
  font-weight: 700;
  color: #bae6fd;
}

/* Bouton 3 : CONTEXTUEL (Ramasser / Lancer / Super) */
.btn-context {
  grid-area: context;
  width: 72px;
  height: 72px;
  background: radial-gradient(circle at 35% 35%, #d97706 0%, #b45309 60%, #451a03 100%);
  border-color: #fde68a;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.45), inset 0 2px 3px rgba(255, 255, 255, 0.4);
}
.btn-context.ready-super {
  background: radial-gradient(circle at 35% 35%, #c026d3 0%, #9333ea 60%, #3b0764 100%);
  border-color: #f0abfc;
  box-shadow: 0 0 18px rgba(192, 38, 211, 0.8), inset 0 2px 3px rgba(255, 255, 255, 0.6);
  animation: pulseSuper 0.8s infinite alternate;
}
@keyframes pulseSuper {
  from { transform: scale(1); filter: brightness(1); }
  to { transform: scale(1.06); filter: brightness(1.3); }
}
.btn-context .btn-icon { font-size: 18px; line-height: 1; }
.btn-context .btn-title {
  font-family: var(--font-arcade);
  font-size: 10px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.5px;
  text-align: center;
}
.btn-context .btn-sub {
  font-size: 8px;
  font-weight: 700;
  color: #fef3c7;
}

/* ============================================================ */
/* RÉGLAGES TAILLE, OPACITÉ & MODE GAUCHER                      */
/* ============================================================ */
.md-controller.controls-size-normal { transform: scale(1); }
.md-controller.controls-size-large { transform: scale(1.15); transform-origin: bottom center; }
.md-controller.controls-size-xl { transform: scale(1.3); transform-origin: bottom center; }

.md-controller.controls-opacity-low { opacity: 0.45; }
.md-controller.controls-opacity-med { opacity: 0.72; }
.md-controller.controls-opacity-high { opacity: 0.96; }

/* Mode Gaucher : Joystick passe à droite, boutons passent à gauche ! */
.md-controller.controls-left-handed {
  flex-direction: row-reverse !important;
}
@media (orientation: landscape) and (max-width: 1024px) {
  .md-controller.controls-left-handed .md-left-side {
    left: auto !important;
    right: max(12px, env(safe-area-inset-right)) !important;
  }
  .md-controller.controls-left-handed .md-right-side {
    right: auto !important;
    left: max(12px, env(safe-area-inset-left)) !important;
  }
}

/* UI Modal Réglages */
.settings-group {
  margin: 14px 0;
  text-align: left;
}
.settings-label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: #cbd5e1;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.settings-options {
  display: flex;
  gap: 8px;
}
.btn-opt {
  flex: 1;
  background: #1e293b;
  border: 1.5px solid #475569;
  color: #e2e8f0;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-opt:hover, .btn-opt.active {
  background: #7c3aed;
  border-color: #c084fc;
  color: #fff;
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.5);
}

/* ============================================================ */
/* RÈGLES DE VISIBILITÉ : TOUCHES UNIQUEMENT SUR TÉLÉPHONES     */
/* SUR ORDINATEUR / PC : STRICTEMENT AUCUNE TOUCHE À L'ÉCRAN    */
/* ============================================================ */

/* Sur téléphone & appareil tactile (par défaut sur écran mobile) */
.md-controller,
#megadrive-controller,
.apt-joystick-zone,
#apt-joystick-zone {
  display: flex;
}
#btn-settings-toggle {
  display: inline-flex;
}

/* Détection tactile native */
@media (hover: none) and (pointer: coarse) {
  .apt-joystick-zone, #apt-joystick-zone { display: flex !important; }
  .md-controller, #megadrive-controller { display: flex !important; }
  #btn-settings-toggle { display: inline-flex !important; }
}

body.is-mobile-touch .apt-joystick-zone,
body.is-mobile-touch #apt-joystick-zone,
body.is-mobile-touch .md-controller,
body.is-mobile-touch #megadrive-controller {
  display: flex !important;
}
body.is-mobile-touch #btn-settings-toggle {
  display: inline-flex !important;
}

/* SUR ORDINATEUR DE BUREAU / PC / SOURIS : TOUJOURS MASQUÉ */
body.is-desktop .md-controller,
body.is-desktop #megadrive-controller,
body.is-desktop .apt-joystick-zone,
body.is-desktop #apt-joystick-zone,
body.is-desktop #btn-settings-toggle {
  display: none !important;
}

@media (min-width: 1100px) and (hover: hover) and (pointer: fine) {
  body:not(.is-mobile-touch) .md-controller,
  body:not(.is-mobile-touch) #megadrive-controller,
  body:not(.is-mobile-touch) .apt-joystick-zone,
  body:not(.is-mobile-touch) #apt-joystick-zone,
  body:not(.is-mobile-touch) #btn-settings-toggle {
    display: none !important;
  }
}



/* ============================================================ */
/* SMARTPHONE EN PAYSAGE / PLEIN ÉCRAN : NE CACHE PAS L'ÉCRAN   */
/* Fond transparent, contrôles flottants aux extrémités gauche/droite */
/* ============================================================ */
@media (orientation: landscape) and (max-width: 1024px) {
  .md-controller {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: transparent !important; /* AUCUN FOND QUI COUVRE L'ÉCRAN */
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    pointer-events: none !important;
    padding: 0 !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-end !important;
  }

  .md-left-side, .md-right-side, .md-center-side {
    pointer-events: auto !important;
  }

  .md-left-side {
    position: absolute !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    left: max(12px, env(safe-area-inset-left)) !important;
    opacity: 0.72;
    transition: opacity 0.15s ease;
  }
  .md-left-side:active {
    opacity: 0.95;
  }

  .md-right-side {
    position: absolute !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    opacity: 0.72;
    transition: opacity 0.15s ease;
  }
  .md-right-side:active {
    opacity: 0.95;
  }

  .md-center-side {
    position: absolute !important;
    bottom: max(6px, env(safe-area-inset-bottom)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    opacity: 0.65;
    flex-direction: row !important;
    gap: 8px !important;
  }
}

/* ============================================================ */
/* SMARTPHONE EN PORTRAIT : ÉCRAN EN HAUT, MANETTE EN BAS       */
/* ============================================================ */
@media (orientation: portrait) and (max-width: 1024px) {
  #viewport-box {
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: center !important;
    padding-top: max(6px, env(safe-area-inset-top)) !important;
  }

  .md-controller {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    background: linear-gradient(180deg, rgba(8, 11, 20, 0.96) 0%, rgba(4, 5, 10, 1) 100%) !important;
    border-top: 2px solid rgba(255, 189, 83, 0.35) !important;
    padding: 8px 12px max(14px, env(safe-area-inset-bottom)) !important;
    z-index: 45 !important;
  }

  .md-dpad-socket {
    width: 148px;
    height: 148px;
  }
  .md-dpad-disc {
    width: 128px;
    height: 128px;
  }
  .md-dpad-center {
    top: 42px; left: 42px; width: 44px; height: 44px;
  }
  .md-dir-btn {
    font-size: 19px;
  }
  .md-dir-btn.dir-up {
    top: 4px; left: 42px; width: 44px; height: 38px;
  }
  .md-dir-btn.dir-down {
    bottom: 4px; left: 42px; width: 44px; height: 38px;
  }
  .md-dir-btn.dir-left {
    top: 42px; left: 4px; width: 38px; height: 44px;
  }
  .md-dir-btn.dir-right {
    top: 42px; right: 4px; width: 38px; height: 44px;
  }
  .md-row-top .md-action-btn {
    width: 46px;
    height: 46px;
  }
  .md-row-top .btn-letter {
    font-size: 16px;
  }
  .md-row-bottom .md-action-btn {
    width: 58px;
    height: 58px;
  }
  .md-row-bottom .btn-letter {
    font-size: 21px;
  }
  .md-btn-row {
    gap: 8px;
  }
  .md-buttons-cluster {
    gap: 8px;
  }
  .md-btn-start {
    width: 80px;
    height: 38px;
    font-size: 11px;
  }
  .md-btn-mode {
    width: 80px;
    height: 30px;
    font-size: 10px;
  }
}

/* ============================================================ */
/* MENU MODALS & SCREENS                                        */
/* ============================================================ */
.game-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: rgba(8, 11, 20, 0.90);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.game-modal.active {
  display: flex;
}

.modal-arcade-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - 28px);
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(135deg, rgba(22, 27, 44, 0.97) 0%, rgba(11, 13, 24, 0.99) 100%);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: clamp(14px, 3.2vh, 26px) clamp(14px, 3.5vw, 26px);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.9), 0 0 20px rgba(255, 189, 83, 0.3);
  text-align: center;
  animation: modalPop 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  margin: auto;
}

@keyframes modalPop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-logo-title {
  font-family: var(--font-arcade);
  font-size: clamp(20px, 4.2vw, 32px);
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 1.5px;
  line-height: 1.15;
  margin-bottom: 4px;
  text-shadow: 0 0 15px rgba(255, 189, 83, 0.6), 2px 2px 0 #000;
  word-break: break-word;
}

.modal-sub-tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.modal-lead-text {
  font-size: clamp(12px, 2.5vw, 14px);
  line-height: 1.5;
  color: #cbd5e1;
  margin-bottom: 16px;
}

.btn-arcade-start {
  display: block;
  width: 100%;
  padding: clamp(10px, 2vh, 14px) 18px;
  margin-bottom: 8px;
  border-radius: 8px;
  border: 2px solid var(--gold);
  background: linear-gradient(90deg, #ffbd53 0%, #f59e0b 100%);
  color: #080b14;
  font-family: var(--font-arcade);
  font-size: clamp(13px, 2.6vw, 16px);
  font-weight: 900;
  letter-spacing: 1.2px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(255, 189, 83, 0.4);
  transition: all 0.2s ease;
}

.btn-arcade-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 189, 83, 0.6);
}

.btn-arcade-secondary {
  display: block;
  width: 100%;
  padding: clamp(9px, 1.8vh, 12px) 16px;
  margin-bottom: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-family: var(--font-arcade);
  font-size: clamp(11px, 2.3vw, 13px);
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-arcade-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Keybindings Reference */
.keys-grid-table {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 18px 0;
  text-align: left;
  font-size: 12px;
}

.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.key-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: #20263c;
  border: 1px solid #4a5578;
  font-family: monospace;
  font-weight: 800;
  color: var(--gold);
}

/* Top Right Fixed Quick Actions */
.top-quick-actions {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  gap: 8px;
  z-index: 60;
  pointer-events: auto;
}

.btn-icon-corner {
  padding: 8px 12px;
  border-radius: 6px;
  background: rgba(16, 21, 41, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(4px);
  text-decoration: none;
}

.btn-icon-corner:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* Hide touch controls on desktop unless activated */
@media (hover: hover) and (pointer: fine) {
  #touch-controls {
    opacity: 0.15;
    transition: opacity 0.2s ease;
  }
  #touch-controls:hover {
    opacity: 0.9;
  }
}
