* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, sans-serif;
    touch-action: none;
}

#scene {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Sky */
#sky {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60%;
    background: linear-gradient(180deg, #87CEEB 0%, #B0E0FF 60%, #E8F4FD 100%);
}

/* Clouds */
.cloud {
    position: absolute;
    background: white;
    border-radius: 50px;
    opacity: 0.9;
}
.cloud::before, .cloud::after {
    content: '';
    position: absolute;
    background: white;
    border-radius: 50%;
}
.cloud1 {
    width: 90px;
    height: 30px;
    top: 12%;
    animation: drift 25s linear infinite;
}
.cloud1::before {
    width: 40px;
    height: 40px;
    top: -20px;
    left: 15px;
}
.cloud1::after {
    width: 50px;
    height: 50px;
    top: -28px;
    left: 35px;
}
.cloud2 {
    width: 70px;
    height: 24px;
    top: 22%;
    animation: drift 32s linear infinite;
    animation-delay: -10s;
}
.cloud2::before {
    width: 35px;
    height: 35px;
    top: -18px;
    left: 10px;
}
.cloud2::after {
    width: 40px;
    height: 40px;
    top: -22px;
    left: 28px;
}
.cloud3 {
    width: 80px;
    height: 26px;
    top: 8%;
    animation: drift 28s linear infinite;
    animation-delay: -18s;
}
.cloud3::before {
    width: 38px;
    height: 38px;
    top: -20px;
    left: 12px;
}
.cloud3::after {
    width: 45px;
    height: 45px;
    top: -25px;
    left: 32px;
}

@keyframes drift {
    from { left: -120px; }
    to { left: 110%; }
}

/* Edinburgh skyline parallax layers */
#skyline-far, #skyline-mid, #skyline-near {
    position: absolute;
    bottom: 35%;
    left: 0;
    width: 100%;
    height: 60px;
    z-index: 0;
}
#skyline-far {
    bottom: 42%;
    height: 40px;
    opacity: 0.25;
    background:
        linear-gradient(to right, transparent 2%, #4a5e4a 2%, #4a5e4a 4%, transparent 4%) 0 100%/100% 30px no-repeat,
        linear-gradient(to right, transparent 8%, #4a5e4a 8%, #4a5e4a 10%, transparent 10%) 0 100%/100% 22px no-repeat,
        linear-gradient(to right, transparent 88%, #4a5e4a 88%, #4a5e4a 91%, transparent 91%) 0 100%/100% 28px no-repeat,
        linear-gradient(to right, transparent 93%, #4a5e4a 93%, #4a5e4a 96%, transparent 96%) 0 100%/100% 18px no-repeat;
}
#skyline-mid {
    bottom: 39%;
    height: 50px;
    opacity: 0.35;
    background:
        linear-gradient(to right, transparent 12%, #5a6e5a 12%, #5a6e5a 16%, transparent 16%) 0 100%/100% 40px no-repeat,
        linear-gradient(to right, transparent 18%, #5a6e5a 18%, #5a6e5a 20%, transparent 20%) 0 100%/100% 25px no-repeat,
        linear-gradient(to right, transparent 72%, #5a6e5a 72%, #5a6e5a 76%, transparent 76%) 0 100%/100% 35px no-repeat,
        linear-gradient(to right, transparent 80%, #5a6e5a 80%, #5a6e5a 84%, transparent 84%) 0 100%/100% 45px no-repeat;
}
#skyline-near {
    bottom: 36%;
    height: 55px;
    opacity: 0.45;
    background:
        linear-gradient(to right, transparent 25%, #4a5a4a 25%, #4a5a4a 30%, transparent 30%) 0 100%/100% 50px no-repeat,
        linear-gradient(to right, transparent 32%, #4a5a4a 32%, #4a5a4a 34%, transparent 34%) 0 100%/100% 30px no-repeat,
        linear-gradient(to right, transparent 55%, #4a5a4a 55%, #4a5a4a 62%, transparent 62%) 0 100%/100% 42px no-repeat,
        linear-gradient(to right, transparent 64%, #4a5a4a 64%, #4a5a4a 67%, transparent 67%) 0 100%/100% 55px no-repeat;
}

/* Waving Scottish flag */
#flag-pole {
    position: absolute;
    bottom: 35%;
    left: 15%;
    width: 3px;
    height: 70px;
    background: #666;
    z-index: 4;
    border-radius: 1px;
}
#flag-pole::before {
    content: '';
    position: absolute;
    top: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 7px;
    height: 7px;
    background: #daa520;
    border-radius: 50%;
}
#flag {
    position: absolute;
    top: 0;
    left: 3px;
    width: 40px;
    height: 26px;
    background: #003399;
    overflow: hidden;
    animation: flagWave 2s ease-in-out infinite;
    transform-origin: left center;
}
.flag-cross {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.flag-cross::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 141%;
    height: 3px;
    background: white;
    transform-origin: top left;
    transform: rotate(33deg);
}
.flag-cross::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 141%;
    height: 3px;
    background: white;
    transform-origin: bottom left;
    transform: rotate(-33deg);
}
.flag-wave {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        transparent 0%, rgba(255,255,255,0.12) 25%,
        transparent 50%, rgba(0,0,0,0.08) 75%,
        transparent 100%);
    animation: flagShine 1.5s ease-in-out infinite;
}
@keyframes flagWave {
    0%, 100% { transform: perspective(100px) rotateY(0deg) skewY(0deg); }
    25% { transform: perspective(100px) rotateY(-5deg) skewY(1.5deg); }
    50% { transform: perspective(100px) rotateY(2deg) skewY(-1deg); }
    75% { transform: perspective(100px) rotateY(-3deg) skewY(0.5deg); }
}
@keyframes flagShine {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
}

/* Confetti */
#confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 25;
    overflow: hidden;
}
.confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    opacity: 1;
    will-change: transform, opacity;
}

/* Edinburgh Castle silhouette */
#castle {
    position: absolute;
    bottom: 40%;
    left: 50%;
    transform: translateX(-50%);
    width: 180px;
    height: 100px;
    z-index: 1;
}
#castle::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20px;
    width: 140px;
    height: 60px;
    background: #5a6e5a;
    clip-path: polygon(0% 100%, 5% 40%, 15% 45%, 20% 20%, 28% 25%, 35% 10%, 42% 25%, 50% 15%, 58% 30%, 65% 5%, 72% 25%, 80% 20%, 88% 35%, 95% 30%, 100% 100%);
}
#castle::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 180px;
    height: 40px;
    background: #4a5e4a;
    clip-path: polygon(0% 100%, 0% 60%, 10% 50%, 25% 55%, 40% 40%, 55% 50%, 70% 35%, 85% 45%, 100% 40%, 100% 100%);
}

