/* Digby's Dino Dig — scene, characters, dig pit, skeleton stage. */

body {
    background: #FFF8EC;
    overflow: hidden;
}

#app {
    position: fixed;
    inset: 0;
    overflow: hidden;
}

/* ── shared backdrop ─────────────────────────────────────────────────────── */

#backdrop { position: absolute; inset: 0; z-index: 0; }
#canyon { width: 100%; height: 100%; display: block; }

#backdrop .bd-far, #backdrop .bd-mid, #backdrop .bd-near { transition: transform 0.9s ease; }
body[data-screen="map"]  #backdrop .bd-far  { transform: translate(7px, 2px); }
body[data-screen="map"]  #backdrop .bd-mid  { transform: translate(-7px, 0); }
body[data-screen="play"] #backdrop .bd-far  { transform: translate(-8px, 4px); }
body[data-screen="play"] #backdrop .bd-mid  { transform: translate(9px, 2px); }
body[data-screen="play"] #backdrop .bd-near { transform: translate(0, 6px); }

.sun-rays {
    animation: dd-rays 70s linear infinite;
    transform-box: fill-box;
    transform-origin: center;
}
@keyframes dd-rays { to { transform: rotate(1turn); } }

.clouds { animation: dd-drift 90s linear infinite; }
.cl-2 { animation-duration: 118s; animation-delay: -35s; }
.cl-3 { animation-duration: 134s; animation-delay: -72s; }
@keyframes dd-drift {
    0%   { transform: translateX(0); }
    50%  { transform: translateX(420px); }
    50.001% { transform: translateX(-820px); }
    100% { transform: translateX(0); }
}

.bird-hop { animation: dd-hop 9s ease-in-out infinite; }
@keyframes dd-hop {
    0%, 88%, 100% { transform: translateY(0); }
    90%, 94% { transform: translateY(-9px); }
    92%, 96% { transform: translateY(0); }
}

/* soaring birds glide across the whole sky — they keep tall (portrait) scenes alive */
.soar { animation: dd-soar 52s linear infinite; opacity: 0.75; }
.soar-2 { animation-duration: 67s; animation-delay: -39s; opacity: 0.55; }
@keyframes dd-soar {
    0%   { transform: translate(-70px, 215px); }
    28%  { transform: translate(330px, 150px); }
    55%  { transform: translate(730px, 195px); }
    78%  { transform: translate(1050px, 140px); }
    100% { transform: translate(1350px, 185px); }
}
.soar .wing {
    animation: dd-flap 1.5s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}
.soar-2 .wing { animation-duration: 1.9s; }
@keyframes dd-flap {
    0%, 100% { transform: scaleY(1); }
    50%      { transform: scaleY(0.4) translateY(3px); }
}

.sway-a, .sway-b, .fg-frond {
    animation: dd-sway 5.2s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: bottom center;
}
.sway-b { animation-delay: -2s; animation-duration: 6s; }
@keyframes dd-sway {
    0%, 100% { transform: rotate(-2.4deg); }
    50%      { transform: rotate(2.4deg); }
}

/* the cactus bows out while a dinosaur is waking up centre-stage */
#canyon .cactus { transition: opacity 0.8s; }
body[data-phase="wake"] #canyon .cactus { opacity: 0; }

#canyon.golden .sun circle:nth-of-type(1) { fill: #FFC300; }
#canyon.golden .sun circle:nth-of-type(2) { fill: #FFE45C; }
#canyon.golden .sun-rays path { fill: #FFD700; opacity: 1; }

/* ── foreground diorama frame ────────────────────────────────────────────── */

#fg-rock, #fg-fern {
    position: fixed;
    bottom: 0;
    z-index: 40;
    pointer-events: none;
    transition: transform 0.7s ease, opacity 0.7s ease;
}
#fg-rock { left: 0;  width: min(26vw, 280px); }
#fg-fern { right: 0; width: min(24vw, 260px); }
#fg-rock svg, #fg-fern svg { display: block; width: 100%; }
.fg-frond.f2 { animation-delay: -1.4s; }
.fg-frond.f3 { animation-delay: -2.8s; }

body[data-screen="play"] #fg-rock { transform: translate(-42%, 60%) scale(0.85); opacity: 0.9; }
body[data-screen="play"] #fg-fern { transform: translate(38%, 56%) scale(0.85); opacity: 0.9; }

/* ── screens ─────────────────────────────────────────────────────────────── */

