/* Cake Express Sort: sunlit luxury patisserie puzzle with Allo typography & glossy tactile pills. */
:root {
    --ink: #462312;
    --cream: #fffaf2;
    --gold-top: #ffe468;
    --gold-bot: #f09e18;
    --gold-lip: #b56a08;
    --berry-top: #ff7ba2;
    --berry-bot: #e63664;
    --berry-lip: #a31840;
    --green-top: #67eb58;
    --green-bot: #1db035;
    --green-lip: #107822;
    --blue-top: #62c8ff;
    --blue-bot: #2882e8;
    --blue-lip: #1654a8;
    --coral-top: #ff8668;
    --coral-bot: #e84836;
    --coral-lip: #a82418;
    --round: "ROND" 100;
    --font: "Allo", system-ui, sans-serif;
    --top: max(10px, env(safe-area-inset-top));
    --bottom: max(12px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #6e4432;
    color: var(--ink);
    font-family: var(--font);
    font-variation-settings: var(--round);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

body { touch-action: none; overscroll-behavior: none; }
/* A picture never comes away under the mouse: a native image drag swallows every click until it's dropped. */
img { -webkit-user-drag: none; user-drag: none; }

button {
    font: inherit;
    color: inherit;
    border: 0;
    padding: 0;
    background: none;
    cursor: pointer;
    touch-action: manipulation;
}

svg { display: block; }

/* ---------------------------------------------------------------- loader */

#loader {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 22px;
    background: radial-gradient(ellipse at 50% 40%, #9a644a, #523020);
    transition: opacity 0.24s;
}

#loader img { width: min(74vw, 340px); animation: breathe-logo 1.5s ease-in-out infinite alternate; }
#loader i {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.28);
    border-top-color: #ffe468;
    animation: spin 0.85s linear infinite;
}
#loader.gone { opacity: 0; pointer-events: none; }
#loader.ready i { display: none; }
#play { min-width: 210px; height: 72px; font-size: 28px; animation: play-in 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
#play[hidden] { display: none; }
#play svg { width: 28px; height: 28px; }
@keyframes play-in { from { transform: scale(0.4); opacity: 0; } }

@keyframes breathe-logo { to { transform: scale(1.04); } }
@keyframes spin { to { transform: rotate(1turn); } }

/* ---------------------------------------------------------------- sunlit patisserie backdrop */

#bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: #6e4432;
}

body[data-world="paris"]  { --back: url(media/back-paris.jpg);  --wash: rgba(114, 64, 52, 0.34); --vig: rgba(56, 28, 22, 0.52); }
body[data-world="garden"] { --back: url(media/back-garden.jpg); --wash: rgba(46, 86, 58, 0.34);  --vig: rgba(24, 48, 30, 0.52); }
body[data-world="vienna"] { --back: url(media/back-vienna.jpg); --wash: rgba(88, 48, 26, 0.36);  --vig: rgba(42, 20, 10, 0.56); }
body[data-world="kyoto"]  { --back: url(media/back-kyoto.jpg);  --wash: rgba(74, 88, 56, 0.34);  --vig: rgba(38, 44, 28, 0.52); }

#bg i {
    position: absolute;
    inset: -12%;
    background: var(--back, url(media/back-paris.jpg)) center / cover;
    animation: drift 48s ease-in-out infinite alternate;
    will-change: transform;
    transition: background-image 0.8s ease;
}

#bg i + i {
    transform: scaleX(-1);
    animation: drift2 40s ease-in-out infinite alternate, breathe 24s ease-in-out infinite alternate;
    opacity: 0.40;
}

#bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(180deg, var(--wash, rgba(114, 64, 52, 0.34)), var(--wash, rgba(114, 64, 52, 0.34))),
        radial-gradient(ellipse at 50% 46%, rgba(255, 248, 236, 0.14) 16%, var(--vig, rgba(56, 28, 22, 0.52)) 100%);
}

@keyframes drift {
    from { transform: scale(1.06) translate(-2.2%, -1.8%) rotate(-1.2deg); }
    to { transform: scale(1.15) translate(2.2%, 2.2%) rotate(1.6deg); }
}

@keyframes drift2 {
    from { transform: scaleX(-1) scale(1.16) translate(2.6%, 1.8%) rotate(2.4deg); }
    to { transform: scaleX(-1) scale(1.07) translate(-2.2%, -2.6%) rotate(-1.8deg); }
}

@keyframes breathe { from { opacity: 0.16; } to { opacity: 0.54; } }

/* ---------------------------------------------------------------- screens */

#home, #game { position: fixed; inset: 0; display: none; }
body[data-screen="home"] #home, body[data-screen="game"] #game { display: block; }

/* ---------------------------------------------------------------- glossy tactile buttons */

.key, .big, .tool {
    position: relative;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--ink);
    background: linear-gradient(#ffffff, #f6e7d4);
    box-shadow: 0 5px 0 #c2a07e, 0 8px 0 rgba(28, 14, 6, 0.28);
    transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s, filter 0.15s;
}

.key:active, .big:active, .tool:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #c2a07e, 0 3px 0 rgba(28, 14, 6, 0.28);
}

.key.round { width: 46px; height: 46px; }
.key.round svg { width: 22px; height: 22px; }

.key .dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ef2c52;
    box-shadow: 0 0 0 2.5px #fff;
    display: none;
}
.key.has-dot .dot { display: block; }

