/* ==========================================================================
   Screen Puzzle Challenge - Child-Friendly 3D Cartoon Stylesheet
   Designed for Grade 1 Students (Ages 5-7) & School Computer Labs
   ========================================================================== */

:root {
    --primary-blue: #0288D1;
    --primary-blue-dark: #01579B;
    --accent-yellow: #FFCA28;
    --accent-yellow-dark: #FFA000;
    --accent-green: #00E676;
    --accent-green-dark: #00C853;
    --accent-pink: #FF4081;
    --accent-pink-dark: #C2185B;
    --accent-purple: #7C4DFF;
    --accent-purple-dark: #512DA8;
    --accent-orange: #FF7043;
    --accent-orange-dark: #E64A19;
    
    --bg-gradient: linear-gradient(135deg, #4FC3F7 0%, #7E57C2 50%, #FF80AB 100%);
    --card-bg: rgba(255, 255, 255, 0.95);
    
    --font-kids: 'Fredoka', 'Quicksand', 'Nunito', 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-kids);
    background: var(--bg-gradient);
    color: #2c3e50;
    position: relative;
}

/* Background animated decorative elements & moving child-friendly cartoon actors */
.bg-decor {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bg-actor {
    position: absolute;
    pointer-events: none;
    will-change: transform;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.16));
}

/* 1. Smiling Sun in Upper Corner */
.bg-cartoon-sun {
    top: 20px;
    right: 35px;
    width: 110px;
    height: 110px;
    animation: sunBob 4s ease-in-out infinite;
    z-index: 1;
}

.sun-rays {
    transform-origin: 50px 50px;
    animation: spinRays 28s linear infinite;
}

@keyframes sunBob {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.05); }
}

