﻿: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: .8rem 1.5rem .2rem;
}
.game-header h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  margin: 0 0 .3rem;
}
.game-header p { color: #6a6486; margin: 0; }

/* Pendant la partie, l'en-tête se fait tout petit pour laisser la place au plateau */
body.playing .back-link { margin-top: .7rem; }
body.playing .game-header { display: none; }
body.playing .hud { margin: -.4rem auto .6rem; }
body.playing .stage { width: min(100%, 1150px, max(500px, calc(100vh - 175px))); }

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

/* ---------- Question + compte à rebours (reste visible en haut) ---------- */
.question {
  position: sticky;
  top: .5rem;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: fit-content;
  max-width: calc(100% - 2rem);
  margin: 0 auto 1rem;
  padding: .5rem 1.6rem .5rem .6rem;
  background: var(--white);
  border-radius: 999px;
  box-shadow: 0 6px 0 rgba(46,42,77,0.08), 0 10px 24px rgba(46,42,77,0.08);
}
.question.pop { animation: questionPop .35s ease; }
@keyframes questionPop {
  0% { transform: scale(.92); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.question-text {
  margin: 0;
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 700;
  line-height: 1.1;
}
.question-text strong {
  color: var(--pink);
  font-weight: 800;
}

.countdown {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}
.countdown svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.countdown-track {
  fill: #FFF6E9;
  stroke: #EFEAF6;
  stroke-width: 9;
}
.countdown-ring {
  fill: none;
  stroke: var(--green);
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke .3s ease;
}
.countdown span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.7rem;
  color: var(--ink);
}
.countdown.hurry .countdown-ring { stroke: var(--red); }
.countdown.hurry span { color: var(--red); animation: hurry .5s ease infinite alternate; }
@keyframes hurry { to { transform: scale(1.15); } }

/* ---------- Plateau carré (6 x 6 pour les communs, 5 x 5 pour les rares) ---------- */
.game-layout {
  display: flex;
  gap: 1.4rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1rem;
  align-items: flex-start;
  justify-content: center;
}
.stage {
  position: relative;
  flex: 0 1 auto;
  /* le plateau tient dans l'écran sous la question (sans devenir minuscule) */
  width: min(100%, 1150px, max(500px, calc(100vh - 330px)));
}
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 6), 1fr);
  /* animaux bien espacés, pour qu'on les distingue facilement */
  gap: clamp(8px, 2vw, 22px);
  padding: clamp(10px, 2vw, 22px);
  background: var(--white);
  border-radius: 24px;
  box-shadow: 0 6px 0 rgba(46,42,77,0.08);
}
.tile {
  position: relative;
  aspect-ratio: 1;
  padding: 3%;
  border: none;
  border-radius: 16%;
  background: linear-gradient(160deg, #FFFDF8, #F6EFFF);
  box-shadow: inset 0 0 0 2px #F0EAF8;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease, opacity .3s ease, box-shadow .2s ease;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 2px 2px rgba(46,42,77,0.18));
}
/* Mode "animaux rares" : la photo remplit toute la case */
.grid.photos .tile { padding: 0; overflow: hidden; }
.grid.photos .tile img {
  object-fit: cover;
  border-radius: inherit;
  filter: none;
}
.grid.photos .tile.asked::after { top: 3px; right: 3px; }
.tile.no-image {
  font-family: 'Baloo 2', sans-serif;
  font-size: .7rem;
  line-height: 1;
}
.tile:hover:not(.asked) {
  transform: scale(1.05);
  z-index: 2;
  background: #FFF4D6;
  box-shadow: inset 0 0 0 3px var(--yellow), 0 6px 14px rgba(46,42,77,0.15);
}

/* Animal déjà demandé : on l'estompe pour alléger le plateau */
.tile.asked {
  cursor: default;
  opacity: .38;
}
.tile.asked::after {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 38%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--white);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: clamp(.55rem, 1.4vw, .9rem);
  line-height: 1;
}
.tile.found { background: #DDF5E4; box-shadow: inset 0 0 0 3px var(--green); }
.tile.found::after { content: "✓"; background: var(--green); }
.tile.missed { background: #FDE2E2; box-shadow: inset 0 0 0 3px #F4A3A3; }
.tile.missed::after { content: "✗"; background: var(--red); }

/* Bonne réponse : petit saut avant de s'estomper */
.tile.found:not(.reveal) { animation: foundJump .5s ease; }
@keyframes foundJump {
  0%   { transform: scale(1); opacity: 1; }
  40%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); }
}
/* Animal raté : on montre où il était */
.tile.reveal {
  opacity: 1;
  z-index: 3;
  background: #FFF4D6;
  box-shadow: inset 0 0 0 4px var(--yellow), 0 0 0 6px rgba(255,201,60,0.4);
  animation: reveal .45s ease 3 alternate;
}
@keyframes reveal { to { transform: scale(1.25); } }
/* Mauvais clic : l'animal tremble */
.tile.wrong { animation: wrongShake .45s ease; background: #FDE2E2; }
@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-4deg); }
  60% { transform: translateX(5px) rotate(4deg); }
}
@media (prefers-reduced-motion: reduce) {
  .tile.found:not(.reveal), .tile.reveal, .tile.wrong, .countdown.hurry span, .question.pop { animation: none; }
}

