:root {
  --cream: #FFF6E9;
  --yellow: #FFC93C;
  --sky: #4FB8E8;
  --pink: #FF6F91;
  --green: #58C97B;
  --ink: #2E2A4D;
  --white: #FFFFFF;
  --red: #E85757;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Quicksand', sans-serif;
  font-weight: 600;
  min-height: 100vh;
  padding-bottom: 3rem;
}

.back-link {
  display: inline-block;
  margin: 1.4rem 0 0 1.6rem;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  color: var(--sky);
  text-decoration: none;
  font-size: 1rem;
}
.back-link:hover { text-decoration: underline; }

.game-header {
  text-align: center;
  padding: 1.2rem 1.5rem .5rem;
}
.game-header h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  margin: 0 0 .4rem;
}
.game-header p { color: #6a6486; margin: 0; }

/* ---------- Sélecteur de continent ---------- */
.continent-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1.2rem;
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}
.continent-btn {
  --c1: var(--sky);
  --c2: var(--pink);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  background: var(--white);
  border: none;
  border-radius: 26px;
  padding: 1.5rem 1rem 1.3rem;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.15;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(46,42,77,0.1);
  transition: transform .2s ease, box-shadow .2s ease;
}
/* Bandeau coloré en haut de la carte, aux couleurs du continent */
.continent-btn::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 58%;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  opacity: .18;
  border-radius: 0 0 50% 50% / 0 0 22% 22%;
  transition: opacity .2s ease;
}
.continent-btn > * { position: relative; }
.continent-btn:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 0 rgba(46,42,77,0.08), 0 14px 30px color-mix(in srgb, var(--c2) 35%, transparent);
}
.continent-btn:hover::before { opacity: .32; }
.continent-btn:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(46,42,77,0.1); }

.continent-icon {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  /* En attendant le chargement de la carte : un globe coloré vide */
  background: radial-gradient(circle at 32% 28%, var(--c1), var(--c2));
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--c2) 25%, transparent);
  animation: globeFloat 4s ease-in-out infinite;
}
.continent-icon.ready {
  background: none;
  box-shadow: none;
}
.continent-btn:nth-child(2) .continent-icon { animation-delay: -.8s; }
.continent-btn:nth-child(3) .continent-icon { animation-delay: -1.6s; }
.continent-btn:nth-child(4) .continent-icon { animation-delay: -2.4s; }
.continent-btn:nth-child(5) .continent-icon { animation-delay: -3.2s; }
.globe-icon {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.globe-halo { opacity: .25; transition: opacity .2s ease; }
.continent-btn:hover .globe-icon { transform: scale(1.1) rotate(-8deg); }
.continent-btn:hover .globe-halo { opacity: .45; }
@keyframes globeFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
@media (prefers-reduced-motion: reduce) {
  .continent-icon { animation: none; }
}

.continent-count {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: .78rem;
  color: var(--white);
  background: linear-gradient(135deg, var(--c1), var(--c2));
  padding: .15rem .7rem;
  border-radius: 999px;
  white-space: nowrap;
}

.loading-note {
  text-align: center;
  color: #9089a8;
  font-family: 'Baloo 2', sans-serif;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1.2rem auto 1.6rem;
  font-family: 'Baloo 2', sans-serif;
  max-width: 900px;
  padding: 0 1rem;
}
.hud-item {
  background: var(--white);
  padding: .5rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(46,42,77,0.08);
  white-space: nowrap;
}
#restart, .ghost-btn-outline {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  border: none;
  padding: .5rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
#restart {
  background: var(--pink);
  color: var(--white);
  box-shadow: 0 5px 0 #c94f6e;
}
#restart:hover { transform: translateY(2px); box-shadow: 0 3px 0 #c94f6e; }
.ghost-btn-outline {
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(46,42,77,0.08);
}
.ghost-btn-outline:hover { transform: translateY(2px); }

/* ---------- Layout de jeu ---------- */
.game-layout {
  display: flex;
  gap: 1.2rem;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 1rem;
  align-items: flex-start;
}

