* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Disable iOS auto-detection links (addresses, dates, etc) */
a[x-apple-data-detectors] {
  color: inherit !important;
  text-decoration: none !important;
  font-size: inherit !important;
  font-family: inherit !important;
  font-weight: inherit !important;
  line-height: inherit !important;
  pointer-events: none !important;
}

html, body {
  font-family: 'Inter', sans-serif;
  background: #1a1a2e;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

/* Safe area padding — default to 0, only apply in PWA standalone */
:root {
  --sat: 0px;
  --sab: 0px;
  --sal: 0px;
  --sar: 0px;
}

/* In PWA standalone mode — apply real safe area insets (except bottom) */
@media all and (display-mode: standalone) {
  :root {
    --sat: env(safe-area-inset-top, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
  }
  #splash-overlay {
    padding-bottom: 20px;
  }
  #gameover-popup {
    padding-bottom: 0;
  }
  #leaderboard-screen {
    padding-bottom: 0;
  }
}

/* Fallback for iOS standalone (navigator.standalone) */
html.pwa-standalone {
  --sat: env(safe-area-inset-top, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
html.pwa-standalone #splash-overlay {
  padding-bottom: 20px;
}
html.pwa-standalone #gameover-popup {
  padding-bottom: 0;
}
html.pwa-standalone #leaderboard-screen {
  padding-bottom: 0;
}
html.pwa-standalone #leaderboard-content,
html.pwa-standalone #guide-content {
  max-height: calc(100dvh - var(--sat) - 60px);
}

/* SPLASH SCREEN */
#splash-screen {
  position: relative;
  width: 100%;
  height: 100%;
}

#splash-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
}

#splash-overlay {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: rgb(0 0 0 / 21%);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  padding: 20px;
  padding-top: var(--sat);
  padding-bottom: var(--sab);
  padding-bottom: calc(20px + var(--sab));
}

#game-title {
  font-family: 'Russo One', sans-serif;
  font-size: clamp(40px, 12vw, 80px);
  color: #e74c3c;
  text-shadow: 0 0 30px rgba(231, 76, 60, 0.5), 0 4px 8px rgba(0,0,0,0.5);
  letter-spacing: 6px;
  margin-bottom: 4px;
}

#game-subtitle {
  font-size: clamp(12px, 3.5vw, 20px);
  color: #888;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: clamp(8px, 2vh, 16px);
}

#btn-legende {
  display: inline-block;
  background: rgba(255,255,255,0.16);
  color: #eee;
  font-family: 'Inter', sans-serif;
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 1px;
  padding: 6px 16px;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 20px;
  margin-bottom: clamp(12px, 3vh, 24px);
  transition: all 0.2s;
  cursor: pointer;
}

#btn-legende:active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

#top3-container {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: clamp(16px, 4vh, 32px);
  width: 100%;
  max-width: 320px;
}

#top3-container h3 {
  color: #ccc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
  margin-bottom: 2px;
}

.map-sub-label {
  text-align: center;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  margin-bottom: 10px;
}

.top3-entry {
  display: flex;
  align-items: center;
  padding: 5px 0;
  color: #ddd;
  font-size: 15px;
}

.top3-entry:first-child .rank { color: #f1c40f; }
.top3-entry:nth-child(2) .rank { color: #bdc3c7; }
.top3-entry:nth-child(3) .rank { color: #cd7f32; }

.rank {
  font-weight: 700;
  width: 28px;
  font-size: 17px;
}

.top3-name {
  flex: 1;
  font-weight: 600;
}

.top3-score {
  font-family: 'Russo One', sans-serif;
  color: #e74c3c;
  font-size: 17px;
  margin-left: 8px;
}

/* BUTTONS */
#splash-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 16px 32px;
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  text-transform: uppercase;
  letter-spacing: 2px;
  /* Mobile touch targets - min 48px height */
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(231, 76, 60, 0.92), rgba(192, 57, 43, 0.92));
  color: white;
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-primary:active {
  box-shadow: 0 2px 8px rgba(231, 76, 60, 0.2);
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #ddd;
  border: 1px solid rgba(255,255,255,0.2);
}

.btn-link {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  padding: 8px;
  min-height: 40px;
  text-decoration: none;
  letter-spacing: 1px;
}

#copyright-text {
  color: rgba(255,255,255,0.35);
  font-size: 11px;
  text-align: center;
  letter-spacing: 1px;
  margin-top: 4px;
}

/* GAME SCREEN */
#game-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  background: #5a4a30;
}