/* ---------- Écran de départ ---------- */
.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(255, 246, 233, 0.75);
  backdrop-filter: blur(3px);
  border-radius: 24px;
}
.start-card {
  background: var(--white);
  border-radius: 24px;
  padding: 1.4rem 1.8rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 0 rgba(46,42,77,0.1), 0 16px 40px rgba(46,42,77,0.15);
}
.start-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0 0 .6rem;
}
.how-to {
  list-style: none;
  margin: 0 0 1.1rem;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  font-size: .95rem;
}
/* Choix du mode : deux grosses cartes */
.mode-title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  margin: 0 0 .6rem;
}
.mode-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: 1rem .6rem .9rem;
  border: none;
  border-radius: 20px;
  font-family: 'Baloo 2', sans-serif;
  color: var(--ink);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.mode-communs { background: linear-gradient(160deg, #FFF4D6, #FFD98A); box-shadow: 0 6px 0 #E3B24F; }
.mode-rares   { background: linear-gradient(160deg, #E3F4FF, #9FD3F5); box-shadow: 0 6px 0 #6FA8D8; }
.mode-btn:hover:not(:disabled) { transform: translateY(-3px) rotate(-1deg); }
.mode-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(46,42,77,0.2); }
.mode-btn:disabled { opacity: .6; cursor: wait; }
.mode-btn img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px rgba(46,42,77,0.2));
}
.mode-btn img.photo {
  object-fit: cover;
  border-radius: 50%;
  border: 4px solid var(--white);
}
.mode-btn strong { font-size: 1.1rem; line-height: 1.1; }
.mode-btn small { font-family: 'Quicksand', sans-serif; font-size: .78rem; color: #5b5578; }
.loading-msg {
  margin: .8rem 0 0;
  font-family: 'Baloo 2', sans-serif;
  color: #9089a8;
}

/* ---------- Classement ---------- */
.leaderboard {
  flex: 0 0 230px;
  background: var(--white);
  border-radius: 22px;
  padding: 1.2rem 1.1rem;
  box-shadow: 0 6px 0 rgba(46,42,77,0.08);
  position: sticky;
  top: 6rem;
}
.leaderboard h2 {
  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;
}
.lb-tabs {
  display: flex;
  gap: .3rem;
  margin: 0 0 .8rem;
  padding: .25rem;
  background: var(--cream);
  border-radius: 999px;
}
.lb-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: .35rem .5rem;
  border-radius: 999px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: .85rem;
  color: #9089a8;
  cursor: pointer;
}
.lb-tab.active { background: var(--white); color: var(--ink); box-shadow: 0 2px 0 rgba(46,42,77,0.1); }
.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-list li.leaderboard-empty {
  display: block;
  background: none;
  text-align: center;
  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: 980px) {
  .game-layout { flex-direction: column; align-items: center; }
  .stage, body.playing .stage { width: min(100%, 1150px); }
  .leaderboard { position: static; flex: none; width: 100%; max-width: 560px; }
  .leaderboard-list { max-height: 220px; }
}
@media (max-width: 600px) {
  .countdown { width: 48px; height: 48px; }
  .countdown span { font-size: 1.3rem; }
  .question { gap: .6rem; padding-right: 1rem; }
  .start-card { padding: 1rem 1.1rem; }
  .start-title { font-size: 1.25rem; }
  .how-to { font-size: .82rem; }
}

/* ---------- Crédits ---------- */
.credits-link {
  max-width: 900px;
  margin: 1.6rem auto 0;
  padding: 0 1rem;
  text-align: center;
  font-size: .78rem;
  color: #9089a8;
}
.credits-link a { color: var(--sky); }
body.playing .credits-link { display: none; }
.credits-list {
  max-width: 960px;
  margin: 1.2rem auto 0;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .7rem;
}
.credit {
  display: flex;
  gap: .7rem;
  align-items: center;
  background: var(--white);
  border-radius: 16px;
  padding: .5rem;
  box-shadow: 0 4px 0 rgba(46,42,77,0.06);
  font-size: .78rem;
  color: #6a6486;
}
.credit img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
  flex-shrink: 0;
}
.credit div { display: flex; flex-direction: column; gap: .15rem; min-width: 0; overflow-wrap: anywhere; }
.credit strong { font-family: 'Baloo 2', sans-serif; font-size: .95rem; color: var(--ink); }
.credit a { color: var(--sky); }

/* ---------- Fin de partie ---------- */
.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: 400px;
  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);
}
#winStats {
  font-family: 'Baloo 2', sans-serif;
  color: #6a6486;
  margin: 0 0 1.1rem;
}
#winStats strong { color: var(--ink); }
.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; }
}