.map-wrap {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
}
.map-container {
  background: var(--white);
  border-radius: 24px;
  box-shadow: 0 6px 0 rgba(46,42,77,0.08);
  padding: .6rem;
  overflow: hidden;
}
.map-container svg {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 110px);
  display: block;
  touch-action: none;
  cursor: grab;
  border-radius: 16px;
}
.map-sea { fill: #E4F4FC; }

.zoom-controls {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.zoom-controls button {
  width: 2.3rem;
  height: 2.3rem;
  border: none;
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(46,42,77,0.15);
}
.zoom-controls button:hover { background: var(--cream); }
.map-hint {
  font-size: .8rem;
  color: #9089a8;
  text-align: center;
  margin: .6rem 0 0;
}
.legend-chosen {
  display: inline-block;
  width: .9em;
  height: .9em;
  vertical-align: -.1em;
  border-radius: 3px;
  background: #FFD35C;
  border: 2px solid #D9820B;
}

.country-context {
  fill: #D9D4E4;
  stroke: var(--white);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.country-target {
  fill: var(--cream);
  stroke: #E0A82E;
  stroke-width: 1.3;
  stroke-dasharray: 4 2;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill .2s ease, stroke .2s ease;
}
/* Pays qui ne sont pas à trouver dans cette partie : discrets, en arrière-plan */
.country-target.is-other {
  fill: #EEEAF3;
  stroke: #FFFFFF;
  stroke-width: 1;
  stroke-dasharray: none;
  cursor: default;
}
/* Les 10 pays tirés au sort : bien visibles, avec une douce pulsation */
.country-target.is-chosen {
  fill: #FFD35C;
  stroke: #D9820B;
  stroke-width: 2;
  stroke-dasharray: none;
  animation: chosenPulse 2.2s ease-in-out infinite;
}
@keyframes chosenPulse {
  0%, 100% { fill: #FFD35C; }
  50%      { fill: #FFE8A3; }
}
@media (prefers-reduced-motion: reduce) {
  .country-target.is-chosen { animation: none; }
}

/* (les règles suivantes coupent la pulsation, sinon elle écraserait la couleur) */
.country-target.drag-over,
.country-target.is-chosen.drag-over {
  fill: #BFE7FA;
  stroke: var(--sky);
  stroke-width: 2.5;
  animation: none;
}
.country-target.placed,
.country-target.is-chosen.placed {
  fill: #BDEBC9;
  stroke: var(--green);
  stroke-width: 2;
  stroke-dasharray: none;
  pointer-events: none;
  animation: none;
}
.country-target.shake-wrong,
.country-target.is-chosen.shake-wrong {
  animation: mapShake .4s ease;
}
@keyframes mapShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.placed-flag { pointer-events: none; }

/* ---------- Drapeaux à placer ---------- */
.chips-col {
  flex: 0 0 280px;
  position: sticky;
  top: 1rem;
}
.chips-panel {
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding: .2rem .4rem .6rem .2rem;
}
.chips-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.05rem;
  text-align: center;
  margin: 0 0 .8rem;
}
.chips-panel {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--white);
  border-radius: 14px;
  padding: .55rem .7rem;
  box-shadow: 0 4px 0 rgba(46,42,77,0.08);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: opacity .2s ease, transform .2s ease;
}
.chip .fi {
  width: 28px;
  height: 21px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(46,42,77,0.1);
}
.chip span.chip-name {
  font-size: .85rem;
  font-weight: 700;
}
.chip.placed {
  opacity: .35;
  cursor: default;
  pointer-events: none;
}
.chip.dragging-source {
  opacity: .3;
}
.chip.wrong-shake {
  animation: chipShake .4s ease;
}
@keyframes chipShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Clone flottant qui suit le doigt / la souris pendant le glisser */
.chip-ghost {
  position: fixed;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--white);
  border-radius: 14px;
  padding: .5rem .8rem;
  box-shadow: 0 8px 20px rgba(46,42,77,0.25);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.05);
}
.chip-ghost .fi {
  width: 30px;
  height: 22px;
  border-radius: 4px;
}

/* ---------- Classement ---------- */
.leaderboards {
  max-width: 1100px;
  margin: 1rem auto 2rem;
  padding: 0 1.5rem;
}
.leaderboards-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.4rem;
  margin: 0 0 .2rem;
  text-align: center;
}
.leaderboards-sub {
  font-size: .8rem;
  color: #9089a8;
  text-align: center;
  margin: 0 0 1rem;
}
.leaderboards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.2rem;
}
.leaderboard {
  margin: 0;
  background: var(--white);
  border-radius: 22px;
  padding: 1.2rem 1.1rem;
  box-shadow: 0 6px 0 rgba(46,42,77,0.08);
}
.leaderboard h3 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.15rem;
  margin: 0 0 .2rem;
  text-align: center;
}
.leaderboard-sub {
  font-size: .75rem;
  color: #9089a8;
  text-align: center;
  margin: 0 0 .9rem;
}
.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  max-height: 420px;
  overflow-y: auto;
}
.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  background: var(--cream);
  border-radius: 10px;
  padding: .4rem .6rem;
}
.leaderboard-list li .rank {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  color: var(--sky);
  width: 1.4rem;
  flex-shrink: 0;
}
.leaderboard-list li:nth-child(1) .rank { color: #E8B923; }
.leaderboard-list li:nth-child(2) .rank { color: #9AA0A6; }
.leaderboard-list li:nth-child(3) .rank { color: #C97A3C; }
.leaderboard-list li .lb-name {
  flex: 1;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-list li .lb-time {
  font-variant-numeric: tabular-nums;
  color: #6a6486;
}
.leaderboard-empty {
  text-align: center;
  font-size: .85rem;
  color: #9089a8;
  padding: 1rem 0;
}
.leaderboard-note {
  margin: .9rem 0 0;
  padding-top: .8rem;
  border-top: 1px dashed #EFEAF6;
  font-size: .72rem;
  line-height: 1.4;
  color: #9089a8;
  text-align: center;
}

@media (max-width: 900px) {
  .game-layout { flex-direction: column; align-items: stretch; }
  .map-wrap, .chips-col { flex: none; width: 100%; }
  .chips-col { position: static; }
  .chips-panel {
    max-height: 40vh;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .leaderboard-list { max-height: 220px; }
  .map-container svg { max-height: 70vh; }
}

/* ---------- Overlays partagés (victoire) ---------- */
.win-banner {
  position: fixed;
  inset: 0;
  background: rgba(46,42,77,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 1rem;
}
.win-banner.show { display: flex; }
.win-card {
  background: var(--white);
  border-radius: 28px;
  padding: 2.2rem 2.4rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 14px 0 rgba(46,42,77,0.12);
}
.win-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.5rem;
  margin: 0 0 .5rem;
  color: var(--pink);
}
#winTime {
  font-family: 'Baloo 2', sans-serif;
  color: #6a6486;
  margin: 0 0 1.1rem;
}
.score-label {
  display: block;
  font-size: .85rem;
  color: #6a6486;
  margin-bottom: .5rem;
}
#pseudoInput {
  width: 100%;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  padding: .6rem .8rem;
  border: 2px solid #EFEAF6;
  border-radius: 12px;
  margin-bottom: .8rem;
  text-align: center;
}
#pseudoInput:focus { outline: none; border-color: var(--sky); }
.score-actions {
  display: flex;
  gap: .6rem;
  justify-content: center;
  margin-bottom: .4rem;
}
#saveScore {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: var(--sky);
  color: var(--white);
  border: none;
  padding: .6rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 5px 0 #2f8fb8;
  cursor: pointer;
  font-size: .9rem;
}
.ghost-btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: transparent;
  color: #9089a8;
  border: none;
  padding: .6rem .8rem;
  cursor: pointer;
  font-size: .9rem;
}
.score-saved {
  display: none;
  font-family: 'Baloo 2', sans-serif;
  color: var(--green);
  margin: .4rem 0 .8rem;
}
#playAgain {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: var(--green);
  color: var(--white);
  border: none;
  padding: .7rem 1.6rem;
  border-radius: 999px;
  box-shadow: 0 5px 0 #3a9c58;
  cursor: pointer;
  margin-top: .6rem;
}

/* ---------- Confettis ---------- */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  font-size: 1.4rem;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: .9; }
}