.screen {
    position: absolute;
    inset: 0;
    z-index: 10;
}
.screen-in { animation: screen-in 0.5s ease-out; }
@keyframes screen-in {
    from { opacity: 0; transform: scale(1.015); }
    to   { opacity: 1; transform: scale(1); }
}

/* ── title screen ────────────────────────────────────────────────────────── */

#screen-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding: 26px 16px calc(12px + env(safe-area-inset-bottom, 0px));
}

#home-link {
    position: absolute;
    top: 14px;
    left: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 48px;
    padding: 6px 18px;
    border-radius: 40px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 12px rgba(90, 60, 130, 0.22);
    color: var(--gk-text);
    text-decoration: none;
    font-weight: bold;
    font-size: 1rem;
    z-index: 20;
    transition: transform 0.15s;
}
#home-link:hover { transform: scale(1.06); }

.title-stack { text-align: center; }

#game-title {
    display: flex;
    flex-direction: column;
    line-height: 1;
    filter: drop-shadow(0 4px 0 rgba(255, 255, 255, 0.75)) drop-shadow(0 8px 14px rgba(90, 60, 130, 0.3));
}
#game-title .t-small {
    font-size: clamp(1.4rem, 3.6vw, 2.1rem);
    color: #8A5A3B;
    transform: rotate(-2deg);
}
#game-title .t-big {
    font-size: clamp(3rem, 9vw, 5.2rem);
    background: linear-gradient(92deg, #E63946 0%, #F77F00 22%, #FCBF49 42%, #7CB518 62%, #00B4D8 82%, #B565D8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 0.02em;
}
.tagline {
    margin-top: 10px;
    font-size: clamp(0.95rem, 2.4vw, 1.2rem);
    color: #6B4A32;
    background: rgba(255, 255, 255, 0.65);
    display: inline-block;
    padding: 4px 18px;
    border-radius: 30px;
}

#title-hero {
    display: flex;
    align-items: center;
    gap: clamp(10px, 4vw, 60px);
}
#title-digby { width: clamp(170px, 24vw, 260px); }
#title-digby .digby-svg { width: 100%; }

#btn-start {
    position: relative;
    font-size: clamp(1.5rem, 4.5vw, 2rem);
    padding: 18px 54px;
    animation: start-beckon 2.4s ease-in-out infinite;
}
/* glow-only pulse (no size change) + an expanding ring on a pseudo-element */
@keyframes start-beckon {
    0%, 100% { box-shadow: 0 6px 20px rgba(124, 181, 24, 0.4); }
    50%      { box-shadow: 0 10px 34px rgba(124, 181, 24, 0.75); }
}
#btn-start::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 60px;
    border: 3px solid rgba(255, 255, 255, 0.85);
    pointer-events: none;
    animation: start-ring 2.4s ease-out infinite;
}
@keyframes start-ring {
    0%, 35% { opacity: 0; transform: scale(0.96); }
    55%     { opacity: 0.9; }
    100%    { opacity: 0; transform: scale(1.22); }
}

@media (orientation: portrait) {
    #title-digby { width: clamp(200px, 36vw, 300px); }
    #title-hero { gap: clamp(8px, 3vw, 30px); }
}

