:root {
  --indigo: #6366f1;
  --indigo-dark: #4338ca;
  --pink: #ec4899;
  --pink-dark: #be185d;
  --emerald: #10b981;
  --emerald-dark: #047857;
  --amber: #f59e0b;
  --amber-dark: #b45309;
  --red: #ef4444;
  --sky: #0ea5e9;
  --purple: #a855f7;
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: 'Fredoka', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(236, 72, 153, 0.12), transparent 60%),
    radial-gradient(1000px 500px at 90% 10%, rgba(99, 102, 241, 0.12), transparent 60%),
    radial-gradient(800px 600px at 50% 110%, rgba(16, 185, 129, 0.1), transparent 60%),
    var(--bg);
}

#app { min-height: 100vh; padding: 24px; max-width: 1200px; margin: 0 auto; }

h1, h2, h3 { font-family: 'Baloo 2', 'Fredoka', sans-serif; letter-spacing: -0.02em; }

/* ---------- Home ---------- */
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}
.brand-mark {
  width: 56px; height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--indigo), var(--pink));
  display: grid; place-items: center;
  color: white; font-size: 28px; font-weight: 800;
  box-shadow: var(--shadow);
}
.brand-name { font-size: clamp(1.8rem, 4.5vw, 2.6rem); color: var(--text); font-weight: 800; }

.tagline {
  text-align: center;
  color: var(--muted);
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  margin: 8px 0 40px;
}

.age-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 28px;
}

.age-column {
  background: var(--surface);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.age-column::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  opacity: 0.04;
  pointer-events: none;
}
.age-column.petits { --accent-a: var(--pink); --accent-b: var(--amber); }
.age-column.grands { --accent-a: var(--indigo); --accent-b: var(--sky); }
.age-column.adultes { --accent-a: #0f172a; --accent-b: #475569; }

.age-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: white;
  margin-bottom: 10px;
}
.age-title { font-size: 1.6rem; color: var(--text); margin-bottom: 4px; }
.age-subtitle { color: var(--muted); font-size: 0.95rem; margin-bottom: 22px; }

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.game-tile {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 20px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 130px;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  text-align: center;
  position: relative;
}
.game-tile:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: transparent; }
.game-tile:active { transform: translateY(-1px); }
.game-tile .tile-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: grid; place-items: center;
  font-size: 32px;
  background: linear-gradient(135deg, var(--accent-a, #e2e8f0), var(--accent-b, #f1f5f9));
  color: white;
  box-shadow: var(--shadow-sm);
}
.game-tile .tile-label { font-size: 1rem; }

/* ---------- Game Screen ---------- */
.game-screen {
  background: var(--surface);
  border-radius: 28px;
  padding: 24px;
  min-height: 85vh;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.btn {
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.2s;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: #f8fafc; }
.btn-primary {
  background: linear-gradient(135deg, var(--indigo), var(--indigo-dark));
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.game-title {
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chip-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #f1f5f9;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

/* ---------- Generic utilities ---------- */
.center { text-align: center; }
.mt-lg { margin-top: 28px; }
.mb-lg { margin-bottom: 28px; }

/* ---------- Tap cards (animals, shapes) ---------- */
.tap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.tap-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 22px;
  padding: 22px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-family: inherit;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}
.tap-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--indigo); }
.tap-card:active { transform: scale(0.96); }
.tap-card .icon { font-size: 3.6rem; line-height: 1; }
.tap-card .name { font-weight: 600; color: var(--text); font-size: 1.05rem; }

/* ---------- Colors palette ---------- */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: 24px;
  cursor: pointer;
  display: grid;
  place-items: end center;
  padding: 12px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 6px rgba(0,0,0,0.3);
  border: 3px solid white;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
  font-size: 1.1rem;
}
.swatch:hover { transform: scale(1.05); }
.swatch:active { transform: scale(0.95); }

/* ---------- Quiz ---------- */
.quiz-card {
  text-align: center;
  font-size: clamp(2rem, 6vw, 3rem);
  padding: 40px 20px;
  background: linear-gradient(135deg, #f8fafc, #eef2ff);
  border-radius: 24px;
  margin: 20px 0;
  font-weight: 700;
  color: var(--text);
  border: 1px solid var(--border);
}
.quiz-answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  max-width: 560px;
  margin: 0 auto;
}
.answer-btn {
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}
.answer-btn:hover { border-color: var(--indigo); transform: translateY(-2px); }
.answer-btn.correct { background: var(--emerald); color: white; border-color: var(--emerald); animation: pop 0.4s; }
.answer-btn.wrong { background: var(--red); color: white; border-color: var(--red); animation: shake 0.4s; }

@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }

/* ---------- Memory ---------- */
.memory-grid {
  display: grid;
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
}
.memory-card {
  aspect-ratio: 1;
  perspective: 1000px;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  font-family: inherit;
}
.memory-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}
.memory-card.revealed .memory-inner,
.memory-card.matched .memory-inner { transform: rotateY(180deg); }
.memory-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: 18px;
  display: grid; place-items: center;
  font-size: 3rem;
}
.memory-front {
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  color: white;
  font-size: 2rem;
  font-weight: 800;
}
.memory-back {
  background: white;
  border: 2px solid var(--border);
  transform: rotateY(180deg);
}
.memory-card.matched .memory-back {
  background: linear-gradient(135deg, var(--emerald), #34d399);
  color: white;
  border-color: transparent;
}

/* ---------- Balloons ---------- */
.stage {
  position: relative;
  width: 100%;
  height: 70vh;
  min-height: 400px;
  border-radius: 24px;
  background: linear-gradient(to bottom, #dbeafe, #eff6ff);
  overflow: hidden;
  border: 1px solid var(--border);
}
.balloon {
  position: absolute;
  bottom: -120px;
  width: 72px;
  height: 90px;
  border-radius: 50%;
  cursor: pointer;
  animation: rise linear forwards;
  display: grid; place-items: center;
  font-size: 1.8rem;
  box-shadow: inset -8px -12px 20px rgba(0,0,0,0.15), 0 6px 20px rgba(0,0,0,0.1);
}
.balloon::after {
  content: ''; position: absolute;
  bottom: -18px; left: 50%;
  width: 2px; height: 24px;
  background: rgba(0,0,0,0.3);
  transform: translateX(-50%);
}
@keyframes rise { to { transform: translateY(-90vh) rotate(8deg); } }
.balloon.popped { animation: burst 0.3s forwards; pointer-events: none; }
@keyframes burst { to { transform: scale(1.8); opacity: 0; } }

/* ---------- Counting ---------- */
.count-board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 30px;
  background: #f8fafc;
  border-radius: 20px;
  min-height: 180px;
  font-size: 3rem;
  border: 1px solid var(--border);
}

/* ---------- Word match ---------- */
.match-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
}
.match-col { display: flex; flex-direction: column; gap: 12px; }
.match-item {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: all 0.2s;
}
.match-item:hover { border-color: var(--indigo); }
.match-item.selected { background: var(--amber); color: white; border-color: var(--amber); }
.match-item.matched { background: var(--emerald); color: white; border-color: var(--emerald); pointer-events: none; opacity: 0.85; }

/* ---------- Canvas painting ---------- */
.paint-toolbar {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
  border: 1px solid var(--border);
}
.color-pick {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 0 2px var(--border);
  cursor: pointer;
}
.color-pick.active { box-shadow: 0 0 0 3px var(--indigo); transform: scale(1.15); }
.paint-canvas {
  width: 100%;
  background: white;
  border: 2px solid var(--border);
  border-radius: 20px;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

/* ---------- Maze ---------- */
.maze-wrap {
  display: grid;
  place-items: center;
  gap: 16px;
}
.maze-canvas {
  background: #f8fafc;
  border-radius: 20px;
  border: 1px solid var(--border);
  touch-action: none;
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(3, 68px);
  gap: 6px;
}
.dpad button {
  font-family: inherit;
  font-size: 1.6rem;
  border: none;
  border-radius: 14px;
  background: var(--indigo);
  color: white;
  cursor: pointer;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.dpad button:active { transform: scale(0.92); }
.dpad button.spacer { visibility: hidden; }

/* ---------- Piano ---------- */
.piano {
  position: relative;
  display: flex;
  width: 100%;
  max-width: 700px;
  height: 220px;
  margin: 20px auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
}
.key-white {
  flex: 1;
  background: linear-gradient(to bottom, #fafafa, #e2e8f0);
  border-right: 1px solid #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 14px;
  font-weight: 700;
  color: var(--muted);
  font-size: 1rem;
  transition: background 0.1s;
}
.key-white:last-child { border-right: none; }
.key-white:active, .key-white.active { background: linear-gradient(to bottom, var(--indigo), var(--indigo-dark)); color: white; }
.key-black {
  position: absolute;
  top: 0;
  width: 8%;
  height: 60%;
  background: linear-gradient(to bottom, #1e293b, #0f172a);
  cursor: pointer;
  border-radius: 0 0 6px 6px;
  z-index: 2;
}
.key-black:active, .key-black.active { background: var(--purple); }

/* ---------- Feedback overlay ---------- */
.toast {
  position: fixed;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(3.5rem, 12vw, 8rem);
  z-index: 1000;
  pointer-events: none;
  animation: toast 1s ease-out forwards;
  filter: drop-shadow(0 10px 30px rgba(0,0,0,0.25));
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(5deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3) rotate(0); }
}

#confetti-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}
.confetti {
  position: absolute;
  width: 10px; height: 14px;
  top: -20px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* Responsive */
@media (max-width: 540px) {
  #app { padding: 14px; }
  .quiz-answers { grid-template-columns: 1fr; }
  .piano { height: 180px; }
  .dpad { grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); }
}