#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#btn-pause {
  position: absolute;
  top: calc(12px + var(--sat));
  left: calc(16px + var(--sal));
  z-index: 20;
  background: rgba(0,0,0,0.25);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  touch-action: manipulation;
}

#btn-pause:active {
  background: rgba(0,0,0,0.4);
}

.pause-icon {
  display: flex;
  gap: 3px;
}

.pause-icon::before,
.pause-icon::after {
  content: '';
  display: block;
  width: 4px;
  height: 14px;
  background: #fff;
  border-radius: 1px;
}

.play-icon {
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #fff;
  margin-left: 2px;
}

#btn-music {
  position: absolute;
  top: calc(12px + var(--sat));
  left: calc(64px + var(--sal));
  z-index: 20;
  background: rgba(0,0,0,0.25);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  touch-action: manipulation;
}

#btn-music:active {
  background: rgba(0,0,0,0.4);
}

#score-display {
  position: absolute;
  top: calc(12px + var(--sat));
  right: calc(16px + var(--sar));
  font-family: 'Russo One', sans-serif;
  font-size: clamp(20px, 5vw, 32px);
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
  pointer-events: none;
}

/* GAMEOVER POPUP */
#gameover-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgb(0 0 0 / 21%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

#gameover-content {
  background: rgba(255,255,255,0.11);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  width: 90%;
  max-width: 360px;
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#gameover-content h2 {
  font-family: 'Russo One', sans-serif;
  font-size: 28px;
  color: #e74c3c;
  margin-bottom: 6px;
}

#final-score-text {
  font-size: 16px;
  color: #ddd;
  margin-bottom: 4px;
}

#final-rank-text {
  font-size: 13px;
  color: #aaa;
  margin-bottom: 16px;
}

#final-score {
  font-family: 'Russo One', sans-serif;
  font-size: 26px;
  color: #f1c40f;
}

#username-display-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}
#username-display {
  font-size: 16px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
}
.btn-change-name {
  background: none;
  border: none;
  color: rgba(255,255,255,0.45);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
  font-family: 'Inter', sans-serif;
}
.btn-change-name:hover { color: rgba(255,255,255,0.75); }

#username-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 0.2s;
  /* Prevent iOS zoom on focus */
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}

#username-input:focus {
  border-color: #e74c3c;
}

#username-input::placeholder {
  color: rgba(255,255,255,0.45);
}

#gameover-always {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
#gameover-buttons {
  display: flex;
  flex-wrap: wrap;
  column-gap: 10px;
  row-gap: 10px;
}
#gameover-buttons .btn {
  flex: 1;
  padding: 0 12px;
  font-size: 13px;
  min-height: 50px;
  height: 50px;
  box-sizing: border-box;
}
/* Accueil toujours sur sa propre ligne quand Envoyer est visible */
#btn-back-home {
  flex-basis: 100%;
}
/* Sans record : Rejouer + Accueil côte à côte, taille égale */
#gameover-buttons.no-envoyer {
  align-items: stretch;
  height: auto;
}
#gameover-buttons.no-envoyer #btn-back-home,
#gameover-buttons.no-envoyer #btn-replay {
  flex: 1 1 0% !important;
  padding: 0 12px !important;
  font-size: 13px !important;
  min-height: 50px !important;
  height: 50px !important;
  margin-top: 0 !important;
  box-sizing: border-box !important;
}