.tool {
    width: 68px;
    height: 68px;
    background: radial-gradient(circle at 50% 32%, #fffefb 0%, #f8ecdb 62%, #ead2b2 100%);
    border: 3px solid #e7b252;
    box-shadow: 0 5px 0 #a8692a, 0 9px 0 rgba(28, 14, 6, 0.30), inset 0 2px 0 #ffffff;
}
.tool img { width: 50px; height: 50px; display: block; pointer-events: none; }
.tool:active { box-shadow: 0 1px 0 #a8692a, 0 4px 0 rgba(28, 14, 6, 0.30), inset 0 2px 0 #ffffff; }
.tool:disabled { opacity: 0.5; cursor: default; filter: grayscale(0.6); }
.tool[hidden] { display: none; }
.tool:disabled:active { transform: none; }
.tool.armed {
    transform: translateY(-4px) scale(1.08);
    border-color: #ff6a4c;
    box-shadow: 0 0 0 4px #ffe468, 0 8px 0 #a8692a, 0 12px 0 rgba(28, 14, 6, 0.34);
}

/* Idle too long: the hint wobbles. While the chef talks about a tool, it glows and bobs. */
.tool.pulse { animation: pulse-hint 1.2s ease-in-out infinite; }
@keyframes pulse-hint {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
.tool.shown {
    animation: shown 0.9s ease-in-out infinite;
    border-color: #fff4a8;
    box-shadow: 0 0 0 4px #ffd84a, 0 0 0 8px rgba(255, 216, 74, 0.35), 0 5px 0 #a8692a, 0 9px 0 rgba(28, 14, 6, 0.3);
}
@keyframes shown {
    0%, 100% { transform: translateY(0) scale(1.04); }
    50% { transform: translateY(-7px) scale(1.12); }
}

/* Stuck: the power-ups that get you out glow and throb; the others step back. */
.tool.urge {
    animation: urge 0.8s ease-in-out infinite;
    border-color: #fff6b8;
    box-shadow: 0 0 0 4px #ffd84a, 0 0 18px 8px rgba(255, 206, 60, 0.9), 0 5px 0 #a8692a, 0 9px 0 rgba(28, 14, 6, 0.3);
    z-index: 1;
}
@keyframes urge {
    0%, 100% { transform: scale(1.06); }
    50% { transform: translateY(-8px) scale(1.24); }
}
#bar.urging .tool:not(.urge) { opacity: 0.35; filter: grayscale(0.7); }

.tool .count, .big .count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border-radius: 12px;
    font-style: normal;
    font-size: 13px;
    font-weight: 900;
    line-height: 24px;
    text-align: center;
    color: #fff;
    background: #ef2c52;
    box-shadow: 0 0 0 2.5px #fff;
    font-feature-settings: "tnum";
}

.big { width: 68px; height: 68px; }
.big svg { width: 30px; height: 30px; }
.big.plain { color: var(--ink); background: linear-gradient(#ffffff, #f6e7d4); box-shadow: 0 5px 0 #c2a07e, 0 8px 0 rgba(28, 14, 6, 0.24); }
.big.berry { color: #fff; background: linear-gradient(var(--berry-top), var(--berry-bot)); box-shadow: 0 5px 0 var(--berry-lip), 0 8px 0 rgba(28, 14, 6, 0.28); }
.big.berry:active { box-shadow: 0 1px 0 var(--berry-lip), 0 3px 0 rgba(28, 14, 6, 0.28); }
.big.coral { color: #fff; background: linear-gradient(var(--coral-top), var(--coral-bot)); box-shadow: 0 5px 0 var(--coral-lip), 0 8px 0 rgba(28, 14, 6, 0.28); }
.big.coral:active { box-shadow: 0 1px 0 var(--coral-lip), 0 3px 0 rgba(28, 14, 6, 0.28); }
.big[hidden] { display: none; }

/* ---------------------------------------------------------------- home / patisserie world map */

#mapview { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#scroller {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    overscroll-behavior: contain;
    scrollbar-width: none;
}
#scroller::-webkit-scrollbar { display: none; }
@media (pointer: fine) { #scroller { cursor: grab; } #scroller.dragging { cursor: grabbing; } }

.bar-top {
    position: absolute;
    top: var(--top);
    left: 14px;
    right: 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    pointer-events: none;
    z-index: 5;
}
.bar-top > * { pointer-events: auto; }

#logo {
    width: min(56vw, 256px);
    margin-top: -6px;
    pointer-events: none;
}

.bar-foot {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(var(--bottom) + 8px);
    display: flex;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
}

.play {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 64px;
    padding: 0 34px;
    border-radius: 32px;
    color: #fff;
    font-size: clamp(20px, 5vw, 25px);
    font-weight: 900;
    letter-spacing: 0.02em;
    border: 2.5px solid rgba(255, 255, 255, 0.62);
    text-shadow: 0 2px 0 rgba(96, 12, 34, 0.50);
    font-feature-settings: "tnum";
    transition: transform 0.08s, box-shadow 0.08s;
}
.play svg { width: 24px; height: 24px; }
.play.berry {
    background: linear-gradient(var(--berry-top), var(--berry-bot));
    box-shadow: 0 6px 0 var(--berry-lip), 0 11px 0 rgba(28, 12, 16, 0.34);
}
.play.berry:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 var(--berry-lip), 0 4px 0 rgba(28, 12, 16, 0.34);
}

/* ---------------------------------------------------------------- gameplay HUD & 3D stage */

#view, #uiview, #fxview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}
#view { cursor: grab; z-index: 1; }
#view.dragging { cursor: grabbing; }
#view.hammer { cursor: crosshair; }
#uiview { pointer-events: none; z-index: 2; }
#fxview { pointer-events: none; z-index: 5; }

#top {
    position: absolute;
    top: var(--top);
    left: 14px;
    pointer-events: none;
    z-index: 6;
}
#top > * { pointer-events: auto; }
.top-left { display: flex; gap: 8px; align-items: center; }

/* The street across the top, the shop in the middle, the van parked beside it. src/street.ts lays it out. */
#street {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 0;
    overflow: hidden;
    background: #cbdedc;
    box-shadow: 0 3px 0 rgba(70, 40, 20, 0.22);
    pointer-events: none;
    z-index: 4;
}
/* --cut: on a short upright screen, the sky cut off the top of the picture (street.ts). */
#street .town {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: calc(-1 * var(--cut, 0px));
    background-image: var(--street);
    background-size: auto 100%;
    background-repeat: no-repeat, repeat-x;
    background-position: var(--street-x, 50%) 0;
}
/* The sky behind the rooftops, drifting slowly left. --sky-w is one picture's width; --sky-t how long it takes. */
#street .sky {
    position: absolute;
    left: 0;
    top: calc(-1 * var(--cut, 0px));
    height: calc((100% + var(--cut, 0px)) * 0.8);
    width: calc(100% + var(--sky-w, 0px));
    background: url(media/street/sky.webp) 0 0 / var(--sky-w, auto) 100% repeat-x;
    animation: sky-drift var(--sky-t, 150s) linear infinite;
    will-change: transform;
}
@keyframes sky-drift { to { transform: translateX(calc(-1 * var(--sky-w, 0px))); } }

