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

html, body {
  height: 100%;
  background: #070a16;
  overflow: hidden;
  font-family: "Courier New", monospace;
  -webkit-user-select: none;
  user-select: none;
}

@media (pointer: coarse) {
  html, body { overflow: auto; min-height: 100%; }
}

/* Plein écran : #cadre devient le conteneur principal */
#cadre:fullscreen,
#cadre:-webkit-full-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100vw !important;
  height: 100vh !important;
  background: #070a16;
  padding: 4px;
}
#cadre:fullscreen #cadre-inner,
#cadre:-webkit-full-screen #cadre-inner {
  width: min(100vw, calc((100vh - 92px) * 30 / 17));
  max-height: calc(100vh - 92px);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
}

#cadre {
  position: relative;
  width: min(100vw, calc(100vh * 30 / 17));
}

@media (pointer: coarse) {
  #cadre {
    width: min(100vw, calc((100vh - 96px) * 30 / 17));
  }
}

#cadre-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 30 / 17;
  max-height: 100%;
}

canvas#jeu {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.ecran {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(7, 10, 24, 0.86);
  z-index: 5;
  text-align: center;
  padding: 18px;
  overflow-y: auto;
}
.ecran.visible { display: flex; }

#logo {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}
.logo-ligne {
  color: #fff;
  font-weight: bold;
  letter-spacing: 6px;
  font-size: clamp(20px, 4.2vw, 40px);
  text-shadow: 3px 3px 0 #c92a2a, 6px 6px 0 rgba(0,0,0,0.5);
}
.logo-ligne.grand {
  color: #ffd43b;
  font-size: clamp(30px, 6.4vw, 62px);
  letter-spacing: 3px;
  text-shadow: 3px 3px 0 #e03131, 6px 6px 0 rgba(0,0,0,0.55);
  animation: logo-vibre 2.4s ease-in-out infinite;
}
@keyframes logo-vibre {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

#titre-mascotte {
  font-size: clamp(34px, 6vw, 58px);
  animation: mascotte-saute 1.6s ease-in-out infinite;
}
@keyframes mascotte-saute {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-16px) scale(0.94, 1.06); }
  60% { transform: translateY(0) scale(1.08, 0.9); }
  75% { transform: translateY(0) scale(1, 1); }
}

#titre-meilleur { color: #9aa5b5; font-size: clamp(12px, 1.6vw, 17px); }
#titre-version { color: #5d6b80; font-size: clamp(10px, 1.4vw, 14px); margin-top: 8px; }

.colonne-boutons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: min(340px, 84%);
}