/* Sans record: Rejouer en rouge pour contraster avec Accueil */
#gameover-buttons.no-envoyer #btn-replay {
  background: linear-gradient(135deg, rgba(231, 76, 60, 0.92), rgba(192, 57, 43, 0.92)) !important;
  color: #fff !important;
  box-shadow: 0 4px 15px rgba(231, 76, 60, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}
#gameover-buttons.no-envoyer #btn-replay:active {
  box-shadow: 0 2px 8px rgba(231, 76, 60, 0.2);
}
#btn-submit-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
#btn-submit-sub {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.75;
  letter-spacing: 0;
  text-transform: none;
}

#btn-back-home {
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  width: auto;
  display: flex;
}

/* LEADERBOARD */
#leaderboard-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgb(0 0 0 / 21%);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

#leaderboard-content {
  width: 90%;
  max-width: 400px;
  max-height: calc(100dvh - 80px);
  background: rgba(255,255,255,0.11);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 16px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
}

#leaderboard-content h2 {
  font-family: 'Russo One', sans-serif;
  font-size: 26px;
  color: #e74c3c;
  text-align: center;
  margin-bottom: 2px;
  flex-shrink: 0;
}

#leaderboard-map-label {
  flex-shrink: 0;
  margin-bottom: 14px;
}

#leaderboard-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  margin-right: -6px;
}

#leaderboard-list::-webkit-scrollbar {
  width: 6px;
  background: transparent;
}

#leaderboard-list::-webkit-scrollbar-track {
  background: transparent;
}

#leaderboard-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

.lb-entry {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  color: #ddd;
  font-size: 15px;
}

.lb-entry:nth-child(odd) {
  background: rgba(255,255,255,0.04);
}

.lb-entry:first-child {
  background: rgba(241, 196, 15, 0.1);
  border: 1px solid rgba(241, 196, 15, 0.2);
}

.lb-rank {
  font-weight: 700;
  width: 32px;
  font-size: 16px;
  color: #888;
}

.lb-entry:nth-child(1) .lb-rank { color: #f1c40f; }
.lb-entry:nth-child(2) .lb-rank { color: #bdc3c7; }
.lb-entry:nth-child(3) .lb-rank { color: #cd7f32; }

.lb-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-family: 'Russo One', sans-serif;
  color: #e74c3c;
  font-size: 17px;
  margin-left: 8px;
}

#btn-back {
  width: 100%;
  margin-top: 20px;
  flex-shrink: 0;
}

/* Empty leaderboard */
.lb-empty {
  text-align: center;
  color: #666;
  padding: 40px 0;
  font-size: 15px;
}

/* GUIDE SCREEN */
#guide-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgb(0 0 0 / 21%);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

#guide-content {
  width: 90%;
  max-width: 420px;
  max-height: calc(100dvh - 80px);
  background: rgba(255,255,255,0.11);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 16px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
}

#guide-scrollable {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  margin-right: -6px;
}

#guide-scrollable::-webkit-scrollbar {
  width: 6px;
  background: transparent;
}

#guide-scrollable::-webkit-scrollbar-track {
  background: transparent;
}

#guide-scrollable::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

.guide-header {
  text-align: center;
  margin-bottom: 28px;
  flex-shrink: 0;
}

.guide-header h2 {
  font-family: 'Russo One', sans-serif;
  font-size: clamp(28px, 8vw, 48px);
  color: #e74c3c;
  text-shadow: 0 0 20px rgba(231, 76, 60, 0.4), 0 3px 6px rgba(0,0,0,0.4);
  letter-spacing: 4px;
  margin-bottom: 4px;
}

.guide-subtitle {
  font-size: clamp(11px, 3vw, 15px);
  color: #aaa;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.guide-section {
  margin-bottom: 24px;
}

.guide-section-title {
  font-family: 'Russo One', sans-serif;
  font-size: 16px;
  color: #e74c3c;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(231, 76, 60, 0.3);
}

