/* ═══════════════ GéoQuiz — thème sombre ═══════════════ */
:root {
  --bg: #0b1220;
  --panel: #121c2f;
  --panel-2: #0e1626;
  --line: #233457;
  --text: #e8eef7;
  --muted: #8fa3c0;
  --accent: #4f8ef7;
  --accent-soft: rgba(79, 142, 247, 0.15);
  --good: #2dd4a7;
  --bad: #ff6b6b;
  --gold: #f0b429;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  /* Pas de flash bleu d'Android sur chaque élément touché : chaque bouton a
     son propre retour (:active, couleurs). */
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(1200px 700px at 75% -10%, #16233d 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  /* Pas de délai de double-tap sur les boutons. */
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hidden { display: none !important; }

/* ═══════════════ Bandeau de mise à jour ═══════════════ */
/* Calé à gauche pour ne pas passer sous le sélecteur de langue. */
.update-banner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 14px;
  z-index: 60;
  max-width: min(430px, calc(100vw - 140px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 14px;
  background: #1c2b47;
  border: 1px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  animation: slide-in 0.28s ease-out;
}
.update-text { font-size: 0.9rem; font-weight: 600; }
.update-banner .btn-primary { padding: 7px 13px; font-size: 0.85rem; white-space: nowrap; }
.update-close {
  color: var(--muted);
  font-size: 0.95rem;
  padding: 2px 4px;
  line-height: 1;
}
@media (hover: hover) { .update-close:hover { color: var(--text); } }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: none; }
}

/* ═══════════════ Sélecteur de langue ═══════════════ */
.lang-switch {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 50;
  display: flex;
  gap: 10px;
  padding: 8px;
  background: #1c2b47;
  border: 1px solid #3a5583;
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}
.lang-switch button {
  padding: 7px 9px;
  border-radius: 11px;
  background: transparent;
  border: 2px solid transparent;
  opacity: 0.55;
  transition: opacity 0.15s, border-color 0.15s, background 0.15s, transform 0.1s;
}
.lang-switch button img {
  width: 46px;
  height: 31px;
  object-fit: cover;
  border-radius: 5px;
  display: block;
}
@media (hover: hover) { .lang-switch button:hover { opacity: 1; transform: translateY(-1px); border-color: var(--accent); } }
.lang-switch button.active {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.25);
}

.screen { min-height: 100vh; display: flex; flex-direction: column; }

/* ═══════════════ Boutons génériques ═══════════════ */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #3b6fd4);
  color: #fff;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: var(--radius);
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 18px rgba(79, 142, 247, 0.35);
}
@media (hover: hover) { .btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(79, 142, 247, 0.5); } }
.btn-big { font-size: 1.15rem; padding: 14px 34px; }

.btn-ghost {
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: var(--radius);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
@media (hover: hover) { .btn-ghost:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); } }

/* ═══════════════ Menu ═══════════════ */
.menu-wrap {
  width: min(880px, 100% - 32px);
  margin: 0 auto;
  padding: 48px 0 64px;
}

.logo { font-size: 2.6rem; letter-spacing: -1px; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); margin: 6px 0 34px; font-size: 1.05rem; }

