/* Pink & Whiskers — "midnight scrapbook" UI
   ink navy outlines, hard offset shadows, moon-cream paper, Mia pink + lamp gold accents
   ── UI COLOUR & FONT TOKENS ── change these to restyle every menu, the HUD and dialogue boxes at once:
     --ink    outlines and dark text        --night  dark screen backgrounds    --umbra  purple accents
     --pink   Mia pink (main buttons)       --whisk  Whiskers orange            --moon   cream panels/pills
     --lamp   gold (stars, coins, toasts)   --paper  dialogue/menu paper       --display / --text  fonts
   Sections below: logo · screens (loading/title/stage select) · HUD · prompts & bubbles · dialogue ·
   stage card · story panel · toasts/hint · modals (pause/settings/results/credits) · overlays · touch controls · PHONES & TABLETS (at the very end) */
:root {
  --ink: #1d1b4b; --night: #120f2e; --umbra: #6b3fd4; --pink: #ff4f9a; --pink-d: #d92671;
  --whisk: #ffa53a; --moon: #fff4d6; --lamp: #ffd23f; --paper: #fffaf0;
  --display: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', sans-serif;
  --text: 'Grandstander', 'Comic Sans MS', 'Trebuchet MS', sans-serif;
  --line: 3px solid var(--ink); --drop: 5px 5px 0 var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--ink); font-family: var(--text); font-weight: 700; -webkit-tap-highlight-color: transparent; user-select: none; touch-action: manipulation; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { display: inline-block; min-width: 1.6em; padding: 0.05em 0.4em; margin: 0 0.1em; border: 2px solid currentColor; border-bottom-width: 4px; border-radius: 7px; font-family: var(--display); font-size: 0.85em; line-height: 1.3; text-align: center; background: rgba(255, 255, 255, 0.12); }
:focus-visible { outline: 3px dashed var(--lamp); outline-offset: 4px; }

/* ---------- logo ---------- */
.logo { margin: 0; font-family: var(--display); font-weight: 400; line-height: 0.82; letter-spacing: 0.01em; display: flex; flex-direction: column; align-items: flex-start; position: relative; z-index: 1; }
.logo span { display: block; -webkit-text-stroke: 0.06em var(--ink); paint-order: stroke fill; text-shadow: 0.06em 0.07em 0 var(--ink); }
.logo .l1 { color: var(--pink); font-size: clamp(64px, 9vw, 132px); transform: rotate(-4deg); transform-origin: left bottom; }
.logo .amp { color: var(--lamp); font-size: clamp(34px, 4vw, 56px); margin: -0.15em 0 -0.25em 1.9em; transform: rotate(8deg); }
.logo .l2 { color: var(--whisk); font-size: clamp(56px, 8vw, 116px); transform: rotate(-1.5deg); }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; z-index: 40; }
.screen.on { display: block; }
#loading { background: radial-gradient(circle at 70% 30%, #2d2a6e 0%, var(--night) 70%); color: var(--moon); display: none; place-items: center; text-align: center; }
#loading.on { display: grid; align-content: center; justify-items: center; gap: 22px; }
#loading .moon { position: absolute; width: 38vmin; height: 38vmin; border-radius: 50%; right: 12vw; top: 9vh; background: radial-gradient(circle at 40% 40%, #fff8e6, #ffe7a8 60%, #f5c86a); box-shadow: 0 0 80px 20px rgba(255, 230, 160, 0.25); }
#loading .logo { align-items: center; }
#loading .bar { width: min(420px, 70vw); height: 22px; border: var(--line); border-color: var(--moon); border-radius: 20px; padding: 3px; position: relative; z-index: 1; }
#loading .fill { height: 100%; width: 0; border-radius: 14px; background: repeating-linear-gradient(-45deg, var(--pink) 0 12px, #ff79b4 12px 24px); transition: width 0.25s; }
#loading .status { margin: 0; font-size: 18px; z-index: 1; }
#loading.error .status { color: #ffb3c8; max-width: 520px; }
#filewarn { max-width: 560px; margin: 0; padding: 14px 18px; border-radius: 14px; background: rgba(255, 255, 255, 0.08); line-height: 1.5; z-index: 1; font-weight: 500; }
#filewarn code { color: var(--lamp); }

#title .art { position: absolute; inset: 0; background-size: cover; background-position: 70% 30%; filter: saturate(1.1); }
#title .art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(18, 15, 46, 0.92) 0%, rgba(18, 15, 46, 0.7) 38%, rgba(18, 15, 46, 0) 70%); }
#title .panel { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 4vh 5vw; max-width: 640px; color: var(--moon); }
#title .moon { position: absolute; left: 2vw; top: 6vh; width: 300px; height: 300px; border-radius: 50%; background: radial-gradient(circle at 45% 40%, rgba(255, 244, 214, 0.35), rgba(255, 244, 214, 0) 65%); }
.ribbon { margin: 4px 0 0; align-self: flex-start; font-family: var(--display); font-size: clamp(20px, 2.3vw, 30px); color: var(--ink); background: var(--moon); padding: 6px 22px 8px; border: var(--line); box-shadow: var(--drop); transform: rotate(-2deg); clip-path: polygon(0 0, 100% 0, 96% 50%, 100% 100%, 0 100%, 4% 50%); }
.pitch { margin: 0; font-size: clamp(16px, 1.45vw, 20px); line-height: 1.5; max-width: 30em; font-weight: 500; }
.menu { display: flex; flex-wrap: wrap; gap: 14px; }
#title .keys { margin: 4px 0 0; font-size: 14px; opacity: 0.85; font-weight: 500; }

