/* Lumiko : jetons de design, mise en page et composants communs */
/* Layout : application plein écran à écrans empilés. Jeu = paniers en haut, Lumi au milieu,
   formes en bas, bande inspirée du pagne wax au sol. Deux thèmes : clair (pastel) et sombre ; les couleurs
   à apprendre (rouge, bleu, jaune) et le jaune de Lumi restent les mêmes dans les deux. */
:root {
  --sky: #EAF5F1;
  --sand: #FFF5E6;
  --ink: #3B3950;
  --ink-soft: #6B6780;
  --card: #FFFFFF;
  --line: #EADFCF;
  --sun: #FFC94D;
  --sun-deep: #EFA235;
  --red: #DD5246;
  --red-soft: #FAD9D4;
  --blue: #3C82CF;
  --blue-soft: #D6E7F8;
  --yellow: #F2B21B;
  --yellow-soft: #FDF0C7;
  --lilac: #E6DEF7;
  --mint: #D3EEDF;
  --peach: #FFE0CA;
  --leaf: #5FAF83;
  --cheek: #F59E97;
  --shadow: rgba(59, 57, 80, .14);
  --on-sun: #3B3950; /* texte sur le jaune, quel que soit le thème */
  --outline: #3B3950; /* contours encre et ombres franches du style « album » */
  --art-sky: #EAF5F1; /* fond des illustrations : reste clair en thème sombre (scènes de jour) */
  --art-card: #FFFFFF;

  --font-display: "Fredoka", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, sans-serif;

  --scale: 1;
  --fit: 1;
  --shape-size: calc(clamp(84px, 24vw, 136px) * var(--scale) * var(--fit));
  --bfit: 1;
  --basket-w: calc(clamp(112px, 34vw, 200px) * (1 + (var(--scale) - 1) / 2) * var(--bfit));
  --btn: calc(56px * var(--scale));
  --fruit: calc(clamp(58px, 16vw, 88px) * var(--scale));
  color-scheme: light;
}

/* Thème sombre : choisi dans Options, ou automatique si le système est en mode sombre */
:root[data-theme="dark"] {
  --sky: #1E2433;
  --sand: #171A24;
  --ink: #ECE8F4;
  --ink-soft: #B3ADC6;
  --card: #262B3B;
  --line: #3A4057;
  --red-soft: #5A2E2B;
  --blue-soft: #24384F;
  --yellow-soft: #4A3F1E;
  --lilac: #3B3456;
  --mint: #24453A;
  --peach: #4D3529;
  --leaf: #6FC497;
  --shadow: rgba(0, 0, 0, .45);
  --outline: #0D0F16;
  --art-sky: #BFD3CC;
  --art-card: #DCE5E1;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sky: #1E2433;
    --sand: #171A24;
    --ink: #ECE8F4;
    --ink-soft: #B3ADC6;
    --card: #262B3B;
    --line: #3A4057;
    --red-soft: #5A2E2B;
    --blue-soft: #24384F;
    --yellow-soft: #4A3F1E;
    --lilac: #3B3456;
    --mint: #24453A;
    --peach: #4D3529;
    --leaf: #6FC497;
    --shadow: rgba(0, 0, 0, .45);
    --outline: #0D0F16;
    --art-sky: #BFD3CC;
    --art-card: #DCE5E1;
    color-scheme: dark;
  }
}

[hidden] { display: none !important; }
html, body { height: 100%; }
html { box-sizing: border-box; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body {
  margin: 0;
  background: var(--sand);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; margin: 0; }
:focus-visible { outline: 4px dashed var(--ink); outline-offset: 5px; }

.app { position: relative; height: 100%; }
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 0;
  background: linear-gradient(180deg, var(--sky) 0%, var(--sand) 72%);
  animation: screen-in .35s ease-out;
}
@keyframes screen-in { from { opacity: 0; } }

/* Bande wax : losanges et points pastel, repère culturel discret au pied de chaque écran */
.wax {
  flex: none;
  margin-top: auto;
  margin-left: calc(-1 * max(16px, env(safe-area-inset-left, 0px)));
  margin-right: calc(-1 * max(16px, env(safe-area-inset-right, 0px)));
  height: 26px;
  background:
    radial-gradient(circle, var(--card) 0 3px, transparent 3.5px) 13px 13px / 26px 26px,
    conic-gradient(from 45deg, var(--peach) 25%, var(--mint) 0 50%, var(--peach) 0 75%, var(--mint) 0) 0 0 / 26px 26px;
  border-top: 5px solid var(--sun);
}

/* ---------- Boutons communs ---------- */
.icon-btn {
  position: relative;
  width: var(--btn);
  height: var(--btn);
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 4px 0 var(--line), 0 6px 14px var(--shadow);
  transition: transform .15s;
}
.icon-btn:active { transform: translateY(2px); }
.icon-btn svg { width: 55%; height: 55%; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: calc(60px * var(--scale));
  padding-inline: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--sun);
  color: var(--on-sun);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: calc(1.3rem * var(--scale));
  box-shadow: 0 5px 0 var(--sun-deep), 0 8px 16px var(--shadow);
  transition: transform .15s;
}
.pill:active { transform: translateY(3px); }
.pill svg { width: 1.4em; height: 1.4em; }
.pill.glow { animation: glow 2.2s ease-in-out infinite; }
@keyframes glow { 50% { transform: scale(1.06); } }