#badge-shelf {
    display: flex;
    gap: clamp(10px, 2.5vw, 26px);
}
.fossil-badge {
    width: clamp(96px, 12vw, 130px);
    padding: 10px 8px 8px;
    text-align: center;
    background: linear-gradient(180deg, #F7E8CB, #EAD3A8);
    border: 3px solid #D9C39A;
    border-radius: 18px;
    box-shadow: 0 6px 14px rgba(90, 60, 130, 0.18);
    opacity: 0.72;
}
.fossil-badge.earned { opacity: 1; box-shadow: 0 6px 18px rgba(232, 168, 40, 0.45); border-color: #E8A828; }
.fossil-badge .fb-bone { height: 34px; }
.fossil-badge .fb-bone svg { height: 100%; }
.fossil-badge .fb-name { font-weight: bold; color: #6B4A32; font-size: 0.95rem; }
.fossil-badge .fb-stars span { color: #CDBB97; font-size: 1.05rem; }
.fossil-badge .fb-stars span.on { color: #F6A800; text-shadow: 0 1px 0 #fff; animation: badge-shimmer 2.6s ease-in-out infinite; }
@keyframes badge-shimmer { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ── Digby rig ───────────────────────────────────────────────────────────── */

.digby-svg { display: block; }
.digby-svg .digby-body {
    animation: dd-breathe 3.4s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: 50% 100%;
}
@keyframes dd-breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.025); } }

.digby-svg .eyelid {
    transform: scaleY(0.06);
    transform-box: fill-box;
    transform-origin: 50% 0;
    animation: dd-blink 4.4s ease-in-out infinite;
}
@keyframes dd-blink {
    0%, 90%, 100% { transform: scaleY(0.06); }
    93%, 96% { transform: scaleY(1); }
}

.digby-svg .brush {
    transform-box: fill-box;
    transform-origin: 60% 82%;
    animation: brush-bob 3.4s ease-in-out infinite;
}
@keyframes brush-bob { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-5deg); } }

.digby-svg.cheer .digby-root { animation: dd-jump 0.42s ease-in-out 2; transform-box: fill-box; transform-origin: bottom center; }
@keyframes dd-jump {
    0%, 100% { transform: translateY(0); }
    40% { transform: translateY(-16px) rotate(-2deg); }
}
.digby-svg.cheer .brush { animation: brush-twirl 0.8s ease-in-out 1; }
@keyframes brush-twirl { to { transform: rotate(1turn); } }

/* ── map screen ──────────────────────────────────────────────────────────── */

.map-title {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) rotate(-1.5deg);
    background: rgba(255, 255, 255, 0.85);
    border: 3px solid #E8A828;
    padding: 8px 30px;
    border-radius: 40px;
    color: #6B4A32;
    font-size: clamp(1.1rem, 3vw, 1.6rem);
    box-shadow: 0 6px 14px rgba(90, 60, 130, 0.2);
    z-index: 15;
    white-space: nowrap;
}

#map-area { position: absolute; inset: 0; }
#rope-path { position: absolute; left: 0; bottom: 0; width: 100%; height: 74%; }

.pit-node {
    position: absolute;
    width: clamp(140px, 19vw, 210px);
    text-align: center;
    z-index: 12;
}
.pit-node.n1 { left: 12%; bottom: 20%; }
.pit-node.n2 { left: 40%; bottom: 36%; }
.pit-node.n3 { left: 69%; bottom: 15%; }
#rope-path .rope-port { display: none; }
@media (orientation: portrait) {
    .pit-node { width: clamp(160px, 26vw, 220px); }
    .pit-node.n1 { left: 6%;  bottom: 30%; }
    .pit-node.n2 { left: 37%; bottom: 52%; }
    .pit-node.n3 { left: 64%; bottom: 20%; }
    #rope-path .rope-land { display: none; }
    #rope-path .rope-port { display: initial; }
}
.stars-row { font-size: clamp(1.1rem, 2.4vw, 1.6rem); height: 1.6em; margin-bottom: -16px; position: relative; z-index: 2; }
.stars-row span { color: rgba(255, 255, 255, 0.75); text-shadow: 0 2px 3px rgba(90, 60, 130, 0.35); margin: 0 1px; }
.stars-row span.on {
    color: #FFC300;
    text-shadow: 0 2px 3px rgba(120, 70, 0, 0.45), 0 0 8px rgba(255, 243, 176, 0.9);
    animation: badge-shimmer 3s ease-in-out infinite;
}

.pit-btn {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s;
}
.pit-btn:hover { transform: scale(1.06); }
.pit-btn:active { transform: scale(0.96); }
.pit-btn svg { width: 100%; display: block; }
.pit-btn.zoom { animation: pit-zoom 0.5s ease-in forwards; }
@keyframes pit-zoom { to { transform: scale(1.6); opacity: 0; } }
.pit-btn.stir .mound-body { animation: mound-stir 0.6s ease-in-out; transform-box: fill-box; transform-origin: bottom center; }
@keyframes mound-stir {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-2.4deg) translateY(-3px); }
    65% { transform: rotate(2.4deg); }
}

.pit-sil { animation: sil-shimmer 3.2s ease-in-out infinite; }
@keyframes sil-shimmer { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.9; } }
.pit-spark { animation: badge-shimmer 2.2s ease-in-out infinite; }

.zz { animation: zz-float 3s ease-in-out infinite; opacity: 0; }
.z2 { animation-delay: 0.8s; }
.z3 { animation-delay: 1.6s; }
@keyframes zz-float {
    0% { opacity: 0; transform: translateY(6px); }
    30%, 60% { opacity: 0.9; }
    100% { opacity: 0; transform: translateY(-14px); }
}