.guide-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.guide-bonus-card {
  border-color: rgba(255, 200, 50, 0.2);
  background: rgba(255, 200, 50, 0.05);
}

.guide-card-visual {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-card-visual canvas {
  display: block;
}

.guide-card.guide-card-vertical {
  flex-direction: column;
  align-items: stretch;
  text-align: center;
}

.guide-visuals-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}

.guide-visual-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.guide-visual-label {
  font-size: 10px;
  color: #aaa;
  letter-spacing: 0.5px;
}

.guide-card-info {
  flex: 1;
  min-width: 0;
}

.guide-card-name {
  font-family: 'Russo One', sans-serif;
  font-size: 15px;
  color: #fff;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.guide-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}

.tag-danger {
  background: rgba(231, 76, 60, 0.2);
  color: #e74c3c;
}

.tag-obstacle {
  background: rgba(241, 196, 15, 0.15);
  color: #f1c40f;
}

.tag-bonus {
  background: rgba(46, 204, 113, 0.15);
  color: #2ecc71;
}

.guide-card-desc {
  font-size: 13px;
  color: #bbb;
  line-height: 1.5;
}

.guide-card-tip {
  font-size: 12px;
  color: #e74c3c;
  margin-top: 4px;
  font-weight: 600;
}

#btn-guide-back {
  width: 100%;
  max-width: 280px;
  margin: 24px auto 0;
  display: flex;
  flex-shrink: 0;
}

/* Small phones (SE, etc) */
@media screen and (max-height: 600px) {
  #game-title {
    font-size: clamp(32px, 10vw, 52px);
  }
  #game-subtitle {
    margin-bottom: 10px;
    font-size: 11px;
  }
  #top3-container {
    padding: 10px 16px;
    margin-bottom: 12px;
  }
  .top3-entry {
    padding: 3px 0;
    font-size: 14px;
  }
  #splash-buttons {
    gap: 8px;
  }
  .btn {
    padding: 12px 24px;
    font-size: 14px;
  }
  #gameover-content {
    padding: 20px 18px;
  }
  #gameover-content h2 {
    font-size: 24px;
  }
}