@keyframes spinRays {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 2. Zooming Cartoon Rocket */
.bg-cartoon-rocket {
    width: 105px;
    height: 65px;
    animation: flyRocket 25s linear infinite;
}

.rocket-flame {
    animation: pulseFlame 0.25s ease-in-out infinite alternate;
}

@keyframes flyRocket {
    0% {
        transform: translate(-140px, 85vh) rotate(-28deg);
        opacity: 0;
    }
    5% { opacity: 1; }
    95% { opacity: 1; }
    100% {
        transform: translate(115vw, -120px) rotate(-28deg);
        opacity: 0;
    }
}

@keyframes pulseFlame {
    0% { transform: scaleX(0.85); fill: #FFEB3B; }
    100% { transform: scaleX(1.35); fill: #FF1744; }
}

/* 3. Drifting Hot Air Balloon */
.bg-cartoon-balloon {
    width: 85px;
    height: 115px;
    animation: floatBalloon 36s linear infinite;
    animation-delay: -14s;
}

@keyframes floatBalloon {
    0% {
        transform: translate(-120px, 42vh) rotate(-3deg);
        opacity: 0;
    }
    4% { opacity: 0.95; }
    50% { transform: translate(50vw, 32vh) rotate(3deg); }
    96% { opacity: 0.95; }
    100% {
        transform: translate(115vw, 24vh) rotate(-3deg);
        opacity: 0;
    }
}

/* 4. Flying Mini-Robot Drone */
.bg-cartoon-robot {
    width: 80px;
    height: 80px;
    animation: flyDrone 28s ease-in-out infinite;
    animation-delay: -8s;
}

.rotor-blade {
    transform-origin: 45px 18px;
    animation: spinRotor 0.1s linear infinite;
}

@keyframes flyDrone {
    0% {
        transform: translate(-110px, 68vh) translateY(0);
        opacity: 0;
    }
    5% { opacity: 0.95; }
    25% { transform: translate(25vw, 62vh) translateY(-14px); }
    50% { transform: translate(55vw, 70vh) translateY(10px); }
    75% { transform: translate(85vw, 60vh) translateY(-12px); }
    95% { opacity: 0.95; }
    100% {
        transform: translate(115vw, 65vh) translateY(0);
        opacity: 0;
    }
}

@keyframes spinRotor {
    0% { transform: scaleX(1); }
    50% { transform: scaleX(0.1); }
    100% { transform: scaleX(1); }
}

/* 5. Floating Computer Mouse on a Balloon */
.bg-cartoon-mouse {
    width: 65px;
    height: 110px;
    animation: driftMouseBalloon 33s ease-in-out infinite;
    animation-delay: -19s;
}

@keyframes driftMouseBalloon {
    0% {
        transform: translate(-100px, 78vh) rotate(-4deg);
        opacity: 0;
    }
    5% { opacity: 0.9; }
    50% { transform: translate(50vw, 72vh) rotate(4deg); }
    95% { opacity: 0.9; }
    100% {
        transform: translate(115vw, 76vh) rotate(-4deg);
        opacity: 0;
    }
}

/* 6. Fluttering Butterflies */
.bg-cartoon-butterfly {
    width: 55px;
    height: 45px;
}

.bg-cartoon-butterfly.b1 {
    animation: flutterFlight1 22s ease-in-out infinite;
    animation-delay: -5s;
}

.bg-cartoon-butterfly.b2 {
    animation: flutterFlight2 27s ease-in-out infinite;
    animation-delay: -16s;
}

.b-wing-l {
    transform-origin: 30px 25px;
    animation: flapWingL 0.22s ease-in-out infinite alternate;
}

.b-wing-r {
    transform-origin: 30px 25px;
    animation: flapWingR 0.22s ease-in-out infinite alternate;
}

@keyframes flapWingL {
    0% { transform: scaleX(1) rotate(0deg); }
    100% { transform: scaleX(0.2) rotate(20deg); }
}

@keyframes flapWingR {
    0% { transform: scaleX(1) rotate(0deg); }
    100% { transform: scaleX(0.2) rotate(-20deg); }
}

@keyframes flutterFlight1 {
    0% {
        transform: translate(-80px, 30vh) rotate(5deg);
        opacity: 0;
    }
    5% { opacity: 0.95; }
    25% { transform: translate(25vw, 20vh) rotate(-8deg); }
    50% { transform: translate(55vw, 35vh) rotate(10deg); }
    75% { transform: translate(85vw, 18vh) rotate(-5deg); }
    95% { opacity: 0.95; }
    100% {
        transform: translate(115vw, 28vh) rotate(5deg);
        opacity: 0;
    }
}

@keyframes flutterFlight2 {
    0% {
        transform: translate(-80px, 75vh) rotate(-6deg);
        opacity: 0;
    }
    5% { opacity: 0.9; }
    30% { transform: translate(30vw, 62vh) rotate(8deg); }
    60% { transform: translate(65vw, 78vh) rotate(-10deg); }
    85% { transform: translate(90vw, 64vh) rotate(6deg); }
    95% { opacity: 0.9; }
    100% {
        transform: translate(115vw, 72vh) rotate(-6deg);
        opacity: 0;
    }
}

/* 7. Smiling Cartoon Clouds */
.bg-cartoon-cloud {
    width: 175px;
    height: 100px;
}

.bg-cartoon-cloud.c-top {
    top: 6%;
    animation: driftCloud 38s linear infinite;
    animation-delay: -6s;
}

.bg-cartoon-cloud.c-mid {
    top: 45%;
    animation: driftCloud 50s linear infinite;
    animation-delay: -24s;
}

.bg-cartoon-cloud.c-bot {
    top: 78%;
    animation: driftCloud 44s linear infinite;
    animation-delay: -12s;
}

@keyframes driftCloud {
    0% { transform: translateX(-240px); }
    100% { transform: translateX(115vw); }
}

/* 8. Smiling Star Friends */
.bg-cartoon-star {
    width: 48px;
    height: 48px;
    animation: swayStar 4s ease-in-out infinite;
}

.bg-cartoon-star.s1 {
    top: 18%;
    left: 20%;
    animation-delay: -1s;
}

.bg-cartoon-star.s2 {
    top: 66%;
    right: 24%;
    animation-delay: -2.8s;
}

.bg-cartoon-star.s3 {
    top: 84%;
    left: 9%;
    animation-delay: -0.7s;
}

@keyframes swayStar {
    0%, 100% { transform: translateY(0) rotate(-6deg) scale(0.95); opacity: 0.8; }
    50% { transform: translateY(-12px) rotate(6deg) scale(1.15); opacity: 1; }
}

/* 9. Smiling Planet with Rings */
.bg-cartoon-planet {
    width: 90px;
    height: 70px;
    animation: floatPlanet 45s linear infinite;
    animation-delay: -30s;
}

@keyframes floatPlanet {
    0% {
        transform: translate(-120px, 15vh) rotate(0deg);
        opacity: 0;
    }
    5% { opacity: 0.85; }
    95% { opacity: 0.85; }
    100% {
        transform: translate(115vw, 15vh) rotate(15deg);
        opacity: 0;
    }
}

/* App Container */
#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    z-index: 1;
}

/* Screen Transitions */
.game-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: scale(0.98);
}

.game-screen.active {
    display: flex;
    opacity: 1;
    transform: scale(1);
}

/* ==========================================================================
   3D Tactile Buttons
   ========================================================================== */
.btn-3d {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-family: var(--font-kids);
    font-size: 1.4rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #FFFFFF;
    border: none;
    border-radius: 30px;
    padding: 14px 28px;
    cursor: pointer;
    outline: none;
    position: relative;
    transition: all 0.15s ease-out;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.25);
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
}