.gros-bouton {
  font-family: inherit;
  font-weight: bold;
  font-size: clamp(14px, 2vw, 19px);
  padding: 11px 22px;
  color: #fff;
  background: linear-gradient(#e03131, #b02525);
  border: none;
  border-bottom: 4px solid #7a1212;
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.06s, filter 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.gros-bouton:hover { filter: brightness(1.15); }
.gros-bouton:active { transform: translateY(2px); border-bottom-width: 2px; }
.gros-bouton.principal {
  background: linear-gradient(#f59f00, #d9740a);
  border-bottom-color: #99500a;
  font-size: clamp(16px, 2.4vw, 23px);
  padding: 13px 26px;
}
.gros-bouton.petit { font-size: clamp(11px, 1.5vw, 14px); padding: 7px 16px; }

h2 {
  color: #ffd43b;
  font-size: clamp(20px, 3.4vw, 32px);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
  letter-spacing: 2px;
}

.legende { color: #9aa5b5; font-size: clamp(10px, 1.4vw, 14px); }

#grille-niveaux {
  display: grid;
  grid-template-columns: repeat(auto-fit, 128px);
  gap: 10px;
  justify-content: center;
  max-height: 52vh;
  overflow-y: auto;
  padding: 6px;
}
.carte-niveau {
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  min-height: 88px;
  background: linear-gradient(#223052, #17233f);
  border: 2px solid #38507e;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.15s;
}
.carte-niveau:hover { transform: translateY(-3px); border-color: #74c0fc; }
.carte-niveau.verrouille { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.7); }
.niv-id { color: #ffd43b; font-weight: bold; font-size: 19px; }
.niv-nom { color: #dbe4f3; font-size: 10.5px; line-height: 1.15; max-width: 116px; }
.niv-etoiles { color: #ffd43b; font-size: 13px; letter-spacing: 2px; }
.niv-record { color: #74c0fc; font-size: 11px; }

#contenu-aide {
  max-width: 620px;
  max-height: 56vh;
  overflow-y: auto;
  text-align: left;
  background: rgba(15, 22, 44, 0.75);
  border: 2px solid #38507e;
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#contenu-aide section h3 { color: #74c0fc; font-size: clamp(14px, 1.9vw, 18px); margin-bottom: 5px; }
#contenu-aide table { width: 100%; border-collapse: collapse; }
#contenu-aide td {
  color: #dbe4f3;
  font-size: clamp(11px, 1.5vw, 14px);
  padding: 3px 6px;
  border-bottom: 1px dashed #2c3d63;
  vertical-align: top;
}
#contenu-aide td:first-child { white-space: nowrap; color: #ffd43b; font-weight: bold; padding-right: 14px; }
#contenu-aide ul { list-style: none; }
#contenu-aide li { color: #dbe4f3; font-size: clamp(11px, 1.5vw, 14px); padding: 2px 0; }
.astuce-aide { color: #8ce99a; font-size: clamp(11px, 1.5vw, 13px); margin-top: 6px; }

#final-stats { color: #dbe4f3; font-size: clamp(13px, 1.9vw, 18px); line-height: 1.65; }
#final-titre { font-size: clamp(24px, 4.4vw, 42px); }

#toast {
  position: absolute;
  left: 50%;
  bottom: 15%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 22, 44, 0.95);
  border: 2px solid #ffd43b;
  color: #ffd43b;
  font-weight: bold;
  font-size: clamp(13px, 1.8vw, 18px);
  padding: 10px 22px;
  border-radius: 30px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 9;
  white-space: nowrap;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

#credits-content {
  text-align: center;
  max-width: 540px;
  overflow-y: auto;
  max-height: 56vh;
}
#credits-logo {
  font-size: clamp(48px, 8vw, 72px);
  animation: mascotte-saute 1.6s ease-in-out infinite;
  margin-bottom: 8px;
}
#credits-titre {
  color: #ffd43b;
  font-size: clamp(28px, 5vw, 48px);
  text-shadow: 3px 3px 0 #e03131, 6px 6px 0 rgba(0,0,0,0.5);
  margin-bottom: 16px;
}
#credits-texte { color: #dbe4f3; font-size: clamp(13px, 2vw, 18px); line-height: 1.6; margin-bottom: 12px; }
#credits-etoiles { color: #ffd43b; font-size: clamp(20px, 3vw, 28px); margin-bottom: 12px; }
#credits-merci { color: #8ce99a; font-size: clamp(12px, 1.6vw, 16px); margin-bottom: 8px; }

/* Highscores */
#liste-highscores {
  max-width: 560px;
  width: 90%;
  max-height: 56vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ligne-hs {
  display: grid;
  grid-template-columns: 40px 1fr auto auto 60px;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(15, 22, 44, 0.75);
  border: 1px solid #2c3d63;
  border-radius: 8px;
  font-size: clamp(12px, 1.6vw, 15px);
}
.ligne-hs.hs-premier {
  background: linear-gradient(135deg, rgba(255, 212, 59, 0.18), rgba(255, 160, 0, 0.12));
  border-color: rgba(255, 212, 59, 0.5);
}
.hs-rang { font-size: 20px; text-align: center; }
.hs-nom { color: #ffd43b; font-weight: bold; letter-spacing: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs-score { color: #74c0fc; font-weight: bold; }
.hs-pieces { color: #9aa5b5; font-size: 0.85em; }
.hs-date { color: #5d6b80; font-size: 0.8em; text-align: right; }

#commandes-tactile { display: none; }

@media (pointer: coarse) {
  body:has(.ecran.visible) #commandes-tactile { display: none !important; }
  body:not(:has(.ecran.visible)) #commandes-tactile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 80px;
    padding: 0 10px;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
  }

  .bouton-tactile {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(120, 170, 255, 0.22), rgba(60, 100, 200, 0.18));
    border: 2px solid rgba(120, 170, 255, 0.45);
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.15);
    transition: transform 0.08s, box-shadow 0.08s, filter 0.08s;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  }

  .bouton-tactile.actif {
    transform: scale(0.82);
    filter: brightness(1.6);
    box-shadow: 0 0 20px rgba(120, 200, 255, 0.7), 0 0 40px rgba(120, 200, 255, 0.35), inset 0 2px 8px rgba(255, 255, 255, 0.3);
  }

  #btn-gauche { background: linear-gradient(145deg, rgba(100, 200, 255, 0.25), rgba(40, 120, 200, 0.2)); border-color: rgba(100, 200, 255, 0.5); }
  #btn-gauche.actif { box-shadow: 0 0 20px rgba(100, 200, 255, 0.8), 0 0 40px rgba(100, 200, 255, 0.4), inset 0 2px 8px rgba(255,255,255,0.3); }

  #btn-droite { background: linear-gradient(145deg, rgba(100, 200, 255, 0.25), rgba(40, 120, 200, 0.2)); border-color: rgba(100, 200, 255, 0.5); }
  #btn-droite.actif { box-shadow: 0 0 20px rgba(100, 200, 255, 0.8), 0 0 40px rgba(100, 200, 255, 0.4), inset 0 2px 8px rgba(255,255,255,0.3); }

  #btn-saut {
    background: linear-gradient(145deg, rgba(255, 212, 59, 0.35), rgba(220, 160, 0, 0.25));
    border: 2px solid rgba(255, 212, 59, 0.6);
  }
  #btn-saut.actif {
    box-shadow: 0 0 24px rgba(255, 212, 59, 0.9), 0 0 48px rgba(255, 180, 0, 0.5), inset 0 2px 8px rgba(255,255,255,0.3);
  }

  #btn-feu {
    background: linear-gradient(145deg, rgba(255, 100, 50, 0.35), rgba(200, 50, 0, 0.25));
    border: 2px solid rgba(255, 120, 50, 0.6);
  }
  #btn-feu.actif {
    box-shadow: 0 0 24px rgba(255, 100, 50, 0.9), 0 0 48px rgba(255, 80, 0, 0.5), inset 0 2px 8px rgba(255,255,255,0.3);
  }

  #btn-start { width: 50px; height: 50px; font-size: 20px;
    background: linear-gradient(145deg, rgba(180, 180, 200, 0.25), rgba(100, 100, 130, 0.2));
    border-color: rgba(180, 180, 200, 0.45);
  }
  #btn-start.actif { box-shadow: 0 0 18px rgba(200, 200, 255, 0.7), inset 0 2px 8px rgba(255,255,255,0.3); }

  #btn-fs { width: 50px; height: 50px; font-size: 20px;
    background: linear-gradient(145deg, rgba(100, 255, 150, 0.25), rgba(0, 180, 80, 0.2));
    border-color: rgba(100, 255, 150, 0.45);
  }
  #btn-fs.actif { box-shadow: 0 0 18px rgba(100, 255, 150, 0.7), inset 0 2px 8px rgba(255,255,255,0.3); }

  .pad-gauche, .pad-droite { display: flex; gap: 10px; align-items: center; }
}