/* The intro: the street zoomed in on the shop and the van, pulling back into place as play begins. */
#street {
    transform-origin: var(--zox, 50%) 0;
    transition: transform 1.1s cubic-bezier(0.65, 0, 0.3, 1);
}
#game.intro #street { transform: translateX(var(--zdx, 0px)) scale(var(--zk, 1)); }
#top, #bar, #uiview { transition: opacity 0.5s 0.5s; }
#game.intro #top, #game.intro #bar, #game.intro #uiview { opacity: 0; pointer-events: none; transition: none; }
#intro {
    --ch: min(56vh, 500px);
    position: absolute;
    inset: 0;
    z-index: 7;
    cursor: pointer;
}
#intro[hidden] { display: none; }
.intro-chef {
    position: absolute;
    left: 50%;
    bottom: 0;
    height: var(--ch);
    transform: translateX(-70%);
    animation: intro-chef-in 0.6s cubic-bezier(0.2, 1.3, 0.4, 1) 0.2s both;
}
@keyframes intro-chef-in { from { transform: translate(-70%, 105%); } }
.intro-bubble {
    position: absolute;
    left: 50%;
    bottom: calc(var(--ch) * 0.6);
    margin-left: calc(var(--ch) * 0.12);
    max-width: min(40vw, 330px);
    padding: 16px 20px;
    border-radius: 24px;
    background: #fffdf8;
    border: 3px solid #e3a76a;
    box-shadow: 0 5px 0 #a3642a;
    transform-origin: 0 80%;
    animation: bubble-pop 0.35s cubic-bezier(0.2, 1.5, 0.4, 1) 0.55s both;
}
.intro-bubble::after {
    content: "";
    position: absolute;
    left: -14px;
    bottom: 22px;
    border: 9px solid transparent;
    border-right: 12px solid #e3a76a;
    border-left: 0;
}
.intro-bubble p { margin: 0; font-size: 23px; font-weight: 820; line-height: 1.15; color: var(--ink); }
#intro.out .intro-chef { transform: translate(-70%, 110%); transition: transform 0.5s cubic-bezier(0.5, 0, 0.75, 0); }
#intro.out .intro-bubble { opacity: 0; transform: scale(0.5); transition: transform 0.25s, opacity 0.25s; }
@media (max-aspect-ratio: 11/10) {
    #intro { --ch: min(48vh, 440px); }
    .intro-chef { transform: translateX(-50%); }
    @keyframes intro-chef-in { from { transform: translate(-50%, 105%); } }
    #intro.out .intro-chef { transform: translate(-50%, 110%); }
    .intro-bubble { left: 6vw; right: 6vw; margin: 0; max-width: none; bottom: calc(var(--ch) + 6px); transform-origin: 50% 100%; text-align: center; }
    .intro-bubble::after { left: 50%; bottom: -14px; margin-left: -9px; border: 9px solid transparent; border-top: 12px solid #e3a76a; border-bottom: 0; }
}

/* The one menu: home and settings drop down under it. */
.top-left { position: relative; }
#menu {
    position: absolute;
    top: calc(100% + 12px);
    left: -6px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 6px 14px;
    border-radius: 29px;
    background: rgba(255, 250, 242, 0.97);
    border: 2.5px solid #e09c5a;
    box-shadow: 0 4px 0 #a36228, 0 7px 0 rgba(28, 14, 6, 0.24);
    transform-origin: 29px 0;
    animation: menu-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
#menu[hidden] { display: none; }
#menu-btn[aria-expanded="true"] { color: #fff; background: linear-gradient(var(--berry-top), var(--berry-bot)); box-shadow: 0 5px 0 var(--berry-lip), 0 8px 0 rgba(28, 14, 6, 0.28); }
@keyframes menu-in { from { transform: scale(0.6); opacity: 0; } }

/* The delivery van: boxes fill its hatch, the badge says how many to go. src/street.ts parks it. */
#game { --vw: clamp(190px, min(56vw, 31vh), 280px); }
#van {
    position: absolute;
    width: var(--vw);
    aspect-ratio: 720 / 406;
    pointer-events: none;
    font-feature-settings: "tnum";
}
.van-drive, .van-bounce { position: absolute; inset: 0; transform-origin: 50% 100%; }
.van-pic { display: block; width: 100%; height: 100%; }
/* Its shadow on the road: dark where the tyres touch, softer under the body. It stays on the road as the van bounces. */
.van-drive { isolation: isolate; }
.van-drive::before {
    content: "";
    position: absolute;
    left: 3%;
    right: 1%;
    bottom: -7%;
    height: 17%;
    z-index: -1;
    background:
        radial-gradient(closest-side, rgba(22, 16, 20, 0.9), rgba(22, 16, 20, 0.5) 45%, rgba(22, 16, 20, 0)) 10% 45% / 32% 80% no-repeat,
        radial-gradient(closest-side, rgba(22, 16, 20, 0.9), rgba(22, 16, 20, 0.5) 45%, rgba(22, 16, 20, 0)) 97% 45% / 32% 80% no-repeat,
        radial-gradient(closest-side, rgba(22, 16, 20, 0.55), rgba(22, 16, 20, 0.28) 70%, rgba(22, 16, 20, 0));
}
.hold {
    position: absolute;
    left: 12.2%;
    top: 18.9%;
    width: 36.1%;
    height: 35.8%;
}
.hold i {
    position: absolute;
    display: block;
}
/* An empty place: a soft dip in the floor. */
.hold i:not(.full)::before {
    content: "";
    position: absolute;
    inset: 12%;
    border-radius: 18%;
    background: rgba(120, 74, 36, 0.16);
    box-shadow: inset 0 1px 2px rgba(70, 38, 14, 0.28);
}
.hold i img { position: absolute; left: -6%; top: -8%; width: 112%; height: 112%; }
.hold i.stow img { animation: stow 0.3s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes stow {
    from { transform: translateY(-40%) scale(1.25); }
    60% { transform: translateY(4%) scale(0.94, 1.04); }
}
.left {
    position: absolute;
    left: -4%;
    top: -2%;
    min-width: calc(var(--vw) * 0.15);
    height: calc(var(--vw) * 0.15);
    padding: 0 calc(var(--vw) * 0.03) 0 calc(var(--vw) * 0.005);
    display: flex;
    align-items: center;
    gap: calc(var(--vw) * 0.01);
    border-radius: 999px;
    font-size: calc(var(--vw) * 0.085);
    font-weight: 900;
    line-height: 1;
    color: #fff;
    background: linear-gradient(180deg, #ff7098, #e63668);
    border: 2.5px solid #fff;
    box-shadow: 0 3px 0 #a61a44;
    text-shadow: 0 2px 0 rgba(96, 12, 34, 0.5);
}
/* The cake beside the number: the order's cake at a wedding. */
.left img {
    width: calc(var(--vw) * 0.13);
    height: calc(var(--vw) * 0.13);
    margin: calc(var(--vw) * -0.02) 0 calc(var(--vw) * -0.01) calc(var(--vw) * -0.03);
    object-fit: contain;
    filter: drop-shadow(0 2px 0 rgba(96, 12, 34, 0.35));
}
.left.final {
    background: linear-gradient(180deg, #ffcf48, #f29616);
    box-shadow: 0 3px 0 #b06208;
    text-shadow: 0 2px 0 rgba(120, 60, 4, 0.5);
    animation: pulse-final 1.1s ease-in-out infinite;
}
.left.bump { animation: bump-goal 0.34s cubic-bezier(0.2, 1.5, 0.4, 1); }
.van-bounce.bump { animation: van-bump 0.32s cubic-bezier(0.3, 1.6, 0.5, 1); }
/* Waiting, it ticks over now and then: a little bob on its springs. */
.van-bounce.idle { animation: van-idle 0.9s ease-in-out; }
@keyframes van-idle {
    12% { transform: translateY(-2.2%); }
    26% { transform: translateY(0.6%) scale(1.01, 0.99); }
    40% { transform: translateY(-1.2%); }
    56% { transform: translateY(0.3%); }
    70% { transform: none; }
}
/* The wedding car: the same size as the van, standing on its floor, and its cake stacking up on the gold board. */
#van.wedding .van-pic { object-fit: contain; object-position: 50% 100%; }
#van.wedding .hold { display: none; }
.stand { position: absolute; aspect-ratio: 1; pointer-events: none; }
.stand .tier { position: absolute; display: block; }
.stand .tier img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.6;
    filter: saturate(0.5) brightness(1.08) drop-shadow(0 0 1px rgba(90, 50, 30, 0.9)) drop-shadow(0 0 1px rgba(90, 50, 30, 0.6));
}
.stand .tier.full img { opacity: 1; filter: drop-shadow(0 2px 2px rgba(60, 30, 20, 0.25)); }
.stand .tier.stow img { animation: stow 0.3s cubic-bezier(0.3, 1.5, 0.5, 1); }
.stand .topper { position: absolute; left: 30%; width: 40%; z-index: 9; opacity: 0; transform: translateY(-60%) scale(0.6); transition: opacity 0.2s, transform 0.4s cubic-bezier(0.3, 1.6, 0.5, 1); }
.stand.done .topper { opacity: 1; transform: none; }
@keyframes van-bump {
    35% { transform: translateY(3%) scale(1.02, 0.97); }
}
@keyframes bump-goal {
    0% { transform: scale(1); }
    40% { transform: scale(1.26); }
    75% { transform: scale(0.95); }
    100% { transform: scale(1); }
}
@keyframes pulse-final {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Order in: a lurch, a puff from the exhaust, and away. A new order drives in from the other side. */
#van.leave .van-drive { animation: van-leave 1.15s cubic-bezier(0.6, 0, 0.9, 0.5) forwards; }
@keyframes van-leave {
    0% { transform: none; }
    14% { transform: translateX(-3%) scale(1.03, 0.96); }
    24% { transform: translateX(-1%) scale(0.98, 1.03); }
    100% { transform: translateX(calc(50vw + 100%)); }
}
#van.gone:not(.leave) .van-drive { transform: translateX(calc(50vw + 100%)); }
#van.arrive .van-drive { animation: van-arrive 0.95s cubic-bezier(0.25, 0.8, 0.35, 1) both; }
@keyframes van-arrive {
    from { transform: translateX(calc(-50vw - 100%)); }
    78% { transform: translateX(2.5%) rotate(-1deg); }
    90% { transform: translateX(-0.8%); }
    to { transform: none; }
}
.puff {
    position: absolute;
    left: 2%;
    bottom: 14%;
    width: 12%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, #ffffff, #efe6dc 60%, rgba(239, 230, 220, 0) 72%);
    opacity: 0;
}
#van.leave .puff { animation: puff 0.9s ease-out forwards; }
#van.leave .puff:nth-child(2) { animation-delay: 0.12s; }
#van.leave .puff:nth-child(3) { animation-delay: 0.24s; }
@keyframes puff {
    0% { opacity: 0; transform: translate(0, 0) scale(0.4); }
    15% { opacity: 0.95; }
    100% { opacity: 0; transform: translate(-160%, -40%) scale(1.9); }
}

/* A finished cake's box on its way up to the van, over everything else. */
.flying-box {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 7;
    pointer-events: none;
    will-change: transform;
}

#bar {
    position: absolute;
    left: 50%;
    bottom: calc(var(--bottom) + 6px);
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    align-items: center;
    z-index: 6;
}

/* On very wide, short windows move the tool tray to the right side so the 3D cake tray stays huge! */
@media (min-aspect-ratio: 16/9) and (max-height: 600px) {
    #bar {
        left: auto;
        right: 16px;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
        flex-direction: column;
        gap: 12px;
    }
    #bar .tool { width: 56px; height: 56px; }
    #bar .tool img { width: 41px; height: 41px; }
}

/* ---------------------------------------------------------------- the chef */

/* Wide screens: she stands in the bottom-left corner beside the board, the bubble over her head. */
#chef {
    --h: min(44vh, 360px);
    position: absolute;
    left: 0;
    bottom: 0;
    width: calc(var(--h) * 0.85);
    height: var(--h);
    z-index: 5;
    cursor: pointer;
}
#chef[hidden] { display: none; }
.chef-body {
    position: absolute;
    left: 6px;
    bottom: 0;
    height: 100%;
    transform-origin: 50% 100%;
    transition: transform 0.36s cubic-bezier(0.5, 0, 0.75, 0);
}
.chef-bubble {
    position: absolute;
    left: 10px;
    bottom: calc(100% + 6px);
    display: flex;
    align-items: center;
    gap: 10px;
    width: max-content;
    max-width: calc(var(--h) * 0.85 + 60px);
    padding: 12px 16px;
    border-radius: 22px;
    background: #fffdf8;
    border: 3px solid #e3a76a;
    box-shadow: 0 5px 0 #a3642a;
    transform-origin: 30% 120%;
    transition: transform 0.25s, opacity 0.25s;
}
.chef-bubble::after {
    content: "";
    position: absolute;
    left: 38%;
    bottom: -14px;
    border: 9px solid transparent;
    border-top: 12px solid #e3a76a;
    border-bottom: 0;
}
.chef-bubble p {
    margin: 0;
    font-size: 19px;
    font-weight: 820;
    line-height: 1.15;
    color: var(--ink);
}
.chef-bubble img { width: 58px; height: 58px; object-fit: contain; flex: none; }
.chef-bubble img[hidden] { display: none; }
#chef.in .chef-body { animation: chef-in 0.5s cubic-bezier(0.2, 1.3, 0.4, 1); }
#chef .chef-bubble.pop { animation: bubble-pop 0.32s cubic-bezier(0.2, 1.5, 0.4, 1); }
#chef.away .chef-body { transform: translateX(-115%) rotate(-8deg); }
#chef.away .chef-bubble { transform: scale(0.5); opacity: 0; }
@keyframes chef-in {
    from { transform: translateX(-110%) rotate(-10deg); }
    65% { transform: translateX(4%) rotate(2deg) scaleY(0.97); }
}
@keyframes bubble-pop {
    from { transform: scale(0.4); opacity: 0; }
}