.btn-3d:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.btn-3d:active {
    transform: translateY(6px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.2);
}

.btn-green {
    background: linear-gradient(to bottom, #00E676, #00C853);
    border-bottom: 5px solid #009624;
}

.btn-yellow {
    background: linear-gradient(to bottom, #FFD54F, #FFB300);
    border-bottom: 5px solid #FF8F00;
    color: #4E342E;
    text-shadow: none;
}

.btn-blue {
    background: linear-gradient(to bottom, #29B6F6, #0288D1);
    border-bottom: 5px solid #01579B;
}

.btn-purple {
    background: linear-gradient(to bottom, #B388FF, #7C4DFF);
    border-bottom: 5px solid #512DA8;
}

.btn-pink {
    background: linear-gradient(to bottom, #FF80AB, #FF4081);
    border-bottom: 5px solid #C2185B;
}

.btn-orange {
    background: linear-gradient(to bottom, #FFAB91, #FF7043);
    border-bottom: 5px solid #D84315;
}

.btn-large {
    font-size: 1.8rem;
    padding: 18px 45px;
    border-radius: 36px;
}

.btn-icon-only {
    width: 58px;
    height: 58px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.6rem;
}

.pulse-glow {
    animation: pulseButton 2s infinite;
}

@keyframes pulseButton {
    0%, 100% { transform: scale(1); box-shadow: 0 8px 0 rgba(0,0,0,0.2), 0 0 20px rgba(0, 230, 118, 0.6); }
    50% { transform: scale(1.05); box-shadow: 0 8px 0 rgba(0,0,0,0.2), 0 0 35px rgba(0, 230, 118, 0.9); }
}

/* ==========================================================================
   Home Screen
   ========================================================================== */
#screen-home {
    justify-content: space-around;
    padding: clamp(10px, 2vh, 24px) clamp(16px, 3vw, 30px);
}

.top-bar-controls {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    z-index: 10;
}

.home-header {
    text-align: center;
    margin-top: 0;
}

.game-title {
    font-size: clamp(1.8rem, 4.6vh, 3.2rem);
    line-height: 1.15;
    font-weight: 900;
    color: #FFF;
    text-shadow: 
        0 4px 0 #0288D1,
        0 8px 0 #01579B,
        0 12px 18px rgba(0, 0, 0, 0.4);
    letter-spacing: 2px;
    animation: titleBob 3s ease-in-out infinite;
    display: inline-block;
}

.game-title span {
    display: inline-block;
    transition: transform 0.2s;
}

.game-title span:hover {
    transform: scale(1.2) rotate(5deg);
}

@keyframes titleBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Mascot & Center Area */
.home-center-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(18px, 3.5vw, 40px);
    max-width: 950px;
    width: 100%;
}

.mascot-container {
    width: clamp(130px, 25vh, 230px);
    height: clamp(130px, 25vh, 230px);
    position: relative;
    animation: mascotFloat 4s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes mascotFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-12px) rotate(2deg); }
}

.mascot-container svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.3));
}

.home-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.4vh, 16px);
    min-width: clamp(220px, 24vw, 280px);
}

/* ==========================================================================
   Level Selection Screen
   ========================================================================== */
#screen-levels {
    justify-content: flex-start;
    gap: clamp(8px, 1.5vh, 16px);
    padding: clamp(10px, 1.8vh, 18px);
}

.screen-title-banner {
    background: #FFF;
    border-radius: 24px;
    padding: clamp(4px, 0.8vh, 8px) clamp(20px, 3vw, 36px);
    border: 3.5px solid #FFD54F;
    box-shadow: 0 6px 16px rgba(0,0,0,0.18);
    text-align: center;
}

.screen-title-banner h2 {
    font-size: clamp(1.3rem, 2.6vh, 2rem);
    font-weight: 900;
    color: #311B92;
}

.levels-grid {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: clamp(12px, 1.8vw, 24px);
    max-width: 1100px;
    width: 100%;
    margin-top: clamp(4px, 0.8vh, 12px);
    max-height: calc(100vh - 100px);
}

.level-card {
    flex: 1;
    background: var(--card-bg);
    border-radius: 24px;
    padding: clamp(10px, 1.6vh, 18px) clamp(10px, 1.4vw, 16px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
    border: 5px solid #B3E5FC;
    transition: transform 0.25s, box-shadow 0.25s;
    position: relative;
    max-width: 320px;
    cursor: pointer;
}

.level-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 16px 28px rgba(0, 0, 0, 0.26);
}

