:root {
  --orange: #ff8a3d;
  --orange-d: #d9621c;
  --green: #35c26f;
  --green-d: #1f9a52;
  --ink: #3b2414;
  --panel: rgba(255, 250, 242, .94);
  --shadow: 0 24px 60px rgba(40, 20, 0, .28);
  --gold: #ffc93c;
}

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #1b1230;
  font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}

#game { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

button { font-family: inherit; border: 0; cursor: pointer; color: inherit; background: none; }
svg { width: 1em; height: 1em; fill: currentColor; display: block; flex-shrink: 0; }
svg.gold { color: var(--gold); filter: drop-shadow(0 1px 0 #c98f00); }

/* ---------- Écrans ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  opacity: 0; visibility: hidden;
  transition: opacity .35s ease, visibility .35s;
}
.screen.show { opacity: 1; visibility: visible; }
.screen.dim { background: rgba(24, 12, 34, .45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

.panel {
  position: relative;
  background: var(--panel);
  border-radius: 30px;
  box-shadow: var(--shadow), inset 0 -6px 0 rgba(0, 0, 0, .06);
  padding: 30px 28px 26px;
  text-align: center;
  width: 100%; max-width: 420px;
  max-height: 100%; overflow: auto;
  transform: scale(.88) translateY(24px);
  transition: transform .5s cubic-bezier(.2, 1.4, .4, 1);
}
.screen.show .panel { transform: none; }
.panel.wide { max-width: 900px; }
.panel h2 { font-size: 34px; font-weight: 700; letter-spacing: -.5px; }
.panel .sub { margin: 6px 0 20px; font-size: 16px; opacity: .75; line-height: 1.35; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 18px; }
.row .btn { width: auto; flex: 1; }

/* ---------- Boutons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 14px 22px; border-radius: 18px;
  font-size: 20px; font-weight: 600; color: #fff;
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.btn svg { font-size: 22px; }
.btn small {
  font-size: 14px; font-weight: 600;
  background: rgba(255, 255, 255, .25);
  padding: 3px 10px; border-radius: 99px;
}
.btn-primary { background: linear-gradient(180deg, #ffa860, #ff7a2e); box-shadow: 0 6px 0 var(--orange-d), 0 14px 26px rgba(255, 122, 46, .35); }
.btn-green   { background: linear-gradient(180deg, #55e08f, #2fbf6a); box-shadow: 0 6px 0 var(--green-d), 0 14px 26px rgba(47, 191, 106, .3); }
.btn-light   { background: #fff; color: var(--ink); box-shadow: 0 6px 0 #e6d7c4, 0 10px 20px rgba(0, 0, 0, .08); }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(5px); }
.btn-primary:active { box-shadow: 0 1px 0 var(--orange-d); }
.btn-green:active { box-shadow: 0 1px 0 var(--green-d); }
.btn-light:active { box-shadow: 0 1px 0 #e6d7c4; }

.icon-btn {
  position: relative; flex-shrink: 0;
  width: 48px; height: 48px; border-radius: 16px;
  background: rgba(255, 255, 255, .92); color: var(--ink);
  display: grid; place-items: center; font-size: 22px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .13);
  transition: transform .12s, box-shadow .12s, opacity .2s;
}
.icon-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .13); }
.icon-btn.big { width: 58px; height: 58px; font-size: 26px; border-radius: 18px; box-shadow: 0 6px 0 #e6d7c4; background: #fff; }
.icon-btn.small { width: 42px; height: 42px; font-size: 18px; border-radius: 14px; }
.icon-btn.off { opacity: .55; }
.icon-btn.off::after {
  content: ''; position: absolute; width: 30px; height: 3px;
  background: #e5484d; border-radius: 2px; transform: rotate(-45deg);
}

.pill {
  background: rgba(255, 255, 255, .9); padding: 6px 14px; border-radius: 99px;
  font-weight: 600; display: inline-flex; gap: 6px; align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .12); font-size: 16px;
}

/* ---------- Logo ---------- */
.logo {
  display: flex; flex-direction: column; align-items: center;
  font-size: clamp(56px, 12vw, 116px); line-height: .88; font-weight: 700; letter-spacing: -1px;
}
.logo span { display: block; }
.logo .l1 {
  color: #fff; transform: rotate(-4deg);
  text-shadow: 0 4px 0 #ff9d4d, 0 8px 0 #c2571a, 0 18px 30px rgba(0, 0, 0, .35);
  animation: floaty 3.2s ease-in-out infinite;
}
.logo .l2 {
  color: #ffd25e; transform: rotate(2deg);
  text-shadow: 0 4px 0 #e08a1a, 0 8px 0 #8f3b0c, 0 18px 30px rgba(0, 0, 0, .35);
  animation: floaty 3.2s ease-in-out infinite .4s;
}
@keyframes floaty {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -8px; }
}
.tagline {
  color: #fff; font-weight: 500; margin-top: 14px;
  font-size: clamp(15px, 2.2vw, 19px);
  text-shadow: 0 2px 10px rgba(0, 0, 0, .45);
}

/* ---------- Splash ---------- */
#splash { background: radial-gradient(ellipse at center, rgba(0,0,0,0) 30%, rgba(20,8,30,.45)); cursor: pointer; }
.splash-inner { text-align: center; }
.tap {
  margin-top: 34px; display: inline-block;
  background: rgba(255, 255, 255, .92); padding: 12px 26px; border-radius: 99px;
  font-weight: 600; font-size: 18px; box-shadow: 0 6px 0 rgba(0,0,0,.15);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* ---------- Menu ---------- */
#menu { background: linear-gradient(90deg, rgba(20,8,30,.0), rgba(20,8,30,.12)); }
.menu-top {
  position: absolute; display: flex; gap: 10px;
  top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right));
}
.menu-wrap { display: flex; flex-direction: column; align-items: center; gap: 26px; width: 100%; max-width: 420px; }
.menu-brand { text-align: center; }
.menu-actions { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 340px; }
.menu-stats { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.hint {
  text-align: center; font-size: 13px; color: #fff; opacity: .9;
  text-shadow: 0 1px 6px rgba(0,0,0,.5); line-height: 1.4;
}
#menu.show .menu-actions > * { animation: rise .55s backwards cubic-bezier(.2, 1.3, .4, 1); }
#menu.show .menu-actions > *:nth-child(2) { animation-delay: .06s; }
#menu.show .menu-actions > *:nth-child(3) { animation-delay: .12s; }
#menu.show .menu-actions > *:nth-child(4) { animation-delay: .18s; }
#menu.show .menu-actions > *:nth-child(5) { animation-delay: .24s; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.95); } }

@media (max-height: 560px) and (orientation: landscape) {
  .menu-wrap { flex-direction: row; max-width: 860px; gap: 48px; justify-content: center; }
  .logo { font-size: clamp(52px, 13vh, 96px); }
  .menu-actions { gap: 10px; }
  .btn { padding: 11px 20px; font-size: 18px; }
}

/* ---------- Niveaux ---------- */
.panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.panel-head h2 { flex: 1; font-size: 28px; text-align: left; }
#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.lvl-card {
  position: relative; overflow: hidden;
  aspect-ratio: 1 / 1.02; border-radius: 22px; padding: 10px;
  background: linear-gradient(160deg, var(--c1), var(--c2));
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .2), inset 0 2px 0 rgba(255, 255, 255, .35);
  animation: pop .5s backwards cubic-bezier(.2, 1.4, .4, 1);
  transition: transform .15s;
}
.lvl-card::before {
  content: ''; position: absolute; left: -20%; right: -20%; bottom: -30%; height: 55%;
  background: rgba(255, 255, 255, .14); border-radius: 50%;
}
.lvl-num { font-size: 42px; font-weight: 700; line-height: 1; text-shadow: 0 3px 0 rgba(0, 0, 0, .22); position: relative; }
.lvl-name { font-size: 13px; font-weight: 600; line-height: 1.1; text-shadow: 0 1px 3px rgba(0, 0, 0, .4); position: relative; }
.lvl-stars { display: flex; gap: 3px; font-size: 18px; color: rgba(0, 0, 0, .25); position: relative; }
.lvl-stars .on { color: var(--gold); filter: drop-shadow(0 1px 0 #b07a00); }
.lvl-card.locked { filter: grayscale(.85) brightness(.7); }
.lvl-lock { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; background: rgba(30, 20, 40, .3); }
.lvl-card:not(.locked):hover { transform: translateY(-4px) rotate(-1.5deg); }
.lvl-card:not(.locked):active { transform: translateY(3px); }
.lvl-card.current { outline: 4px solid #fff; outline-offset: -4px; }
.lvl-card.shake { animation: shake .4s; }
@keyframes pop { from { opacity: 0; transform: scale(.6); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

@media (max-width: 640px) {
  #level-grid { grid-template-columns: repeat(2, 1fr); }
  .panel.wide { padding: 20px 16px; }
}
@media (min-width: 641px) and (max-width: 820px) { #level-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-height: 560px) and (orientation: landscape) {
  #level-grid { grid-template-columns: repeat(5, 1fr); gap: 10px; }
  .lvl-card { aspect-ratio: auto; height: 104px; }
  .lvl-num { font-size: 32px; }
  .panel-head { margin-bottom: 12px; }
  .panel { padding: 18px 20px; }
}

/* ---------- Panneaux de fin ---------- */
.ribbon {
  display: inline-block; margin: -52px auto 10px;
  background: linear-gradient(180deg, #ffa860, #ff7a2e); color: #fff;
  padding: 10px 28px; border-radius: 16px; font-size: 24px; font-weight: 700;
  box-shadow: 0 6px 0 var(--orange-d), 0 12px 24px rgba(255, 122, 46, .35);
  transform: rotate(-2deg);
}
.big-stars { display: flex; justify-content: center; align-items: flex-end; gap: 6px; margin: 10px 0 18px; }
.big-stars svg { font-size: 64px; color: rgba(0, 0, 0, .12); }
.big-stars svg:nth-child(2) { font-size: 82px; }
.big-stars svg.got { color: var(--gold); filter: drop-shadow(0 4px 0 #c98f00); animation: starPop .6s backwards cubic-bezier(.2, 1.6, .4, 1); }
@keyframes starPop { from { transform: scale(0) rotate(-90deg); opacity: 0; } }
.stats { display: flex; gap: 12px; justify-content: center; margin-bottom: 8px; }
.stat {
  flex: 1; max-width: 150px; background: #fff; border-radius: 18px; padding: 12px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: 0 4px 0 #eadcc9;
}
.stat svg, .stat .i-orange { font-size: 24px; width: 24px; height: 24px; }
.stat b { font-size: 22px; }
.stat small { font-size: 13px; opacity: .6; font-weight: 500; }
.toggles { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
#ending .panel h2 { margin-top: 4px; }
#ending .stats { margin: 10px 0 18px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  opacity: 0; transform: translateY(-24px); transition: opacity .4s, transform .4s;
}
#hud.show { opacity: 1; transform: none; }
.hud-group { display: flex; gap: 8px; align-items: center; }
.chip {
  background: rgba(255, 255, 255, .9); border-radius: 14px; padding: 6px 12px; height: 42px;
  display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 19px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .13);
}
#hearts { gap: 3px; padding: 6px 10px; }
#hearts svg { font-size: 24px; color: #ff4d6d; filter: drop-shadow(0 2px 0 #c42a48); }
#hearts svg.empty { color: rgba(0, 0, 0, .15); filter: none; }
#hearts svg.lost { animation: heartLost .5s; }
@keyframes heartLost { 30% { transform: scale(1.5); } }
#hud-stars { gap: 2px; padding: 6px 10px; }
#hud-stars svg { font-size: 20px; color: rgba(0, 0, 0, .15); }
#hud-stars svg.got { color: var(--gold); filter: drop-shadow(0 1px 0 #c98f00); animation: starPop .5s cubic-bezier(.2, 1.6, .4, 1); }
#hud-oranges.bump { animation: heartLost .3s; display: inline-block; }
#btn-pause { pointer-events: auto; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 4px; }
#hud-level { font-weight: 700; color: #fff; font-size: 15px; text-shadow: 0 2px 6px rgba(0, 0, 0, .5); white-space: nowrap; }
.progress { position: relative; width: min(26vw, 240px); height: 10px; background: rgba(255, 255, 255, .45); border-radius: 99px; box-shadow: inset 0 2px 3px rgba(0,0,0,.15); }
#progress-fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #ffd25e, #ff7a2e); }
#progress-dot {
  position: absolute; top: 50%; left: 0; width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border-radius: 50%; background: #b77840; border: 3px solid #fff; box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
.i-orange {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 35% 35%, #ffe0a0, #ff9a1a 55%, #e06a00);
}
.i-orange::after {
  content: ''; position: absolute; width: 8px; height: 5px; top: -2px; right: 1px;
  background: #4caf50; border-radius: 0 80% 0 80%;
}
@media (max-width: 560px) { .hud-center { display: none; } .chip { height: 38px; font-size: 17px; padding: 4px 10px; } #hearts svg { font-size: 20px; } }

/* ---------- Contrôles tactiles ---------- */
#touch {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: none; justify-content: space-between; align-items: flex-end;
  padding: 0 max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  pointer-events: none;
}
body.touch.playing #touch { display: flex; }
#dpad { display: flex; gap: 14px; pointer-events: auto; touch-action: none; }
.tbtn {
  width: 80px; height: 80px; border-radius: 50%;
  background: rgba(255, 255, 255, .26); border: 2px solid rgba(255, 255, 255, .6);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; color: #fff; font-size: 38px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .22);
  transition: transform .08s, background .08s;
  touch-action: none;
}
.tbtn.on { transform: scale(.9); background: rgba(255, 255, 255, .5); }
#btn-jump { width: 100px; height: 100px; background: rgba(255, 138, 61, .55); border-color: rgba(255, 225, 200, .85); pointer-events: auto; font-size: 44px; }
#btn-jump.on { background: rgba(255, 138, 61, .8); }
@media (max-height: 420px) { .tbtn { width: 68px; height: 68px; } #btn-jump { width: 84px; height: 84px; } }

/* ---------- Bannière / toast ---------- */
#banner {
  position: fixed; left: 50%; top: 36%; z-index: 15; text-align: center; color: #fff; pointer-events: none;
  transform: translate(-50%, -50%) scale(.6); opacity: 0;
}
#banner small { display: block; font-size: 18px; font-weight: 600; letter-spacing: 5px; text-transform: uppercase; text-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
#banner strong { display: block; font-size: clamp(32px, 7vw, 66px); font-weight: 700; white-space: nowrap; text-shadow: 0 4px 0 #c2571a, 0 10px 26px rgba(0, 0, 0, .4); }
#banner.show { animation: banner 2.8s ease forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.95); }
}
#toast {
  position: fixed; left: 50%; top: 70px; z-index: 15; pointer-events: none;
  background: rgba(255, 255, 255, .95); padding: 8px 18px; border-radius: 99px; font-weight: 600;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .12);
  transform: translate(-50%, -20px); opacity: 0;
}
#toast.show { animation: toast 1.8s ease forwards; }
@keyframes toast { 12%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -10px); } }