.pit-label {
    display: inline-block;
    margin-top: 2px;
    background: #8A5A3B;
    color: #FFF3D6;
    font-weight: bold;
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    padding: 3px 16px;
    border-radius: 30px;
    box-shadow: 0 3px 8px rgba(90, 60, 130, 0.3);
}

.map-dino {
    position: absolute;
    right: -34%;
    bottom: 12%;
    width: 74%;
    pointer-events: none;
    animation: dino-dance 1.6s ease-in-out infinite;
    transform-origin: bottom center;
}
.mini-dino-svg { width: 100%; display: block; filter: drop-shadow(0 4px 6px rgba(90, 60, 130, 0.25)); }
@keyframes dino-dance {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg) translateY(-4px); }
}

.steam {
    position: absolute;
    left: 44%;
    top: 32%;
    width: 12px;
    height: 30px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.85));
    animation: steam-rise 2.4s ease-out infinite;
    pointer-events: none;
}
.steam.s2 { left: 56%; animation-delay: 1.2s; }
@keyframes steam-rise {
    0% { opacity: 0; transform: translateY(8px) scaleX(1); }
    35% { opacity: 0.85; }
    100% { opacity: 0; transform: translateY(-34px) scaleX(1.7); }
}

#map-digby {
    position: absolute;
    left: 1.5%;
    bottom: 22%;
    width: clamp(90px, 11vw, 130px);
    pointer-events: none;
    z-index: 12;
}
@media (orientation: portrait) {
    #map-digby { left: 1%; bottom: 40%; }
}
#map-digby .digby-svg { width: 100%; }

/* ── play layout ─────────────────────────────────────────────────────────── */

.play-layout {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 12px;
    padding: 76px 16px 14px;
}

#dig-area {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#tray {
    align-self: center;
    width: 192px;
    max-height: 100%;
    padding: 14px 10px 12px;
    background: linear-gradient(180deg, #C98B4B, #A96F35);
    border: 4px solid #8F5E2B;
    border-radius: 22px;
    box-shadow: inset 0 3px 0 rgba(255, 245, 220, 0.4), 0 10px 24px rgba(90, 60, 130, 0.25);
    transition: opacity 0.7s, transform 0.85s cubic-bezier(0.5, 0, 0.7, 0.4);
    z-index: 15;
}
#tray.tray-faded { opacity: 0; transform: translateX(140%); pointer-events: none; }
#tray-head {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 6px;
    filter: drop-shadow(0 2px 2px rgba(90, 60, 130, 0.3));
}
#tray-slots {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.tray-slot {
    position: relative;
    width: 76px;
    height: 76px;
    border-radius: 16px;
    border: 3px dashed rgba(74, 50, 20, 0.45);
    background: rgba(255, 248, 236, 0.28);
    cursor: pointer;
    padding: 4px;
    transition: transform 0.15s, box-shadow 0.2s, background 0.3s;
}
.tray-slot .slot-num {
    font-size: 1.7rem;
    font-weight: bold;
    color: rgba(74, 50, 20, 0.5);
}
.tray-slot .slot-num.done { color: #7CB518; }
.tray-slot.filled {
    border: 3px solid #E8A828;
    background: #FFF6DF;
    box-shadow: 0 4px 10px rgba(90, 60, 130, 0.22);
}
.tray-slot.filled:not(:disabled):hover { transform: scale(1.08); }
.tray-slot.filled .bone-svg { width: 90%; height: 66%; display: block; margin: 0 auto; }
.tray-slot .chip {
    position: absolute;
    right: -8px;
    bottom: -8px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F77F00;
    color: #fff;
    border: 3px solid #fff;
    border-radius: 50%;
    font-size: 1.05rem;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(90, 60, 130, 0.35);
}
.tray-slot.stamp { animation: slot-stamp 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes slot-stamp {
    0% { transform: scale(1.35); }
    100% { transform: scale(1); }
}
.tray-slot.emptied { border-style: dashed; background: rgba(255, 248, 236, 0.22); box-shadow: none; }
.tray-slot.glow {
    box-shadow: 0 0 0 4px rgba(255, 217, 0, 0.75), 0 0 22px 6px rgba(255, 217, 0, 0.6);
    animation: slot-glow 1.1s ease-in-out infinite;
}
@keyframes slot-glow {
    0%, 100% { box-shadow: 0 0 0 4px rgba(255, 217, 0, 0.75), 0 0 20px 4px rgba(255, 217, 0, 0.5); }
    50% { box-shadow: 0 0 0 6px rgba(255, 217, 0, 0.95), 0 0 30px 10px rgba(255, 217, 0, 0.75); }
}
.tray-slot.hint-bounce { animation: slot-bounce 0.7s ease-in-out infinite; }
@keyframes slot-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-9px); }
}
.tray-slot.wiggle { animation: slot-wiggle 0.5s ease-in-out; }
@keyframes slot-wiggle {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-7deg); }
    50% { transform: rotate(6deg); }
    75% { transform: rotate(-4deg); }
}

