:root {
  --fond: #fff4fb;
  --carte: #ffffff;
  --texte: #4a3a5c;
  --doux: #8c7aa3;
  --rose: #ff6fae;
  --violet: #9b6bff;
  --ombre: 0 4px 14px rgba(120, 70, 160, .16);
  --rayon: 22px;
}
* { box-sizing: border-box; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: "Chalkboard SE", "Comic Sans MS", "Marker Felt", ui-rounded, system-ui, sans-serif;
  background: var(--fond) radial-gradient(circle at 10% 0%, #ffe3f1 0, transparent 40%) no-repeat;
  color: var(--texte);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- Accueil ---------- */
#accueil { height: 100%; display: flex; flex-direction: column; }
.titre { text-align: center; padding: 18px 16px 6px; }
.titre h1 { margin: 0; font-size: clamp(30px, 5vw, 52px); letter-spacing: 1px; }
.titre h1 span:nth-child(6n+1) { color: #ff5c8a; }
.titre h1 span:nth-child(6n+2) { color: #ff9f1c; }
.titre h1 span:nth-child(6n+3) { color: #f7c600; }
.titre h1 span:nth-child(6n+4) { color: #3ec46d; }
.titre h1 span:nth-child(6n+5) { color: #3a9bff; }
.titre h1 span:nth-child(6n+6) { color: #a66bff; }
.titre p { margin: 4px 0 0; color: var(--doux); font-size: 19px; }
#categories { display: flex; gap: 10px; padding: 12px 16px; overflow-x: auto; flex-shrink: 0; scrollbar-width: none; }
#categories::-webkit-scrollbar { display: none; }
#categories button {
  flex-shrink: 0; padding: 10px 18px; border-radius: 999px; background: var(--carte); box-shadow: var(--ombre);
  font-size: 19px; white-space: nowrap; transition: transform .15s;
}
#categories button.actif { background: linear-gradient(135deg, #ff8cc6, #a77bff); color: #fff; transform: scale(1.06); }
#grille {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 16px 40px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; align-content: start;
}
.vignette {
  position: relative; background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 10px 10px 6px;
  display: flex; flex-direction: column; align-items: center; transition: transform .15s;
}
.vignette:active { transform: scale(.96); }
.vignette img { width: 100%; aspect-ratio: 1; object-fit: contain; pointer-events: none; border-radius: 14px; }
.vignette span { font-size: 16px; padding: 4px 0 2px; }
.vignette .poubelle { position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; border-radius: 50%; background: #fff; box-shadow: var(--ombre); font-size: 20px; }
.vide { grid-column: 1 / -1; text-align: center; color: var(--doux); font-size: 20px; padding: 40px; }

/* ---------- Atelier ---------- */
#atelier { height: 100%; display: flex; flex-direction: column; }
.barre { display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex-shrink: 0; }
.espace { flex: 1; }
.rond { width: 52px; height: 52px; border-radius: 50%; background: var(--carte); box-shadow: var(--ombre); font-size: 24px; display: grid; place-items: center; }
.rond:disabled { opacity: .35; }
.pilule { padding: 12px 18px; border-radius: 999px; background: var(--carte); box-shadow: var(--ombre); font-size: 18px; white-space: nowrap; }
.pilule.fini { background: linear-gradient(135deg, #ffb347, #ff6fae); color: #fff; font-size: 20px; }
.pilule.rouge { background: #ff6f6f; color: #fff; }

.corps { flex: 1; min-height: 0; display: grid; grid-template-columns: 128px 1fr 270px; gap: 10px; padding: 0 10px 10px; }
.outils, .palette { background: var(--carte); border-radius: var(--rayon); box-shadow: var(--ombre); overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.outils::-webkit-scrollbar, .palette::-webkit-scrollbar { display: none; }
.outils { padding: 10px 8px; display: flex; flex-direction: column; gap: 10px; }
.liste-outils { display: grid; grid-template-columns: 1fr; gap: 8px; }
.outil { display: flex; flex-direction: column; align-items: center; font-size: 34px; padding: 6px 0 4px; border-radius: 18px; line-height: 1.1; transition: transform .12s; }
.outil small, .option small { font-size: 13px; color: var(--doux); }
.outil.actif { background: linear-gradient(135deg, #ffe0f0, #ece3ff); transform: scale(1.05); box-shadow: inset 0 0 0 3px #d9b8ff; }
#options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; border-top: 2px dashed #f1e2f7; padding-top: 10px; }
.option { display: flex; flex-direction: column; align-items: center; font-size: 26px; padding: 6px 0 2px; border-radius: 14px; line-height: 1.1; }
.option.actif { background: #ffeaf5; box-shadow: inset 0 0 0 3px #ffb3d6; }
.option.tampon { font-size: 30px; padding: 4px 0; }
#bloc-taille { margin-top: auto; border-top: 2px dashed #f1e2f7; padding-top: 8px; }
.apercu-taille { height: 70px; display: grid; place-items: center; }
#pastille-taille { display: block; border-radius: 50%; background: #333; }
#taille { width: 100%; height: 36px; accent-color: var(--rose); }

#zone { position: relative; overflow: hidden; touch-action: none; border-radius: var(--rayon); background: repeating-conic-gradient(#fbeef8 0 25%, #fff7fc 0 50%) 0 0 / 28px 28px; }
#feuille { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; box-shadow: 0 6px 24px rgba(120, 70, 160, .22); border-radius: 6px; touch-action: none; }
#feuille canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#c-traits, #c-deco { pointer-events: none; }

.palette { padding: 12px; }
.choisies { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grosse { width: 70px; height: 70px; border-radius: 50%; box-shadow: var(--ombre), inset 0 0 0 4px #fff; border: 3px solid #e9dcf3; }
.petite { width: 44px; height: 44px; border-radius: 50%; box-shadow: var(--ombre), inset 0 0 0 3px #fff; border: 3px solid #e9dcf3; }
.petite.cible, .grosse.cible { border-color: var(--violet); box-shadow: 0 0 0 4px #d8c4ff, inset 0 0 0 3px #fff; }
.melange { font-size: 16px; padding: 10px 14px; }
.aide { font-size: 14px; color: var(--doux); margin: 8px 2px; min-height: 18px; }
.famille h3 { font-size: 15px; margin: 12px 2px 6px; color: var(--doux); font-weight: normal; }
.pastilles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pastille { aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12), 0 2px 5px rgba(0, 0, 0, .12); border: 2px solid rgba(0, 0, 0, .06); transition: transform .1s; }
.pastille.actif { transform: scale(1.15); box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--violet); }
.pastille.plus { background: conic-gradient(red, orange, yellow, lime, cyan, blue, magenta, red); display: grid; place-items: center; font-size: 22px; color: #fff; text-shadow: 0 1px 3px #000; }

/* iPad en hauteur : outils en haut, palette en bas */
@media (orientation: portrait) {
  .corps { grid-template-columns: 1fr; grid-template-rows: auto 1fr 210px; }
  .outils { flex-direction: row; overflow-x: auto; overflow-y: hidden; align-items: center; }
  .liste-outils { grid-template-columns: repeat(4, 74px); }
  .outil { font-size: 30px; }
  #options { display: flex; border-top: 0; border-left: 2px dashed #f1e2f7; padding: 0 0 0 10px; }
  .option { min-width: 62px; }
  #bloc-taille { margin: 0 0 0 auto; border-top: 0; border-left: 2px dashed #f1e2f7; padding: 0 0 0 10px; min-width: 150px; display: flex; align-items: center; gap: 6px; }
  .apercu-taille { height: 60px; width: 60px; flex-shrink: 0; }
  .palette { display: flex; gap: 14px; overflow-x: auto; overflow-y: hidden; }
  .choisies { flex-direction: column; flex-wrap: nowrap; flex-shrink: 0; width: 110px; }
  .palette .aide { display: none; }
  #familles { display: flex; gap: 14px; }
  .famille { flex-shrink: 0; width: 190px; }
  .famille h3 { margin-top: 0; }
}

/* ---------- Fenêtres ---------- */
#bravo, #confirmer { position: fixed; inset: 0; background: rgba(80, 40, 110, .35); display: grid; place-items: center; z-index: 20; padding: 16px; }
.carte { background: #fff; border-radius: 28px; padding: 22px; text-align: center; max-width: 560px; width: 100%; box-shadow: 0 20px 60px rgba(80, 40, 110, .35); animation: pop .35s cubic-bezier(.2, 1.6, .5, 1); }
.carte .gros { font-size: 40px; }
.carte p { font-size: 20px; margin: 8px 0 12px; }
#bravo-image { width: min(360px, 70vw); aspect-ratio: 1; border-radius: 18px; box-shadow: var(--ombre); -webkit-touch-callout: default; pointer-events: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
#confettis { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
#confettis span { position: absolute; top: -60px; font-size: 34px; animation: tombe linear forwards; }
@keyframes tombe { to { transform: translateY(115vh) rotate(720deg); } }