.menu-section {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 26px 0 12px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 14px;
  transition: border-color 0.15s, transform 0.12s, background 0.15s;
}
@media (hover: hover) { .mode-card:hover { transform: translateY(-3px); border-color: #3a5583; } }
.mode-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.mode-icon { font-size: 1.7rem; }
.mode-label { font-weight: 700; }
.mode-desc { font-size: 0.82rem; color: var(--muted); }

.chip-row { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}
@media (hover: hover) { .chip:hover { border-color: #3a5583; } }
.chip.selected { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.menu-footer {
  margin-top: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.menu-pool { color: var(--muted); font-size: 0.92rem; }
.menu-record { color: var(--gold); font-size: 0.98rem; margin-top: 2px; }

/* ═══════════════ Écran de jeu ═══════════════ */
#screen-game { height: 100vh; }

.game-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.game-mode-label { font-weight: 600; color: var(--muted); flex: 1; }

.game-stats { display: flex; gap: 26px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 58px; }
.stat-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat-value { font-size: 1.12rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.progress-bar { height: 4px; background: var(--panel); }
#progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width 0.4s ease;
}

.game-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
  padding: 14px;
}

.question-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

/* Modes sans carte : panneau centré plus large */
.game-layout.no-map { justify-content: center; }
.game-layout.no-map .map-wrap { display: none; }
.game-layout.no-map .question-panel { width: min(620px, 100%); }

.q-instruction { color: var(--muted); font-size: 1rem; }

.target-name { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.5px; }

.target-flag {
  width: min(240px, 100%);
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 8px;
  display: block;
}

.shape-svg {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.shape-path { fill: #6f8fc2; stroke: #a9c4ef; stroke-width: 0.6; }

/* Options — drapeaux et noms */
.q-options { display: grid; gap: 10px; }
.q-options.grid-flags { grid-template-columns: repeat(2, 1fr); }
.no-map .q-options.grid-flags { grid-template-columns: repeat(4, 1fr); }
.q-options.grid-names { grid-template-columns: repeat(2, 1fr); }

.flag-btn {
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 7px;
  transition: transform 0.1s, border-color 0.15s, opacity 0.2s;
}
.flag-btn img { width: 100%; aspect-ratio: 3 / 2; object-fit: contain; display: block; }
@media (hover: hover) { .flag-btn:hover { transform: translateY(-2px); border-color: var(--accent); } }

.name-btn {
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 10px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: transform 0.1s, border-color 0.15s, opacity 0.2s;
}
@media (hover: hover) { .name-btn:hover { transform: translateY(-2px); border-color: var(--accent); } }

.flag-btn.wrong, .name-btn.wrong {
  opacity: 0.3;
  pointer-events: none;
  border-color: var(--bad);
  animation: shake 0.3s;
}
.flag-btn.correct, .name-btn.correct {
  border-color: var(--good);
  box-shadow: 0 0 0 3px rgba(45, 212, 167, 0.3);
}
.flag-btn.faded, .name-btn.faded { opacity: 0.25; pointer-events: none; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Mode saisie libre */
.type-form { display: flex; gap: 10px; }
.type-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: #fff;
  color: #0b1220;
  font: inherit;
  font-weight: 600;
}
.type-input::placeholder { color: #7c8aa0; font-weight: 400; }
.type-input:focus { outline: none; border-color: var(--accent); }
.type-input:disabled { background: #cfe8dc; border-color: var(--good); }

.q-feedback { min-height: 1.5em; font-weight: 600; }
.q-feedback.good { color: var(--good); }
.q-feedback.bad { color: var(--bad); }

.q-actions { margin-top: auto; display: flex; justify-content: flex-end; }

/* ═══════════════ Carte ═══════════════ */
.map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(900px 500px at 50% 40%, #10203a 0%, #0a1526 75%),
    var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
#map-svg { width: 100%; height: 100%; display: block; cursor: grab; }
#map-svg:active { cursor: grabbing; }

.country {
  fill: #26374f;
  stroke: #0b1220;
  /* Épaisseur en pixels d'écran, quel que soit le zoom : rien à recalculer
     pendant le geste. Trait plus marqué sur petit écran. */
  stroke-width: 0.45px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill 0.12s;
}
@media (max-width: 619px) { .country { stroke-width: 0.75px; } }
@media (hover: hover) { .country:hover { fill: #3b5c8f; } }
.map-disabled .country { cursor: default; }
@media (hover: hover) { .map-disabled .country:hover { fill: #26374f; } }

.country.found { fill: #1d6f52; }
@media (hover: hover) { .country.found:hover { fill: #279670; } }
.country.wrong { fill: #d64545 !important; }
.country.revealed { animation: pulse-target 0.55s ease-in-out 5 alternate; fill: var(--gold); }

@keyframes pulse-target {
  from { fill: var(--gold); }
  to { fill: #8a5f00; }
}

.map-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.map-controls button {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 1.15rem;
  transition: border-color 0.12s, background 0.12s;
}
@media (hover: hover) { .map-controls button:hover { border-color: var(--accent); background: var(--accent-soft); } }

/* ═══════════════ Écran de fin ═══════════════ */
#screen-end { align-items: center; justify-content: center; }

.end-card {
  width: min(560px, 100% - 32px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 42px 36px;
  text-align: center;
}
.end-emoji { font-size: 3.4rem; }
#end-title { margin: 8px 0 4px; }
.end-score {
  font-size: 2.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--good));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.end-record { min-height: 1.6em; color: var(--gold); font-weight: 600; margin: 6px 0 18px; }

.end-stats {
  display: flex;
  justify-content: center;
  gap: 38px;
  margin-bottom: 30px;
}
.end-stat { display: flex; flex-direction: column; }
.end-stat-value { font-size: 1.35rem; font-weight: 700; }
.end-stat-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.end-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

/* ═══════════════ Classement en ligne ═══════════════ */
.board {
  margin: 20px 0 4px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  text-align: left;
}

.pseudo-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 9px;
}
.pseudo-row { display: flex; gap: 8px; }
.pseudo-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.pseudo-input:focus { outline: none; border-color: var(--accent); }

.board-status { font-size: 0.92rem; color: var(--muted); min-height: 1.4em; }
.board-change {
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: underline;
  padding: 0;
}

.board-list { list-style: none; margin-top: 10px; display: grid; gap: 5px; }
.board-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 0.92rem;
}
.board-row.is-me { border-color: var(--accent); background: var(--accent-soft); }
.board-pos { width: 2.1em; flex-shrink: 0; color: var(--muted); }
.board-row.is-me .board-pos { color: var(--text); }
.board-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-score { color: var(--gold); font-weight: 700; white-space: nowrap; }

/* ═══════════════ Installation de l'app ═══════════════ */
.install-row { margin-top: 18px; }
.install-ios {
  margin-top: 9px;
  padding: 10px 12px;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* ═══════════════ Accueil sur grand écran ═══════════════ */
/* Le classement passe à droite et l'espacement se resserre un peu : tout
   l'accueil, bouton Jouer compris, tient dans la hauteur d'écran sans
   défilement — sans rien rapetisser au point de gêner la lecture. */
@media (min-width: 1080px) {
  /* Assez large pour que la colonne de gauche garde les 880 px d'origine :
     en dessous, « Océanie » passait seule à la ligne. */
  .menu-wrap { width: min(1240px, 100% - 32px); padding: 34px 0 40px; }
  .logo { font-size: 2.25rem; }
  .tagline { margin-bottom: 22px; }
  .menu-section { margin: 20px 0 10px; }
  .menu-footer { margin-top: 26px; }

  .menu-cols {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 36px;
    align-items: start;
  }
  /* Placement explicite : le bouton d'installation se loge sous le
     classement, dans la place libre, sans rallonger la page. */
  .menu-main { grid-column: 1; grid-row: 1 / span 2; }
  #menu-board-wrap { grid-column: 2; grid-row: 1; width: 310px; }
  #install-row { grid-column: 2; grid-row: 2; width: 310px; margin-top: 16px; }
}

/* Fenêtre moins haute (portable, barre de favoris, barre des tâches) :
   on resserre encore pour que le bouton Jouer reste au-dessus de la ligne
   de flottaison. Mesuré : ~800 px de contenu au lieu de ~900. */
@media (min-width: 1080px) and (max-height: 940px) {
  .menu-wrap { padding: 22px 0 28px; }
  .logo { font-size: 2rem; }
  .tagline { margin-bottom: 14px; font-size: 0.98rem; }
  .menu-section { margin: 14px 0 8px; }
  .mode-card { padding: 11px 12px; }
  .mode-icon { font-size: 1.45rem; }
  .menu-footer { margin-top: 18px; }
}

/* Portable peu haut, ou écran Windows mis à l'échelle à 125 % (fenêtre CSS
   d'environ 740 px) : on ne touche plus qu'aux marges et au logo, les cartes
   de mode gardent leur confort de lecture. */
@media (min-width: 1080px) and (max-height: 800px) {
  .menu-wrap { padding: 18px 0 22px; }
  .logo { font-size: 1.85rem; }
  .tagline { margin-bottom: 10px; font-size: 0.94rem; }
  .menu-section { margin: 12px 0 7px; }
  .menu-footer { margin-top: 15px; }
}

/* ═══════════════ Responsive ═══════════════ */
@media (max-width: 900px) {
  /* Sélecteur de langue : compact et non flottant (défile avec la page). */
  .lang-switch { position: absolute; top: 10px; right: 12px; padding: 5px; gap: 6px; }
  .lang-switch button { padding: 4px 5px; border-radius: 8px; }
  .lang-switch button img { width: 30px; height: 20px; }

  /* ── Menu compact : tout choisir sans friction ──
     Cartes de mode sur 2 colonnes (icône + nom, sans description),
     régions et nombre de questions en lignes défilables, bouton Jouer
     et record dans une barre fixe toujours visible en bas. */
  .menu-wrap { padding: 14px 0 100px; }
  .logo { font-size: 1.75rem; }
  /* Accroche décorative : sur un téléphone, la hauteur va aux réglages. */
  .tagline { display: none; }
  .menu-section { margin: 11px 0 6px; }

  .mode-grid { grid-template-columns: repeat(2, 1fr); gap: 7px; }
  .mode-card { flex-direction: row; align-items: center; gap: 8px; padding: 8px 10px; }
  .mode-icon { font-size: 1.15rem; }
  .mode-label { font-size: 0.92rem; }
  .mode-desc { display: none; }

  /* Les régions passent à la ligne au lieu de défiler latéralement : sur un
     écran de 360 px, 5 régions sur 7 étaient hors champ sans aucun indice
     qu'elles existaient. */
  .chip-row { flex-wrap: wrap; gap: 7px; }
  .chip { white-space: nowrap; flex-shrink: 0; padding: 7px 13px; font-size: 0.88rem; }

  /* Classement : le podium suffit sur petit écran, le reste ferait défiler. */
  #menu-board .board-row:nth-child(n + 4) { display: none; }

  .menu-footer {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    margin-top: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(14, 22, 38, 0.94);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    flex-wrap: nowrap;
    gap: 12px;
  }
  .menu-meta { min-width: 0; }
  .menu-pool { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-record { font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .btn-big { flex-shrink: 0; font-size: 1.05rem; padding: 12px 24px; }

  /* Header : bouton + mode sur une ligne, les 4 compteurs en dessous
     (sinon Série et Temps débordent à droite sur petit écran). */
  .game-header { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; }
  .game-mode-label { font-size: 0.88rem; }
  .game-stats { width: 100%; justify-content: space-between; gap: 8px; }
  .stat { min-width: 0; }

  .game-layout { flex-direction: column; overflow-y: auto; }
  .question-panel { width: 100%; order: 0; overflow-y: visible; }
  .game-layout.no-map { justify-content: flex-start; }
  .map-wrap { order: 1; min-height: 52vh; }
  /* Frontières : trait plus contrasté sur petit écran (l'épaisseur, elle,
     est calculée en pixels réels dans map.js). */
  .country { stroke: #050a14; }
  .q-options.grid-flags { grid-template-columns: repeat(4, 1fr); }
}

/* ═══════════════ Petits pays : pastilles cliquables ═══════════════ */
/* Rayons posés par map.js (taille fixe à l'écran). La zone de toucher est
   plus large que l'anneau visible. */
.micro { cursor: pointer; }
.micro-hit { fill: transparent; pointer-events: all; }
.micro-ring {
  fill: rgba(143, 179, 230, 0.12);
  stroke: #8fb3e6;
  stroke-width: 1.2px;
  stroke-opacity: 0.75;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  transition: fill 0.12s, stroke 0.12s;
}
.map-disabled .micro { cursor: default; }
@media (hover: hover) { .micro:hover .micro-ring { fill: rgba(143, 179, 230, 0.35); stroke-opacity: 1; } }
.micro.found .micro-ring { fill: rgba(45, 212, 167, 0.45); stroke: var(--good); }
.micro.wrong .micro-ring { fill: rgba(214, 69, 69, 0.55); stroke: #ff8a8a; }
.micro.revealed .micro-ring {
  fill: rgba(240, 180, 41, 0.5);
  stroke: var(--gold);
  stroke-opacity: 1;
  animation: pulse-ring 0.55s ease-in-out 5 alternate;
}
@keyframes pulse-ring { to { stroke-opacity: 0.3; fill: rgba(240, 180, 41, 0.15); } }

/* ═══════════════ Retour au toucher ═══════════════ */
/* Sur téléphone, pas de survol : c'est l'appui qui répond. */
.flag-btn:active, .name-btn:active, .mode-card:active, .chip:active,
.btn-primary:active, .btn-ghost:active, .map-controls button:active {
  transform: scale(0.96);
  transition-duration: 0.05s;
}

/* Après une réponse, le panneau de question se touche pour passer à la suite. */
.question-panel { cursor: default; }

/* ═══════════════ Moins d'animations si l'appareil le demande ═══════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