/* portrait: pit on top, tray along the bottom */
@media (orientation: portrait) {
    .play-layout { flex-direction: column; padding: 72px 12px 10px; }
    #tray {
        align-self: center;
        width: min(100%, 720px);
        padding: 10px 12px;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    #tray.tray-faded { transform: translateY(160%); }
    #tray-head { margin-bottom: 0; }
    #tray-slots { flex: 1; }
}

/* ── the dig pit ─────────────────────────────────────────────────────────── */

#pit-wrap {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    transition: transform 0.6s ease-in, opacity 0.6s ease-in;
}
#pit-wrap.slide-away { transform: translateY(70vh) rotate(2deg); opacity: 0; }
#pit-wrap.stage-in {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: gk-pop-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.pit-frame {
    position: relative;
    padding: 18px;
    border-radius: 26px;
    background:
        repeating-linear-gradient(90deg, rgba(60, 30, 8, 0.2) 0 3px, rgba(255, 240, 210, 0.05) 3px 46px),
        linear-gradient(180deg, #A96F35, #8A5626);
    box-shadow: inset 0 3px 0 rgba(255, 245, 220, 0.35), 0 14px 30px rgba(90, 60, 130, 0.3);
    border: 4px solid #6E4620;
}
.rope {
    position: absolute;
    width: 34px;
    height: 34px;
    z-index: 25;
    pointer-events: none;
}
.rope svg { width: 100%; height: 100%; }
.rope-tl { top: -10px; left: -10px; }
.rope-tr { top: -10px; right: -10px; }
.rope-bl { bottom: -10px; left: -10px; }
.rope-br { bottom: -10px; right: -10px; }

.grid-wrap { position: relative; border-radius: 12px; overflow: hidden; }

.pit-floor {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 35%, #8A5F3E, #67422B 82%);
    pointer-events: none;
}
.pit-floor svg { display: block; width: 100%; height: 100%; }
.pit-floor::after {
    /* carved-out depth: soft shadow lip around the whole excavation */
    content: '';
    position: absolute;
    inset: 0;
    box-shadow: inset 0 14px 30px rgba(24, 10, 2, 0.55), inset 0 -10px 24px rgba(24, 10, 2, 0.4),
                inset 12px 0 24px rgba(24, 10, 2, 0.3), inset -12px 0 24px rgba(24, 10, 2, 0.3);
}

.bone-layer { position: absolute; inset: 0; pointer-events: none; }
.bone-in-dirt {
    position: absolute;
    left: calc(var(--c) * var(--tile) + var(--tile) * 0.06);
    top: calc(var(--r) * var(--tile) + var(--tile) * 0.08);
    width: calc(var(--w) * var(--tile) - var(--tile) * 0.12);
    height: calc(var(--h) * var(--tile) - var(--tile) * 0.16);
    filter: drop-shadow(0 3px 3px rgba(46, 20, 5, 0.4));
}
.bone-in-dirt .bone-svg { width: 100%; height: 100%; display: block; }
.bone-in-dirt { opacity: 0; transition: opacity 0.3s; }
.bone-in-dirt.peek { opacity: 1; }