.btn { border: var(--line); border-radius: 999px; padding: 12px 26px 13px; font-family: var(--display); font-size: 21px; letter-spacing: 0.02em; background: var(--moon); color: var(--ink); box-shadow: 0 5px 0 var(--ink); transform: translateY(0); transition: transform 0.08s, box-shadow 0.08s, background 0.15s; }
.btn:hover { background: #fff; transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--pink); color: #fff; -webkit-text-stroke: 0; }
.btn.primary:hover { background: #ff69aa; }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; box-shadow: none; }
.btn[hidden] { display: none; }

/* ---------- stage select ---------- */
#levels { background: radial-gradient(circle at 80% 0%, #3a2f7a, var(--night) 60%); color: var(--moon); padding: 4vh 4vw; overflow: auto; }
#levels .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 3vh; }
#levels h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(32px, 4vw, 54px); color: var(--lamp); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 4px 4px 0 var(--ink); }
#levels .grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2.6vw 2vw; }
.lvl { position: relative; display: flex; flex-direction: column; text-align: left; padding: 10px 10px 12px; border: var(--line); border-radius: 6px; background: var(--paper); box-shadow: var(--drop); transform: rotate(var(--tilt)); transition: transform 0.12s; }
.lvl:hover:not([disabled]) { transform: rotate(0deg) translateY(-4px) scale(1.02); }
.lvl .thumb { position: relative; display: block; aspect-ratio: 16 / 9; overflow: hidden; border: 2px solid var(--ink); border-radius: 3px; background: #2a2650; }
.lvl .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lvl .num { margin-top: 8px; font-size: 13px; color: var(--pink-d); }
.lvl .lt { font-family: var(--display); font-size: clamp(15px, 1.4vw, 20px); line-height: 1.1; color: var(--ink); }
.lvl .st { margin-top: 4px; letter-spacing: 3px; font-size: 18px; color: #c9c3dc; }
.lvl .st .got { color: var(--lamp); -webkit-text-stroke: 1px var(--ink); font-style: normal; }
.lvl .st i { font-style: normal; }
.lvl.locked { cursor: not-allowed; }
.lvl.locked .thumb img { filter: grayscale(1) brightness(0.45); }
.lvl .lock { position: absolute; left: 8px; right: 8px; top: 50%; transform: translateY(-50%); padding: 6px 8px; font-size: 13px; text-align: center; background: var(--ink); color: var(--moon); border-radius: 8px; }
.lvl.done::after { content: '✓'; position: absolute; top: -12px; right: -10px; width: 34px; height: 34px; border-radius: 50%; background: var(--lamp); border: var(--line); display: grid; place-items: center; font-family: var(--display); font-size: 18px; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; display: none; justify-content: space-between; align-items: flex-start; padding: 14px 18px; z-index: 20; pointer-events: none; transition: opacity 0.3s; }
#hud.on { display: flex; }
#hud.dim, #hud.dim ~ #objective { opacity: 0; }
#hud .left { display: flex; align-items: center; gap: 10px; }
#hud .portrait { width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--ink); background: var(--pink); overflow: hidden; box-shadow: 0 0 0 3px var(--pink), 4px 5px 0 3px var(--ink); }
#hud .portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
#hud .stack { display: flex; flex-direction: column; gap: 6px; }
.hearts { display: flex; gap: 2px; }
.hearts i { font-style: normal; font-size: 34px; line-height: 1; color: var(--pink); -webkit-text-stroke: 2.5px var(--ink); paint-order: stroke fill; text-shadow: 2px 3px 0 var(--ink); transition: transform 0.2s, color 0.2s; }
.hearts i.lost { color: #4a4470; transform: scale(0.8); }
.hearts.hit { animation: shake 0.35s; }
#hud .cat { display: flex; align-items: center; gap: 6px; padding: 3px 12px 3px 3px; border: var(--line); border-radius: 30px; background: var(--moon); font-size: 14px; box-shadow: 3px 3px 0 var(--ink); }
#hud .cat img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 2px solid var(--ink); }
#hud .cat[data-state=missing] { background: #3a3366; color: var(--moon); }
#hud .cat[data-state=missing] img { filter: grayscale(1) brightness(0.6); }
#hud .cat[data-state=busy], #hud .cat[data-state=waiting] { background: var(--whisk); }
#hud .right { display: flex; gap: 10px; align-items: center; }
.pill { display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 16px 0 8px; border: var(--line); border-radius: 30px; background: var(--moon); font-family: var(--display); font-size: 24px; box-shadow: 3px 4px 0 var(--ink); }
.pill[hidden] { display: none; }
.pill.bump { animation: bump 0.3s; }
.ico { font-style: normal; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid var(--ink); font-size: 18px; line-height: 1; }
.ico.coin { background: radial-gradient(circle at 35% 35%, #fff3b0, var(--lamp) 45%, #e8a400); }
.ico.star { background: var(--lamp); color: var(--ink); }
.ico.key, .ico.fuse { background: #9fe8ff; }
.pausebtn { pointer-events: auto; width: 46px; height: 46px; border: var(--line); border-radius: 12px; background: var(--moon); box-shadow: 3px 4px 0 var(--ink); display: flex; gap: 6px; align-items: center; justify-content: center; }
.pausebtn span { width: 6px; height: 18px; background: var(--ink); border-radius: 2px; }
#objective { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 19; display: none; max-width: min(46vw, 560px); padding: 9px 22px 10px; background: var(--ink); color: var(--moon); border-radius: 30px; border: 3px solid var(--moon); font-size: 17px; text-align: center; pointer-events: none; }
#objective.on { display: block; }
#objective.empty { opacity: 0; }
#objective.pop { animation: pop 0.5s; }
#objective::before { content: '🐾'; margin-right: 8px; }
#abilities { position: fixed; left: 16px; bottom: 14px; z-index: 18; display: none; gap: 14px; flex-wrap: wrap; max-width: 60vw; color: var(--moon); font-size: 13px; opacity: 0.8; text-shadow: 0 1px 2px var(--night); pointer-events: none; }
#abilities.on { display: flex; }
body.touch #abilities { display: none; }

/* ---------- prompts + bubbles ---------- */
#prompt { position: fixed; left: 0; top: 0; z-index: 21; display: none; pointer-events: none; will-change: transform; }
#prompt.on { display: block; }
/* "Press E" prompt above characters/objects.
   Position: set every frame by UI.prompt() in assets/js/ui.js (it glides — speed = CONFIG.ui.promptGlide).
   Float/bob + fade-in: the two animations below. Their timing comes from CONFIG.ui via these CSS variables:
     --prompt-float-time (one up/down cycle), --prompt-float-px (float height), --prompt-fade-time (fade-in).
   14px = gap between the object and the bottom of the box. */
#prompt .pin { display: flex; align-items: center; gap: 8px; padding: 5px 14px 6px 6px; background: var(--moon); border: var(--line); border-radius: 30px; box-shadow: 3px 4px 0 var(--ink); font-size: 16px; white-space: nowrap; transform: translate(-50%, calc(-100% - 14px)); animation: promptin var(--prompt-fade-time, 0.5s) cubic-bezier(0.25, 0.8, 0.3, 1) both, float var(--prompt-float-time, 5.5s) var(--prompt-fade-time, 0.5s) cubic-bezier(0.45, 0, 0.55, 1) infinite; }
#prompt kbd { background: var(--pink); color: #fff; border-color: var(--ink); }
@keyframes promptin { from { opacity: 0; transform: translate(-50%, calc(-100% - 6px)); } }
@keyframes float { 0%, 100% { transform: translate(-50%, calc(-100% - 14px)); } 50% { transform: translate(-50%, calc(-100% - 14px - var(--prompt-float-px, 3px))); } }
#bubbles { position: fixed; inset: 0; z-index: 22; pointer-events: none; }
.bubble { position: absolute; left: 0; top: 0; max-width: 280px; padding: 8px 14px; margin-top: -10px; background: #fff; border: var(--line); border-radius: 18px; font-size: 15px; line-height: 1.3; translate: -50% -100%; animation: bubin 0.35s cubic-bezier(0.2, 1.2, 0.4, 1); will-change: transform; }
@keyframes bubin { from { opacity: 0; scale: 0.85; } }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -12px; width: 14px; height: 14px; background: #fff; border-right: var(--line); border-bottom: var(--line); transform: translateX(-50%) rotate(45deg); }
.bubble.out { opacity: 0; transition: opacity 0.3s; }

/* ---------- dialog ---------- */
#dialog { position: fixed; left: 50%; bottom: 26px; z-index: 30; width: min(880px, 92vw); display: flex; gap: 18px; align-items: flex-start; padding: 16px 22px 18px 16px; background: var(--paper); border: 4px solid var(--ink); border-radius: 20px; box-shadow: 7px 7px 0 var(--ink); transform: translate(-50%, 140%); transition: transform 0.25s cubic-bezier(0.3, 1.4, 0.6, 1); cursor: pointer; }
#dialog.on { transform: translate(-50%, 0); }
#dialog .face { flex: none; width: 104px; height: 104px; border-radius: 50%; overflow: hidden; border: 4px solid var(--ink); background: var(--moon); margin-top: -40px; box-shadow: 4px 4px 0 var(--ink); }
#dialog[data-who=umbra] .face { background: #2a1a4a; }
#dialog .face img { width: 100%; height: 100%; object-fit: cover; display: block; }
#dialog .name { display: inline-block; font-family: var(--display); font-size: 22px; color: #fff; background: var(--pink); padding: 2px 14px 4px; border: 3px solid var(--ink); border-radius: 10px; margin: -34px 0 8px; transform: rotate(-2deg); }
#dialog[data-who=whiskers] .name { background: var(--whisk); }
#dialog[data-who=umbra] .name { background: var(--umbra); }
#dialog[data-who=noodle] .name, #dialog[data-who=beep] .name { background: #3aa0d8; }
#dialog .text { font-size: clamp(17px, 1.6vw, 21px); line-height: 1.45; min-height: 2.9em; font-weight: 700; max-width: 40em; }
#dialog .next { text-align: right; font-size: 13px; opacity: 0.7; margin-top: 4px; }
#dialog.typing .next { visibility: hidden; }

/* ---------- stage card ---------- */
#stagecard { position: fixed; inset: 0; z-index: 31; pointer-events: none; display: grid; place-items: center; }
#stagecard .band { display: flex; flex-direction: column; align-items: center; padding: 22px 12vw 26px; background: var(--ink); color: var(--moon); border-top: 6px solid var(--pink); border-bottom: 6px solid var(--lamp); transform: rotate(-3deg) scaleX(0); opacity: 0; }
#stagecard.on .band { animation: band 2.3s cubic-bezier(0.2, 0.9, 0.3, 1) forwards; }
#stagecard .sub { font-size: 17px; color: var(--lamp); }
#stagecard .ttl { font-family: var(--display); font-size: clamp(34px, 5vw, 70px); line-height: 1.05; text-align: center; -webkit-text-stroke: 0; }

/* ---------- story panel ---------- */
#story { position: fixed; inset: 0; z-index: 35; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(18, 15, 46, 0.86); cursor: pointer; }
#story.on { display: flex; animation: fadein 0.35s; }
#story figure { margin: 0; width: min(760px, 86vw); background: var(--paper); border: 5px solid var(--ink); box-shadow: 10px 10px 0 var(--ink); padding: 12px 12px 0; transform: rotate(-1.2deg); animation: panelin 0.5s cubic-bezier(0.2, 1.3, 0.5, 1); }
#story img { width: 100%; max-height: 56vh; object-fit: cover; display: block; border: 3px solid var(--ink); }
#story .caption { padding: 14px 6px 16px; font-size: clamp(17px, 1.7vw, 22px); line-height: 1.45; }
#story .cont { color: var(--moon); margin: 0; font-size: 15px; opacity: 0.85; }

/* ---------- toasts / hint ---------- */
#toasts { position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 26; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { display: flex; gap: 10px; align-items: center; padding: 8px 18px 9px 10px; background: var(--lamp); border: var(--line); border-radius: 14px; box-shadow: 4px 4px 0 var(--ink); font-size: 16px; animation: drop 0.35s cubic-bezier(0.2, 1.4, 0.5, 1); transition: opacity 0.35s, transform 0.35s; max-width: 70vw; }
.toast.long { background: var(--paper); max-width: 560px; line-height: 1.4; }
.toast i { font-style: normal; font-size: 22px; }
.toast.out { opacity: 0; transform: translateY(-10px); }
#hint { position: fixed; right: 18px; bottom: 18px; z-index: 25; pointer-events: none; display: flex; gap: 10px; align-items: center; max-width: 380px; padding: 10px 16px 10px 10px; background: #e6f6ff; border: var(--line); border-radius: 16px; box-shadow: 4px 4px 0 var(--ink); transform: translateY(160%); transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.6, 1); }
#hint.on { transform: translateY(0); }
#hint img { width: 58px; height: 58px; border-radius: 50%; border: 3px solid var(--ink); object-fit: cover; }
#hint b { font-family: var(--display); font-weight: 400; color: #2a7ab8; }
#hint[data-who=mia] { background: #fff0f6; }
#hint[data-who=mia] b { color: var(--pink-d); }
#hint p { margin: 2px 0 0; font-size: 15px; line-height: 1.35; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 45; display: none; background: rgba(18, 15, 46, 0.72); padding: 3vh 3vw; overflow: auto; }
.modal.on { display: grid; animation: fadein 0.25s; }
.sheet { width: min(760px, 94vw); margin: auto; background: var(--paper); border: 5px solid var(--ink); border-radius: 22px; box-shadow: 10px 10px 0 var(--ink); padding: 26px 30px 30px; animation: panelin 0.4s cubic-bezier(0.2, 1.3, 0.5, 1); }
.sheet h2 { margin: 0 0 14px; font-family: var(--display); font-weight: 400; font-size: 44px; color: var(--pink); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink); }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 26px; margin: 22px 0 18px; font-size: 15px; }
.opts label { display: flex; flex-direction: column; gap: 4px; }
.opts label.row { flex-direction: row; align-items: center; gap: 10px; }
.opts input[type=range] { accent-color: var(--pink); width: 100%; }
.opts select { font: inherit; border: var(--line); border-radius: 10px; padding: 4px 8px; background: #fff; }
.opts input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--pink); }
.controls { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; padding: 14px 16px; background: #f1ebff; border-radius: 14px; font-size: 14px; font-weight: 500; }
.controls dt { white-space: nowrap; } .controls dd { margin: 0; }
#results .sheet { text-align: center; }
#results .done { margin: 0; color: var(--umbra); font-size: 18px; }
.r-stars { display: flex; justify-content: center; gap: 12px; margin: 6px 0 14px; }
.r-stars i { font-style: normal; font-size: 64px; line-height: 1; color: #d9d3ea; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; transform: scale(0); animation: starpop 0.45s cubic-bezier(0.2, 1.6, 0.5, 1) forwards; }
.r-stars i.got { color: var(--lamp); text-shadow: 3px 4px 0 var(--ink); }
.stats { display: flex; justify-content: center; gap: 34px; margin-bottom: 22px; }
.stats b { display: block; font-family: var(--display); font-size: 34px; font-weight: 400; }
.stats span { font-size: 14px; opacity: 0.75; }
#results .menu, #credits .sheet { justify-content: center; }
#credits p { font-size: 18px; line-height: 1.55; font-weight: 500; max-width: 36em; }
#credits .gag { background: #fff0c2; border: 3px dashed var(--ink); border-radius: 12px; padding: 12px 16px; }
#credits .small { font-size: 13px; opacity: 0.7; }

/* ---------- fx overlays ---------- */
#fade { position: fixed; inset: 0; background: var(--night); opacity: 0; pointer-events: none; z-index: 50; transition: opacity 0.3s; }
#fade.on { opacity: 1; }
#flash { position: fixed; inset: 0; opacity: 0; pointer-events: none; z-index: 29; mix-blend-mode: screen; }
#flash.go { animation: flash 0.45s; }
#cine i { position: fixed; left: 0; right: 0; height: 0; background: #08061a; z-index: 28; transition: height 0.4s; }
#cine i:first-child { top: 0; } #cine i:last-child { bottom: 0; }
#cine.on i { height: 8vh; }
#fly { position: fixed; inset: 0; pointer-events: none; z-index: 27; }
.flyer { position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px; border-radius: 50%; border: 2.5px solid var(--ink); transition: transform 0.55s cubic-bezier(0.5, -0.3, 0.7, 1), opacity 0.55s; }
.flyer.coin { background: radial-gradient(circle at 35% 35%, #fff3b0, var(--lamp) 45%, #e8a400); }
.flyer.star, .flyer.card { background: var(--lamp); border-radius: 30%; transform-origin: center; }
.flyer.key, .flyer.fuse { background: #9fe8ff; }

/* ---------- touch ---------- */
#touch { position: fixed; inset: auto 0 0 0; z-index: 24; display: none; justify-content: space-between; align-items: flex-end; padding: 0 22px 22px; pointer-events: none; }
body.touch #touch.on { display: flex; }
#touch button { pointer-events: auto; width: 74px; height: 74px; border-radius: 50%; border: 3px solid rgba(29, 27, 75, 0.9); background: rgba(255, 244, 214, 0.78); font-family: var(--display); font-size: 26px; touch-action: none; }
#touch button.down { background: var(--pink); color: #fff; }
#touch button[hidden] { display: none; }
#touch .pad, #touch .acts { display: flex; gap: 12px; align-items: flex-end; }
#touch .acts { flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
#touch .big { width: 96px; height: 96px; font-size: 34px; }
#touch .tpause { position: fixed; top: 82px; right: 18px; width: 50px; height: 50px; font-size: 18px; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes bump { 50% { transform: scale(1.18); } }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
#objective.pop { animation: objpop 0.5s; }
@keyframes objpop { 0% { transform: translateX(-50%) scale(0.7); } 60% { transform: translateX(-50%) scale(1.07); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes bob { 50% { margin-top: -50px; } }
@keyframes drop { from { transform: translateY(-24px); opacity: 0; } }
@keyframes fadein { from { opacity: 0; } }
@keyframes panelin { from { transform: rotate(-6deg) scale(0.8); opacity: 0; } }
@keyframes starpop { to { transform: scale(1); } }
@keyframes flash { 0% { opacity: 0.75; } 100% { opacity: 0; } }
@keyframes band { 0% { transform: rotate(-3deg) scaleX(0); opacity: 1; } 18% { transform: rotate(-3deg) scaleX(1); opacity: 1; } 82% { transform: rotate(-3deg) scaleX(1); opacity: 1; } 100% { transform: rotate(-3deg) scaleX(1) translateX(30vw); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
/* the game keeps its own night palette in both light and dark viewer themes */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --paper: #fffaf0; --moon: #fff4d6; } }
:root[data-theme="dark"] { --paper: #fffaf0; --moon: #fff4d6; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }

/* settings panel: close button, menu mode, quality buttons */
.sheet { position: relative; }
.xclose { position: absolute; top: 14px; right: 14px; width: 46px; height: 46px; border: var(--line); border-radius: 50%; background: var(--moon); font-family: var(--display); font-size: 22px; line-height: 1; box-shadow: 0 4px 0 var(--ink); }
.xclose:hover { background: #fff; }
.xclose:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#pause .t-menu, #pause.menu-mode .t-game, #pause.menu-mode .game-only { display: none; }
#pause.menu-mode .t-menu { display: inline; }
.opts .quality { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.seg { display: inline-flex; border: var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-left: 2px solid var(--ink); padding: 7px 16px; background: transparent; font-family: var(--text); font-weight: 700; font-size: 15px; }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--pink); color: #fff; }
.qinfo { flex-basis: 100%; margin: 0; font-size: 14px; font-weight: 500; opacity: 0.8; }

/* =====================================================================
   PHONES & TABLETS
   Everything in this section only affects touch devices and small screens;
   the laptop / desktop look above stays exactly as it was.
     • TOUCH CONTROLS ...... body.touch (ui.js turns it on for phones and tablets)
                             button sizes: --tb (small buttons), --tj (jump), --tp (◀ ▶), --tgap (spacing)
     • NARROW WINDOWS ...... (max-width: 1000px)           tablets, half-width laptop windows
     • COMPACT ............. (max-width: 600px), (max-height: 560px)   any phone, either way round
     • PHONE LANDSCAPE ..... (orientation: landscape) and (max-height: 560px)
     • PHONE PORTRAIT ...... (orientation: portrait) and (max-width: 600px)
   --hud-h and --obj-h are measured live by ui.js (height of the HUD row and of the objective pill),
   so the objective, pop-up messages and hints always sit just below the HUD and never overlap it.
   ===================================================================== */
:root {
  --tb: clamp(46px, 12.5vmin, 72px);   /* small touch buttons (E, S, F, Q, C) */
  --tj: calc(var(--tb) * 1.32);        /* jump button */
  --tp: calc(var(--tb) * 1.18);        /* ◀ ▶ buttons */
  --tgap: clamp(6px, 1.6vmin, 12px);
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}

/* ---------- touch controls: ◀ ▶ bottom-left, a compact button cluster bottom-right ----------
     F  Q  C        ← appear when unlocked (flashlight, Whiskers)
     S  E  JUMP                                                            */
#touch { padding: 0 calc(14px + var(--sr)) calc(14px + var(--sb)) calc(14px + var(--sl)); }
#touch button { width: var(--tb); height: var(--tb); padding: 0; display: grid; place-items: center; line-height: 1; font-size: calc(var(--tb) * 0.4); border-width: 2.5px; box-shadow: 0 3px 0 rgba(29, 27, 75, 0.55); }
#touch .pad { gap: var(--tgap); }
#touch .pad button { width: var(--tp); height: var(--tp); font-size: calc(var(--tp) * 0.36); }
#touch .acts { display: grid; max-width: none; gap: var(--tgap); align-items: end; justify-items: center;
  grid-template-columns: var(--tb) var(--tb) var(--tj); grid-template-rows: var(--tb) var(--tj);
  grid-template-areas: "flash cat call" "down act jump"; }
#touch [data-k=flash] { grid-area: flash; } #touch [data-k=cat] { grid-area: cat; } #touch [data-k=call] { grid-area: call; }
#touch [data-k=down] { grid-area: down; } #touch [data-k=act] { grid-area: act; } #touch [data-k=jump] { grid-area: jump; }
#touch .big { width: var(--tj); height: var(--tj); font-size: calc(var(--tj) * 0.42); }
#touch .tpause { display: none; }   /* the HUD already has a pause button */
.pausebtn { position: relative; }
.pausebtn::after { content: ''; position: absolute; inset: -8px; }   /* bigger tap area, same look */

/* keyboard-only hints are useless on a phone */
body.touch #title .keys, body.touch #pause .controls { display: none; }
@media (hover: none) and (pointer: coarse) { #title .keys, #pause .controls { display: none; } }
/* hover effects stick after a tap on touch screens, so skip them there */
@media (hover: none) {
  .btn:hover { transform: none; box-shadow: 0 5px 0 var(--ink); background: var(--moon); }
  .btn.primary:hover { background: var(--pink); }
  .btn.ghost:hover { background: transparent; box-shadow: none; }
  .lvl:hover:not([disabled]) { transform: rotate(var(--tilt)); }
}

/* ---------- narrow windows & tablets ---------- */
@media (max-width: 1000px) {
  #levels .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #hud .portrait { width: 58px; height: 58px; } .hearts i { font-size: 28px; } .pill { height: 40px; font-size: 20px; }
  #objective { top: calc(var(--hud-h, 86px) + 2px); width: max-content; max-width: min(560px, 80vw); font-size: 15px; }
  #toasts { top: calc(var(--hud-h, 86px) + var(--obj-h, 40px) + 12px); }
}

/* ---------- COMPACT: phones, either way round ---------- */
@media (max-width: 600px), (max-height: 560px) {
  /* logo (loading + title) */
  .logo .l1 { font-size: clamp(42px, 15vmin, 72px); }
  .logo .amp { font-size: clamp(22px, 7vmin, 36px); }
  .logo .l2 { font-size: clamp(36px, 13.5vmin, 64px); }
  #loading.on { gap: 14px; }
  #loading .status { font-size: 15px; }
  #filewarn { max-width: 90vw; font-size: 13px; padding: 10px 14px; }

  /* title */
  #title .panel { gap: 12px; padding: calc(16px + var(--st)) calc(5vw + var(--sr)) calc(16px + var(--sb)) calc(5vw + var(--sl)); }
  #title .moon { width: 180px; height: 180px; }
  .ribbon { font-size: 17px; padding: 4px 16px 6px; border-width: 2.5px; box-shadow: 3px 3px 0 var(--ink); }
  .pitch { font-size: 14px; }
  #title .keys { font-size: 12px; }
  .menu { gap: 10px; }
  .btn { font-size: 16px; padding: 8px 18px 9px; border-width: 2.5px; box-shadow: 0 4px 0 var(--ink); }

  /* stage select */
  #levels { padding: calc(14px + var(--st)) calc(16px + var(--sr)) calc(20px + var(--sb)) calc(16px + var(--sl)); }
  #levels .head { margin-bottom: 14px; gap: 12px; }
  #levels h2 { font-size: 28px; -webkit-text-stroke-width: 1.5px; text-shadow: 3px 3px 0 var(--ink); }
  #levels .grid { gap: 16px 14px; }
  .lvl { padding: 6px 6px 8px; border-width: 2.5px; box-shadow: 4px 4px 0 var(--ink); }
  .lvl .num { margin-top: 5px; font-size: 11px; }
  .lvl .lt { font-size: 13px; }
  .lvl .st { margin-top: 2px; font-size: 13px; letter-spacing: 2px; }
  .lvl .lock { left: 6px; right: 6px; padding: 4px 6px; font-size: 10px; line-height: 1.2; border-radius: 6px; }
  .lvl.done::after { top: -9px; right: -8px; width: 24px; height: 24px; font-size: 13px; border-width: 2.5px; }

  /* HUD */
  #hud { padding: calc(8px + var(--st)) calc(10px + var(--sr)) 6px calc(10px + var(--sl)); }
  #hud .left { gap: 7px; }
  #hud .portrait { width: 44px; height: 44px; border-width: 3px; box-shadow: 0 0 0 2px var(--pink), 3px 3px 0 2px var(--ink); }
  #hud .stack { gap: 4px; }
  .hearts i { font-size: 21px; -webkit-text-stroke-width: 2px; text-shadow: 1px 2px 0 var(--ink); }
  #hud .cat { gap: 4px; padding: 2px 9px 2px 2px; font-size: 11px; border-width: 2px; box-shadow: 2px 2px 0 var(--ink); }
  #hud .cat img { width: 20px; height: 20px; }
  #hud .right { gap: 6px; }
  .pill { height: 32px; gap: 5px; padding: 0 10px 0 4px; font-size: 16px; border-width: 2.5px; box-shadow: 2px 3px 0 var(--ink); }
  .ico { width: 22px; height: 22px; font-size: 12px; border-width: 2px; }
  .pausebtn { width: 36px; height: 36px; gap: 4px; border-width: 2.5px; border-radius: 10px; box-shadow: 2px 3px 0 var(--ink); }
  .pausebtn span { width: 4px; height: 13px; }
  .flyer { width: 18px; height: 18px; margin: -9px; border-width: 2px; }

  /* objective, pop-up messages, hint card */
  #objective { top: calc(var(--hud-h, 58px) + 2px); width: max-content; max-width: min(560px, calc(100vw - 24px)); padding: 5px 14px 6px; font-size: 13px; line-height: 1.3; border-width: 2px; }
  #objective::before { margin-right: 5px; }
  #toasts { top: calc(var(--hud-h, 58px) + var(--obj-h, 30px) + 8px); width: calc(100vw - 24px); gap: 6px; }
  .toast, .toast.long { max-width: min(520px, 100%); padding: 5px 12px 6px 8px; gap: 7px; font-size: 13px; border-width: 2.5px; border-radius: 11px; box-shadow: 3px 3px 0 var(--ink); }
  .toast i { font-size: 17px; }
  #hint { right: calc(10px + var(--sr)); bottom: calc(10px + var(--sb)); max-width: min(340px, calc(100vw - 20px)); gap: 8px; padding: 7px 12px 7px 7px; border-width: 2.5px; border-radius: 13px; box-shadow: 3px 3px 0 var(--ink); }
  #hint img { width: 40px; height: 40px; border-width: 2px; }
  #hint b { font-size: 14px; }
  #hint p { font-size: 13px; }

  /* "Press E" prompt + speech bubbles */
  #prompt .pin { gap: 6px; padding: 3px 10px 4px 4px; font-size: 13px; border-width: 2.5px; box-shadow: 2px 3px 0 var(--ink); }
  .bubble { max-width: 200px; padding: 6px 11px; font-size: 13px; border-width: 2.5px; border-radius: 14px; }
  .bubble::after { bottom: -9px; width: 11px; height: 11px; border-right-width: 2.5px; border-bottom-width: 2.5px; }

  /* dialogue box */
  #dialog { bottom: calc(10px + var(--sb)); width: min(720px, calc(100vw - 20px)); gap: 12px; padding: 10px 14px 10px 10px; border-width: 3px; border-radius: 16px; box-shadow: 4px 4px 0 var(--ink); }
  #dialog .face { width: 58px; height: 58px; margin-top: -24px; border-width: 3px; box-shadow: 3px 3px 0 var(--ink); }
  #dialog .name { margin: -24px 0 5px; padding: 1px 10px 3px; font-size: 16px; border-width: 2.5px; border-radius: 8px; }
  #dialog .text { font-size: clamp(14px, 3.9vmin, 16px); line-height: 1.4; min-height: 2.8em; }
  #dialog .next { margin-top: 2px; font-size: 11px; }

  /* stage title card */
  #stagecard .band { padding: 12px 8vw 14px; border-top-width: 4px; border-bottom-width: 4px; }
  #stagecard .sub { font-size: 13px; }
  #stagecard .ttl { font-size: clamp(26px, 7vmin, 40px); }

  /* story panel */
  #story { gap: 10px; padding: 10px; }
  #story figure { width: min(560px, 92vw); padding: 8px 8px 0; border-width: 4px; box-shadow: 6px 6px 0 var(--ink); }
  #story img { border-width: 2px; }
  #story .caption { padding: 10px 4px 12px; font-size: clamp(14px, 4vmin, 17px); line-height: 1.4; }
  #story .cont { font-size: 13px; }

  /* pause / settings / results / credits */
  .modal { padding: calc(10px + var(--st)) calc(10px + var(--sr)) calc(10px + var(--sb)) calc(10px + var(--sl)); }
  .sheet { width: min(720px, 100%); padding: 16px 18px 18px; border-width: 4px; border-radius: 18px; box-shadow: 6px 6px 0 var(--ink); }
  .sheet h2 { margin-bottom: 10px; padding-right: 44px; font-size: 30px; -webkit-text-stroke-width: 1.5px; text-shadow: 2px 2px 0 var(--ink); }
  .xclose { top: 10px; right: 10px; width: 38px; height: 38px; font-size: 18px; border-width: 2.5px; }
  .opts { gap: 10px 20px; margin: 14px 0 6px; font-size: 14px; }
  .seg button { padding: 6px 12px; font-size: 14px; }
  .qinfo { font-size: 12px; }
  .controls { padding: 10px 12px; font-size: 13px; }
  #results .sheet h2 { padding: 0; }
  #results .done { font-size: 15px; }
  .r-stars { margin: 4px 0 10px; gap: 8px; }
  .r-stars i { font-size: 44px; -webkit-text-stroke-width: 2.5px; }
  .stats { gap: 24px; margin-bottom: 14px; }
  .stats b { font-size: 26px; }
  .stats span { font-size: 12px; }
  #credits p { font-size: 15px; line-height: 1.5; }
  #credits .gag { padding: 10px 12px; }
  #credits .small { font-size: 11px; }
}

/* ---------- PHONE LANDSCAPE: very little height, plenty of width ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  #title .panel { max-width: min(560px, 58vw); justify-content: center; }
  #title .pitch { display: none; }
  #levels .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lvl .thumb { aspect-ratio: 2 / 1; }
  .opts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* story: picture on the left, words on the right */
  #story figure { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: center; gap: 0 14px; width: min(780px, 94vw); padding: 8px; }
  #story img { max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px); }
  #story .caption { padding: 4px 6px 4px 0; }
  /* hint card sits low in the middle, between the two groups of touch buttons */
  body.touch #hint { left: 50%; right: auto; width: max-content; max-width: min(380px, calc(100vw - 2 * (2 * var(--tb) + var(--tj) + 2 * var(--tgap) + 34px))); transform: translate(-50%, 160%); }
  body.touch #hint.on { transform: translate(-50%, 0); }
}

/* ---------- PHONE PORTRAIT: narrow and tall ---------- */
@media (orientation: portrait) and (max-width: 1100px) {
  /* title on upright phones and tablets: logo at the top, picture in the middle, buttons at the bottom */
  #title .art { background-position: 64% 30%; }
  #title .art::after { background: linear-gradient(180deg, rgba(18, 15, 46, 0.55) 0%, rgba(18, 15, 46, 0) 26%, rgba(18, 15, 46, 0) 44%, rgba(18, 15, 46, 0.86) 66%, rgba(18, 15, 46, 0.96) 100%); }
  #title .panel { max-width: none; justify-content: flex-start; }
  #title .pitch { margin-top: auto; }
  #title .menu { max-width: 520px; }
  #title .menu .btn { flex: 1 1 40%; }
  #title .menu .btn.primary { flex-basis: 100%; }
}

@media (orientation: portrait) and (max-width: 600px) {
  /* stage select: two cards per row */
  #levels .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* HUD: pause stays top-right; if many counters are showing they wrap onto a second row */
  #hud { gap: 8px; }
  #hud .left { flex: none; }
  #hud .right { flex: 1 1 0; min-width: 0; flex-direction: row-reverse; flex-wrap: wrap; row-gap: 6px; }
  #hud .pausebtn { order: 0; } #hud .fuses { order: 1; } #hud .keys { order: 2; } #hud .stars { order: 3; } #hud .coins { order: 4; }
  /* menus: one column of settings, buttons share the width */
  .opts { grid-template-columns: minmax(0, 1fr); }
  .sheet .menu .btn { flex: 1 1 auto; }
  #results .menu .btn.primary { flex-basis: 100%; }
  .stats { gap: 18px; }
  #story img { max-height: 46vh; max-height: 46dvh; }
  /* HUD counters a little slimmer so coins, stars, one more counter and pause fit on one row */
  .pill { height: 30px; gap: 4px; padding: 0 8px 0 3px; font-size: 15px; }
  .ico { width: 20px; height: 20px; font-size: 11px; }
  #hud .cat { font-size: 10px; padding-right: 7px; }
  /* Whiskers' badge tucks under the portrait so the counters on the right get the whole row */
  #hud .left { display: grid; grid-template-columns: auto auto; grid-template-areas: "face hearts" "cat cat"; align-items: center; gap: 4px 7px; }
  #hud .stack { display: contents; }
  #hud .portrait { grid-area: face; } #hud .hearts { grid-area: hearts; } #hud .cat { grid-area: cat; justify-self: start; }
  /* hint card floats just above the touch buttons (fades in and out instead of sliding off the bottom) */
  body.touch #hint { left: calc(10px + var(--sl)); right: calc(10px + var(--sr)); max-width: none; bottom: calc(var(--tb) + var(--tj) + var(--tgap) + 26px + var(--sb));
    opacity: 0; visibility: hidden; transform: translateY(14px); transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.6, 1), opacity 0.25s, visibility 0s 0.35s; }
  body.touch #hint.on { opacity: 1; visibility: visible; transform: none; transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.6, 1), opacity 0.25s, visibility 0s; }
  body.touch:has(#dialog.on) #hint.on { opacity: 0; visibility: hidden; }   /* out of the way while someone is talking */
}
