:root {
  --pink: #ff5fa2;
  --pink-light: #ffd3e6;
  --cream: #fff7e8;
  --ink: #5a2342;
  --gold: #ffc531;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #ffd6ec; font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif; color: var(--ink); }
canvas#c { display: block; width: 100vw; height: 100vh; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.pill { background: rgba(255, 247, 232, 0.92); border: 3px solid var(--pink); border-radius: 999px; padding: 4px 16px; font-weight: 800; font-size: 20px; box-shadow: 0 4px 0 rgba(90, 35, 66, 0.18); }
#hud-candies { position: absolute; top: 14px; left: 14px; font-size: 24px; }
#hud-objective { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); max-width: min(640px, 62vw); text-align: center; font-size: 17px; font-weight: 700; border-radius: 18px; }
#hud-right { position: absolute; top: 14px; right: 14px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#hud-timer { font-size: 26px; min-width: 96px; text-align: center; }
#hud-timer.urgent { background: #ffe0e0; border-color: #ff3b3b; color: #c00; animation: pulse 0.5s infinite alternate; }
#hud-goal { font-size: 22px; }
#hud-map { width: 220px; height: 250px; border: 3px solid var(--pink); border-radius: 20px; box-shadow: 0 4px 0 rgba(90, 35, 66, 0.18); }
@media (max-width: 640px) { #hud-map { width: 150px; height: 170px; } }
#hud-prompt { position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); font-size: 20px; animation: bob 1s infinite alternate ease-in-out; }
#hud-help { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 13px; background: rgba(255,255,255,0.65); padding: 2px 12px; border-radius: 10px; white-space: nowrap; }
@keyframes pulse { to { transform: scale(1.08); } }
@keyframes bob { to { transform: translate(-50%, -6px); } }
#hud-candies.bump { animation: bump 0.28s ease-out; }
@keyframes bump { 40% { scale: 1.25; } }
#hud-boost { position: absolute; top: 108px; left: 14px; background: linear-gradient(90deg, #ffd3e6, #fff3b0, #c9f3ff, #e2d4ff); animation: pulse 0.35s infinite alternate; }
.round-btn { pointer-events: auto; font-family: inherit; font-size: 22px; width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--pink); background: rgba(255, 247, 232, 0.92); color: var(--ink); cursor: pointer; box-shadow: 0 4px 0 rgba(90, 35, 66, 0.18); display: grid; place-items: center; padding: 0; }
.round-btn:active { transform: translateY(3px); box-shadow: none; }
.round-btn.small { width: 36px; height: 36px; font-size: 17px; }
#btn-pause { position: absolute; bottom: 14px; right: 14px; }
#btn-close { position: absolute; bottom: 14px; right: 68px; font-size: 18px; }

/* ---------- juice: floating texts, countdown, toast ---------- */
#fx-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.fx-text { position: absolute; left: 0; top: 0; font-weight: 800; font-size: 26px; color: #fff; -webkit-text-stroke: 1.5px var(--pink); text-shadow: 0 3px 0 rgba(90, 35, 66, 0.25); white-space: nowrap; animation: fxpop 0.25s ease-out; }
.fx-text.combo { font-size: 30px; color: var(--gold); -webkit-text-stroke-color: #c26b00; }
.fx-text.gold { font-size: 38px; color: var(--gold); -webkit-text-stroke-color: #b06a00; }
.fx-text.clock { font-size: 34px; color: #bff0ff; -webkit-text-stroke-color: #2b88d8; }
.fx-text.rainbow { font-size: 34px; background: linear-gradient(90deg, #ff4f9a, #ffd23f, #5cdb6e, #4fd1ff, #9b5cff); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 1px #fff; }
@keyframes fxpop { from { scale: 0.3; } 70% { scale: 1.2; } }
#countdown { position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%); pointer-events: none; font-size: clamp(90px, 18vw, 180px); font-weight: 800; color: #fff; -webkit-text-stroke: 4px var(--pink); text-shadow: 0 8px 0 rgba(90, 35, 66, 0.25); white-space: nowrap; }
#countdown.pop, #toast.pop { animation: cdpop 0.4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes cdpop { from { scale: 0.2; opacity: 0; } }
#toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); pointer-events: none; background: linear-gradient(90deg, #fff3b0, #ffe0f0); border: 3px solid var(--gold); border-radius: 18px; padding: 8px 20px; font-weight: 800; font-size: 22px; box-shadow: 0 6px 0 rgba(90, 35, 66, 0.18); max-width: 92vw; text-align: center; }

/* ---------- dialog ---------- */
#dialog { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(520px, 70vw); background: rgba(255, 247, 232, 0.72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); border: 3px solid rgba(255, 95, 162, 0.85); border-radius: 18px; padding: 10px 14px 10px; box-shadow: 0 5px 0 rgba(90, 35, 66, 0.15); }
#dialog-who { position: absolute; top: -15px; left: 16px; background: var(--pink); color: white; font-weight: 800; padding: 0 12px; border-radius: 999px; font-size: 14px; }
#dialog-text { font-size: 15px; line-height: 1.3; margin: 4px 0 8px; white-space: pre-line; padding-right: 30px; }
#dialog-listen { position: absolute; top: 6px; right: 8px; }
#dialog .round-btn.small { width: 28px; height: 28px; font-size: 13px; border-width: 2px; }
#dialog button.btn { font-size: 14px; padding: 4px 14px; box-shadow: 0 3px 0 #c23b77; }
#dialog button.btn.secondary { box-shadow: 0 3px 0 #d9b3c7; }
#dialog-buttons { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
button.btn { font-family: inherit; font-weight: 800; font-size: 18px; border: none; border-radius: 999px; padding: 6px 20px; cursor: pointer; background: var(--pink); color: white; box-shadow: 0 4px 0 #c23b77; }
button.btn.secondary { background: #f3d7e6; color: var(--ink); box-shadow: 0 4px 0 #d9b3c7; }
button.btn:hover { filter: brightness(1.07); }
button.btn:active { transform: translateY(3px); box-shadow: none; }

/* ---------- full screens ---------- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; background: radial-gradient(circle at 50% 30%, rgba(255, 240, 248, 0.88), rgba(255, 190, 220, 0.9)); text-align: center; padding: 16px; }
.screen h1 { font-size: clamp(42px, 9vw, 84px); margin: 0; color: var(--pink); text-shadow: 0 5px 0 #fff, 0 9px 0 rgba(90, 35, 66, 0.18); }
.screen p { font-size: 22px; margin: 8px 0 18px; }
.progress { width: min(420px, 80vw); height: 18px; background: #fff; border: 3px solid var(--pink); border-radius: 999px; overflow: hidden; }
#load-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #ff9fc8, var(--pink)); transition: width 0.15s; }
.cards { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.card { font-family: inherit; background: var(--cream); border: 4px solid var(--pink); border-radius: 24px; padding: 12px 12px 6px; cursor: pointer; width: min(230px, 42vw); box-shadow: 0 6px 0 rgba(90, 35, 66, 0.2); transition: transform 0.15s; }
.card:hover { transform: translateY(-6px) rotate(-1deg); }
.card img { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #fff; border-radius: 16px; }
.card span { display: block; font-size: 28px; font-weight: 800; color: var(--pink); }
#end-buttons, .btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
#select-stats { font-weight: 800; color: var(--pink); background: rgba(255, 247, 232, 0.9); border-radius: 999px; padding: 4px 18px; margin-top: 18px; }
#end-stars { display: flex; gap: 8px; margin: 4px 0; }
#end-stars .star { font-size: clamp(56px, 10vw, 84px); color: #e9cbd9; text-shadow: 0 5px 0 rgba(90, 35, 66, 0.15); }
#end-stars .star.on { color: var(--gold); animation: starIn 0.45s cubic-bezier(.2, 1.8, .4, 1) both; -webkit-text-stroke: 2px #e09a00; }
@keyframes starIn { from { scale: 0; rotate: -90deg; } }
#end-stats { display: grid; gap: 6px; margin-bottom: 6px; min-width: min(380px, 88vw); }
.stat { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(255, 247, 232, 0.9); border-radius: 14px; padding: 4px 16px; font-size: 19px; }
.stat b { color: var(--pink); }
.stat em { font-style: normal; font-size: 14px; font-weight: 800; color: #fff; background: var(--gold); border-radius: 999px; padding: 0 10px; }
#end-teaser { font-size: 18px !important; font-weight: 700; }
.screen > :first-child { margin-top: auto !important; }
.screen > :last-child { margin-bottom: auto !important; }
#screen-end { z-index: 6; }
.panel { display: grid; gap: 10px; background: var(--cream); border: 4px solid var(--pink); border-radius: 22px; padding: 16px 22px; margin: 14px 0 18px; min-width: min(420px, 90vw); text-align: left; }
.panel .row { display: flex; align-items: center; justify-content: space-between; gap: 14px; font-size: 19px; font-weight: 700; cursor: pointer; }
.panel input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--pink); order: 2; }
.panel input[type="range"] { accent-color: var(--pink); width: 160px; }

@media (max-width: 640px) {
  #hud-objective { top: 58px; max-width: 92vw; font-size: 15px; }
  #hud-help { display: none; }
  .pill { font-size: 17px; }
}

/* ---------- energy ---------- */
#hud-energy, #shop-energy { display: flex; align-items: center; gap: 8px; }
#hud-energy { position: absolute; top: 62px; left: 14px; }
#hud-energy .bar, #shop-energy .bar { width: 130px; height: 14px; background: #f1dbe7; border-radius: 7px; overflow: hidden; }
#energy-fill, #shop-energy-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #7ee07a, #b8f56a); border-radius: 7px; transition: width 0.25s, background 0.4s; }
#hud-energy.low { border-color: #ff9a3b; animation: pulse 0.6s infinite alternate; }
#hud-energy.low #energy-fill, #shop-energy.low #shop-energy-fill { background: linear-gradient(90deg, #ff7a3b, #ffc531); }
#hud-energy.empty { border-color: #ff3b3b; background: #ffe0e0; }
#energy-icon { display: inline-block; }
#hud-energy.gain { animation: bump 0.4s ease-out; }
#hud-energy.hurt { animation: hurt 0.4s ease-out; border-color: #ff3b3b; }
@keyframes hurt { 20% { translate: -6px 0; } 40% { translate: 6px 0; } 60% { translate: -4px 0; } 80% { translate: 3px 0; } }
.fx-text.hurt { font-size: 30px; color: #ffd2d2; -webkit-text-stroke-color: #d42a2a; }
.fx-text.energy { font-size: 28px; color: #fff3a8; -webkit-text-stroke-color: #3a9a2e; }

/* ---------- shop interior ---------- */
#screen-shop { --side: min(36vw, 340px); position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; justify-content: center; align-items: flex-end; padding: 12px; background: #4a2638; animation: shopin 0.35s ease-out; }
@keyframes shopin { from { opacity: 0; transform: scale(1.04); } }
/* the picture fills the screen minus the menu column, so Capi / the hedgehog are never hidden */
#shop-bg { position: absolute; inset: 0 calc(var(--side) - 30px) 0 0; background: #3a2030 42% 40% / cover no-repeat; }
#shop-panel { position: relative; width: var(--side); max-height: 100%; overflow-y: auto; background: rgba(255, 247, 232, 0.8); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); border: 3px solid var(--pink); border-radius: 18px; padding: 10px 12px 12px; box-shadow: 0 5px 0 rgba(90, 35, 66, 0.2); }
#shop-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#shop-head .pill { font-size: 14px; padding: 1px 10px; border-width: 2px; }
#shop-energy .bar { width: 70px; height: 10px; }
#shop-title { margin: 0 auto 0 0; font-size: 20px; color: var(--pink); width: 100%; }
#shop-wallet { font-size: 15px; }
#shop-text { margin: 4px 0 6px; font-size: 14px; font-weight: 700; min-height: 1.3em; line-height: 1.25; }
#shop-menu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 8px; }
#shop-panel button.btn { font-size: 14px; padding: 4px 14px; }
#shop-exit { margin-left: auto; } /* in the header: always visible, even on a short iPhone screen */
.shop-item { font-family: inherit; color: var(--ink); background: rgba(255, 255, 255, 0.85); border: 2px solid var(--pink-light); border-radius: 14px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; box-shadow: 0 4px 0 rgba(90, 35, 66, 0.15); transition: transform 0.1s, border-color 0.15s; }
.shop-item:hover:not(.off) { transform: translateY(-3px); border-color: var(--pink); }
.shop-item:active:not(.off) { transform: translateY(2px); box-shadow: none; }
.shop-item.off { opacity: 0.5; filter: grayscale(0.6); }
.shop-item .emoji { font-size: 24px; line-height: 1.1; }
.shop-item .name { font-weight: 800; font-size: 12px; text-align: center; line-height: 1.1; }
.shop-item .info { font-size: 12px; font-weight: 700; display: flex; gap: 6px; }
.shop-item .price { color: #c2386f; }
.shop-item .gain { color: #3a9a2e; }
.shop-item.bought { animation: bump 0.35s ease-out; }


/* ---------- castle hall (before the labyrinth) ---------- */
#screen-hall { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 16px; overflow: hidden; animation: shopin 0.35s ease-out; }
#hall-bg { position: absolute; inset: 0; background: #3a2030 center 62% / cover no-repeat; transform-origin: 50% 62%; }
#hall-flash { position: absolute; inset: 0; background: radial-gradient(circle at 50% 60%, #fff, #ffe3f0); opacity: 0; pointer-events: none; }
#hall-panel { position: relative; width: min(520px, 70vw); background: rgba(255, 247, 232, 0.75); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); border: 3px solid var(--pink); border-radius: 18px; padding: 8px 14px 10px; box-shadow: 0 5px 0 rgba(90, 35, 66, 0.2); text-align: center; }
#hall-panel h2 { margin: 0; font-size: 20px; color: var(--pink); }
#hall-text { margin: 4px 0 8px; font-size: 14px; font-weight: 700; }
#hall-panel button.btn { font-size: 14px; padding: 4px 14px; }
/* the heroine walks to the big door: zoom into it, then a white flash */
#screen-hall.opening #hall-bg { transition: transform 1.3s ease-in; transform: scale(3.2); }
#screen-hall.opening #hall-flash { transition: opacity 0.5s ease-in 0.85s; opacity: 1; }
#screen-hall.opening #hall-panel { transition: opacity 0.3s; opacity: 0; }

/* ---------- phones / tablets ---------- */
html, body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
canvas#c { height: 100dvh; }
#touch-ui { position: absolute; inset: 0; pointer-events: none; }
#tc-zone { position: absolute; left: 0; top: 25%; bottom: 0; width: 50%; pointer-events: auto; }
#tc-stick { position: absolute; left: calc(70px + env(safe-area-inset-left)); top: calc(100% - 90px - env(safe-area-inset-bottom)); width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255, 247, 232, 0.35); border: 3px solid rgba(255, 95, 162, 0.55); pointer-events: none; opacity: 0.6; transition: opacity 0.2s; }
#tc-stick.on { opacity: 1; }
#tc-stick.run { border-color: var(--gold); box-shadow: 0 0 18px var(--gold); }
#tc-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(255, 247, 232, 0.95); border: 3px solid var(--pink); }
#tc-buttons { position: absolute; right: calc(16px + env(safe-area-inset-right)); bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; flex-direction: column-reverse; align-items: center; gap: 12px; }
.tc-btn { pointer-events: auto; width: 74px; height: 74px; border-radius: 50%; font-size: 32px; font-family: inherit; border: 4px solid var(--pink); background: rgba(255, 247, 232, 0.92); color: var(--ink); box-shadow: 0 5px 0 rgba(90, 35, 66, 0.2); display: grid; place-items: center; padding: 0; touch-action: none; }
.tc-btn.on { transform: translateY(4px) scale(0.95); box-shadow: none; }
#tc-act { width: 88px; height: 88px; font-size: 40px; background: #fff3b0; border-color: var(--gold); animation: pulse 0.7s infinite alternate; }
#tc-throw { background: #ffd3e6; }
body.touch #hud-help { display: none; }
body.touch #hud-prompt { bottom: calc(150px + env(safe-area-inset-bottom)); font-size: 16px; }
body.touch #btn-pause, body.touch #btn-close { top: calc(10px + env(safe-area-inset-top)); bottom: auto; right: auto; left: calc(50% - 46px); width: 40px; height: 40px; font-size: 18px; }
body.touch #btn-close { left: calc(50% + 6px); font-size: 16px; }
body.touch #hud-objective { top: calc(56px + env(safe-area-inset-top)); }
body.touch #dialog { bottom: calc(14px + env(safe-area-inset-bottom)); }
/* phone: small, see-through toast (energy warnings…) so it never hides the game */
body.touch #toast { top: calc(44px + env(safe-area-inset-top)); font-size: 13px; padding: 3px 10px; border-width: 2px; border-radius: 10px; max-width: 50vw; background: linear-gradient(90deg, rgba(255, 243, 176, 0.6), rgba(255, 224, 240, 0.6)); border-color: rgba(255, 197, 49, 0.6); box-shadow: none; }
body.touch button.btn { font-size: 17px; padding: 8px 18px; }
body.touch #dialog button.btn, body.touch #shop-panel button.btn, body.touch #hall-panel button.btn { font-size: 15px; padding: 6px 16px; }
#rotate-hint { display: none; }
/* phone held upright (touch screen, whatever pointer type the browser reports) */
@media (orientation: portrait) {
  body.touch #rotate-hint { display: flex; position: fixed; inset: 0; z-index: 50; flex-direction: column; align-items: center; justify-content: center; text-align: center; font-size: 26px; font-weight: 800; color: var(--pink); background: radial-gradient(circle, #fff0f8, #ffbedc); }
}
@media (max-height: 500px) {
  .pill { font-size: 15px; padding: 2px 12px; }
  #hud-candies { font-size: 18px; top: 8px; left: 10px; }
  #hud-energy { top: 46px; left: 10px; }
  #hud-energy .bar { width: 90px; }
  #hud-objective { top: 8px; font-size: 13px; max-width: 46vw; }
  body.touch #hud-objective { top: 8px; }
  body.touch #btn-pause, body.touch #btn-close { top: auto; bottom: 8px; }
  body.touch #dialog { bottom: calc(56px + env(safe-area-inset-bottom)); } /* above the ⏸ ✕ buttons */
  #screen-end h1 { font-size: 32px; }
  #end-stars .star { font-size: 38px; }
  #end-stars { margin: 0; }
  #end-text { font-size: 14px !important; margin: 2px 0 4px !important; }
  #end-stats { grid-template-columns: 1fr 1fr; gap: 3px 8px; min-width: min(560px, 90vw); margin-bottom: 2px; }
  .stat { font-size: 13px; padding: 1px 10px; }
  .stat em { font-size: 11px; }
  #end-teaser { font-size: 13px !important; margin: 2px 0 6px !important; }
  #end-buttons button.btn, .screen .btn-row button.btn { font-size: 15px; padding: 6px 16px; }
  #hud-right { top: 8px; right: 10px; }
  #hud-timer { font-size: 20px; }
  #hud-map { width: 120px; height: 136px; }
  .tc-btn { width: 62px; height: 62px; font-size: 26px; }
  #tc-act { width: 74px; height: 74px; }
  #tc-buttons { bottom: 14px; }
  #dialog { padding: 8px 12px; width: min(460px, 60vw); } #dialog-text { font-size: 13px; margin: 2px 0 6px; }
  .screen h1 { font-size: 40px; } .screen p { font-size: 17px; margin: 4px 0 8px; }
  .card { width: min(150px, 30vw); padding: 6px; } .card span { font-size: 20px; }
  .panel { padding: 10px 16px; margin: 8px 0; gap: 6px; }
  #screen-shop { padding: 8px; }
  #shop-panel { padding: 6px 10px 8px; } #hall-panel { padding: 6px 12px; } #shop-title, #hall-panel h2 { font-size: 16px; }
  #shop-text, #hall-text { font-size: 12px; }
  /* short screens (phone in landscape): one compact line per item, the "Sortir" button stays on the header line */
  #shop-menu { grid-template-columns: 1fr; }
  .shop-item { flex-direction: row; padding: 1px 8px; gap: 6px; }
  .shop-item .emoji { font-size: 17px; }
  .shop-item .name { flex: 1; text-align: left; font-size: 12px; }
  .shop-item .info { white-space: nowrap; font-size: 11px; }
  #shop-head .pill { font-size: 12px; padding: 0 8px; }
  #shop-energy .bar { width: 44px; }
  #shop-panel #shop-exit { font-size: 12px; padding: 2px 10px; }
  #shop-menu { gap: 4px; margin-bottom: 6px; }
}
