:root {
  --card: 76px;
  --ink: #2b2f45;
  --pink: #ff5c8a;
  --yellow: #ffd23f;
  --green: #37c97a;
  --blue: #4fc3f7;
  --orange: #ff7a1a;
  --purple: #8e6bff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif; color: var(--ink); background: #bfe8ff; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; height: 100dvh; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ---- barre du haut ---- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; min-height: 76px; }
.bar h2 { margin: 0; font-size: clamp(20px, 4vw, 30px); text-align: center; flex: 1; text-shadow: 0 2px 0 #fff8; }
.round-btn { width: 68px; height: 68px; border-radius: 50%; background: #fff; font-size: 32px; box-shadow: 0 5px 0 #0002, 0 8px 14px #0002; transition: transform .1s; flex: none; }
.round-btn:active { transform: translateY(3px) scale(.96); }
.round-btn.play { background: var(--green); color: #fff; font-size: 38px; width: 80px; height: 80px; }
.round-btn:disabled { opacity: .45; }
.big-btn { min-height: 76px; padding: 0 36px; border-radius: 40px; background: var(--pink); color: #fff; font-size: 32px; font-weight: 800; box-shadow: 0 7px 0 #c23a64, 0 10px 18px #0003; transition: transform .1s; }
.big-btn.alt { background: var(--blue); box-shadow: 0 7px 0 #2a8fc0, 0 10px 18px #0003; }
.big-btn:active { transform: translateY(4px); }
.small-btn { min-height: 64px; padding: 0 20px; border-radius: 32px; background: var(--orange); color: #fff; font-size: 24px; font-weight: 800; box-shadow: 0 5px 0 #b8540a; }

/* ---- écran titre ---- */
#screen-title { align-items: center; justify-content: center; background: linear-gradient(180deg, #7fd4ff 0%, #c9f0ff 55%, #aef0a8 100%); }
.title-box { display: flex; flex-direction: column; align-items: center; gap: 28px; padding: 28px 40px; border-radius: 40px; background: #ffffffa8; backdrop-filter: blur(4px); }
.title-box { position: relative; z-index: 1; box-shadow: 0 14px 40px #2a8fc033; animation: box-in .6s cubic-bezier(.3,1.6,.5,1) both; }
.title-box h1 { margin: 0; font-size: clamp(40px, 9vw, 84px); line-height: 1.05; text-align: center; }
.title-box h1 .word { display: inline-block; white-space: nowrap; }
.title-box h1 .word > span { display: inline-block; animation: wave 2.4s ease-in-out infinite; animation-delay: calc(var(--i) * .12s); text-shadow: 0 5px 0 #fff, 0 8px 12px #0002; }
.title-box h1 .w1 > span { color: #ff6b8a; }
.title-box h1 .w1 > span:nth-child(even) { color: #ffa53a; }
.title-box h1 .w2 > span { color: #2fa8e8; }
.title-box h1 .w2 > span:nth-child(even) { color: #3cc47c; }
.title-robot { font-size: clamp(64px, 14vw, 120px); line-height: 1; margin-bottom: -10px; animation: robot-hop 1.6s ease-in-out infinite; transform-origin: 50% 100%; filter: drop-shadow(0 10px 8px #0003); }
.play-btn { position: relative; overflow: hidden; font-size: 36px; padding: 0 48px; transition: transform .2s cubic-bezier(.3,1.6,.5,1), box-shadow .2s; }
.play-btn::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; background: linear-gradient(100deg, transparent, #ffffff99, transparent); transform: skewX(-20deg); pointer-events: none; }
.play-btn:hover, .play-btn:focus-visible { animation: play-pulse 1s ease-in-out infinite; box-shadow: 0 7px 0 #c23a64, 0 14px 26px #c23a6455; }
.play-btn:hover::after, .play-btn:focus-visible::after { animation: shine 1.2s ease-in-out infinite; }
.play-btn:active { animation: none; transform: translateY(4px) scale(.97); }
.title-floaters { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.title-floaters span { position: absolute; font-size: clamp(28px, 5vw, 48px); opacity: .85; animation: floaty 6s ease-in-out infinite; }
.title-floaters span:nth-child(1) { left: 8%; top: 14%; }
.title-floaters span:nth-child(2) { right: 10%; top: 18%; animation-delay: -1s; animation-duration: 7s; }
.title-floaters span:nth-child(3) { left: 14%; bottom: 16%; font-size: clamp(40px, 8vw, 80px); animation-delay: -2s; }
.title-floaters span:nth-child(4) { right: 16%; bottom: 14%; animation-delay: -3s; }
.title-floaters span:nth-child(5) { left: 46%; top: 6%; animation-delay: -4s; animation-duration: 5s; }
.title-floaters span:nth-child(6) { right: 4%; top: 52%; font-size: clamp(40px, 8vw, 80px); animation-delay: -2.5s; animation-duration: 8s; }
.title-floaters span:nth-child(7) { left: 4%; top: 50%; animation-delay: -1.5s; }
@keyframes wave { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-12px) rotate(-4deg); } }
@keyframes robot-hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 15% { transform: translateY(0) scale(1.1, .9); } 45% { transform: translateY(-22px) scale(.95, 1.06) rotate(-6deg); } 70% { transform: translateY(0) scale(1.06, .94); } 85% { transform: rotate(4deg); } }
@keyframes play-pulse { 0%, 100% { transform: scale(1.06); } 25% { transform: scale(1.1) rotate(-2deg); } 75% { transform: scale(1.1) rotate(2deg); } }
@keyframes shine { from { left: -60%; } to { left: 130%; } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-18px) rotate(8deg); } }
@keyframes box-in { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .title-box, .title-box h1 .word > span, .title-robot, .play-btn:hover, .play-btn:hover::after, .title-floaters span { animation: none; } }
.logo { width: clamp(80px, 18vw, 160px); border-radius: 28px; }

/* ---- grille de niveaux ---- */
#screen-levels { background: linear-gradient(180deg, #7fd4ff, #d6f5ff 70%, #bdf2b0); }
.level-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 18px; padding: 16px 24px 28px; align-content: safe center; justify-items: center; max-width: 760px; width: 100%; margin: 0 auto; overflow-y: auto; }
.level-btn { width: 112px; height: 112px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; box-shadow: 0 7px 0 #0002, 0 10px 18px #0002; transition: transform .1s; }
.level-btn:active:not(:disabled) { transform: translateY(4px); }
.level-btn.done { background: #fff6c2; }
.level-btn.locked { background: #d5dde3; opacity: .8; }
.level-num { font-size: 42px; font-weight: 900; line-height: 1; }
.level-stars { font-size: 16px; letter-spacing: -1px; min-height: 18px; }

/* ---- écran de jeu ---- */
#screen-game { background: linear-gradient(180deg, #62c3ff 0%, #b7e9ff 55%, #d9f5ff 100%); }
.stage { position: relative; flex: 1; min-height: 0; touch-action: none; }
.stage { z-index: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: -1; }
#screen-game > .bar, #screen-game > .panel { position: relative; z-index: 1; }
.goal { position: absolute; z-index: 2; left: 50%; top: 8px; transform: translateX(-50%); max-width: 92%; padding: 8px 18px; border-radius: 22px; background: #ffffffcc; font-size: 20px; font-weight: 700; text-align: center; pointer-events: none; }
.bubble { position: absolute; z-index: 3; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px; width: max-content; max-width: 94%; padding: 14px 22px; border-radius: 30px; background: #fff; font-size: 24px; font-weight: 800; text-align: center; box-shadow: 0 8px 22px #0003; animation: pop-in .35s cubic-bezier(.3,1.6,.5,1); }
.bubble[hidden] { display: none; }
@keyframes pop-in { from { transform: translateX(-50%) scale(.5); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.panel { background: #ffffffb8; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border-radius: 28px 28px 0 0; padding: 10px 12px 12px; box-shadow: 0 -6px 20px #0002; display: flex; flex-direction: column; gap: 10px; }
.strip-row { display: flex; align-items: stretch; gap: 10px; }
.strip { flex: 1; min-height: calc(var(--card) + 24px); max-height: 26vh; overflow-y: auto; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; padding: 10px; border-radius: 22px; background: #e8f3fb; border: 3px dashed #9cc5e0; position: relative; }
.strip-hint { align-self: center; font-size: 34px; opacity: .5; padding: 0 10px; }
.counter { align-self: center; min-width: 84px; text-align: center; font-size: 26px; font-weight: 900; background: #fff; border-radius: 20px; padding: 10px 8px; }
.counter[hidden] { display: none; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.palette { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px; border-radius: 22px; border: 3px solid transparent; }
.actions { display: flex; gap: 10px; align-items: center; }
.palette.locked, .strip.locked { opacity: .65; pointer-events: none; }

/* ---- cartes ---- */
.card { width: var(--card); height: var(--card); border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 42px; box-shadow: 0 5px 0 #0003; cursor: grab; touch-action: none; position: relative; transition: transform .12s, box-shadow .12s; flex: none; background: #fff; }
.t-forward { background: #bfe6ff; } .t-left { background: #ffe29a; } .t-right { background: #ffe29a; }
.t-repeat { background: #ffc4d6; }
.pcard:hover { transform: translateY(-2px); }
.pcard.pressed, .item.pressed { transform: scale(.94); }
.item.drag-src { opacity: .35; }
.removing { animation: remove .18s forwards; }
@keyframes remove { to { transform: scale(.2) rotate(20deg); opacity: 0; } }
.ghost { position: fixed; z-index: 100; pointer-events: none; opacity: .92; transform: scale(1.12) rotate(-4deg); box-shadow: 0 14px 24px #0004; }
.ghost.block { background: #ffd9e6; }
.current { transform: scale(1.18); z-index: 2; outline: 5px solid #ffcc00; box-shadow: 0 0 0 8px #ffcc0066, 0 0 24px 6px #ffe066; }
.card.current { background-image: linear-gradient(#fff8, #fff8); }
.current-block { outline: 4px solid #ffcc0099; }
.error-blink { animation: blink .45s 4; outline: 5px solid #ff5c5c; }
@keyframes blink { 50% { background: #ff9c9c; transform: scale(1.18); } }
.ins-before { box-shadow: -8px 0 0 #ff5c8a; }
.ins-end { box-shadow: inset -8px 0 0 #ff5c8a; }
.drop-hover { background-color: #d4ecff; }
.drop-bad { background-color: #ffd6d6; }
.palette-del { border-color: #ff5c5c; background: #ffe3e3; }
.controls { border-radius: 22px; border: 3px solid transparent; transition: background .15s; }
.controls.palette-del { border-color: #ff5c5c; background: #ffe3e3; }
.shake { animation: shake .4s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }

/* ---- bloc répéter ---- */
.block { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 22px; background: #ffd0df; box-shadow: 0 5px 0 #0003; border: 4px solid transparent; touch-action: none; flex: none; position: relative; transition: transform .12s; }
.block.active { border-color: var(--pink); background: #ffc2d6; }
.block-head { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.block-icon { font-size: 30px; line-height: 1; }
.badge { min-width: 68px; height: 40px; border-radius: 20px; background: var(--pink); color: #fff; font-weight: 900; font-size: 24px; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 3px 0 #c23a64; }
.block-body { display: flex; gap: 6px; padding: 6px; min-width: calc(var(--card) + 12px); min-height: calc(var(--card) + 12px); background: #fff8; border-radius: 16px; align-items: center; flex-wrap: wrap; max-width: calc(var(--card) * 4 + 40px); }
.block-body .card { --card: 64px; font-size: 36px; }
.slot-empty { width: 56px; height: 56px; border-radius: 14px; border: 3px dashed #e08bab; display: flex; align-items: center; justify-content: center; font-size: 28px; color: #e08bab; }

/* ---- victoire ---- */
.win { position: absolute; inset: 0; background: #0006; display: flex; align-items: center; justify-content: center; z-index: 50; }
.win[hidden] { display: none; }
.win-box { background: #fff; border-radius: 36px; padding: 28px 36px; text-align: center; display: flex; flex-direction: column; gap: 18px; align-items: center; animation: pop-in2 .5s cubic-bezier(.3,1.6,.5,1); max-width: 94%; }
@keyframes pop-in2 { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.win-title { font-size: 44px; font-weight: 900; }
.win-stars { font-size: 64px; letter-spacing: 4px; }
.win-stars span { display: inline-block; animation: star-in .5s both cubic-bezier(.3,1.8,.5,1); }
.win-stars .off { filter: grayscale(1) opacity(.35); }
@keyframes star-in { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.win-actions { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.confetti { position: absolute; top: -20px; width: 14px; height: 22px; border-radius: 4px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); } }

@media (max-width: 640px) {
  :root { --card: 68px; }
  .round-btn { width: 64px; height: 64px; font-size: 28px; }
  .round-btn.play { width: 72px; height: 72px; }
  .controls { flex-wrap: wrap; justify-content: center; }
  .bubble { font-size: 20px; }
}
@media (max-height: 560px) {
  .bar { min-height: 64px; padding: 4px 10px; }
  .goal { display: none; }
}

/* images RunningHub optionnelles (classes posées par src/assets.js) */
.img-title #screen-title { background: url("assets/img/title.png") center/cover no-repeat; }
.img-sky .stage { background: url("assets/img/sky.png") center/cover no-repeat; }
.turn-ico { width: 1em; height: 1em; color: #2b6cb0; display: block; pointer-events: none; }
.block-done { align-self: stretch; display: flex; align-items: center; justify-content: center; min-width: 64px; border-radius: 18px; background: var(--green); color: #fff; font-size: 38px; font-weight: 900; box-shadow: 0 4px 0 #0003; cursor: pointer; touch-action: none; animation: pop-in .3s cubic-bezier(.3,1.6,.5,1); }
.block-done:active { transform: translateY(3px); box-shadow: 0 1px 0 #0003; }

/* carte mise en avant (nouvelle carte, suggestion de boucle) */
.spotlight { animation: spotlight 1s ease-in-out infinite; box-shadow: 0 0 0 5px #ffd23f, 0 0 22px 6px #ffd23faa; position: relative; z-index: 2; }
@keyframes spotlight { 50% { transform: scale(1.14) translateY(-4px); } }

.surprise-row { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 24px 24px; flex-wrap: wrap; }
.surprise-label { font-weight: 800; font-size: 1.3rem; color: var(--ink); }
.surprise-btn { min-width: 80px; height: 80px; border-radius: 24px; border: 0; font-size: 2.4rem; cursor: pointer; background: var(--purple); color: #fff; box-shadow: 0 6px 0 #5b3fd0; touch-action: manipulation; }
.surprise-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #5b3fd0; }
/* titre lisible sur le décor qui passe sous l'en-tête */
#screen-game .bar h2 { text-shadow: 0 0 6px #fff, 0 0 12px #fff, 0 2px 0 #fff; }

/* téléphone : l'écran des niveaux tient sans masquer le niveau 1 */
@media (max-width: 480px) {
  .level-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 10px 12px 12px; }
  .level-btn { width: 72px; height: 72px; }
  .level-num { font-size: 26px; }
  .level-stars { font-size: 11px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .level-grid { grid-template-columns: repeat(8, 1fr); gap: 8px; padding: 6px 16px; }
  .level-btn { width: 64px; height: 64px; box-shadow: 0 4px 0 #0002; }
  .level-num { font-size: 22px; }
  .level-stars { font-size: 9px; }
  .surprise-row { padding: 4px 8px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .surprise-row { padding: 2px 8px calc(4px + env(safe-area-inset-bottom)); gap: 10px; }
  .surprise-btn { min-width: 56px; height: 52px; font-size: 1.6rem; border-radius: 18px; }
  .surprise-label { font-size: 1rem; }
}
@media (max-width: 480px) { .surprise-row { padding: 4px 8px calc(12px + env(safe-area-inset-bottom)); } .surprise-btn { height: 60px; } }