/* Barre de maintien (porte d'accès parents) */
.hold { --p: 0; }
.icon-btn.hold::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: conic-gradient(var(--leaf) calc(var(--p) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  pointer-events: none;
}
.tile.hold::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 8px;
  width: calc(var(--p) * 100%);
  background: var(--leaf);
}

/* ---------- Ami de jeu (Lumi ou Kiko, animé par puppet.js) ---------- */
.lumi-wrap { flex: none; }

/* ---------- Accueil ---------- */
.home-inner {
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-block: 12px 24px;
}
.wordmark { font-family: var(--font-display); font-weight: 700; font-size: clamp(2.4rem, 9vw, 3.4rem); line-height: 1; letter-spacing: .01em; }
.wordmark span { color: var(--sun-deep); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tile {
  position: relative;
  overflow: hidden;
  min-height: calc(132px * var(--scale));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border: 0;
  border-radius: 28px;
  background: var(--tile, var(--card));
  color: var(--tile-ink, var(--ink));
  text-align: left;
  box-shadow: 0 5px 0 rgba(59, 57, 80, .08);
  transition: transform .15s;
}
.tile:active { transform: translateY(3px); }
.tile svg { width: calc(54px * var(--scale)); height: calc(54px * var(--scale)); }
.tile strong { font-family: var(--font-display); font-weight: 600; font-size: calc(1.45rem * var(--scale)); }
.tile small { display: block; font-size: .85rem; color: var(--ink-soft); font-weight: 700; }
.version { margin: 0; text-align: center; font-size: .8rem; color: var(--ink-soft); }

/* ---------- Sous-écrans (Jouer, Histoires, Parents, Options) ---------- */
.page { width: 100%; max-width: 760px; margin-inline: auto; display: flex; flex-direction: column; gap: 18px; padding-block: 4px 28px; }
.page-head { display: flex; align-items: center; gap: 14px; }
.page-head h1 { font-size: clamp(1.6rem, 6vw, 2.1rem); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 14px; }
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border: 0;
  border-radius: 24px;
  background: var(--card);
  text-align: left;
  box-shadow: 0 4px 0 var(--line);
}
.card[disabled] { cursor: default; background: rgba(255, 255, 255, .55); box-shadow: none; }
.card[disabled] .preview { filter: saturate(.35); opacity: .7; }
.card h3 { font-size: 1.25rem; }
.card p { margin: 0; color: var(--ink-soft); font-size: .95rem; }
.preview { height: 86px; border-radius: 16px; background: var(--sky); display: flex; align-items: center; justify-content: center; gap: 16px; }
.preview i { display: block; width: 46px; height: 46px; background: var(--c); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .78rem; font-weight: 800; letter-spacing: .03em; padding: 4px 10px; border-radius: 999px; background: var(--sky); color: var(--ink); }
.chip.soon { background: var(--peach); }
.levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.level-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 18px; background: var(--card); text-align: left; transition: transform .15s; }
.level-btn:active { transform: translateY(2px); }
.level-btn b { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; display: block; }
.level-btn small { color: var(--ink-soft); font-weight: 700; font-size: .8rem; }
.level-btn .stars { display: flex; gap: 2px; flex: none; }
.level-btn .stars svg { width: 16px; height: 16px; }
.level-btn.done { border-color: var(--leaf); }

.panel { background: var(--card); border-radius: 24px; padding: 18px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 4px 0 var(--line); }
.panel h2 { font-size: 1.3rem; }
.panel p, .panel li { margin: 0; line-height: 1.55; max-width: 65ch; user-select: text; -webkit-user-select: text; }
.panel ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }
.setting { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; padding-block: 10px; border-top: 2px solid var(--sand); }
.setting:first-of-type { border-top: 0; }
.setting > span, .setting > label { font-weight: 800; }
.setting .hint { flex-basis: 100%; margin-top: -6px; font-size: .9rem; color: var(--ink-soft); }
input[type="range"] { width: min(240px, 100%); accent-color: var(--leaf); height: 32px; }
select { font: inherit; font-weight: 700; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
.switch { appearance: none; -webkit-appearance: none; width: 58px; height: 34px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .2s; margin: 0; flex: none; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: var(--card); box-shadow: 0 2px 4px var(--shadow); transition: transform .2s; }
.switch:checked { background: var(--leaf); }
.switch:checked::after { transform: translateX(24px); }
.seg { display: inline-flex; background: var(--sand); border-radius: 999px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 8px 14px; border-radius: 999px; font-weight: 800; cursor: pointer; }
.seg input:checked + label { background: var(--card); box-shadow: 0 2px 6px var(--shadow); }
.seg input:focus-visible + label { outline: 3px dashed var(--ink); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--sky); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.8rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--ink-soft); font-weight: 700; }
.text-btn { align-self: flex-start; border: 2px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 16px; font-weight: 800; }
.text-btn.confirm { border-color: var(--red); color: var(--red); }

/* Étoiles de félicitation */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.fx svg { position: absolute; width: 26px; height: 26px; animation: rise 1.2s ease-out forwards; }
@keyframes rise {
  0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
  25% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1) rotate(40deg); opacity: 0; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--sand);
  font-weight: 800;
  text-align: center;
}

/* Animations réduites (réglage parent ou préférence système) */
.calm .pill.glow, .calm .animal, .calm .screen { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .pill.glow, .screen { animation: none; }
}

@media (max-height: 640px) {
  .guide .lumi-wrap { height: 72px; }
  .baskets { padding-top: 2px; }
}