/* intro promise: bone shadows shimmer once above the dirt */
.bone-shimmer {
    position: absolute;
    left: calc(var(--c) * var(--tile) + var(--tile) * 0.06);
    top: calc(var(--r) * var(--tile) + var(--tile) * 0.08);
    width: calc(var(--w) * var(--tile) - var(--tile) * 0.12);
    height: calc(var(--h) * var(--tile) - var(--tile) * 0.16);
    z-index: 28;
    pointer-events: none;
    animation: shimmer-once 2.2s ease-in-out forwards;
    opacity: 0;
}
.bone-shimmer .bone-svg { width: 100%; height: 100%; display: block; }
.bone-shimmer .bone-ink :is(path, circle, rect, ellipse) {
    fill: rgba(74, 59, 92, 0.4);
    stroke: none;
}
.bone-shimmer .glint { display: none; }
@keyframes shimmer-once {
    0%, 100% { opacity: 0; }
    30%, 60% { opacity: 0.55; }
}
.bone-in-dirt.gleam { animation: gleam-pop 0.55s ease-out; filter: drop-shadow(0 0 14px #FFE9A8); }
@keyframes gleam-pop {
    0% { transform: scale(1); }
    45% { transform: scale(1.18); }
    100% { transform: scale(1); }
}

.bone-svg .glint { animation: glint-move 3.4s ease-in-out infinite; }
@keyframes glint-move {
    0%, 55%, 100% { opacity: 0; transform: translateX(0); }
    70% { opacity: 0.85; }
    85% { opacity: 0; transform: translateX(30px); }
}

.grid {
    position: relative;
    display: grid;
    touch-action: none;
    cursor: pointer;
}
.tile {
    position: relative;
    width: var(--tile);
    height: var(--tile);
    transition: opacity 0.35s;
}
.tile svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.tile .tg-crack, .tile .tg-half { opacity: 0; }
.tile.stage-1 .tg-crack { opacity: 1; }
.tile.stage-2 .tg-full, .tile.stage-2 .tg-crack { opacity: 0; }
.tile.stage-2 .tg-half { opacity: 1; }
.tile.cleared { opacity: 0; pointer-events: none; }

.tile.bump svg { animation: tile-bump 0.16s ease-out; }
@keyframes tile-bump {
    0% { transform: scale(0.94); }
    100% { transform: scale(1); }
}
.tile.wobble { animation: tile-wobble 0.3s ease-in-out; }
@keyframes tile-wobble {
    0%, 100% { transform: translateX(0); }
    30% { transform: translateX(-3px); }
    70% { transform: translateX(3px); }
}

.tile.hint-soft::after {
    content: '';
    position: absolute;
    inset: 6%;
    border-radius: 12px;
    pointer-events: none;
    animation: hint-soft-glow 2.8s ease-in-out infinite;
}
@keyframes hint-soft-glow {
    0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 240, 170, 0); }
    50% { box-shadow: inset 0 0 18px 4px rgba(255, 240, 170, 0.55); }
}
.tile.idle-pulse::after {
    content: '';
    position: absolute;
    inset: 4%;
    border-radius: 12px;
    pointer-events: none;
    animation: idle-pulse-glow 0.8s ease-in-out 3;
}
@keyframes idle-pulse-glow {
    0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 220, 120, 0); }
    50% { box-shadow: inset 0 0 20px 6px rgba(255, 220, 120, 0.8); }
}

.crust { position: absolute; inset: 0; z-index: 5; }
.crust svg { width: 100%; height: 100%; }
.crust .crust-cracks { opacity: 0; }
.tile.crust-cracked .crust { animation: crust-shake 0.24s ease-in-out; }
.tile.crust-cracked .crust .crust-cracks { opacity: 1; }
@keyframes crust-shake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-2px, 1px) rotate(-2deg); }
    75% { transform: translate(2px, -1px) rotate(2deg); }
}

/* ── particles & fx ──────────────────────────────────────────────────────── */

.sand-bit {
    position: absolute;
    width: var(--sz);
    height: var(--sz);
    border-radius: 50%;
    pointer-events: none;
    z-index: 30;
    animation: sand-fly 0.55s ease-out forwards;
}
@keyframes sand-fly {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    60% { transform: translate(calc(-50% + var(--dx) * 0.7), calc(-50% + var(--dy))) scale(0.9); opacity: 1; }
    100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 74px)) scale(0.5); opacity: 0; }
}

.float-bit {
    position: absolute;
    font-size: 26px;
    pointer-events: none;
    z-index: 35;
    animation: float-up 1.7s ease-out forwards;
}
@keyframes float-up {
    0% { transform: translateY(0) scale(0.5); opacity: 0; }
    20% { opacity: 1; transform: translateY(-14px) scale(1.1); }
    100% { transform: translateY(-120px) scale(1); opacity: 0; }
}

.fly-clone {
    position: fixed;
    z-index: 960;
    pointer-events: none;
    filter: drop-shadow(0 6px 8px rgba(90, 60, 130, 0.35));
}
.fly-clone .bone-svg { width: 100%; height: 100%; display: block; }