/* Landscape mode adjustments */
@media screen and (orientation: landscape) and (max-height: 500px) {

  /* ---- SPLASH ---- */
  #splash-overlay {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: center;
    justify-items: center;
    align-items: center;
    align-content: center;
    gap: 0 24px;
    padding: 8px calc(24px + var(--sar)) 8px calc(24px + var(--sal));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #game-title {
    grid-column: 1 / -1;
    font-size: clamp(24px, 8vh, 36px);
    text-align: center;
    margin-bottom: 0;
    letter-spacing: 4px;
  }

  #game-subtitle {
    grid-column: 1 / -1;
    font-size: 10px;
    margin-bottom: 4px;
    margin-top: 0;
  }

  #btn-legende {
    grid-column: 1 / -1;
    width: auto;
    text-align: center;
    font-size: 11px;
    padding: 4px 12px;
    margin: 6px 0 12px 0;
  }

  #top3-container {
    grid-column: 1;
    margin-bottom: 0;
    max-width: 280px;
    padding: 8px 14px;
  }

  #top3-container h3 {
    font-size: 10px;
    margin-bottom: 4px;
  }

  .top3-entry {
    padding: 2px 0;
    font-size: 13px;
  }

  #splash-buttons {
    grid-column: 2;
    width: auto;
    gap: 6px;
  }

  #splash-buttons .btn {
    padding: 8px 20px;
    font-size: 13px;
    min-height: 36px;
  }

  #copyright-text {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 9px;
    margin-top: 2px;
  }

  /* ---- GAMEOVER POPUP ---- */
  #gameover-popup {
    padding: 8px calc(8px + var(--sar)) 8px calc(8px + var(--sal));
  }

  #gameover-content {
    padding: 16px 24px;
    max-width: 70%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  #gameover-content h2 {
    width: 100%;
    font-size: 22px;
    margin-bottom: 2px;
  }

  #final-score-text {
    font-size: 14px;
    margin-bottom: 2px;
    width: 100%;
  }

  #final-rank-text {
    font-size: 11px;
    margin-bottom: 4px;
    width: 100%;
  }

  #final-score {
    font-size: 20px;
  }

  #gameover-form {
    display: contents;
  }

  #username-display-row {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 2px;
  }

  #username-input {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 0;
  }

  #gameover-buttons {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    column-gap: 8px;
    row-gap: 8px;
    align-items: stretch;
  }

  #gameover-buttons .btn.btn-secondary,
  #btn-back-home {
    flex: 1;
    padding: 0 12px;
    font-size: 12px;
    min-height: 40px;
    height: 40px;
    margin-top: 0;
    text-decoration: none;
    background: rgba(200,200,200,0.15);
    color: #ddd;
    border: 1px solid rgba(255,255,255,0.2);
  }

  #gameover-buttons .btn.btn-primary {
    flex: 1;
    padding: 0 12px;
    font-size: 12px;
    min-height: 40px;
    height: 40px;
    margin-top: 0;
  }

  #btn-back-home {
    flex-basis: auto;
  }

  #gameover-buttons.no-envoyer {
    height: auto;
    flex-wrap: nowrap;
  }

  #gameover-buttons.no-envoyer #btn-back-home,
  #gameover-buttons.no-envoyer #btn-replay {
    min-height: 40px;
    height: 40px !important;
  }


  /* Hard lock: same button size/alignment in landscape for visible gameover buttons */
  #gameover-buttons > #btn-submit-score,
  #gameover-buttons > #btn-replay,
  #gameover-buttons > #btn-back-home {
    flex: 1 1 0 !important;
    flex-basis: 0 !important;
    width: 0 !important;
    max-width: none !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 12px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    align-items: center !important;
    justify-content: center !important;
  }


  /* no-envoyer: keep 2 buttons compact (same visual size as 3-button mode), centered */
  #gameover-buttons.no-envoyer {
    justify-content: center;
  }
  #gameover-buttons.no-envoyer > #btn-replay,
  #gameover-buttons.no-envoyer > #btn-back-home {
    flex: 0 0 calc((100% - 16px) / 3) !important;
    width: calc((100% - 16px) / 3) !important;
    max-width: calc((100% - 16px) / 3) !important;
  }


  /* GAMEOVER landscape: force portrait design */
  #gameover-content {
    background: rgba(255,255,255,0.11);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 16px;
    padding: 28px 24px;
    text-align: center;
    width: 90%;
    max-width: 360px;
    display: block;
    gap: 0;
  }

  #gameover-content h2 {
    width: auto;
    font-size: 28px;
    margin-bottom: 6px;
  }

  #final-score-text {
    width: auto;
    font-size: 16px;
    margin-bottom: 4px;
  }

  #final-rank-text {
    width: auto;
    font-size: 13px;
    margin-bottom: 16px;
  }

  #final-score {
    font-size: 26px;
  }

  #username-display-row {
    width: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
  }

  #username-input {
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 14px;
  }

  #gameover-buttons {
    width: auto;
    display: flex;
    flex-wrap: wrap;
    column-gap: 10px;
    row-gap: 10px;
    align-items: stretch;
    justify-content: initial;
  }

  #gameover-buttons .btn {
    flex: 1;
    padding: 0 12px;
    font-size: 13px;
    min-height: 50px;
    height: 50px;
    box-sizing: border-box;
  }

  #btn-back-home {
    flex-basis: 100%;
    margin: 0;
    width: auto;
    display: flex;
  }

  #gameover-buttons.no-envoyer {
    height: auto;
    flex-wrap: wrap;
    justify-content: initial;
  }

  #gameover-buttons.no-envoyer #btn-back-home,
  #gameover-buttons.no-envoyer #btn-replay {
    flex: 1 1 0% !important;
    width: auto !important;
    max-width: none !important;
    min-height: 50px !important;
    height: 50px !important;
  }


  /* Final decision: portrait-like gameover layout in landscape */
  #gameover-buttons {
    display: flex !important;
    flex-wrap: wrap !important;
    column-gap: 10px !important;
    row-gap: 10px !important;
    justify-content: initial !important;
    align-items: stretch !important;
  }

  #gameover-buttons > #btn-submit-score,
  #gameover-buttons > #btn-replay,
  #gameover-buttons > #btn-back-home {
    min-height: 50px !important;
    height: 50px !important;
    padding: 0 12px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  /* 3 buttons: Envoyer + Rejouer on first row, Accueil full-width second row */
  #gameover-buttons > #btn-submit-score,
  #gameover-buttons > #btn-replay {
    flex: 1 1 0% !important;
    flex-basis: 0 !important;
    width: auto !important;
    max-width: none !important;
  }
  #gameover-buttons > #btn-back-home {
    flex: 1 1 100% !important;
    flex-basis: 100% !important;
    width: 100% !important;
    max-width: none !important;
  }

  /* no-envoyer: keep exactly two equal buttons on one row */
  #gameover-buttons.no-envoyer > #btn-replay,
  #gameover-buttons.no-envoyer > #btn-back-home {
    flex: 1 1 0% !important;
    flex-basis: 0 !important;
    width: auto !important;
    max-width: none !important;
  }

  /* ---- LEADERBOARD ---- */
  #leaderboard-screen {
    padding: 8px calc(8px + var(--sar)) 8px calc(8px + var(--sal));
  }

  #leaderboard-content {
    padding: 16px;
    margin: auto;
    max-width: 60%;
    height: calc(100dvh - 40px);
    max-height: none;
    overflow: hidden;
  }

  #leaderboard-content h2 {
    font-size: 20px;
    margin-bottom: 10px;
  }

  .lb-entry {
    padding: 6px 10px;
    font-size: 13px;
    margin-bottom: 2px;
  }

  #btn-back {
    margin-top: 12px;
    padding: 10px 16px;
    font-size: 13px;
    min-height: 38px;
  }

  /* ---- GUIDE ---- */
  #guide-screen {
    padding: 8px calc(8px + var(--sar)) 8px calc(8px + var(--sal));
  }

  #guide-content {
    padding: 16px;
    margin: auto;
    max-width: 90%;
    height: calc(100dvh - 40px);
    max-height: none;
    overflow: hidden;
  }

  .guide-header {
    margin-bottom: 16px;
  }

  .guide-header h2 {
    font-size: clamp(24px, 6vh, 36px);
  }

  .guide-section {
    margin-bottom: 16px;
  }

  .guide-section-title {
    font-size: 13px;
    margin-bottom: 10px;
  }

  .guide-card {
    padding: 10px;
    margin-bottom: 8px;
    gap: 12px;
  }

  .guide-card-visual {
    width: 60px;
    height: 60px;
  }

  .guide-card-name {
    font-size: 13px;
  }

  .guide-card-desc {
    font-size: 12px;
  }

  .guide-card-tip {
    font-size: 11px;
  }

  #btn-guide-back {
    margin-top: 16px;
    padding: 10px 16px;
    font-size: 13px;
    min-height: 38px;
  }
}