.level-card.level-1 { border-color: #81C784; }
.level-card.level-2 { border-color: #FFB74D; }
.level-card.level-3 { border-color: #BA68C8; }

.level-badge {
    border-radius: 16px;
    padding: 3px 14px;
    font-size: clamp(0.95rem, 1.6vh, 1.15rem);
    font-weight: 900;
    color: #FFF;
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
    margin-bottom: clamp(4px, 0.8vh, 8px);
}

.level-1 .level-badge { background: #4CAF50; }
.level-2 .level-badge { background: #FF9800; }
.level-3 .level-badge { background: #9C27B0; }

.level-title {
    font-size: clamp(1.15rem, 2vh, 1.45rem);
    font-weight: 900;
    color: #263238;
    margin-bottom: 2px;
    text-align: center;
}

.level-desc {
    font-size: clamp(0.85rem, 1.5vh, 1rem);
    font-weight: 700;
    color: #546E7A;
    text-align: center;
    margin-bottom: clamp(4px, 0.8vh, 8px);
}

.level-icon-preview {
    width: clamp(70px, 12vh, 110px);
    height: clamp(70px, 12vh, 110px);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: clamp(6px, 1vh, 10px);
    border: 3.5px solid #E0E0E0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    background: #FFF;
    display: flex;
    align-items: center;
    justify-content: center;
}

.level-icon-preview svg {
    width: 100%;
    height: 100%;
}

.level-stars-status {
    display: flex;
    gap: 4px;
    font-size: clamp(1.1rem, 1.8vh, 1.45rem);
    color: #FFD54F;
    margin-bottom: clamp(6px, 1vh, 12px);
    font-weight: 800;
}

/* ==========================================================================
   Preview Screen (Look at the picture before solving)
   ========================================================================== */
#screen-preview {
    justify-content: center;
    gap: 16px;
    padding: clamp(10px, 1.5vh, 18px);
}

.preview-box {
    background: var(--card-bg);
    border-radius: 26px;
    padding: clamp(12px, 2vh, 20px) clamp(16px, 2.5vw, 28px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
    border: 5px solid #FFD54F;
    max-width: 520px;
    width: 100%;
    max-height: 94vh;
}

.preview-title {
    font-size: clamp(1.3rem, 2.5vh, 1.8rem);
    font-weight: 900;
    color: #311B92;
    margin-bottom: 2px;
    text-align: center;
}

.preview-prompt {
    font-size: clamp(0.95rem, 1.8vh, 1.15rem);
    font-weight: 800;
    color: #00897B;
    margin-bottom: clamp(6px, 1vh, 10px);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-image-wrap {
    width: min(30vh, 240px);
    height: min(30vh, 240px);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
    border: 3.5px solid #FFF;
    margin-bottom: clamp(8px, 1.5vh, 14px);
    background: #FFF;
}

.preview-image-wrap svg {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Main Game Playing Screen
   ========================================================================== */
#screen-game {
    padding: clamp(6px, 1vh, 12px) clamp(10px, 1.8vw, 20px);
    justify-content: flex-start;
}

.game-nav-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: clamp(4px, 0.8vh, 8px) clamp(10px, 1.4vw, 18px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
    border: 3px solid #81D4FA;
    margin-bottom: clamp(6px, 1vh, 10px);
    gap: 8px;
    flex-wrap: wrap;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: clamp(6px, 0.9vw, 10px);
}

.nav-center-info {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 12px);
}

.puzzle-title-tag {
    font-size: clamp(1rem, 1.8vh, 1.25rem);
    font-weight: 900;
    color: #283593;
    background: #E8EAF6;
    padding: 4px 14px;
    border-radius: 14px;
    border: 2px solid #C5CAE9;
    white-space: nowrap;
}

.level-tag {
    font-size: clamp(0.95rem, 1.6vh, 1.1rem);
    font-weight: 800;
    color: #FFF;
    background: #4CAF50;
    padding: 4px 12px;
    border-radius: 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

/* Nav Stats Bar: Timer, Score, Pieces Count */
.nav-stats-bar {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 12px);
}

.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: clamp(4px, 0.8vh, 6px) clamp(8px, 1.2vw, 14px);
    border-radius: 18px;
    font-weight: 800;
    font-size: clamp(0.95rem, 1.7vh, 1.18rem);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    transition: all 0.25s ease;
}

.stat-pill-icon {
    font-size: 1.15em;
    line-height: 1;
}

.stat-pill-val {
    font-weight: 900;
}

.stat-pill-unit {
    font-size: 0.82em;
    opacity: 0.85;
    font-weight: 700;
}

/* 1. Timer Pill */
.stat-timer-pill {
    background: #E0F7FA;
    border: 2.5px solid #00BCD4;
    color: #006064;
}

/* Gentle visual warning when 30 seconds remain (soft amber color change, no distracting flashing) */
.stat-timer-pill.timer-warning {
    background: #FFF3E0;
    border-color: #FF9800;
    color: #E65100;
    box-shadow: 0 0 12px rgba(255, 152, 0, 0.45);
}

/* 2. Score Pill */
.stat-score-pill {
    background: #FFF9C4;
    border: 2.5px solid #FFD54F;
    color: #5D4037;
}

/* 3. Pieces Pill */
.stat-pieces-pill {
    background: #E8F5E9;
    border: 2.5px solid #81C784;
    color: #1B5E20;
}

/* Game Play Area (Side-by-side) */
.play-arena {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(14px, 2.2vw, 28px);
    width: 100%;
    flex: 1;
    position: relative;
    max-height: calc(100vh - 85px);
    padding-bottom: 24px; /* leaves room for right side creator credit */
}

/* Board Frame */
.board-container {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    padding: clamp(8px, 1.3vh, 12px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
    border: 5px solid #00BCD4;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.board-viewport {
    position: relative;
    width: min(calc(100vh - 135px), calc(100vw - 420px), 430px);
    height: min(calc(100vh - 135px), calc(100vw - 420px), 430px);
    border-radius: 16px;
    overflow: hidden;
    background: #ECEFF1;
    box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Ghost background image inside board (opacity depends on level) */
#board-ghost-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.22;
    transition: opacity 0.3s;
}

/* Canvas guide lines overlay */
#board-guide-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* Placed pieces layer on board */
#board-placed-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
}

/* Solved Full Image Overlay (revealed upon victory without seams) */
#board-solved-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: none;
    border-radius: 16px;
    box-shadow: 0 0 30px rgba(0, 230, 118, 0.8);
    animation: solvedPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes solvedPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Side Reference & Piece Tray Area */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.2vh, 12px);
    height: 100%;
    max-height: min(calc(100vh - 135px), calc(100vw - 420px), 430px);
    width: clamp(260px, 28vw, 360px);
    flex-shrink: 0;
}

/* Reference Card */
.reference-card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 18px;
    padding: clamp(6px, 1vh, 10px) clamp(10px, 1.4vw, 14px);
    border: 3.5px solid #FFCA28;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.2vw, 14px);
    flex-shrink: 0;
}

.reference-card .ref-img-box {
    width: clamp(55px, 8.5vh, 75px);
    height: clamp(55px, 8.5vh, 75px);
    border-radius: 12px;
    overflow: hidden;
    border: 2.5px solid #0288D1;
    background: #FFF;
    flex-shrink: 0;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
}

.reference-card .ref-img-box img,
.reference-card .ref-img-box svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.ref-info-box h4 {
    font-size: clamp(0.95rem, 1.7vh, 1.15rem);
    font-weight: 900;
    color: #4527A0;
    margin-bottom: 2px;
}

.ref-info-box p {
    font-size: clamp(0.8rem, 1.4vh, 0.92rem);
    font-weight: 800;
    color: #00897B;
}

/* Piece Tray */
.piece-tray-card {
    flex: 1;
    min-height: 0;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 20px;
    padding: clamp(6px, 1vh, 10px);
    border: 3.5px solid #B388FF;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
}

.tray-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 4px;
    margin-bottom: 4px;
    border-bottom: 2px dashed #D1C4E9;
    flex-shrink: 0;
}

.tray-header span {
    font-size: clamp(0.85rem, 1.5vh, 1rem);
    font-weight: 800;
    color: #5E35B1;
}

.piece-tray-slots {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: clamp(6px, 1vh, 10px);
    align-items: center;
    justify-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
}
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 12px;
    align-items: center;
    justify-items: center;
    overflow-y: auto;
    padding: 6px;
}

