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

* { box-sizing: border-box; }

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;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1.6rem auto;
  font-family: 'Baloo 2', sans-serif;
  max-width: 640px;
  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;
}
.progress-wrap {
  flex: 1 1 140px;
  min-width: 140px;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.progress-track {
  flex: 1;
  height: 14px;
  background: var(--white);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 4px 0 rgba(46,42,77,0.08);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--sky));
  transition: width .4s ease;
  position: relative;
  overflow: hidden;
}
.progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.55) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: shine 2.2s linear infinite;
}
@keyframes shine {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
.progress-fill.complete {
  background: linear-gradient(90deg, var(--yellow), #FFA23C);
}
.progress-trophy {
  font-size: 1.3rem;
  flex-shrink: 0;
  opacity: .35;
  filter: grayscale(1);
  transition: opacity .3s ease, filter .3s ease;
}
.progress-trophy.complete {
  opacity: 1;
  filter: none;
  animation: trophyPop .6s ease;
}
@keyframes trophyPop {
  0% { transform: scale(1) rotate(0deg); }
  35% { transform: scale(1.5) rotate(-12deg); }
  60% { transform: scale(1.15) rotate(8deg); }
  100% { transform: scale(1) rotate(0deg); }
}
#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; }

/* ---------- Layout jeu + classement ---------- */
.game-layout {
  display: flex;
  gap: 1.6rem;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 1rem;
  align-items: flex-start;
  justify-content: center;
}

/* ---------- Board 8x8 ---------- */
.board {
  max-width: 760px;
  flex: 1 1 640px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: .5rem;
}
@media (max-width: 640px) {
  .board { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Leaderboard ---------- */
.leaderboard {
  flex: 0 0 220px;
  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: 1.5rem;
}
.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;
}
.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  max-height: 480px;
  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-empty a { color: var(--sky); }
.leaderboard-list li.lb-me {
  box-shadow: 0 0 0 2px var(--green) inset;
}
.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; }
  .leaderboard { flex: none; position: static; max-width: 760px; margin: 0 auto; width: 100%; }
  .leaderboard-list { max-height: 220px; }
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 4px 0 rgba(46,42,77,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  padding: 4px;
  overflow: hidden;
}
.tile:hover { transform: translateY(-3px); }
.tile:active { transform: translateY(1px); }

.tile .fi {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(46,42,77,0.08);
}

.tile-check {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--green);
  color: var(--white);
  font-size: .7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 #3a9c58;
  opacity: 0;
  transform: scale(0);
  transition: opacity .2s ease, transform .2s ease;
}

.tile.found {
  background: #EAF9EE;
  box-shadow: 0 4px 0 #bfe9c9;
}
.tile.found .tile-check {
  opacity: 1;
  transform: scale(1);
}

.tile.shake {
  animation: shake .5s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-4deg); }
  40% { transform: translateX(6px) rotate(4deg); }
  60% { transform: translateX(-5px) rotate(-3deg); }
  80% { transform: translateX(5px) rotate(3deg); }
}

.tile.pop {
  animation: pop .45s ease;
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25) rotate(6deg); }
  100% { transform: scale(1); }
}

/* ---------- Overlays / modals ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(46,42,77,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 1rem;
}
.overlay.show { display: flex; }

.quiz-card, .sheet-card {
  background: var(--white);
  border-radius: 28px;
  padding: 2rem 1.8rem;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 14px 0 rgba(46,42,77,0.12);
  animation: card-in .3s ease;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(16px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.quiz-flag, .sheet-flag {
  margin-bottom: .8rem;
  display: flex;
  justify-content: center;
}
.quiz-flag .fi, .sheet-flag .fi {
  display: block;
  width: 150px;
  height: 112px;
  border-radius: 12px;
  box-shadow: 0 6px 0 rgba(46,42,77,0.12), inset 0 0 0 1px rgba(46,42,77,0.1);
  border: 3px solid var(--white);
}

.quiz-question {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.2rem;
  margin: 0 0 1.2rem;
}

.quiz-options {
  display: grid;
  gap: .7rem;
}
.quiz-options button {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  background: var(--cream);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: .7rem .8rem;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, border-color .2s ease;
}
.quiz-options button:hover { transform: translateY(-2px); border-color: var(--sky); }
.quiz-options button.correct {
  background: var(--green);
  color: var(--white);
  animation: pop .45s ease;
}
.quiz-options button.wrong {
  background: var(--red);
  color: var(--white);
  animation: shake .5s ease;
}
.quiz-options button:disabled { cursor: default; }

.feedback {
  min-height: 1.6rem;
  font-family: 'Baloo 2', sans-serif;
  margin-top: .8rem;
  font-size: 1.05rem;
}
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }

.sheet-card h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.6rem;
  margin: 0 0 .5rem;
  color: var(--pink);
}
.sheet-line {
  margin: .2rem 0;
  font-size: .95rem;
}
.sheet-fact {
  margin: .9rem 0 1.3rem;
  color: #5b5578;
  font-size: .95rem;
  line-height: 1.45;
}
#closeSheet {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: var(--sky);
  color: var(--white);
  border: none;
  padding: .65rem 1.5rem;
  border-radius: 999px;
  box-shadow: 0 5px 0 #2f8fb8;
  cursor: pointer;
}

/* ---------- Win banner ---------- */
.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;
  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.6rem;
  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;
}

/* ---------- Confetti ---------- */
.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; }
}