/* Upright screens: she stands whole beside her bubble, in the gap between the street and the board (--room, from main.ts). */
@media (max-aspect-ratio: 11/10) {
    #chef {
        --band: var(--room, clamp(96px, 14vh, 140px));
        top: calc(var(--street-h, 200px) - 24px);
        bottom: auto;
        width: 100%;
        height: var(--band);
        pointer-events: none;
    }
    #chef > * { pointer-events: auto; }
    .chef-body {
        top: 0;
        bottom: auto;
        left: 4px;
        height: 100%;
        /* Her picture stops at the apron: its hem melts into the counter. */
        -webkit-mask-image: linear-gradient(to bottom, #000 84%, transparent 99%);
        mask-image: linear-gradient(to bottom, #000 84%, transparent 99%);
    }
    .chef-bubble {
        left: calc(var(--band) * 0.8 + 14px);
        right: 10px;
        top: 46%;
        bottom: auto;
        translate: 0 -50%;
        max-width: none;
        width: auto;
        padding: 9px 14px;
        transform-origin: 0 50%;
    }
    .chef-bubble::after {
        left: -14px;
        top: 50%;
        bottom: auto;
        margin-top: -9px;
        border: 9px solid transparent;
        border-right: 12px solid #e3a76a;
        border-left: 0;
    }
    .chef-bubble p { font-size: 17px; }
    .chef-bubble img { width: 46px; height: 46px; }
}

/* The rat: he leans out from behind a flour sack at the right edge, as the chef does from the left. Out while she
   talks about him, and the move before he strikes. His run is in the scene. He and the sack sway from its foot. */
#rat {
    --h: min(46vh, 380px);
    position: absolute;
    right: 0;
    bottom: 0;
    width: calc(var(--h) * 0.83);
    height: var(--h);
    z-index: 4;
    pointer-events: none;
    transform: translateX(108%);
    transition: transform 0.32s cubic-bezier(0.5, 0, 0.75, 0);
}
#rat[hidden] { display: none; }
#rat img { position: absolute; right: 0; bottom: 0; height: 100%; transform-origin: 78% 100%; }
#rat.out { transform: none; transition: transform 0.5s cubic-bezier(0.2, 1.35, 0.4, 1); }
#rat.out img { animation: rat-sniff 1.8s ease-in-out infinite; }
#rat.out.warn img { animation: rat-twitch 1.1s ease-in-out infinite; }
@keyframes rat-sniff {
    0%, 100% { rotate: 0deg; translate: 0 0; }
    30% { rotate: -2.5deg; translate: -1.5% 0; }
    45% { rotate: 0.6deg; }
    62% { rotate: -1.2deg; translate: -0.8% 0; }
}
@keyframes rat-twitch {
    0%, 100% { rotate: 0deg; translate: 0 0; }
    10% { rotate: -4deg; translate: -3% 0; }
    20% { rotate: -1deg; }
    30% { rotate: -4.5deg; translate: -3.5% 0; }
    48% { rotate: 0deg; translate: 0 0; }
}
@media (max-aspect-ratio: 11/10) {
    #rat {
        --h: calc(var(--room, clamp(96px, 14vh, 140px)) * 1.15);
        top: calc(var(--street-h, 200px) - 30px);
        bottom: auto;
        -webkit-mask-image: linear-gradient(to bottom, #000 84%, transparent 99%);
        mask-image: linear-gradient(to bottom, #000 84%, transparent 99%);
    }
    #rat img { top: 0; bottom: auto; }
    /* Both out: her bubble fits between them. */
    #game.rat-out .chef-bubble { right: calc(var(--band) * 0.96 + 8px); }
}

/* ---------------------------------------------------------------- modal sheets & cards */

.sheet {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(34, 18, 12, 0.56);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    animation: fade-in 0.2s ease-out;
}
.sheet[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } }

