/* ── Écran rotation (portrait uniquement) ───────────────────────────────────── */
#rotate-screen {
  display:         none;
  position:        fixed;
  inset:           0;
  z-index:         9999;
  background:      #1a1a2e;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  text-align:      center;
}

.rotate-content {
  color: #fff;
}

.rotate-icon {
  font-size:     80px;
  display:       block;
  animation:     rotatePulse 1.5s ease-in-out infinite;
}

.rotate-arrow {
  font-size:     48px;
  color:         #f1c40f;
  animation:     rotatePulse 1.5s ease-in-out infinite reverse;
  margin:        8px 0;
}

.rotate-content p {
  font-size:     20px;
  font-weight:   700;
  line-height:   1.5;
  color:         #fff;
  margin-top:    12px;
}

@keyframes rotatePulse {
  0%, 100% { transform: rotate(-15deg); }
  50%       { transform: rotate(15deg);  }
}

/* Affiché via JS uniquement quand le jeu est actif en portrait */
body.needs-rotation #rotate-screen {
  display: flex;
}

/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after {
  margin:     0;
  padding:    0;
  box-sizing: border-box;
}

html, body {
  width:    100%;
  height:   100%;
  overflow: hidden;
  background: #87CEEB;
  /* Empêche le zoom et le scroll sur mobile */
  touch-action:   none;
  -ms-touch-action: none;
  /* Safe area pour les téléphones avec encoche/barre de navigation */
  padding-top:    env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Hauteur réelle du viewport mobile (évite le décalage barre d'adresse Chrome) */
@supports (height: 100dvh) {
  html, body, #canvas {
    height: 100dvh;
  }
}

/* ── Canvas principal ─────────────────────────────────────────────────────── */
#canvas {
  position:         absolute;
  top:              0;
  left:             0;
  width:            100%;
  height:           100%;
  image-rendering:  pixelated;
}

/* ── HUD en jeu ────────────────────────────────────────────────────────────── */
#hud {
  position:        absolute;
  top:             10px;
  left:            0;
  right:           0;
  display:         none;
  justify-content: space-between;
  align-items:     center;
  padding:         0 16px;
  pointer-events:  none;
  z-index:         5;
}

.hud-block {
  background:    rgba(0, 0, 0, 0.5);
  border-radius: 12px;
  padding:       8px 24px;
  color:         #fff;
  font-size:     26px;
}

#timer {
  font-size:      32px;
  font-weight:    700;
  letter-spacing: 2px;
  color:          #f1c40f;
}

/* Bouton musique cliquable dans le HUD */
#hud .hud-block:last-child {
  pointer-events: all;
  display:        flex;
  gap:            10px;
  align-items:    center;
}

#music-btn {
  cursor: pointer;
}

/* ── Barre de power-ups ────────────────────────────────────────────────────── */
#powerup-bar {
  position:         absolute;
  bottom:           14px;
  left:             50%;
  transform:        translateX(-50%);
  display:          none;
  gap:              8px;
  z-index:          5;
  pointer-events:   none;
}

.powerup-slot {
  width:         38px;
  height:        38px;
  border-radius: 8px;
  display:       flex;
  align-items:   center;
  justify-content: center;
  font-size:     18px;
  background:    rgba(0, 0, 0, 0.4);
  border:        1.5px solid rgba(255, 255, 255, 0.2);
  opacity:       0.3;
  transition:    opacity 0.2s, border-color 0.2s;
}

.powerup-slot.on {
  opacity:      1;
  border-color: #f1c40f;
}

/* ── Overlay (menus, victoire, game over…) ─────────────────────────────────── */
#overlay {
  position:        absolute;
  inset:           0;
  display:         flex;
  align-items:     center;
  justify-content: center;
  z-index:         10;
  background:      rgba(0, 0, 0, 0.45);
}

/* Mode menu : fond légèrement plus transparent pour laisser le décor visible */
#overlay.menu-mode {
  background: rgba(0, 0, 0, 0.55);
  align-items: center;
}

#overlay.menu-mode #panel {
  max-width:  580px;
  background: rgba(6, 12, 30, 0.92);
  border:     1px solid rgba(241, 196, 15, 0.4);
  box-shadow: 0 0 60px rgba(241, 196, 15, 0.15), 0 12px 50px rgba(0,0,0,0.7);
}

/* ── Page d'accueil ──────────────────────────────────────────────────────────── */
.menu-header {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  margin-bottom:  10px;
  gap:            6px;
}

.menu-logo-img {
  height:        140px;
  width:         auto;
  background:    #fff;
  border-radius: 14px;
  padding:       8px 14px;
  filter:        drop-shadow(0 4px 16px rgba(241,196,15,0.5));
}