.beetle {
    position: absolute;
    width: 48px;
    z-index: 32;
    pointer-events: none;
    animation: beetle-run 1.3s ease-in forwards;
}
.beetle svg { width: 100%; }
@keyframes beetle-run {
    0% { transform: translate(-50%, -50%) scale(0.4) rotate(0); opacity: 0; }
    18% { transform: translate(-50%, -50%) scale(1.1) rotate(-8deg); opacity: 1; }
    40% { transform: translate(calc(-50% + var(--runx) * 0.3), -60%) rotate(8deg); opacity: 1; }
    100% { transform: translate(calc(-50% + var(--runx)), -50%) rotate(-6deg); opacity: 0; }
}
.geode {
    position: absolute;
    width: 52px;
    z-index: 32;
    pointer-events: none;
    animation: geode-pop 1.55s ease-out forwards;
}
.geode svg { width: 100%; }
@keyframes geode-pop {
    0% { transform: translate(-50%, -50%) scale(0.2) rotate(-14deg); opacity: 0; }
    25% { transform: translate(-50%, -58%) scale(1.15) rotate(6deg); opacity: 1; }
    50% { transform: translate(-50%, -58%) scale(1) rotate(-3deg); opacity: 1; }
    100% { transform: translate(-50%, -80%) scale(0.9) rotate(0); opacity: 0; }
}

.ghost-paw {
    position: absolute;
    width: 80px;
    z-index: 45;
    opacity: 0.8;
    pointer-events: none;
    filter: drop-shadow(0 3px 5px rgba(90, 60, 130, 0.35));
    animation: paw-rub 0.85s ease-in-out infinite;
}
.ghost-paw svg { width: 100%; opacity: 0.85; }
@keyframes paw-rub {
    0%, 100% { transform: translateX(-15px) rotate(-9deg); }
    50% { transform: translateX(15px) rotate(9deg); }
}

/* ── Digby on his ledge ──────────────────────────────────────────────────── */

#play-digby {
    position: absolute;
    left: 2px;
    bottom: 0;
    width: clamp(96px, 11vw, 132px);
    z-index: 20;
    pointer-events: none;
}
#play-digby .digby-svg { width: 88%; margin: 0 auto; }
#play-digby .ledge { display: block; width: 100%; margin-top: -22px; filter: drop-shadow(0 4px 6px rgba(90, 60, 130, 0.3)); }

/* ── wanted-number bubble (assembly) ─────────────────────────────────────── */

#want-bubble {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 4px solid var(--gk-pink);
    border-radius: 50px;
    padding: 4px 22px;
    box-shadow: 0 8px 18px rgba(90, 60, 130, 0.3);
    z-index: 22;
    pointer-events: none;
}
#want-bubble .wb-bone { font-size: 1.5rem; }
#want-bubble .wb-num {
    font-size: 2.1rem;
    font-weight: bold;
    color: var(--gk-pink);
}
#want-bubble.pop { animation: slot-stamp 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }

/* ── skeleton / assembly stage ───────────────────────────────────────────── */

.stage-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
#skeleton-svg {
    width: 100%;
    height: 100%;
    max-width: 860px;
    display: block;
}

.sk-slot .ghost :is(path, circle, rect, ellipse) {
    fill: rgba(255, 255, 255, 0.42);
    stroke: rgba(74, 59, 92, 0.4);
    stroke-width: 2;
    stroke-dasharray: 6 5;
}
.sk-placed-bone { animation: placed-pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); transform-box: fill-box; transform-origin: center; }
@keyframes placed-pop {
    0% { opacity: 0.4; }
    40% { opacity: 1; }
    100% { opacity: 1; }
}

.sk-badge { opacity: 0.25; transition: opacity 0.3s; }
.sk-badge.current { opacity: 1; }
.sk-badge.current .badge-in {
    animation: badge-pulse 0.9s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}
@keyframes badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.22); }
}

#sk-flash { transition: opacity 0.1s; }
#sk-flash.flashing { animation: sk-flash-a 0.3s ease-out; }
@keyframes sk-flash-a {
    0% { opacity: 0; }
    30% { opacity: 0.55; }
    100% { opacity: 0; }
}
#sk-flash.big-flash { animation: sk-flash-b 0.5s ease-out; }
@keyframes sk-flash-b {
    0% { opacity: 0; }
    25% { opacity: 0.95; }
    100% { opacity: 0; }
}