/* Rolling hills */
#hills {
    position: absolute;
    bottom: 30%;
    left: 0;
    width: 100%;
    height: 20%;
    z-index: 2;
}
#hills::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -10%;
    width: 120%;
    height: 100%;
    background: #6aaa5a;
    border-radius: 50% 50% 0 0;
    clip-path: ellipse(60% 80% at 30% 100%);
}
#hills::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -5%;
    width: 120%;
    height: 100%;
    background: #5d9e4e;
    border-radius: 50% 50% 0 0;
    clip-path: ellipse(55% 70% at 70% 100%);
}

/* Ground / grass */
#ground {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 35%;
    background: linear-gradient(180deg, #7bc068 0%, #5da64a 40%, #4d8f3a 100%);
    z-index: 3;
}

#grass-detail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 8px;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 6px,
        #8fd47a 6px,
        #8fd47a 8px
    );
    opacity: 0.5;
}

/* Mali character */
#mali {
    position: absolute;
    bottom: 28%;
    left: 20%;
    width: 60px;
    height: 90px;
    z-index: 10;
    transition: none;
    cursor: pointer;
}

/* Hair */
#mali .hair {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 28px;
    background: #3a2518;
    border-radius: 50% 50% 30% 30%;
    z-index: 2;
}
#mali .hair::before {
    content: '';
    position: absolute;
    top: 12px;
    left: -5px;
    width: 14px;
    height: 30px;
    background: #3a2518;
    border-radius: 0 0 40% 60%;
}
#mali .hair::after {
    content: '';
    position: absolute;
    top: 12px;
    right: -5px;
    width: 14px;
    height: 30px;
    background: #3a2518;
    border-radius: 0 0 60% 40%;
}

