:root {
  --sky: #8FD3FE;
  --sea: #2EC4B6;
  --sun: #FFD166;
  --coral: #FF8C69;
  --violet: #9B7EDE;
  --wood: #C8874A;
  --ink: #3D2C4E;
  --cream: #FFF8EC;
  --paper: #FBF1DC;
  --sepia: #5D4632;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, #CDEBFF 55%, #FFE9C7 100%);
}
#app { position: relative; width: 100%; height: 100dvh; }

.screen {
  position: absolute; inset: 0;
  display: none; overflow-y: auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.screen.active { display: block; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.screen.paper {
  background: var(--paper);
  background-image: radial-gradient(rgba(93,70,50,.06) 1px, transparent 1px);
  background-size: 6px 6px;
}

/* Titres et textes */
.title, .page-title {
  font-family: 'Baloo 2', 'Nunito', sans-serif; font-weight: 800;
  color: var(--ink); text-align: center; line-height: 1.1; margin: 8px 0;
}
.title { font-size: clamp(30px, 7vw, 54px); text-shadow: 3px 3px 0 #fff; }
.page-title { font-size: clamp(26px, 5.5vw, 40px); }
.subtitle, .page-sub { text-align: center; font-size: 18px; margin: 6px auto 18px; max-width: 560px; }
.ink { color: var(--sepia); text-shadow: none; }
.ink-soft { color: var(--sepia); opacity: .8; text-align: center; }

.page { max-width: 640px; margin: 0 auto; padding: 72px 0 32px; }
.page.center, .accueil-inner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100%; padding-top: 24px;
}
.accueil-inner { min-height: 100dvh; max-width: 640px; margin: 0 auto; }

/* Boutons façon cartoon */
.btn {
  display: block; width: 100%; max-width: 380px; margin: 10px auto;
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 21px;
  padding: 14px 20px; border-radius: 22px; border: 3px solid var(--ink);
  cursor: pointer; transition: transform .1s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink) !important; }
.btn-main { background: var(--sun); color: var(--ink); box-shadow: 0 6px 0 var(--ink); }
.btn-soft { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--ink); }
.btn.danger { margin-top: 32px; color: #B23A48; }
.btn-small {
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 16px;
  padding: 8px 14px; border-radius: 16px; border: 3px solid var(--ink);
  background: #fff; color: var(--ink); box-shadow: 0 4px 0 var(--ink); cursor: pointer;
}
.icon-btn.gear {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 16px; z-index: 2;
  width: 50px; height: 50px; font-size: 26px; border-radius: 50%;
  border: 3px solid var(--ink); background: #fff; box-shadow: 0 4px 0 var(--ink); cursor: pointer;
}

.topbar {
  position: absolute; top: env(safe-area-inset-top); left: 0; right: 0;
  display: flex; justify-content: space-between; gap: 8px; padding: 12px 16px; z-index: 3;
}

/* Lumi */
.lumi svg { width: 100%; height: 100%; display: block; overflow: visible; }
.lumi-big { width: clamp(220px, 50vw, 320px); height: clamp(140px, 32vw, 200px); }
.lumi-small { width: 96px; height: 62px; flex: 0 0 auto; }
.lumi .aile { transform-box: fill-box; animation: battement 1.6s ease-in-out infinite; }
.lumi .aile-g { transform-origin: right center; }
.lumi .aile-d { transform-origin: left center; }
@keyframes battement { 0%,100% { transform: rotate(0deg); } 50% { transform: rotate(-9deg); } }
.lumi .aile-d { animation-name: battement-d; }
@keyframes battement-d { 0%,100% { transform: rotate(0deg); } 50% { transform: rotate(9deg); } }
.float { animation: float 3.2s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* Bulle de Lumi */
.bubble-wrap {
  position: absolute; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; align-items: flex-end; gap: 8px; z-index: 3;
  max-width: 720px; margin: 0 auto; pointer-events: none;
}
.bubble-wrap.static { position: static; margin: 16px auto; }
.bubble {
  pointer-events: auto;
  background: #fff; border: 3px solid var(--ink); border-radius: 22px;
  padding: 12px 16px; font-size: 18px; line-height: 1.35; min-height: 54px;
  box-shadow: 0 5px 0 rgba(61,44,78,.35); flex: 1;
}
.bubble:empty { display: none; }
.bubble.big { flex: 0 0 auto; width: 100%; max-width: 560px; margin: 16px auto; font-size: 20px; font-style: italic; }

/* Niveau */
#screen-niveau { padding: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

/* Carte des niveaux */
.levels { display: flex; flex-direction: column; gap: 16px; margin-top: 12px; }
.level-card {
  display: flex; gap: 14px; align-items: center;
  border: 3px solid var(--ink); border-radius: 24px; padding: 14px;
  box-shadow: 0 6px 0 var(--ink); background: #fff;
}
.lv1 { background: linear-gradient(135deg, #BFF0EA, #FFF3C9); }
.lv2 { background: linear-gradient(135deg, #FFD9EC, #FFF3C9); }
.lv3 { background: linear-gradient(135deg, #E3D9FF, #FFE3C2); }
.level-card.locked { opacity: .6; }
.level-num {
  flex: 0 0 64px; height: 64px; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--sun); display: grid; place-items: center;
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 26px;
}
.level-info h3 { margin: 0; font-family: 'Baloo 2', sans-serif; font-size: 22px; }
.level-info p { margin: 2px 0 8px; opacity: .8; }
.level-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.soon { font-weight: 700; opacity: .7; }

/* Personnage */
.perso { width: 170px; height: 200px; }
.perso svg { width: 100%; height: 100%; }
.perso-name { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 22px; margin: 4px 0 0; }

/* Grimoire */
.question { font-family: 'Baloo 2', sans-serif; font-size: 22px; color: var(--sepia); text-align: center; margin: 22px 0 12px; }
textarea {
  width: 100%; font-family: 'Nunito', sans-serif; font-size: 19px; color: var(--sepia);
  background: rgba(255,255,255,.6); border: 2px dashed #B79C7A; border-radius: 16px; padding: 14px;
  resize: vertical; outline: none;
}
textarea:focus { border-style: solid; background: #fff; }
.trace { border-bottom: 2px dashed #D8C4A4; padding: 14px 4px; color: var(--sepia); }
.trace .q { font-size: 15px; opacity: .75; margin: 0 0 6px; }
.trace .c { font-size: 19px; margin: 0; white-space: pre-wrap; }
.trace .d { font-size: 13px; opacity: .6; margin-top: 6px; }
.empty { text-align: center; color: var(--sepia); opacity: .75; margin-top: 30px; }

/* Récompense */
.reward-glow {
  width: 170px; height: 170px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle, #FFF5C2 0%, rgba(255,209,102,.6) 45%, transparent 70%);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.08); } }
.balise { width: 80px; height: 110px; }
.balise svg { width: 100%; height: 100%; }

/* Réglages */
.setting {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  padding: 14px 18px; margin: 12px 0; font-size: 19px; font-weight: 700;
}
.setting input { width: 26px; height: 26px; accent-color: var(--sea); }

@media (max-width: 480px) {
  .topbar .btn-small { font-size: 14px; padding: 7px 10px; }
  .bubble { font-size: 16px; }
}