.menu-title {
  font-size:      28px;
  font-weight:    900;
  line-height:    1.2;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color:          #f1c40f;
  text-shadow:    0 0 24px rgba(241,196,15,0.6), 0 2px 8px rgba(0,0,0,0.8);
  margin:         6px 0 8px;
  animation:      menuTitlePulse 3s ease-in-out infinite;
}

.menu-date {
  font-size:   13px;
  color:       rgba(255,255,255,0.7);
  margin:      0 0 10px;
  letter-spacing: 0.5px;
}

.menu-slogan {
  display:         flex;
  align-items:     center;
  gap:             4px;
  margin:          0 0 14px;
  padding:         14px 18px;
  background:      rgba(241,196,15,0.07);
  border-radius:   12px;
  border:          1px solid rgba(241,196,15,0.2);
  text-align:      center;
}

.menu-slogan p {
  font-size:   18px;
  font-style:  italic;
  color:       rgba(255,255,255,0.95);
  line-height: 1.7;
  margin:      0;
  flex:        1;
}

.menu-slogan-quote {
  font-size:   28px;
  color:       #f1c40f;
  line-height: 1;
  opacity:     0.8;
  flex-shrink: 0;
}

.menu-levels {
  display:         flex;
  align-items:     center;
  justify-content: center;
  gap:             8px;
  margin:          0 0 18px;
  padding:         12px;
  background:      rgba(255,255,255,0.04);
  border-radius:   12px;
  border:          1px solid rgba(255,255,255,0.08);
}

.menu-level-badge {
  display:        flex;
  flex-direction: column;
  align-items:    center;
  gap:            4px;
}

.menu-level-thumb {
  width:         90px;
  height:        54px;
  border-radius: 8px;
  overflow:      hidden;
  border:        2px solid rgba(241,196,15,0.4);
  box-shadow:    0 2px 8px rgba(0,0,0,0.5);
}

.menu-level-thumb img {
  width:      100%;
  height:     100%;
  object-fit: cover;
  object-position: left center;
  image-rendering: pixelated;
}

.menu-level-num {
  font-size:   11px;
  font-weight: 900;
  color:       #f1c40f;
  letter-spacing: 1px;
}