/* Head */
#mali .head {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 30px;
    background: #FFDAB9;
    border-radius: 50%;
    z-index: 3;
}

/* Sunglasses */
#mali .sunglasses {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 12px;
    z-index: 4;
}
#mali .lens {
    position: absolute;
    top: 0;
    width: 11px;
    height: 10px;
    background: #222;
    border-radius: 3px;
    border: 1.5px solid #e84393;
}
#mali .left-lens { left: 0; }
#mali .right-lens { right: 0; }
#mali .bridge {
    position: absolute;
    top: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 2px;
    background: #e84393;
}

/* Smile */
#mali .smile {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 6px;
    border-bottom: 2.5px solid #e07a5f;
    border-radius: 0 0 50% 50%;
}

/* Rosy cheeks */
#mali .cheek {
    position: absolute;
    bottom: 7px;
    width: 6px;
    height: 4px;
    background: #ffb3b3;
    border-radius: 50%;
    opacity: 0.6;
}
#mali .left-cheek { left: 3px; }
#mali .right-cheek { right: 3px; }

/* Body (dress) */
#mali .body {
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 28px;
    background: #e84393;
    border-radius: 8px 8px 12px 12px;
    z-index: 2;
}
#mali .body::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -4px;
    width: 36px;
    height: 10px;
    background: #d63384;
    border-radius: 0 0 50% 50%;
}

/* Arms */
#mali .arm {
    position: absolute;
    top: 36px;
    width: 6px;
    height: 20px;
    background: #FFDAB9;
    border-radius: 3px;
    z-index: 1;
    transform-origin: top center;
}
#mali .left-arm { left: 10px; }
#mali .right-arm { right: 10px; }

.walking-right .left-arm { animation: swingArmForward 0.5s ease-in-out infinite alternate; }
.walking-right .right-arm { animation: swingArmBack 0.5s ease-in-out infinite alternate; }
.walking-left .left-arm { animation: swingArmBack 0.5s ease-in-out infinite alternate; }
.walking-left .right-arm { animation: swingArmForward 0.5s ease-in-out infinite alternate; }

/* Idle: no arm/leg animation */
.mali-idle .left-arm,
.mali-idle .right-arm { animation: none !important; }
.mali-idle .left-leg,
.mali-idle .right-leg { animation: none !important; }
.mali-idle .left-shoe,
.mali-idle .right-shoe { animation: none !important; }

@keyframes swingArmForward {
    from { transform: rotate(-20deg); }
    to { transform: rotate(20deg); }
}
@keyframes swingArmBack {
    from { transform: rotate(20deg); }
    to { transform: rotate(-20deg); }
}

/* Legs */
#mali .leg {
    position: absolute;
    top: 58px;
    width: 7px;
    height: 18px;
    background: #FFDAB9;
    border-radius: 3px;
    z-index: 1;
    transform-origin: top center;
}
#mali .left-leg { left: 18px; }
#mali .right-leg { right: 18px; }

.walking-right .left-leg, .walking-left .left-leg {
    animation: walkLeg 0.5s ease-in-out infinite alternate;
}
.walking-right .right-leg, .walking-left .right-leg {
    animation: walkLeg 0.5s ease-in-out infinite alternate-reverse;
}

@keyframes walkLeg {
    from { transform: rotate(-15deg); }
    to { transform: rotate(15deg); }
}

/* Shoes */
#mali .shoe {
    position: absolute;
    top: 74px;
    width: 10px;
    height: 6px;
    background: #222;
    border-radius: 3px 5px 3px 3px;
    z-index: 1;
}
#mali .left-shoe { left: 16px; animation: walkShoeL 0.5s ease-in-out infinite alternate; }
#mali .right-shoe { right: 16px; animation: walkShoeR 0.5s ease-in-out infinite alternate-reverse; }

@keyframes walkShoeL {
    from { transform: translateY(-4px) translateX(-3px); }
    to { transform: translateY(2px) translateX(3px); }
}
@keyframes walkShoeR {
    from { transform: translateY(-4px) translateX(-3px); }
    to { transform: translateY(2px) translateX(3px); }
}

/* Direction flip */
.walking-left {
    transform: scaleX(-1);
}

