:root {
  --pink: #ff6bcb;
  --purple: #6a5cff;
  --cyan: #2ee6e6;
  --yellow: #ffd23f;
  --green: #3ddc84;
  --ink: #2a2350;
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #1b1640;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
}

.hidden { display: none !important; }

/* ---------- Écran d'accueil ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.start-card {
  background: rgba(255,255,255,0.92);
  border-radius: var(--radius);
  padding: 32px 28px 28px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0,0,0,0.35);
  max-width: 420px;
  width: 100%;
  animation: pop 0.5s ease;
}
.title {
  font-size: clamp(28px, 8vw, 44px);
  margin: 0 0 8px;
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}
.subtitle { font-size: clamp(15px, 4.5vw, 20px); margin: 0 0 22px; color: #5b5480; }
.hint-line { font-size: 13px; color: #8a84a8; margin: 16px 0 0; }

.big-btn {
  font: inherit;
  font-weight: 800;
  font-size: clamp(20px, 6vw, 26px);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 16px 38px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  box-shadow: 0 10px 0 rgba(0,0,0,0.18), 0 14px 24px rgba(106,92,255,0.45);
  transition: transform .08s ease, box-shadow .08s ease;
}
.big-btn:active { transform: translateY(6px); box-shadow: 0 4px 0 rgba(0,0,0,0.18); }
.big-btn.small { font-size: 18px; padding: 12px 26px; }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  gap: 8px;
  pointer-events: none;
}
.hud-left, .hud-right { display: flex; gap: 8px; pointer-events: auto; }
.badge {
  background: rgba(255,255,255,0.92);
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 800;
  font-size: clamp(13px, 3.6vw, 17px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  white-space: nowrap;
}
.icon-btn {
  background: rgba(255,255,255,0.92);
  border: none;
  border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- Mot en cours ---------- */
.word-zone {
  position: fixed;
  top: 22vh;
  left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(6px, 2vw, 14px);
  min-height: 22vh;
  flex-wrap: wrap;
  padding: 0 12px;
}
.tile {
  font-weight: 900;
  font-size: clamp(46px, 16vw, 110px);
  line-height: 1;
  color: #fff;
  text-shadow: 0 6px 0 rgba(0,0,0,0.18);
  animation: bounceIn .45s cubic-bezier(.2,1.4,.5,1);
  filter: drop-shadow(0 8px 14px rgba(0,0,0,0.25));
}
.tile.pop { animation: tilePop .4s ease; }