.menu-level-name {
  font-size:   10px;
  color:       #aaa;
  text-align:  center;
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.menu-level-arrow {
  font-size: 22px;
  color:     #f1c40f;
  opacity:   0.6;
  padding:   0 4px;
}

.menu-play-btn {
  width:     100%;
  font-size: 18px !important;
  padding:   14px 0 !important;
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.menu-secondary-btns {
  display:         flex;
  gap:             10px;
  justify-content: center;
}

.menu-secondary-btns .btn {
  flex: 1;
}

@keyframes menuTitlePulse {
  0%, 100% { text-shadow: 0 0 24px rgba(241,196,15,0.6), 0 2px 8px rgba(0,0,0,0.8); }
  50%       { text-shadow: 0 0 40px rgba(241,196,15,0.9), 0 2px 8px rgba(0,0,0,0.8); }
}

#panel {
  background:    rgba(8, 16, 36, 0.95);
  border-radius: 16px;
  padding:       24px 28px 28px;
  text-align:    center;
  color:         #fff;
  max-width:     480px;
  width:         92%;
  border:        1px solid rgba(241, 196, 15, 0.2);
  box-shadow:    0 8px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255,255,255,0.06);
  position:      relative;
  overflow:      hidden;
  animation:     panelBounceIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* ── Titres d'écran ─────────────────────────────────────────────────────────── */
.screen-title {
  font-size:      22px;
  font-weight:    900;
  letter-spacing: 0.5px;
  margin-bottom:  4px;
}

.victory-title {
  font-size:   34px;
  color:       #f1c40f;
  text-shadow: 0 0 20px rgba(241,196,15,0.7), 0 2px 6px rgba(0,0,0,0.6);
  margin-bottom: 6px;
}

/* ── Stat Cards ──────────────────────────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap:    10px;
  margin: 14px 0 10px;
}

.stat-cards--single {
  grid-template-columns: 1fr;
}

.stat-card {
  background:    rgba(241, 196, 15, 0.06);
  border:        1.5px solid rgba(241, 196, 15, 0.28);
  border-radius: 12px;
  padding:       14px 12px;
  text-align:    center;
}

.stat-label {
  font-size:      10px;
  font-weight:    700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color:          #888;
  margin-bottom:  6px;
}

.stat-value {
  font-size:   32px;
  font-weight: 900;
  color:       #f1c40f;
  line-height: 1;
}

.stat-value--time {
  font-family:     'Courier New', monospace;
  font-size:       26px;
  letter-spacing:  2px;
}

.stat-value--xl {
  font-size:    40px;
  font-family:  'Courier New', monospace;
  letter-spacing: 3px;
  text-shadow:  0 0 14px rgba(241,196,15,0.5);
}

/* ── Textes secondaires des écrans ──────────────────────────────────────────── */
.screen-penalty {
  font-size:   20px;
  font-weight: 700;
  margin:      10px 0 6px;
  line-height: 1.5;
}

.screen-next {
  font-size:     20px;
  font-weight:   800;
  color:         #fff;
  margin-bottom: 16px;
}

/* ── Formulaire gagnant ─────────────────────────────────────────────────────── */
.winner-label {
  display:     block;
  font-size:   12px;
  color:       #aaa;
  margin:      10px 0 6px;
  letter-spacing: 0.5px;
}

/* ── Boutons agrandis ───────────────────────────────────────────────────────── */
.btn-large {
  padding:     13px 38px;
  font-size:   15px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.btn-gold {
  background:  linear-gradient(135deg, #f9d71c 0%, #e6a817 100%);
  color:       #1a1200;
  font-weight: 900;
}

.btn-gold:hover {
  background: linear-gradient(135deg, #ffe54d 0%, #f0b820 100%);
}

/* ── Écran règles ───────────────────────────────────────────────────────────── */
.rules-section {
  background:    rgba(255,255,255,0.06);
  border:        1px solid rgba(241,196,15,0.18);
  border-radius: 10px;
  padding:       10px 14px;
  margin-bottom: 8px;
  text-align:    left;
}

.rules-title {
  font-size:   13px;
  font-weight: 800;
  color:       #f1c40f;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rules-text {
  font-size:   13px;
  color:       #ddd;
  line-height: 1.5;
}

.rules-grid {
  display:               grid;
  grid-template-columns: auto 1fr;
  gap:                   4px 12px;
  font-size:             13px;
  color:                 #ddd;
  align-items:           center;
}

.rules-key {
  background:    rgba(255,255,255,0.12);
  border:        1px solid rgba(255,255,255,0.25);
  border-radius: 5px;
  padding:       1px 7px;
  font-family:   monospace;
  font-size:     12px;
  color:         #fff;
  white-space:   nowrap;
}

.rules-lives {
  font-size:   15px;
  color:       #e74c3c;
  font-weight: 700;
  margin:      8px 0 12px;
  text-align:  center;
}

/* ── Animation d'entrée du panel ───────────────────────────────────────────── */
@keyframes panelBounceIn {
  0%   { transform: scale(0.4) translateY(-30px); opacity: 0; }
  60%  { transform: scale(1.06) translateY(4px);  opacity: 1; }
  100% { transform: scale(1)    translateY(0);    opacity: 1; }
}

/* ── Confetti (fin de niveau) ───────────────────────────────────────────────── */
.confetti-container {
  position:       absolute;
  top:            0;
  left:           0;
  right:          0;
  height:         100%;
  pointer-events: none;
  overflow:       hidden;
  border-radius:  14px;
}

.confetti-piece {
  position:  absolute;
  top:       -14px;
  width:     8px;
  height:    12px;
  border-radius: 2px;
  animation: confettiFall 1.8s ease-in forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(0)     rotate(0deg);   opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(320px) rotate(540deg); opacity: 0; }
}

/* ── Étoiles/feux d'artifice (victoire) ─────────────────────────────────────── */
.stars-container {
  position:       absolute;
  top:            0;
  left:           0;
  right:          0;
  height:         100%;
  pointer-events: none;
  overflow:       hidden;
  border-radius:  14px;
}

.star-piece {
  position:  absolute;
  font-size: 22px;
  animation: starBurst 1.4s ease-out forwards;
}

@keyframes starBurst {
  0%   { transform: scale(0) translateY(0);     opacity: 1; }
  50%  { transform: scale(1.4) translateY(-60px); opacity: 1; }
  100% { transform: scale(0.6) translateY(-100px); opacity: 0; }
}

#panel h2 {
  font-size:     22px;
  margin-bottom: 8px;
}

#panel p {
  font-size:     13px;
  color:         #bbb;
  margin-bottom: 14px;
  line-height:   1.6;
}

#panel input {
  width:         100%;
  padding:       10px 14px;
  border-radius: 8px;
  border:        1px solid rgba(255, 255, 255, 0.2);
  background:    rgba(255, 255, 255, 0.1);
  color:         #fff;
  font-size:     14px;
  margin-bottom: 12px;
  outline:       none;
}

#panel input::placeholder {
  color: #888;
}