.card {
    position: relative;
    width: min(92vw, 370px);
    padding: 28px 24px 26px;
    border-radius: 30px;
    background: linear-gradient(#fffdf9, #fae9d6);
    border: 3px solid #e3a76a;
    box-shadow: 0 10px 0 #a3642a, 0 22px 42px rgba(20, 10, 6, 0.45);
    text-align: center;
    animation: pop-card 0.26s cubic-bezier(0.2, 1.35, 0.4, 1);
}

@keyframes pop-card {
    from { transform: scale(0.86) translateY(16px); opacity: 0; }
}

.card h2 {
    margin: 6px 0 14px;
    font-size: 30px;
    font-weight: 900;
    color: var(--ink);
    letter-spacing: 0.02em;
}

.card .close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #845232;
    background: rgba(140, 86, 42, 0.14);
}
.card .close svg { width: 17px; height: 17px; }

.card .row {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

/* Win card stars & glints. Each star slams in from above, squashes as it lands and throws sparkles (Flux);
   the empty ones are dark sockets, and rays turn behind them. */
@property --spin { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
.stars {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 6px;
    height: 82px;
    margin-top: -6px;
}
.stars::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 340px;
    height: 210px;
    margin: -105px 0 0 -170px;
    background: repeating-conic-gradient(from var(--spin), rgba(255, 196, 60, 0.5) 0deg 8deg, transparent 8deg 20deg);
    -webkit-mask-image: radial-gradient(closest-side, #000 22%, transparent 100%);
    mask-image: radial-gradient(closest-side, #000 22%, transparent 100%);
    opacity: 0;
    scale: 0.3;
    transition: opacity 0.5s, scale 0.7s cubic-bezier(0.2, 1.4, 0.4, 1);
    pointer-events: none;
}
.stars.rays::before { opacity: 1; scale: 1; animation: rays-turn 16s linear infinite; }
@keyframes rays-turn { to { --spin: 360deg; } }
.stars .star {
    position: relative;
    width: 66px;
    height: 66px;
    z-index: 1;
}
.stars .star:nth-child(2) { width: 82px; height: 82px; translate: 0 -8px; }
.stars .star::before {
    content: '';
    position: absolute;
    inset: 3%;
    background: url(media/star.webp) center / contain no-repeat;
    filter: brightness(0);
    opacity: 0.13;
}
.stars .star img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transform-origin: 50% 80%;
}
.stars .star.lit img { animation: star-slam 0.62s cubic-bezier(0.3, 0.6, 0.4, 1) both; }
@keyframes star-slam {
    0% { opacity: 0; transform: translateY(-90px) scale(3.2) rotate(-150deg); filter: brightness(2.4); }
    12% { opacity: 1; }
    50% { transform: translateY(0) scale(0.94) rotate(8deg); filter: brightness(1.7); }
    63% { transform: scale(1.26, 0.78) rotate(0deg); }
    77% { transform: scale(0.92, 1.1); }
    89% { transform: scale(1.03, 0.97); }
    100% { opacity: 1; transform: none; filter: none; }
}
/* A shine sweeps across each star once it's down. */
.stars .star::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(112deg, transparent 38%, rgba(255, 255, 255, 0.95) 49%, transparent 60%) no-repeat;
    background-size: 260% 100%;
    background-position: 140% 0;
    -webkit-mask: url(media/star.webp) center / contain no-repeat;
    mask: url(media/star.webp) center / contain no-repeat;
    opacity: 0;
    pointer-events: none;
}
.stars .star.lit::after { animation: star-shine 0.75s 0.5s ease-in-out both; }
@keyframes star-shine {
    0% { opacity: 1; background-position: 140% 0; }
    100% { opacity: 1; background-position: -40% 0; }
}

/* Next counts down: a gold ring behind the button fills up, then the next level starts. */
@property --fill { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
.countdown { position: relative; display: inline-grid; }
.countdown .pie {
    position: absolute;
    inset: -13px;
    translate: 0 3px;
    border-radius: 50%;
    background: conic-gradient(#ffbf1f var(--fill), rgba(150, 84, 36, 0.15) 0);
    box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(120, 60, 20, 0.25);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.countdown.on .pie { opacity: 1; animation: count-down var(--secs, 2.5s) linear forwards; }
@keyframes count-down { from { --fill: 0deg; } to { --fill: 360deg; } }
.sheet > #fxview { z-index: 3; }

/* A new power-up: its picture big, rays turning behind it, a count of what she gives you, her line under it. */
.tool-show {
    position: relative;
    width: 150px;
    height: 136px;
    margin: -8px auto 0;
    display: grid;
    place-items: center;
}
.tool-show[hidden] { display: none; }
.tool-show::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 300px;
    height: 230px;
    margin: -115px 0 0 -150px;
    background: repeating-conic-gradient(from var(--spin), rgba(255, 196, 60, 0.5) 0deg 8deg, transparent 8deg 20deg);
    -webkit-mask-image: radial-gradient(closest-side, #000 22%, transparent 100%);
    mask-image: radial-gradient(closest-side, #000 22%, transparent 100%);
    animation: rays-turn 16s linear infinite;
    pointer-events: none;
}
.tool-show img {
    position: relative;
    width: 136px;
    height: 136px;
    object-fit: contain;
    filter: drop-shadow(0 6px 5px rgba(90, 40, 10, 0.3));
    animation: tool-pop 0.7s 0.15s cubic-bezier(0.2, 1.5, 0.4, 1) both, tool-bob 2.4s 1s ease-in-out infinite;
}
@keyframes tool-pop { from { transform: scale(0.2) rotate(-40deg); opacity: 0; } }
@keyframes tool-bob { 50% { translate: 0 -7px; } }
.tool-show .count {
    position: absolute;
    top: 4px;
    right: 0;
    min-width: 40px;
    height: 32px;
    padding: 0 8px;
    border-radius: 16px;
    font-style: normal;
    font-size: 18px;
    font-weight: 900;
    line-height: 32px;
    color: #fff;
    background: #ef2c52;
    box-shadow: 0 0 0 3px #fff;
    animation: tool-pop 0.5s 0.65s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.tool-show .count[hidden] { display: none; }
/* A wedding: the three tiers stack up one by one, the doves land on top, rays turning behind. Sizes follow van.ts. */
.wedding-show {
    position: relative;
    width: 200px;
    height: 222px;
    margin: -4px auto 0;
}
.wedding-show[hidden] { display: none; }
.wedding-show::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 320px;
    height: 300px;
    margin: -150px 0 0 -160px;
    background: repeating-conic-gradient(from var(--spin), rgba(255, 196, 60, 0.5) 0deg 8deg, transparent 8deg 20deg);
    -webkit-mask-image: radial-gradient(closest-side, #000 22%, transparent 100%);
    mask-image: radial-gradient(closest-side, #000 22%, transparent 100%);
    animation: rays-turn 16s linear infinite;
    pointer-events: none;
}
.wedding-show img {
    position: absolute;
    left: 50%;
    translate: -50% 0;
    filter: drop-shadow(0 4px 4px rgba(90, 40, 10, 0.28));
    animation: tier-drop 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) both;
}
.wedding-show .tier:nth-child(1) { width: 124px; bottom: 0; z-index: 1; animation-delay: 0.2s; }
.wedding-show .tier:nth-child(2) { width: 97px; bottom: 73px; z-index: 2; animation-delay: 0.5s; }
.wedding-show .tier:nth-child(3) { width: 75px; bottom: 130px; z-index: 3; animation-delay: 0.8s; }
.wedding-show .doves { width: 56px; bottom: 174px; z-index: 4; animation: tool-pop 0.6s 1.15s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
/* Which cake: a slice of it, beside the stack. */
.wedding-show .flavor {
    left: auto;
    right: -4px;
    bottom: 6px;
    translate: none;
    width: 62px;
    height: 62px;
    object-fit: contain;
    z-index: 5;
    animation: tool-pop 0.5s 1.45s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
@keyframes tier-drop {
    from { transform: translateY(-90px) scale(0.9); opacity: 0; }
    40% { opacity: 1; }
    75% { transform: translateY(0) scale(1.06, 0.92); }
}
.tool-line {
    margin: 6px 4px 0;
    font-size: 21px;
    font-weight: 800;
    line-height: 1.25;
    color: var(--ink);
}

/* The glove showing how to use a power-up you've just been given: its fingertip on the target, tapping. */
#guide {
    position: fixed;
    left: 0;
    top: 0;
    width: 68px;
    height: 68px;
    z-index: 25;
    pointer-events: none;
    transform-origin: 18% 14%;
    filter: drop-shadow(0 4px 5px rgba(40, 20, 10, 0.35));
    animation: guide-tap 1.1s ease-in-out infinite;
}
#guide[hidden] { display: none; }
@keyframes guide-tap {
    0%, 100% { transform: translate(14px, 18px); }
    40%, 58% { transform: translate(0, 0) scale(0.88); }
}

.stars .glint {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--s);
    height: var(--s);
    background: radial-gradient(circle, #fff 0%, #ffe870 35%, transparent 70%);
    clip-path: polygon(50% 0%, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0% 50%, 38% 38%);
    opacity: 0;
    pointer-events: none;
}
.stars.sparkle .glint { animation: twinkle var(--d) ease-in-out infinite alternate; }
@keyframes twinkle {
    from { opacity: 0.12; transform: scale(0.5) rotate(0deg); }
    to { opacity: 0.95; transform: scale(1.12) rotate(24deg); }
}

.unlock-box {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 4px auto 8px;
    padding: 8px 16px 8px 12px;
    border-radius: 18px;
    background: #fff4df;
    border: 2px solid #e6b06a;
}
.unlock-box[hidden] { display: none; }
#win-unlock-pic { width: 64px; height: 64px; object-fit: contain; display: block; }
.unlock-box span { font-size: 16px; font-weight: 850; color: #7e3f14; }

.chip {
    display: inline-block;
    margin: 4px auto 0;
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.03em;
}
.chip.gold { background: #ffe478; color: #784208; border: 2px solid #eab028; }

/* A milestone gift: a picture of each power-up and how many more. */
.gift { display: flex; justify-content: center; gap: 14px; margin: 6px 0 2px; }
.gift[hidden] { display: none; }
.gift span { display: inline-flex; align-items: center; gap: 2px; font-size: 19px; font-weight: 900; color: #7e3f14; }
.gift img { width: 40px; height: 40px; }

/* She stands behind the card, leaning on its top edge, and rises up from behind it as it opens. */
.card-wrap {
    position: relative;
    margin-top: 156px;
    animation: pop-card 0.26s cubic-bezier(0.2, 1.35, 0.4, 1);
}
.card-wrap > .card { z-index: 1; animation: none; }
.card-chef {
    position: absolute;
    left: 50%;
    bottom: calc(100% - 58px);
    width: 186px;
    transform: translateX(-50%);
    pointer-events: none;
    animation: card-chef 0.55s 0.1s cubic-bezier(0.2, 1.3, 0.4, 1) backwards;
}
@keyframes card-chef { from { transform: translate(-50%, 62%); } }
.big.tool { width: 72px; height: 72px; }
.big.tool img { width: 52px; height: 52px; }
.chip[hidden] { display: none; }

/* Daily card */
.sub { margin: 4px 0 8px; font-size: 16px; font-weight: 700; color: #7c5234; }
.sub.done { display: inline-flex; align-items: center; gap: 6px; color: #1d9a34; font-weight: 900; }
.sub.done svg { width: 18px; height: 18px; }
.sub[hidden] { display: none; }
.streak { margin: 8px 0 18px; font-size: 18px; font-weight: 800; color: var(--ink); }
.streak b {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 12px;
    border-radius: 12px;
    background: #ffe066;
    color: #784208;
    font-feature-settings: "tnum";
}
#daily-go { margin: 0 auto; }

/* Settings form */
.card.form { text-align: left; }
.card.form h2 { text-align: center; margin-bottom: 18px; }

.line {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0 6px;
    font-size: 18px;
    font-weight: 800;
    color: var(--ink);
}
.line svg { width: 22px; height: 22px; color: #9c5828; }
.line span { flex: 1; }

.switch {
    appearance: none;
    width: 52px;
    height: 30px;
    border-radius: 15px;
    background: #dcc5ad;
    position: relative;
    cursor: pointer;
    transition: background 0.18s;
}
.switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.22);
    transition: transform 0.18s;
}
.switch:checked { background: #e63968; }
.switch:checked::after { transform: translateX(22px); }

input[type="range"] {
    width: 100%;
    accent-color: #e63968;
    margin: 2px 0 8px;
    cursor: pointer;
}

.credit {
    margin: 18px 0 0;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: #9c7a5c;
}

@media (max-width: 440px) {
    #top { left: 10px; }
    .key.round { width: 42px; height: 42px; }
    .key.round svg { width: 20px; height: 20px; }
    #bar { gap: 12px; }
    .tool { width: 52px; height: 52px; }
    .tool img { width: 36px; height: 36px; }
}

/* The test range's arrows, in the empty top-right corner. */
#range {
    position: absolute;
    top: var(--top);
    right: 14px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 22px;
    font-weight: 900;
    color: #6a3a1c;
}
#range button { font-size: 26px; line-height: 1; }