/* ---------- Liste de mots ---------- */
.word-list {
  position: fixed;
  z-index: 10;
  left: 0; right: 0;
  bottom: calc(var(--kb-h, 230px) + 10px + var(--safe-b));
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 0 12px;
}
.chip {
  background: rgba(255,255,255,0.85);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: clamp(13px, 3.8vw, 18px);
  letter-spacing: 2px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  transition: transform .2s ease, background .2s ease, opacity .2s ease;
}
.chip.found { background: var(--green); color: #fff; opacity: .6; text-decoration: line-through; }
.chip.hint { background: var(--yellow); box-shadow: 0 0 0 3px rgba(255,210,63,.55); }

/* ---------- Clavier tactile ---------- */
.keyboard {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 15;
  padding: 8px 6px calc(8px + var(--safe-b));
  background: linear-gradient(180deg, rgba(27,22,64,0) 0%, rgba(27,22,64,0.55) 30%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kb-row { display: flex; gap: 6px; justify-content: center; }
.key {
  flex: 1 1 0;
  max-width: 64px;
  aspect-ratio: 1 / 1.15;
  border: none;
  border-radius: 14px;
  font: inherit;
  font-weight: 900;
  font-size: clamp(16px, 4.6vw, 24px);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,0.22);
  transition: transform .06s ease, box-shadow .06s ease, filter .1s ease;
  display: grid; place-items: center;
}
.key:active, .key.down { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.22); filter: brightness(1.15); }
.key.wide { flex: 1.6 1 0; max-width: 110px; aspect-ratio: auto; padding: 0 8px; font-size: 18px; }
.key.erase { background: linear-gradient(135deg, #ff7a7a, #ff5c8a); }

/* ---------- Mascotte ---------- */
.mascot {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: calc(var(--kb-h, 230px) + 8px + var(--safe-b));
  z-index: 16;
  width: 116px; height: 116px;
  pointer-events: none;
}
.blob {
  position: absolute;
  inset: 0;
  border-radius: 48% 52% 47% 53% / 55% 50% 50% 45%;
  background: radial-gradient(circle at 35% 30%, #7af5f5, var(--cyan) 60%, #1bb8c9);
  box-shadow: 0 12px 24px rgba(0,0,0,0.3), inset 0 -10px 16px rgba(0,0,0,0.12);
  animation: blobFloat 3s ease-in-out infinite;
}
.blob .eye {
  position: absolute; top: 34%;
  width: 26px; height: 26px;
  background: #fff; border-radius: 50%;
  display: grid; place-items: center;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.1);
}
.blob .eye.left { left: 24%; }
.blob .eye.right { right: 24%; }
.blob .eye span { width: 11px; height: 11px; background: var(--ink); border-radius: 50%; transition: transform .2s ease; }
.blob.blink .eye { height: 4px; }
.blob.blink .eye span { opacity: 0; }
.blob .mouth {
  position: absolute; left: 50%; bottom: 24%;
  width: 34px; height: 18px;
  transform: translateX(-50%);
  border-bottom: 5px solid var(--ink);
  border-radius: 0 0 40px 40px;
  transition: all .2s ease;
}
.blob.happy .mouth { height: 26px; border-bottom-width: 6px; }
.blob.sad .mouth { border-bottom: none; border-top: 5px solid var(--ink); border-radius: 40px 40px 0 0; bottom: 20%; }
.blob.sleep .mouth { width: 16px; height: 10px; }
.blob.dance { animation: blobDance .5s ease-in-out infinite; }
.speech {
  position: absolute;
  right: 60%;
  bottom: 70%;
  min-width: 130px;
  max-width: 60vw;
  background: #fff;
  border-radius: 16px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateY(8px) scale(.9);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.speech.show { opacity: 1; transform: translateY(0) scale(1); }
.speech::after {
  content: ""; position: absolute; right: 18px; bottom: -9px;
  border: 10px solid transparent; border-top-color: #fff; border-bottom: 0;
}

/* ---------- Mini-jeu ---------- */
.minigame { position: fixed; inset: 0; z-index: 18; pointer-events: none; }
.mg-banner {
  position: absolute; top: 12vh; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.94);
  border-radius: 999px;
  padding: 10px 22px;
  font-weight: 800;
  font-size: clamp(16px, 5vw, 22px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  white-space: nowrap;
}

/* ---------- Tiroir autocollants ---------- */
.drawer { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(20,16,50,0.6); padding: 20px; }
.drawer-card {
  background: #fff; border-radius: var(--radius); padding: 22px;
  max-width: 460px; width: 100%; text-align: center;
  box-shadow: 0 18px 60px rgba(0,0,0,0.4);
}
.drawer-card h2 { margin: 0 0 16px; }
.sticker-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
.sticker {
  aspect-ratio: 1; border-radius: 16px; display: grid; place-items: center;
  font-size: 28px; background: #eee9ff;
}
.sticker.locked { filter: grayscale(1); opacity: .35; }
.sticker.unlocked { background: linear-gradient(135deg, var(--yellow), var(--pink)); animation: pop .4s ease; }

/* ---------- Animations ---------- */
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bounceIn { 0% { transform: scale(0) rotate(-20deg); opacity: 0; } 60% { transform: scale(1.25) rotate(6deg); } 100% { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes tilePop { 0%,100% { transform: scale(1); } 50% { transform: scale(1.3); } }
@keyframes blobFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes blobDance { 0%,100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-14px) rotate(8deg); } }
@keyframes chipHint { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

@media (min-width: 820px) {
  .key { max-width: 56px; }
  .speech { font-size: 16px; }
}

/* ---------- Bouton texte (accueil) ---------- */
.text-btn {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: #6a5cff;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  opacity: .8;
}
.text-btn:active { transform: scale(.96); }

/* ---------- Menu de catégories ---------- */
.menu-card {
  background: rgba(255,255,255,0.94);
  border-radius: var(--radius);
  padding: 26px 22px;
  max-width: 540px;
  width: 100%;
  box-shadow: 0 18px 60px rgba(0,0,0,0.35);
  animation: pop .4s ease;
}
.menu-title { text-align: center; margin: 0 0 18px; font-size: clamp(22px, 6vw, 30px); color: var(--ink); }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.cat-card {
  border: none;
  border-radius: 18px;
  padding: 20px 12px;
  cursor: pointer;
  font: inherit;
  color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  box-shadow: 0 8px 0 rgba(0,0,0,0.15), 0 12px 22px rgba(106,92,255,0.35);
  transition: transform .08s ease, box-shadow .08s ease;
}
.cat-card:nth-child(4n+2) { background: linear-gradient(135deg, #2ee6e6, #6a5cff); }
.cat-card:nth-child(4n+3) { background: linear-gradient(135deg, #3ddc84, #2ee6e6); }
.cat-card:nth-child(4n+4) { background: linear-gradient(135deg, #ff8c42, #ff6bcb); }
.cat-card:active { transform: translateY(5px); box-shadow: 0 3px 0 rgba(0,0,0,0.15); }
.cat-emoji { font-size: clamp(40px, 12vw, 60px); line-height: 1; }
.cat-label { font-weight: 800; font-size: clamp(15px, 4vw, 19px); }

/* ---------- Indice imagier (grande image) ---------- */
.clue {
  position: fixed;
  top: 6vh; left: 0; right: 0;
  z-index: 9;
  text-align: center;
  font-size: clamp(52px, 17vw, 120px);
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,0.3));
  animation: bounceIn .4s ease;
}

/* ---------- Lettre guidée (surbrillance fixe, sans clignotement) ---------- */
.key.guide {
  outline: 4px solid #fff;
  outline-offset: -2px;
  filter: brightness(1.18);
  box-shadow: 0 0 0 6px rgba(255,255,255,0.35), 0 5px 0 rgba(0,0,0,0.22);
  z-index: 1;
}

/* ---------- Espace parents ---------- */
.parent-card { max-width: 560px; width: 100%; max-height: 88vh; overflow-y: auto; text-align: left; }
.parent-card h2 { margin: 0 0 14px; text-align: center; }
.gate-q { font-size: 18px; text-align: center; margin: 10px 0; }
.field {
  width: 100%;
  border: 2px solid #ded7ff;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  margin-bottom: 10px;
  background: #fbfaff;
}
.field:focus { outline: none; border-color: var(--purple); }
.field-label { display: block; font-weight: 700; margin: 6px 0 4px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; }
.cat-edit { border: 1px solid #eee; border-radius: 14px; padding: 12px; margin-bottom: 12px; background: #faf9ff; }
.cat-edit-head { margin-bottom: 8px; }
.word-row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.word-row .w-name { flex: 0 0 32%; margin: 0; text-transform: uppercase; }
.word-row .w-clue { flex: 1; margin: 0; }
.word-row .del { border: none; background: #ffe1e8; border-radius: 10px; width: 38px; height: 38px; cursor: pointer; font-size: 16px; flex: 0 0 auto; }
.add-word { border: none; background: #e9e4ff; color: var(--purple); font: inherit; font-weight: 700; border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 14px; }
.sticky-save { position: sticky; bottom: -22px; background: linear-gradient(180deg, rgba(255,255,255,0), #fff 30%); padding-top: 12px; padding-bottom: 4px; }
.big-btn.ghost { background: #efeefb; color: var(--ink); box-shadow: 0 6px 0 rgba(0,0,0,0.08); }