/* ============================================================
   OPTIONS SCREEN
   ============================================================ */
#options-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgb(0 0 0 / 21%);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

#options-content {
  width: 90%;
  max-width: 420px;
  max-height: calc(100dvh - 80px);
  background: rgba(255,255,255,0.11);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 16px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
}

#options-title {
  font-family: 'Russo One', sans-serif;
  font-size: 26px;
  color: #e74c3c;
  text-align: center;
  margin-bottom: 20px;
  flex-shrink: 0;
}

#options-scrollable {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  margin-right: -6px;
}

#options-scrollable::-webkit-scrollbar { width: 6px; background: transparent; }
#options-scrollable::-webkit-scrollbar-track { background: transparent; }
#options-scrollable::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

.options-section {
  margin-bottom: 24px;
}

.options-section-title {
  font-family: 'Russo One', sans-serif;
  font-size: 13px;
  color: #e74c3c;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(231, 76, 60, 0.25);
}

.options-cards-row {
  display: flex;
  gap: 12px;
}

.options-card {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
  overflow: hidden;
}

.options-card:active:not(.options-card-locked) {
  transform: scale(0.97);
}

.options-card.selected {
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.08);
}

.options-card-locked {
  cursor: default;
  pointer-events: none;
  opacity: 0.6;
}

