/*
VOICE  : arcade cartoon, joyeux, bruyant
IDEA   : une borne de fête foraine « tape-taupe » avec des bonbons qui ont des yeux
PICTURE: la grille de cases blanches à gros contours, des ronds-bonbons qui rebondissent
COLOUR : jaune soleil + encre noire, accents rose / bleu / vert / orange / violet
TYPE   : Lilita One (titres, chiffres) + Nunito 800 (texte)
*/
@font-face { font-family: "Lilita One"; src: url("/fonts/lilita-one.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Nunito"; src: url("/fonts/nunito-800.woff2") format("woff2"); font-weight: 800; font-display: swap; }
* { box-sizing: border-box; min-width: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #ffd23f; --bg2: #ffc300; --ink: #1b1b1f; --card: #fff; --muted: #5b4a1a;
  --pink: #ff5fa2; --blue: #3ec1f3; --green: #2ee59d; --orange: #ff8a00; --purple: #9b5de5; --red: #ff3b3b;
  --b: 3px solid var(--ink); --sh: 5px 5px 0 var(--ink);
  color-scheme: light;
}
html, body { margin: 0; min-height: 100%; }
body {
  background:
    repeating-linear-gradient(-45deg, transparent 0 22px, #ffffff22 22px 44px),
    radial-gradient(circle at 50% -10%, #fff3b0 0%, var(--bg) 45%, var(--bg2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font: 800 16px/1.4 "Nunito", system-ui, sans-serif;
  overscroll-behavior: none; overflow-x: clip;
  user-select: none; -webkit-user-select: none;
}
.screen {
  min-height: 100dvh; max-width: 520px; margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.screen[hidden] { display: none; }

/* Titre */
.logo { text-align: center; margin: 8px 0 0; }
h1 {
  font: 400 clamp(52px, 15vw, 76px)/0.9 "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; margin: 0;
  color: var(--pink); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 5px 5px 0 var(--ink); transform: rotate(-4deg); letter-spacing: 1px;
}
h1 span { color: var(--blue); display: block; transform: translateX(28px); }
.logo-dots { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }
.logo-dots i { width: 18px; height: 18px; border-radius: 50%; border: var(--b); animation: hop 1.2s ease-in-out infinite; }
.logo-dots i:nth-child(1) { background: var(--pink); }
.logo-dots i:nth-child(2) { background: var(--blue); animation-delay: .15s; }
.logo-dots i:nth-child(3) { background: var(--green); animation-delay: .3s; }
.logo-dots i:nth-child(4) { background: var(--orange); animation-delay: .45s; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }

h2 { font: 400 1.3rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; margin: 0 0 8px; }
.sub { text-align: center; margin: 0; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .9rem; text-align: center; min-height: 1.2em; margin: 0; }

/* Champs et boutons */
.field { display: flex; flex-direction: column; gap: 6px; }
.field input {
  font: 800 1.1rem "Nunito", sans-serif; padding: 12px 14px; border-radius: 14px;
  border: var(--b); background: var(--card); color: var(--ink); box-shadow: var(--sh);
  user-select: text; -webkit-user-select: text; outline: none;
}
.field input:focus { box-shadow: 5px 5px 0 var(--pink); }

.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.level {
  padding: 12px 8px; border-radius: 16px; border: var(--b); background: var(--card); color: var(--ink);
  box-shadow: var(--sh); display: flex; flex-direction: column; align-items: center; gap: 2px;
  font: inherit; cursor: pointer; transition: transform .08s;
}
.level strong { font: 400 1.35rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; }
.level small { font-size: .85rem; color: var(--muted); }
.level:nth-child(1).active { background: var(--green); }
.level:nth-child(2).active { background: var(--blue); }
.level:nth-child(3).active { background: var(--orange); }
.level:nth-child(4).active { background: var(--pink); }
.level.active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--ink); }
.level.active small { color: var(--ink); }

.btn {
  font: 400 1.25rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; letter-spacing: .5px; padding: 12px 16px; border-radius: 16px;
  border: var(--b); background: var(--card); color: var(--ink); box-shadow: var(--sh);
  cursor: pointer; text-align: center; text-decoration: none; transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translate(4px, 4px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--pink); color: #fff; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.btn.big { font-size: 2rem; padding: 14px; }
.btn.ghost { background: #ffffffaa; box-shadow: 3px 3px 0 var(--ink); font-size: 1rem; }
.btn.fb { background: #1877f2; color: #fff; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.row, .share { display: flex; gap: 12px; }
.row .btn, .share .btn { flex: 1; }
.play-wrap { display: flex; gap: 12px; align-items: stretch; }
.play-wrap .big { flex: 1; }
.play-wrap .ghost { flex: none; width: 72px; padding: 0; font-size: 2rem; }
#sound.off { background: #ffffff55; text-decoration: line-through; color: #0007; }

/* Classement */
.board-scores { background: var(--card); border: var(--b); border-radius: 18px; padding: 14px 16px; box-shadow: var(--sh); }
#leaderboard { margin: 0; padding: 0; list-style: none; counter-reset: r; }
#leaderboard li { counter-increment: r; display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 2px dashed #0002; }
#leaderboard li:last-child { border-bottom: 0; }
#leaderboard li::before {
  content: counter(r); flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink);
  display: grid; place-items: center; font: 400 .95rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; background: var(--bg);
}
#leaderboard li:nth-child(1)::before { background: #ffd700; }
#leaderboard li:nth-child(2)::before { background: #d9e3ea; }
#leaderboard li:nth-child(3)::before { background: #e8a46b; }
#leaderboard li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard li b { font-variant-numeric: tabular-nums; white-space: nowrap; }
#leaderboard li.muted::before { display: none; }

/* Compte à rebours */
#countdown { justify-content: center; align-items: center; }
.count {
  font: 400 11rem/1 "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; color: var(--pink);
  -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; text-shadow: 8px 8px 0 var(--ink);
  animation: boing .7s cubic-bezier(.3, 1.6, .5, 1) infinite;
}
@keyframes boing { 0% { transform: scale(.2) rotate(-20deg); } 60% { transform: scale(1.1) rotate(4deg); } 100% { transform: scale(1) rotate(0); } }

/* Jeu */
#game { justify-content: flex-start; }
#game .board { margin: auto; }
#quit { margin-top: 0; }
.hud { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.pill {
  background: var(--card); border: var(--b); border-radius: 14px; padding: 4px 4px 6px; box-shadow: 3px 3px 0 var(--ink);
  font-size: .75rem; text-align: center; display: flex; flex-direction: column; line-height: 1.1;
}
.pill b { font: 400 1.35rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill.bad b { color: var(--red); }
.combo {
  text-align: center; height: 2.2rem; font: 400 2rem/1 "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; color: var(--orange);
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink);
}
.combo.bump { animation: bump .3s ease-out; }
@keyframes bump { 0% { transform: scale(1.5) rotate(-6deg); } 100% { transform: scale(1); } }

.board {
  --n: 3;
  width: min(100%, 62dvh); aspect-ratio: 1; margin: 0 auto; padding: 10px;
  display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 10px;
  background: var(--purple); border: var(--b); border-radius: 22px; box-shadow: 7px 7px 0 var(--ink);
  touch-action: none;
}
.board.shake { animation: shake .3s; }
@keyframes shake { 20% { transform: translate(-8px, 2px) rotate(-1deg); } 40% { transform: translate(7px, -2px) rotate(1deg); } 60% { transform: translate(-5px, 1px); } 80% { transform: translate(3px, 0); } }

.cell {
  position: relative; border-radius: 16px; background: var(--card); border: var(--b);
  box-shadow: inset 0 -6px 0 #0001; display: grid; place-items: center; touch-action: none; cursor: pointer;
}
.dot {
  --c: var(--pink);
  position: relative; width: 74%; height: 74%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 32% 28%, #fff9 0 12%, transparent 13%), var(--c);
  border: 3px solid var(--ink); box-shadow: inset -6px -8px 0 #0002;
  transform: scale(0);
}
/* Les yeux */
.dot::before, .dot::after {
  content: ""; position: absolute; top: 30%; width: 24%; height: 30%; border-radius: 50%;
  background: radial-gradient(circle at 50% 60%, var(--ink) 0 38%, #fff 40%); border: 2px solid var(--ink);
}
.dot::before { left: 20%; }
.dot::after { right: 20%; }
.cell.on .dot { animation: popin .28s cubic-bezier(.3, 1.8, .5, 1) forwards, wobble 1s .3s ease-in-out infinite; }
@keyframes popin { 0% { transform: scale(0) rotate(-30deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes wobble { 0%, 100% { transform: scale(1) rotate(0); } 25% { transform: scale(1.04, .96) rotate(-4deg); } 75% { transform: scale(.96, 1.04) rotate(4deg); } }

.cell.hit  { animation: hitc .3s ease-out; }
.cell.miss { animation: missc .4s ease-out; }
.cell.wrong { animation: wrongc .3s ease-out; }
@keyframes hitc   { 0% { background: #c6ffe7; transform: scale(.92); } 100% { background: var(--card); transform: none; } }
@keyframes missc  { 0% { background: #d5d0e6; } 100% { background: var(--card); } }
@keyframes wrongc { 0% { background: #ffc2c2; transform: rotate(-4deg); } 50% { transform: rotate(4deg); } 100% { background: var(--card); transform: none; } }

/* Confettis et temps qui s'envole */
.bit {
  position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; border: 2px solid var(--ink); border-radius: 3px;
  pointer-events: none; animation: burst .55s ease-out forwards; z-index: 2;
}
@keyframes burst {
  0% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.4) rotate(var(--r)); opacity: 0; }
}
.float {
  position: absolute; left: 50%; top: 40%; pointer-events: none; z-index: 3; white-space: nowrap;
  font: 400 1.4rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  animation: floatup .7s ease-out forwards;
}
.float.bad { color: var(--red); }
@keyframes floatup { 0% { transform: translate(-50%, 0) scale(.6); opacity: 1; } 30% { transform: translate(-50%, -14px) scale(1.15); } 100% { transform: translate(-50%, -48px) scale(1); opacity: 0; } }

/* Résultat */
#result { justify-content: center; }
.stars { display: flex; justify-content: center; gap: 6px; font-size: 3.2rem; line-height: 1; }
.stars i { font-style: normal; color: #fff6; -webkit-text-stroke: 2px var(--ink); transform: scale(0); }
.stars i.on { color: #ffd700; }
.stars i.show { animation: starpop .4s cubic-bezier(.3, 1.8, .5, 1) forwards; }
@keyframes starpop { to { transform: scale(1); } }
.score-ring {
  --p: 0;
  width: 190px; height: 190px; margin: 0 auto; border-radius: 50%; border: var(--b); box-shadow: 6px 6px 0 var(--ink);
  background: conic-gradient(var(--pink) calc(var(--p) * 1%), #fff 0);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 18px; border-radius: 50%; background: var(--bg); border: var(--b); }
.score-ring span, .score-ring small { position: relative; font-family: "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; font-weight: 400; }
.score-ring span { font-size: 4rem; font-variant-numeric: tabular-nums; }
.score-ring small { font-size: 1.6rem; margin-top: 18px; }
.msg { text-align: center; font: 400 1.7rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; margin: 0; transform: rotate(-2deg); }
.stats { list-style: none; padding: 4px 16px; margin: 0; background: var(--card); border: var(--b); border-radius: 18px; box-shadow: var(--sh); }
.stats li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 2px dashed #0002; }
.stats li:last-child { border-bottom: 0; }
.stats b { font: 400 1.1rem "Lilita One", "Arial Rounded MT Bold", "Arial Black", sans-serif; font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .logo-dots i, .cell.on .dot, .count { animation: none !important; }
  .cell.on .dot { transform: scale(1); }
}