/* warm halo blooms behind the dino at the wake-up moment */
#wake-glow { opacity: 0; }
#skeleton-svg.waking #wake-glow {
    animation: wake-glow-in 2.6s ease-out 0.3s forwards;
    transform-box: fill-box;
    transform-origin: center;
}
@keyframes wake-glow-in {
    0%   { opacity: 0; transform: scale(0.4); }
    45%  { opacity: 1; transform: scale(1.06); }
    100% { opacity: 0.85; transform: scale(1); }
}

/* skeleton scaffolding melts away as the dino wakes up */
#skeleton-svg .fossil-plate, #skeleton-svg #sk-placed,
#skeleton-svg #sk-slots, #skeleton-svg #sk-badges { transition: opacity 1.1s ease 0.45s; }
#skeleton-svg.waking .fossil-plate, #skeleton-svg.waking #sk-placed,
#skeleton-svg.waking #sk-slots, #skeleton-svg.waking #sk-badges { opacity: 0; }

/* skin reveal + wake */
#skin-holder .skin { clip-path: inset(0 100% 0 0); }
#skin-holder.revealed .skin { animation: skin-wipe 1.15s ease-in-out forwards; }
@keyframes skin-wipe {
    from { clip-path: inset(0 100% 0 0); }
    to   { clip-path: inset(0 0 0 0); }
}
.instant .skin { clip-path: none; }

.skin .eyelid {
    transform: scaleY(1);
    transform-box: fill-box;
    transform-origin: 50% 0;
}
.awake .skin .eyelid, .awake.skin .eyelid, #skin-holder.awake .eyelid {
    animation: wake-blink 3.8s ease-in-out infinite;
}
@keyframes wake-blink {
    0% { transform: scaleY(1); }
    8% { transform: scaleY(0.06); }
    80%, 100% { transform: scaleY(0.06); }
    88%, 92% { transform: scaleY(1); }
    96% { transform: scaleY(0.06); }
}

.skin .mouth-open { opacity: 0; }
.roaring .mouth-open { opacity: 1; }
.roaring .mouth-closed { opacity: 0; }

.awake .tail-s {
    animation: tail-wag 0.9s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: 8% 85%;
}
@keyframes tail-wag {
    0%, 100% { transform: rotate(-4deg); }
    50% { transform: rotate(7deg); }
}
.awake .arm-s {
    animation: tail-wag 0.7s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: 80% 20%;
}

#skin-holder.bouncing {
    animation: dino-bounce 0.6s ease-in-out 5;
    transform-box: fill-box;
    transform-origin: bottom center;
}
@keyframes dino-bounce {
    0%, 100% { transform: translateY(0) scaleY(1); }
    30% { transform: translateY(-22px) scaleY(1.04); }
    85% { transform: translateY(0) scaleY(0.96); }
}

/* ── info popover ────────────────────────────────────────────────────────── */

#info-btn {
    position: fixed;
    bottom: 14px;
    left: 14px;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 4px 12px rgba(90, 60, 130, 0.25);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 60;
    transition: transform 0.15s;
}
#info-btn:hover { transform: scale(1.1); }
body[data-screen="play"] #info-btn { display: none; }

#info-overlay {
    position: fixed;
    inset: 0;
    z-index: 930;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(74, 59, 92, 0.45);
    animation: gk-fade-in 0.25s ease-out;
}
.info-card {
    position: relative;
    max-width: min(90vw, 520px);
    max-height: 80vh;
    overflow-y: auto;
    animation: gk-pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.info-card h3 { color: var(--gk-orange); margin-bottom: 10px; font-size: 1.3rem; padding-right: 56px; }
.info-card p { margin-bottom: 10px; font-size: 1rem; line-height: 1.45; }
.info-card .info-tip {
    background: #FFF6DF;
    border-radius: 14px;
    padding: 10px 14px;
    border: 2px dashed #E8A828;
    margin-bottom: 0;
}
#info-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: var(--gk-pink);
    color: #fff;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(90, 60, 130, 0.3);
}
#info-close:active { transform: scale(0.92); }

/* ── reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .sun-rays, .clouds, .bird-hop, .soar, .soar .wing, .sway-a, .sway-b, .fg-frond,
    .digby-svg .digby-body, .digby-svg .brush, .map-dino, #btn-start, #btn-start::after,
    .pit-sil, .zz, .steam, .tile.hint-soft::after,
    .sk-badge.current .badge-in, .tray-slot.glow, .tray-slot.hint-bounce,
    .bone-svg .glint { animation: none; }
}