/* Individual Puzzle Piece Item in Tray */
.puzzle-piece-item {
    position: relative;
    cursor: grab;
    transition: transform 0.15s ease;
    user-select: none;
    -webkit-user-drag: none;
}

.puzzle-piece-item:hover {
    transform: scale(1.08);
}

.puzzle-piece-item:active {
    cursor: grabbing;
}

.puzzle-piece-item canvas {
    display: block;
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.22));
    transition: filter 0.15s;
}

.puzzle-piece-item.hint-highlight {
    animation: hintWiggle 0.6s ease-in-out infinite;
}

@keyframes hintWiggle {
    0%, 100% { transform: scale(1.1) rotate(0deg); }
    25% { transform: scale(1.15) rotate(-6deg); }
    75% { transform: scale(1.15) rotate(6deg); }
}

/* Active Dragging Piece */
.dragging-piece {
    position: fixed !important;
    pointer-events: none !important;
    z-index: 999999 !important;
    cursor: grabbing !important;
    transform: scale(1.08) translate(-50%, -50%) !important;
    filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.35)) !important;
    transition: none !important;
}

/* Hint Glowing Slot Overlay */
.hint-slot-glow {
    position: absolute;
    pointer-events: none;
    border: 5px solid #FFD54F;
    border-radius: 14px;
    background: rgba(255, 235, 59, 0.35);
    box-shadow: 0 0 25px #FFD54F;
    animation: pulseGlow 1s ease-in-out infinite;
    z-index: 5;
}