/* Bounce while walking */
#mali {
    animation: bounce 0.25s ease-in-out infinite alternate;
}
@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-3px); }
}
.walking-left {
    animation: bounceFlip 0.25s ease-in-out infinite alternate;
}
@keyframes bounceFlip {
    from { transform: scaleX(-1) translateY(0); }
    to { transform: scaleX(-1) translateY(-3px); }
}

/* Small flowers scattered */
#ground::before {
    content: '🌼 🌸 🌼 🌸 🌼';
    position: absolute;
    top: 15%;
    left: 10%;
    font-size: 12px;
    letter-spacing: 20px;
    opacity: 0.7;
}
#ground::after {
    content: '🌸 🌼 🌸';
    position: absolute;
    top: 35%;
    right: 10%;
    font-size: 10px;
    letter-spacing: 30px;
    opacity: 0.6;
}

/* Bagpiper character */
#bagpiper {
    position: absolute;
    bottom: 28%;
    width: 50px;
    height: 80px;
    z-index: 15;
    transition: none;
    will-change: left;
}
#bagpiper.bagpiper-hidden {
    display: none;
}
#bagpiper.bagpiper-walk-right {
    animation: bounce 0.25s ease-in-out infinite alternate;
}
#bagpiper.bagpiper-walk-left {
    animation: bounceFlip 0.25s ease-in-out infinite alternate;
}

/* Tam o'shanter */
.bp-tam {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 10px;
    background: #003399;
    border-radius: 50% 50% 30% 30%;
    z-index: 3;
}
.bp-tam::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
}
.bp-tam::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: -2px;
    width: 32px;
    height: 4px;
    background: #002266;
    border-radius: 2px;
}

/* Head */
.bp-head {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 22px;
    background: #FFDAB9;
    border-radius: 50%;
    z-index: 2;
}
.bp-eye {
    position: absolute;
    top: 7px;
    right: 5px;
    width: 4px;
    height: 4px;
    background: #333;
    border-radius: 50%;
}
.bp-cheek {
    position: absolute;
    bottom: 4px;
    right: 3px;
    width: 5px;
    height: 3px;
    background: #ffb3b3;
    border-radius: 50%;
    opacity: 0.6;
}

/* Body (jacket) */
.bp-body {
    position: absolute;
    top: 26px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 18px;
    background: #2d2d2d;
    border-radius: 4px 4px 0 0;
    z-index: 2;
}

/* Kilt */
.bp-kilt {
    position: absolute;
    top: 42px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 14px;
    background: repeating-linear-gradient(
        90deg,
        #003399 0px, #003399 3px,
        #006633 3px, #006633 6px,
        #003399 6px, #003399 8px,
        #228B22 8px, #228B22 10px
    );
    border-radius: 0 0 4px 4px;
    z-index: 2;
}
.bp-kilt::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px, transparent 3px,
        rgba(255,255,255,0.1) 3px, rgba(255,255,255,0.1) 4px
    );
}

/* Arms */
.bp-arm-back {
    position: absolute;
    top: 28px;
    left: 6px;
    width: 5px;
    height: 16px;
    background: #2d2d2d;
    border-radius: 3px;
    z-index: 1;
    transform-origin: top center;
    transform: rotate(10deg);
}
.bp-arm-front {
    position: absolute;
    top: 28px;
    right: 4px;
    width: 5px;
    height: 16px;
    background: #2d2d2d;
    border-radius: 3px;
    z-index: 3;
    transform-origin: top center;
    transform: rotate(-30deg);
}

/* Bagpipes */
.bp-pipes {
    position: absolute;
    top: 22px;
    right: -8px;
    z-index: 4;
}
.bp-bag {
    position: absolute;
    top: 10px;
    right: 0;
    width: 18px;
    height: 14px;
    background: #8B4513;
    border-radius: 50%;
}
.bp-chanter {
    position: absolute;
    top: 24px;
    right: 6px;
    width: 3px;
    height: 16px;
    background: #333;
    border-radius: 1px;
    transform: rotate(15deg);
    transform-origin: top center;
}
.bp-drone {
    position: absolute;
    width: 2.5px;
    background: #333;
    border-radius: 1px;
}
.bp-drone::before {
    content: '';
    position: absolute;
    top: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 4px;
    background: #333;
    border-radius: 2px 2px 0 0;
}
.bp-drone1 {
    top: -8px;
    right: 4px;
    height: 20px;
    transform: rotate(-8deg);
}
.bp-drone2 {
    top: -12px;
    right: 8px;
    height: 24px;
    transform: rotate(-15deg);
}
.bp-drone3 {
    top: -10px;
    right: 12px;
    height: 22px;
    transform: rotate(-22deg);
}