.options-map-preview {
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 6px;
  display: block;
}

.options-char-preview {
  width: 100%;
  aspect-ratio: 5/3;
  border-radius: 6px;
  display: block;
}

.options-card-label {
  font-family: 'Russo One', sans-serif;
  font-size: 11px;
  color: #ddd;
  letter-spacing: 1px;
  text-align: center;
}

.options-card-sub {
  font-size: 10px;
  color: #bbb;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.options-card-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 4px;
  padding: 2px 7px;
}

.options-card-selected-badge {
  display: none;
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.15);
}

.options-card.selected .options-card-selected-badge {
  display: block;
}

.options-card-locked-badge {
  display: block;
  color: #f0c040;
  background: rgba(100, 80, 10, 0.5);
  border: 1px solid rgba(240, 192, 64, 0.3);
}

#btn-options-back {
  width: 100%;
  max-width: 280px;
  margin: 20px auto 0;
  display: flex;
  flex-shrink: 0;
}

html.pwa-standalone #options-content {
  max-height: calc(100dvh - var(--sat) - 60px);
}

/* ============================================================
   MAP INTRO OVERLAY
   ============================================================ */
#map-intro {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 10, 25, 0.60);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.75s ease;
}
#map-intro.visible {
  opacity: 1;
  pointer-events: all;
}
#map-intro-inner {
  text-align: center;
  transform: translateY(8px);
  opacity: 0;
  transition: opacity 0.5s ease 0.1s, transform 0.5s ease 0.1s;
}
#map-intro.visible #map-intro-inner {
  opacity: 1;
  transform: translateY(0);
}
#map-intro-label {
  font-family: 'Inter', sans-serif;
  font-size: clamp(11px, 2.5vw, 14px);
  color: rgba(255,255,255,0.5);
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
#map-intro-name {
  font-family: 'Russo One', sans-serif;
  font-size: clamp(52px, 14vw, 100px);
  color: #fff;
  letter-spacing: 10px;
  text-shadow:
    0 0 60px rgba(231, 76, 60, 0.7),
    0 0 20px rgba(231, 76, 60, 0.4),
    0 3px 12px rgba(0,0,0,0.9);
}
.map-intro-stoneham #map-intro-name {
  text-shadow:
    0 0 60px rgba(74, 154, 220, 0.75),
    0 0 20px rgba(26, 74, 122, 0.50),
    0 3px 12px rgba(0,0,0,0.9);
}

/* ============================================================
   MAP STONEHAM — dark semi-transparent overrides (light sky)
   ============================================================ */
body.map-stoneham #btn-legende,
body.map-stoneham #top3-container,
body.map-stoneham .btn-secondary,
body.map-stoneham .btn-link,
body.map-stoneham #gameover-content,
body.map-stoneham #leaderboard-content,
body.map-stoneham #guide-content,
body.map-stoneham #options-content {
  background: rgba(15,20,35,0.38) !important;
}

body.map-stoneham #gameover-content,
body.map-stoneham #leaderboard-content,
body.map-stoneham #guide-content,
body.map-stoneham #options-content {
  background: rgba(15,20,35,0.52) !important;
}

body.map-stoneham #gameover-popup {
  background: rgba(0,0,0,0.32);
}