@keyframes pulseGlow {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.04); opacity: 1; }
}

/* Hint Arrow pointing to target slot */
.hint-arrow {
    position: absolute;
    font-size: 3rem;
    color: #FF5252;
    z-index: 6;
    animation: bounceArrow 0.8s ease-in-out infinite;
    pointer-events: none;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

@keyframes bounceArrow {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-14px); }
}

/* Sparkle / Star Particle Burst */
.sparkle-particle {
    position: fixed;
    pointer-events: none;
    z-index: 99999;
    font-size: 28px;
    animation: sparkleAnim 0.75s ease-out forwards;
}

@keyframes sparkleAnim {
    0% { transform: translate(0, 0) scale(0.5) rotate(0deg); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(1.4) rotate(var(--rot)); opacity: 0; }
}

/* ==========================================================================
   Modals (How To Play, Win Screen)
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 20, 40, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal-backdrop.active {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: #FFF;
    border-radius: 36px;
    padding: 30px 40px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
    border: 8px solid #FFD54F;
    max-width: 680px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-backdrop.active .modal-card {
    transform: scale(1);
}

/* How to play card */
.how-to-play-card {
    max-width: 760px;
}

.instructions-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin: 24px 0 28px 0;
    width: 100%;
}

.instruction-step {
    background: #F3E5F5;
    border-radius: 20px;
    padding: 18px 12px;
    border: 3px solid #CE93D8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.step-num {
    background: #7B1FA2;
    color: #FFF;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 900;
}

.step-visual {
    font-size: 3rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.instruction-step p {
    font-size: 1rem;
    font-weight: 800;
    color: #4A148C;
}

/* Animated Hand Demo in How To Play */
.demo-animation-box {
    position: relative;
    width: 220px;
    height: 70px;
    background: #FFF;
    border-radius: 12px;
    border: 2px dashed #BA68C8;
    overflow: hidden;
}

.demo-piece {
    position: absolute;
    width: 40px;
    height: 40px;
    background: #00E676;
    border-radius: 8px;
    top: 15px;
    left: 15px;
    animation: demoDragPiece 3.5s infinite;
}

.demo-hand {
    position: absolute;
    font-size: 28px;
    top: 25px;
    left: 25px;
    animation: demoDragHand 3.5s infinite;
}

.demo-slot {
    position: absolute;
    width: 44px;
    height: 44px;
    border: 3px solid #29B6F6;
    border-radius: 10px;
    top: 13px;
    right: 15px;
    background: rgba(41, 182, 246, 0.2);
}

@keyframes demoDragPiece {
    0%, 20% { transform: translateX(0); }
    60%, 80% { transform: translateX(140px); }
    100% { transform: translateX(0); }
}

@keyframes demoDragHand {
    0%, 15% { transform: translateX(0) scale(1); }
    20% { transform: translateX(0) scale(0.9); }
    60%, 80% { transform: translateX(140px) scale(0.9); }
    85%, 100% { transform: translateX(0) scale(1); }
}

/* ==========================================================================
   Win Celebration Modal
   ========================================================================== */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10001;
}