/* Legs */
.bp-leg {
    position: absolute;
    top: 54px;
    width: 6px;
    height: 14px;
    background: #FFDAB9;
    border-radius: 3px;
    z-index: 1;
    transform-origin: top center;
}
.bp-left-leg { left: 14px; }
.bp-right-leg { right: 14px; }
.bagpiper-walk-right .bp-left-leg,
.bagpiper-walk-left .bp-left-leg {
    animation: walkLeg 0.5s ease-in-out infinite alternate;
}
.bagpiper-walk-right .bp-right-leg,
.bagpiper-walk-left .bp-right-leg {
    animation: walkLeg 0.5s ease-in-out infinite alternate-reverse;
}

/* Shoes */
.bp-shoe {
    position: absolute;
    top: 66px;
    width: 8px;
    height: 5px;
    background: #222;
    border-radius: 2px 4px 2px 2px;
    z-index: 1;
}
.bp-left-shoe { left: 12px; animation: walkShoeL 0.5s ease-in-out infinite alternate; }
.bp-right-shoe { right: 12px; animation: walkShoeR 0.5s ease-in-out infinite alternate-reverse; }

/* Star-jump animation on tap */
#mali.star-jump .left-arm {
    animation: starArmLeft 0.4s ease-out forwards !important;
}
#mali.star-jump .right-arm {
    animation: starArmRight 0.4s ease-out forwards !important;
}
#mali.star-jump .left-leg {
    animation: starLegLeft 0.4s ease-out forwards !important;
}
#mali.star-jump .right-leg {
    animation: starLegRight 0.4s ease-out forwards !important;
}
#mali.star-jump .left-shoe {
    animation: starShoeLeft 0.4s ease-out forwards !important;
}
#mali.star-jump .right-shoe {
    animation: starShoeRight 0.4s ease-out forwards !important;
}
#mali.star-jump {
    animation: starJumpBounce 0.4s ease-out !important;
}

@keyframes starArmLeft {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(-140deg); }
    60%  { transform: rotate(-150deg); }
    100% { transform: rotate(0deg); }
}
@keyframes starArmRight {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(140deg); }
    60%  { transform: rotate(150deg); }
    100% { transform: rotate(0deg); }
}
@keyframes starLegLeft {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(-35deg); }
    60%  { transform: rotate(-35deg); }
    100% { transform: rotate(0deg); }
}
@keyframes starLegRight {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(35deg); }
    60%  { transform: rotate(35deg); }
    100% { transform: rotate(0deg); }
}
@keyframes starShoeLeft {
    0%   { transform: translateY(0) translateX(0); }
    30%  { transform: translateY(-2px) translateX(-5px); }
    60%  { transform: translateY(-2px) translateX(-5px); }
    100% { transform: translateY(0) translateX(0); }
}
@keyframes starShoeRight {
    0%   { transform: translateY(0) translateX(0); }
    30%  { transform: translateY(-2px) translateX(5px); }
    60%  { transform: translateY(-2px) translateX(5px); }
    100% { transform: translateY(0) translateX(0); }
}
@keyframes starJumpBounce {
    0%   { transform: translateY(0); }
    30%  { transform: translateY(-15px); }
    60%  { transform: translateY(-12px); }
    100% { transform: translateY(0); }
}
.walking-left.star-jump {
    animation: starJumpBounceFlip 0.4s ease-out !important;
}
@keyframes starJumpBounceFlip {
    0%   { transform: scaleX(-1) translateY(0); }
    30%  { transform: scaleX(-1) translateY(-15px); }
    60%  { transform: scaleX(-1) translateY(-12px); }
    100% { transform: scaleX(-1) translateY(0); }
}

/* ========== GAME UI ========== */

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 30;
    pointer-events: none;
}
#hud-score {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.5);
}
#hud-lives {
    font-size: 1.3rem;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.3);
}
#hud.hidden { display: none; }