/* ── Boutons ───────────────────────────────────────────────────────────────── */
.btn {
  display:       inline-block;
  padding:       10px 28px;
  font-size:     14px;
  background:    #e67e22;
  border:        none;
  border-radius: 8px;
  color:         #fff;
  cursor:        pointer;
  margin:        4px;
  transition:    background 0.15s;
}

.btn:hover {
  background: #d35400;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.25);
}

.btn-facebook {
  background:      #1877f2;
  color:           #fff !important;
  text-decoration: none;
  font-weight:     700;
  letter-spacing:  0.5px;
  border:          none;
  display:         block;
  width:           100%;
  margin-top:      8px;
}

.btn-facebook:hover {
  background: #1565c0;
}

/* ── Tableau des scores ────────────────────────────────────────────────────── */
#score-table {
  width:           100%;
  border-collapse: collapse;
  margin-top:      10px;
  font-size:       13px;
}

#score-table th {
  color:         #f1c40f;
  padding:       4px 8px;
  text-align:    left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

#score-table td {
  padding:       5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

/* ── Contrôles tactiles ────────────────────────────────────────────────────── */
#touch-controls {
  position:        fixed;
  bottom:          16px;
  left:            0;
  right:           0;
  display:         flex;
  justify-content: space-between;
  padding:         0 18px;
  z-index:         20;
  pointer-events:  none;
}

.touch-left-group {
  display: flex;
  gap:     10px;
}

.touch-btn {
  width:         70px;
  height:        70px;
  font-size:     22px;
  font-weight:   bold;
  border-radius: 50%;
  background:    rgba(255, 255, 255, 0.25);
  border:        2px solid rgba(255, 255, 255, 0.6);
  color:         #fff;
  pointer-events: all;
  touch-action:  none;
  pointer-events: all;
  cursor:        pointer;
  user-select:   none;
  -webkit-user-select: none;
  text-shadow:   0 1px 3px rgba(0,0,0,0.6);
}

.touch-btn--jump {
  width:           80px;
  height:          80px;
  font-size:       14px;
  font-weight:     900;
  letter-spacing:  1px;
  background:      rgba(255, 180, 0, 0.45);
  border:          2px solid rgba(255, 200, 0, 0.8);
  box-shadow:      0 0 12px rgba(255,180,0,0.4);
}

/* ── Media queries mobile ────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #panel {
    max-width:     95vw;
    padding:       16px 12px;
    max-height:    85vh;
    overflow-y:    auto;
  }
}

/* Paysage sur petit écran — compacter les écrans interstitiels */
@media (max-height: 450px) {
  #panel {
    max-height:    95vh;
    overflow-y:    auto;
    padding:       10px 12px;
  }

  #panel h2 {
    font-size:     16px;
    margin-bottom: 4px;
  }

  .stat-cards { gap: 4px; margin: 4px 0; }
  .stat-card  { padding: 4px 6px; }
  .stat-value { font-size: 18px; }
  .stat-value--xl { font-size: 22px; }
  .stat-label { font-size: 10px; }

  .winner-label { font-size: 12px; margin: 4px 0 2px; }

  #panel input { padding: 6px 10px; margin-bottom: 6px; font-size: 13px; }

  .btn { padding: 6px 18px; font-size: 12px; margin: 2px; }
  .btn-large { padding: 8px 22px; font-size: 13px; }

  .confetti-container, .stars-container { display: none; }

  /* HUD compact */
  #hud { top: 4px; padding: 0 8px; }
  .hud-block { font-size: 14px; padding: 4px 10px; border-radius: 8px; }
  #timer { font-size: 16px; }

  /* Power-ups compact */
  #powerup-bar { bottom: 8px; gap: 4px; }
  .powerup-slot { width: 26px; height: 26px; font-size: 13px; border-radius: 6px; }
}

  .screen-title {
    font-size:     16px;
  }

  .victory-title {
    font-size:     22px;
  }

  .stat-value {
    font-size:     22px;
  }

  .stat-value--xl {
    font-size:     28px;
  }

  .stat-value--time {
    font-size:     18px;
  }

  .stat-cards {
    gap:           6px;
  }

  .stat-card {
    padding:       8px 6px;
  }

  .screen-penalty,
  .screen-next {
    font-size:     13px;
  }

  .btn-large {
    padding:       10px 24px;
    font-size:     13px;
  }

  .menu-title {
    font-size:     20px;
  }

  .menu-logo-img {
    max-height:    80px;
  }

  .menu-level-preview {
    width:         70px;
    height:        40px;
  }

  .menu-levels {
    gap:           8px;
  }

  #touch-controls {
    bottom:        10px;
  }

  .touch-btn {
    width:         60px;
    height:        60px;
    font-size:     18px;
  }

  .touch-btn--jump {
    width:         68px;
    height:        68px;
    font-size:     12px;
  }
}