.win-modal-card {
    border-color: #00E676;
    background: linear-gradient(to bottom, #FFFFFF 0%, #E8F5E9 100%);
    padding: clamp(16px, 2.5vh, 28px) clamp(18px, 3.5vw, 36px);
    max-height: 94vh;
    overflow-y: auto;
}

.win-title {
    font-size: clamp(2.2rem, 4.5vh, 3.2rem);
    font-weight: 900;
    color: #2E7D32;
    text-shadow: 0 3px 0 #A5D6A7;
    margin-bottom: 4px;
    animation: bounceTitle 0.6s ease;
}

@keyframes bounceTitle {
    0% { transform: scale(0.5); }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.win-subtitle {
    font-size: clamp(1.1rem, 2vh, 1.45rem);
    font-weight: 800;
    color: #00897B;
    margin-bottom: 12px;
}

.win-stars-display {
    display: flex;
    gap: clamp(10px, 1.5vw, 16px);
    margin-bottom: clamp(10px, 1.8vh, 18px);
}

.win-star {
    font-size: clamp(2.8rem, 5.5vh, 3.8rem);
    color: #CFD8DC;
    transform: scale(0);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), color 0.3s;
}

.win-star.awarded {
    color: #FFD54F;
    transform: scale(1);
    text-shadow: 0 4px 14px rgba(255, 213, 79, 0.7);
    animation: starSpinWin 0.6s ease;
}

@keyframes starSpinWin {
    0% { transform: scale(0) rotate(-180deg); }
    80% { transform: scale(1.3) rotate(20deg); }
    100% { transform: scale(1) rotate(0deg); }
}

/* Detailed Child-Friendly Scoring & Time Results */
.win-stats-container {
    display: flex;
    gap: clamp(8px, 1.5vw, 16px);
    margin-bottom: clamp(12px, 2vh, 20px);
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

.win-stat-badge {
    flex: 1;
    min-width: 105px;
    background: #FFF;
    border: 3px solid #81D4FA;
    border-radius: 18px;
    padding: clamp(6px, 1vh, 10px) clamp(10px, 1.5vw, 16px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.win-stat-label {
    font-size: clamp(0.75rem, 1.3vh, 0.85rem);
    font-weight: 900;
    color: #546E7A;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.win-stat-val-group {
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.win-stat-val {
    font-size: clamp(1.4rem, 2.6vh, 1.85rem);
    font-weight: 900;
    color: #0288D1;
}

.win-stat-unit {
    font-size: clamp(0.85rem, 1.5vh, 1rem);
    font-weight: 800;
    color: #78909C;
}

.win-button-row {
    display: flex;
    gap: clamp(8px, 1.2vw, 16px);
    flex-wrap: wrap;
    justify-content: center;
}

.win-auto-notice {
    margin-top: 10px;
    font-size: clamp(0.85rem, 1.5vh, 1rem);
    font-weight: 800;
    color: #00897B;
    background: #E0F2F1;
    border: 2px solid #80CBC4;
    border-radius: 16px;
    padding: 4px 14px;
    display: inline-block;
    animation: pulseAutoNotice 1.8s infinite;
}

@keyframes pulseAutoNotice {
    0%, 100% { opacity: 0.9; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.03); }
}

/* ==========================================================================
   Modal 3: Time's Up Modal
   ========================================================================== */
.time-up-modal-card {
    border-color: #FF9800;
    background: linear-gradient(to bottom, #FFFFFF 0%, #FFF8E1 100%);
    padding: clamp(16px, 2.8vh, 28px) clamp(20px, 3.5vw, 36px);
    max-height: 94vh;
    overflow-y: auto;
    max-width: 560px;
    width: 100%;
}

.time-up-icon {
    font-size: clamp(2.5rem, 4.8vh, 3.5rem);
    margin-bottom: 4px;
}

.time-up-title {
    font-size: clamp(1.8rem, 3.4vh, 2.4rem);
    font-weight: 900;
    color: #E65100;
    text-shadow: 0 2px 0 #FFE0B2;
    margin-bottom: 4px;
}

.time-up-subtitle {
    font-size: clamp(1.05rem, 1.8vh, 1.25rem);
    font-weight: 800;
    color: #5D4037;
    margin-bottom: 14px;
}

.time-up-stats {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
    width: 100%;
}

.time-up-stats .stat-box {
    background: #FFF;
    border: 3px solid #FFD54F;
    border-radius: 18px;
    padding: clamp(6px, 1vh, 10px) clamp(12px, 2vw, 20px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    min-width: 120px;
}

.time-up-stats .stat-label {
    font-size: clamp(0.72rem, 1.2vh, 0.82rem);
    font-weight: 900;
    color: #795548;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.time-up-stats .stat-num {
    font-size: clamp(1.4rem, 2.6vh, 1.85rem);
    font-weight: 900;
    color: #E65100;
}

.time-up-stats .stat-unit {
    font-size: clamp(0.85rem, 1.5vh, 0.95rem);
    font-weight: 800;
    color: #8D6E63;
    margin-left: 2px;
}

.time-up-button-row {
    display: flex;
    gap: clamp(10px, 1.5vw, 16px);
    justify-content: center;
    flex-wrap: wrap;
}

/* ==========================================================================
   Modal 4: Level Completed Modal
   ========================================================================== */
.level-complete-modal-card {
    border-color: #FFC107;
    background: linear-gradient(to bottom, #FFFFFF 0%, #FFFDE7 100%);
    padding: clamp(16px, 2.8vh, 28px) clamp(20px, 3.5vw, 36px);
    max-height: 94vh;
    overflow-y: auto;
    max-width: 580px;
    width: 100%;
}

.level-complete-trophy {
    font-size: clamp(2.8rem, 5.5vh, 4rem);
    margin-bottom: 4px;
    animation: trophyBob 2s ease-in-out infinite;
}

@keyframes trophyBob {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.08); }
}

.level-complete-title {
    font-size: clamp(1.8rem, 3.4vh, 2.4rem);
    font-weight: 900;
    color: #E65100;
    text-shadow: 0 2px 0 #FFE082;
    margin-bottom: 4px;
}

.level-complete-subtitle {
    font-size: clamp(1.05rem, 1.8vh, 1.25rem);
    font-weight: 800;
    color: #5D4037;
    margin-bottom: 14px;
}

.level-complete-stars-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #FFF9C4;
    border: 3px solid #FBC02D;
    border-radius: 20px;
    padding: 6px 20px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(251, 192, 45, 0.25);
}

.lc-star-icon {
    font-size: 1.6rem;
}

.lc-stars-count {
    font-size: clamp(1.25rem, 2.4vh, 1.7rem);
    font-weight: 900;
    color: #E65100;
}

.level-complete-stats-grid {
    display: flex;
    gap: 14px;
    margin-bottom: 20px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

.lc-stat-card {
    flex: 1;
    min-width: 120px;
    background: #FFF;
    border: 3px solid #81D4FA;
    border-radius: 18px;
    padding: clamp(6px, 1vh, 10px) clamp(10px, 1.5vw, 16px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.lc-stat-label {
    font-size: clamp(0.72rem, 1.2vh, 0.82rem);
    font-weight: 900;
    color: #546E7A;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.lc-stat-val-group {
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.lc-stat-val {
    font-size: clamp(1.4rem, 2.6vh, 1.85rem);
    font-weight: 900;
    color: #0288D1;
}

.lc-stat-unit {
    font-size: clamp(0.85rem, 1.5vh, 0.95rem);
    font-weight: 800;
    color: #78909C;
}

.level-complete-button-row {
    display: flex;
    gap: clamp(10px, 1.5vw, 16px);
    justify-content: center;
    flex-wrap: wrap;
}

/* ==========================================================================
   Creator Credit Badge (Right side across game screens)
   ========================================================================== */
.creator-credit {
    position: fixed;
    right: 20px;
    bottom: 8px;
    z-index: 10002;
    font-family: var(--font-kids);
    font-size: 0.95rem;
    font-weight: 800;
    color: #4A148C;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 16px;
    border-radius: 20px;
    border: 2.5px solid #BA68C8;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
    letter-spacing: 0.4px;
    pointer-events: none;
    white-space: nowrap;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: all 0.2s ease;
}

/* ==========================================================================
   Responsive Adaptations for Common School Lab Monitors (1024x768, 1280x720, 1366x768)
   ========================================================================== */
@media (max-width: 1100px) {
    .play-arena {
        gap: 16px;
    }
    .game-title {
        font-size: clamp(2rem, 4.2vw, 2.8rem);
    }
    .instructions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .creator-credit {
        font-size: 0.85rem;
        padding: 5px 12px;
        right: 14px;
        bottom: 6px;
    }
}

@media (max-height: 720px) {
    .mascot-container {
        width: clamp(130px, 24vh, 180px);
        height: clamp(130px, 24vh, 180px);
    }
    .game-title {
        font-size: clamp(1.8rem, 4vh, 2.4rem);
    }
    .btn-3d {
        padding: clamp(6px, 1.2vh, 10px) clamp(12px, 1.8vw, 20px);
        font-size: clamp(0.95rem, 1.6vh, 1.15rem);
    }
    .btn-large {
        padding: clamp(8px, 1.5vh, 12px) clamp(16px, 2.2vw, 28px);
        font-size: clamp(1.1rem, 1.9vh, 1.35rem);
    }
    .creator-credit {
        font-size: 0.8rem;
        padding: 4px 10px;
        right: 10px;
        bottom: 4px;
    }
}