/* Collectible items */
#collectibles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 11;
}
.collectible {
    position: absolute;
    font-size: 28px;
    line-height: 1;
    will-change: transform;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
    transition: none;
}
.collectible.collected {
    transition: transform 0.25s ease-out, opacity 0.25s ease-out;
    transform: scale(1.6) translateY(-20px) !important;
    opacity: 0 !important;
}

/* Overlay screens */
#start-screen,
#gameover-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
#start-screen.hidden,
#gameover-screen.hidden {
    display: none;
}
.overlay-box {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 20px;
    padding: 28px 32px;
    text-align: center;
    max-width: 340px;
    width: 88%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.overlay-box h1 {
    font-size: 1.7rem;
    color: #003399;
    margin-bottom: 6px;
    font-weight: 800;
}
.overlay-box .tagline {
    font-size: 1rem;
    color: #666;
    margin-bottom: 16px;
}
.overlay-box .instructions {
    margin-bottom: 20px;
    font-size: 0.95rem;
    color: #444;
    line-height: 1.5;
}
.overlay-box .controls-hint {
    font-size: 0.82rem;
    color: #888;
    margin-top: 6px;
}
.overlay-box .final-score {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e84393;
    margin: 12px 0 20px;
}

#start-btn,
#restart-btn {
    background: #e84393;
    color: #fff;
    border: none;
    padding: 14px 40px;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(232, 67, 147, 0.4);
    transition: transform 0.15s, box-shadow 0.15s;
}
#start-btn:active,
#restart-btn:active {
    transform: scale(0.95);
}

/* Show desktop/mobile hints appropriately */
.desktop-hint { display: none; }
.mobile-hint { display: block; }
@media (hover: hover) and (pointer: fine) {
    .desktop-hint { display: block; }
    .mobile-hint { display: none; }
}

/* Touch controls */
#touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 12px;
    padding: 0 12px 14px;
    z-index: 30;
    pointer-events: none;
}
#touch-controls.hidden {
    display: none;
}
#touch-controls button {
    pointer-events: auto;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-size: 24px;
    color: #003399;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
#touch-controls button:active,
#touch-controls button.pressed {
    background: rgba(232, 67, 147, 0.5);
    border-color: #e84393;
    transform: scale(0.92);
}
#btn-jump {
    width: 76px;
    height: 76px;
    font-size: 28px;
    margin-bottom: 4px;
}

/* Music button */
#music-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.85);
    font-size: 22px;
    cursor: pointer;
    z-index: 31;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: transform 0.15s;
}
#music-btn:active {
    transform: scale(0.92);
}
#music-btn.muted {
    opacity: 0.5;
}

/* When touch controls visible, move music button up */
#scene:has(#touch-controls:not(.hidden)) #music-btn {
    bottom: 96px;
}
/* Fallback for browsers without :has() — JS adds this class */
#music-btn.controls-visible {
    bottom: 96px;
}

/* Hit flash — uses filter so it doesn't conflict with animation property */
#mali.hit-flash {
    filter: brightness(2) saturate(0.3);
}

/* Invincibility blink — uses opacity so bounce animation continues */
#mali.invincible {
    animation: invBlink 0.3s linear infinite, bounce 0.25s ease-in-out infinite alternate !important;
}
#mali.invincible.walking-left {
    animation: invBlink 0.3s linear infinite, bounceFlip 0.25s ease-in-out infinite alternate !important;
}
@keyframes invBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.3; }
}

/* Desktop adjustments */
@media (min-width: 600px) {
    #mali {
        width: 80px;
        height: 120px;
    }
    #castle { width: 260px; height: 140px; }
    #bagpiper { width: 65px; height: 104px; }
    #flag-pole { height: 90px; }
    #flag { width: 52px; height: 34px; }
    .flag-cross::before, .flag-cross::after { height: 4px; }
    .overlay-box h1 { font-size: 2rem; }
    #hud-score { font-size: 1.4rem; }
    #hud-lives { font-size: 1.5rem; }
    .collectible { font-size: 32px; }
}

/* Hide touch controls on devices with fine pointer (desktop) */
@media (hover: hover) and (pointer: fine) {
    #touch-controls { display: none !important; }
}
