/* ============================================
   SAVE THE PRINCESS - Illustrated Style!
   A fairy tale garden maze with scenic background
   ============================================ */

:root {
    /* Sky colors */
    --sky-top: #64b5f6;
    --sky-mid: #90caf9;
    --sky-bottom: #bbdefb;

    /* Hedge / wall - thick 3D green tubes */
    --hedge-top: #8bc34a;
    --hedge-mid: #689f38;
    --hedge-dark: #33691e;
    --hedge-shadow: #1b5e20;
    --hedge-highlight: #aed581;

    /* Path - semi-transparent so background shows */
    --path-tint: rgba(255, 253, 231, 0.35);
    --path-visited: rgba(165, 214, 167, 0.45);

    /* Characters */
    --prince-blue: #1565c0;
    --prince-cape: #1976d2;
    --prince-glow: rgba(21, 101, 192, 0.5);
    --princess-pink: #d81b60;
    --princess-dress: #f06292;

    /* Traps */
    --fire-orange: #ff6d00;
    --fire-red: #d84315;
    --fire-glow: rgba(255, 109, 0, 0.6);

    /* Prison tower */
    --tower-stone: #90a4ae;
    --tower-dark: #607d8b;
    --tower-bars: #37474f;

    /* Key */
    --key-gold: #ffc107;
    --key-glow: rgba(255, 193, 7, 0.6);

    /* UI */
    --heart-red: #e53935;
    --star-gold: #ffc107;
    --text-dark: #3e2723;
    --text-mid: #5d4037;

    /* Cell size */
    --cell-size: 48px;
}

/* ====== RESET ====== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
    font-family: 'Nunito', sans-serif;
    color: var(--text-dark);
    /* The sky! */
    background: linear-gradient(180deg,
        #4fc3f7 0%,
        #81d4fa 25%,
        #b3e5fc 50%,
        #e1f5fe 75%,
        #e8f5e9 100%
    );
    -webkit-user-select: none;
    user-select: none;
}

.material-symbols-rounded {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

/* ============================================
   SCENIC BACKGROUND - Fairy Tale Kingdom!
   All pure CSS, no images.
   ============================================ */
.scene {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

/* ====== SUN ====== */
.sun {
    position: absolute;
    top: 25px;
    right: 60px;
    width: 70px;
    height: 70px;
    background: radial-gradient(circle,
        #fff9c4 0%,
        #fff176 25%,
        #ffee58 50%,
        #fdd835 75%,
        transparent 76%
    );
    border-radius: 50%;
    animation: sunGlow 4s ease-in-out infinite;
}

.sun-rays {
    position: absolute;
    inset: -30px;
    background: radial-gradient(circle,
        rgba(255, 249, 196, 0.3) 0%,
        rgba(255, 241, 118, 0.15) 40%,
        transparent 70%
    );
    border-radius: 50%;
    animation: raysRotate 10s linear infinite;
}

@keyframes sunGlow {
    0%, 100% { filter: brightness(1); transform: scale(1); }
    50% { filter: brightness(1.15); transform: scale(1.05); }
}

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

/* ====== CASTLE SILHOUETTE ====== */
.castle-bg {
    position: absolute;
    bottom: 38%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: 0;
    opacity: 0.2;
    z-index: 0;
}

.castle-tower {
    background: linear-gradient(to bottom, #78909c, #90a4ae);
    border-radius: 4px 4px 0 0;
    position: relative;
}

/* Tower tops (merlons/battlements) */
.castle-tower::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 12px solid #78909c;
}

.castle-tower-left {
    width: 22px;
    height: 70px;
}

.castle-tower-center {
    width: 28px;
    height: 95px;
}

.castle-tower-right {
    width: 22px;
    height: 60px;
}

/* Flags on the center tower */
.castle-tower-center::after {
    content: '';
    position: absolute;
    top: -18px;
    left: 50%;
    width: 12px;
    height: 8px;
    background: #ef5350;
    border-radius: 0 2px 2px 0;
    transform-origin: left;
    animation: flagWave 2s ease-in-out infinite;
}

@keyframes flagWave {
    0%, 100% { transform: skewY(0deg); }
    50% { transform: skewY(-5deg); }
}

.castle-wall {
    width: 35px;
    height: 40px;
    background: linear-gradient(to bottom, #90a4ae, #78909c);
    position: relative;
}

/* Battlement pattern on walls */
.castle-wall::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 0;
    right: 0;
    height: 6px;
    background: repeating-linear-gradient(
        to right,
        #90a4ae 0px, #90a4ae 6px,
        transparent 6px, transparent 10px
    );
}

/* ====== ROLLING HILLS ====== */
.hill {
    position: absolute;
    border-radius: 50%;
}

/* Far hills - smaller, lighter, higher */
.hill-far-1 {
    width: 500px;
    height: 150px;
    background: linear-gradient(to bottom, #a5d6a7, #81c784);
    bottom: 30%;
    left: -50px;
    opacity: 0.5;
}

.hill-far-2 {
    width: 450px;
    height: 130px;
    background: linear-gradient(to bottom, #a5d6a7, #81c784);
    bottom: 32%;
    right: -80px;
    opacity: 0.45;
}

/* Mid hills - medium, medium green */
.hill-mid-1 {
    width: 600px;
    height: 180px;
    background: linear-gradient(to bottom, #81c784, #66bb6a);
    bottom: 22%;
    left: -100px;
    opacity: 0.6;
}

.hill-mid-2 {
    width: 550px;
    height: 160px;
    background: linear-gradient(to bottom, #81c784, #66bb6a);
    bottom: 20%;
    right: -60px;
    opacity: 0.55;
}

/* Near hills - large, darker green, lower */
.hill-near-1 {
    width: 800px;
    height: 200px;
    background: linear-gradient(to bottom, #66bb6a, #4caf50);
    bottom: 8%;
    left: -150px;
    opacity: 0.7;
}

.hill-near-2 {
    width: 700px;
    height: 180px;
    background: linear-gradient(to bottom, #66bb6a, #43a047);
    bottom: 5%;
    right: -100px;
    opacity: 0.65;
}

/* ====== FOREGROUND GRASS ====== */
.grass-ground {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 15%;
    background: linear-gradient(to bottom, #4caf50, #388e3c);
    /* Wavy top edge */
    border-radius: 100% 100% 0 0 / 20px 20px 0 0;
}

/* Grass texture dots */
.grass-ground::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 10% 20%, rgba(102, 187, 106, 0.8) 2px, transparent 3px),
        radial-gradient(ellipse at 25% 60%, rgba(129, 199, 132, 0.6) 2px, transparent 3px),
        radial-gradient(ellipse at 45% 30%, rgba(76, 175, 80, 0.7) 1.5px, transparent 2px),
        radial-gradient(ellipse at 60% 70%, rgba(102, 187, 106, 0.5) 2px, transparent 3px),
        radial-gradient(ellipse at 80% 40%, rgba(129, 199, 132, 0.6) 1.5px, transparent 2px),
        radial-gradient(ellipse at 90% 15%, rgba(76, 175, 80, 0.7) 2px, transparent 3px);
}

/* ====== FLOATING CLOUDS ====== */
.cloud {
    position: absolute;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 50px;
    pointer-events: none;
    animation: cloudDrift var(--speed) linear infinite;
}

.cloud::before,
.cloud::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
}

.cloud::before {
    width: 65%;
    height: 130%;
    top: -55%;
    left: 18%;
}

.cloud::after {
    width: 45%;
    height: 110%;
    top: -35%;
    left: 55%;
}

@keyframes cloudDrift {
    from { transform: translateX(calc(100vw + 150px)); }
    to { transform: translateX(-250px); }
}

/* ====== FLOATING LEAVES ====== */
.floating-leaf {
    position: fixed;
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
    animation: leafFall var(--duration) linear infinite;
}

.floating-leaf .material-symbols-rounded {
    font-size: 18px;
    animation: leafTumble var(--spin) linear infinite;
}

@keyframes leafFall {
    0% { transform: translate(0, -30px); opacity: 0; }
    10% { opacity: 0.5; }
    90% { opacity: 0.4; }
    100% { transform: translate(var(--drift), calc(100vh + 30px)); opacity: 0; }
}

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

/* ====== BUTTERFLIES ====== */
.butterfly {
    position: fixed;
    pointer-events: none;
    z-index: 1;
    animation: bfPath var(--duration) ease-in-out infinite;
}

.butterfly .material-symbols-rounded {
    font-size: 20px;
    animation: bfWings 0.25s ease-in-out infinite alternate;
    opacity: 0.6;
}

@keyframes bfPath {
    0% { transform: translate(0, 0); }
    25% { transform: translate(var(--bx1), var(--by1)); }
    50% { transform: translate(var(--bx2), var(--by2)); }
    75% { transform: translate(var(--bx3), var(--by3)); }
    100% { transform: translate(0, 0); }
}

@keyframes bfWings {
    from { transform: scaleX(1); }
    to { transform: scaleX(0.2); }
}

/* ============================================
   GAME CONTAINER
   ============================================ */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    padding: 8px;
    position: relative;
    z-index: 2;
}

/* ====== HUD ====== */
#hud {
    width: 100%;
    max-width: 800px;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
    z-index: 5;
}

.back-btn {
    position: absolute;
    left: 8px;
    top: 8px;
    color: var(--text-mid);
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: background 0.2s;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.95);
}

.hud-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-title h1 {
    font-family: 'Fredoka One', cursive;
    font-size: 1.4em;
    color: #fff;
    text-shadow:
        0 2px 4px rgba(0, 0, 0, 0.2),
        0 0 20px rgba(255, 255, 255, 0.3);
}

.hud-icon {
    font-size: 30px !important;
    color: var(--princess-dress);
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
}

.hud-stats {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    padding: 6px 20px;
    border-radius: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.95em;
    font-weight: 700;
    color: var(--text-mid);
}

#lives-display .material-symbols-rounded {
    font-size: 22px;
    color: var(--heart-red);
    transition: transform 0.3s, opacity 0.3s;
}

#lives-display .heart-lost {
    color: #ccc;
    opacity: 0.3;
    transform: scale(0.8);
}

#key-indicator .material-symbols-rounded {
    font-size: 22px;
    color: var(--key-gold);
}

#key-indicator.has-key .material-symbols-rounded {
    animation: keyBounce 0.5s;
}

@keyframes keyBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.4) rotate(20deg); }
}

/* ====== MAZE AREA ====== */
#maze-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    overflow: hidden;
    z-index: 3;
}

/* ====== MAZE GRID ====== */
#maze-grid {
    display: grid;
    gap: 0;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    /* Soft shadow to lift maze off the background */
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ====== CELLS ====== */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.3s;
}

/* ============================================
   WALL CELLS - Thick 3D illustrated hedges!
   These look like the puffy rounded tubes
   in the reference image. Heavy shadows and
   highlights give a cartoon 3D look.
   ============================================ */
.cell-wall {
    background: linear-gradient(
        160deg,
        var(--hedge-highlight) 0%,
        var(--hedge-top) 20%,
        var(--hedge-mid) 50%,
        var(--hedge-dark) 85%,
        var(--hedge-shadow) 100%
    );
    /* Multiple inset shadows create the puffy 3D tube effect */
    box-shadow:
        inset 0 5px 8px rgba(255, 255, 255, 0.35),
        inset 0 -5px 8px rgba(0, 0, 0, 0.3),
        inset 5px 0 8px rgba(255, 255, 255, 0.15),
        inset -5px 0 8px rgba(0, 0, 0, 0.2);
}

/* Leaf/foliage texture dots on the hedge */
.cell-wall::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 15% 25%, rgba(174, 213, 129, 0.7) 2.5px, transparent 3px),
        radial-gradient(circle at 55% 15%, rgba(139, 195, 74, 0.6) 2px, transparent 3px),
        radial-gradient(circle at 80% 35%, rgba(174, 213, 129, 0.5) 2px, transparent 2.5px),
        radial-gradient(circle at 25% 65%, rgba(104, 159, 56, 0.5) 1.5px, transparent 2px),
        radial-gradient(circle at 70% 75%, rgba(139, 195, 74, 0.6) 2px, transparent 2.5px),
        radial-gradient(circle at 45% 50%, rgba(174, 213, 129, 0.4) 1.5px, transparent 2px),
        radial-gradient(circle at 90% 60%, rgba(104, 159, 56, 0.5) 2px, transparent 2.5px),
        radial-gradient(circle at 35% 85%, rgba(139, 195, 74, 0.4) 1.5px, transparent 2px);
    z-index: 1;
}

/* Glossy highlight strip across top of hedge */
.cell-wall::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 10%;
    right: 30%;
    height: 6px;
    background: linear-gradient(90deg,
        transparent,
        rgba(255, 255, 255, 0.25),
        rgba(255, 255, 255, 0.4),
        rgba(255, 255, 255, 0.25),
        transparent
    );
    border-radius: 50%;
    z-index: 2;
}

/* ============================================
   PATH CELLS - Semi-transparent!
   The beautiful background shows through.
   ============================================ */
.cell-path {
    background: var(--path-tint);
}

/* Visited paths - a soft green footprint trail */
.cell-visited {
    background: var(--path-visited);
}

/* Small flower petal left on visited cells */
.cell-visited::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50% 0 50% 0;
    background: rgba(240, 98, 146, 0.4);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
}

/* ============================================
   PRISON - Stone tower with iron bars
   ============================================ */
.cell-prison {
    background: linear-gradient(145deg,
        #b0bec5 0%,
        var(--tower-stone) 30%,
        var(--tower-dark) 100%
    );
    box-shadow:
        inset 0 3px 6px rgba(255, 255, 255, 0.2),
        inset 0 -3px 6px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Stone brick texture */
.cell-prison::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px);
    background-size: calc(var(--cell-size) / 3) calc(var(--cell-size) / 3);
    z-index: 1;
}

/* Iron bars */
.prison-bars {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(to right,
        transparent, transparent 5px,
        var(--tower-bars) 5px, var(--tower-bars) 7px
    );
    opacity: 0.65;
    z-index: 3;
    transition: opacity 0.8s;
}

.princess-char {
    position: relative;
    z-index: 2;
    font-size: calc(var(--cell-size) * 0.6) !important;
    color: var(--princess-pink);
    filter: drop-shadow(0 1px 3px rgba(216, 27, 96, 0.4));
    animation: princessWave 2.5s ease-in-out infinite;
}

@keyframes princessWave {
    0%, 100% { transform: translateY(0); }
    30% { transform: translateY(-2px) rotate(3deg); }
    60% { transform: translateY(1px) rotate(-3deg); }
}

.prison-lock {
    position: absolute;
    bottom: 1px;
    right: 1px;
    font-size: 14px !important;
    color: var(--tower-bars);
    z-index: 4;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}

/* Unlocked state */
.cell-prison.unlocked .prison-bars {
    opacity: 0;
}

.cell-prison.unlocked .prison-lock {
    color: var(--key-gold);
}

.cell-prison.unlocked {
    box-shadow:
        inset 0 3px 6px rgba(255, 255, 255, 0.2),
        inset 0 -3px 6px rgba(0, 0, 0, 0.2),
        0 0 20px rgba(255, 193, 7, 0.3);
}

/* ============================================
   FIRE TRAP
   ============================================ */
.cell-fire {
    background: var(--path-tint);
}

/* Scorch marks */
.cell-fire::before {
    content: '';
    position: absolute;
    inset: 12%;
    background: radial-gradient(circle,
        rgba(62, 39, 35, 0.3),
        rgba(121, 85, 72, 0.15),
        transparent
    );
    border-radius: 50%;
    z-index: 0;
}

.fire-icon {
    font-size: calc(var(--cell-size) * 0.6) !important;
    color: var(--fire-orange);
    filter: drop-shadow(0 0 8px var(--fire-glow));
    animation: fireFlicker 0.4s ease-in-out infinite alternate;
    position: relative;
    z-index: 1;
}

/* Warm glow circle */
.cell-fire::after {
    content: '';
    position: absolute;
    inset: -4px;
    background: radial-gradient(circle,
        rgba(255, 171, 0, 0.25), transparent 65%);
    animation: fireGlow 0.5s ease-in-out infinite alternate;
    z-index: 0;
}

@keyframes fireFlicker {
    0% { transform: scale(1) rotate(-3deg); color: var(--fire-orange); }
    100% { transform: scale(1.1) rotate(3deg); color: var(--fire-red); }
}

@keyframes fireGlow {
    from { opacity: 0.4; }
    to { opacity: 0.8; }
}

/* ============================================
   SPIKE / THORN TRAP
   ============================================ */
.cell-spike {
    background: var(--path-tint);
}

.spike-icon {
    font-size: calc(var(--cell-size) * 0.6) !important;
    color: #81c784;
    transition: transform 0.3s, opacity 0.3s, color 0.3s;
    position: relative;
    z-index: 1;
}

/* Spikes UP = dangerous */
.cell-spike.spikes-up .spike-icon {
    color: #d32f2f;
    filter: drop-shadow(0 0 4px rgba(211, 47, 47, 0.5));
    transform: scale(1.2);
    animation: thornPop 0.2s ease-out;
}

.cell-spike.spikes-up::after {
    content: '';
    position: absolute;
    inset: 8%;
    border: 2px solid rgba(244, 67, 54, 0.35);
    border-radius: 4px;
    animation: dangerBlink 0.7s ease-in-out infinite;
}

/* Spikes DOWN = safe */
.cell-spike.spikes-down .spike-icon {
    color: #c8e6c9;
    transform: scale(0.55);
    opacity: 0.3;
}

@keyframes thornPop {
    0% { transform: scale(0.55); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1.2); }
}

@keyframes dangerBlink {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.7; }
}

/* ============================================
   GOLDEN KEY
   ============================================ */
.cell-key {
    background: var(--path-tint);
}

.key-icon-cell {
    font-size: calc(var(--cell-size) * 0.55) !important;
    color: var(--key-gold);
    filter: drop-shadow(0 2px 8px var(--key-glow));
    animation: keyFloat 2s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

.cell-key::after {
    content: '';
    position: absolute;
    inset: 10%;
    background: radial-gradient(circle, var(--key-glow), transparent 60%);
    opacity: 0.3;
    animation: keySparkle 1.5s ease-in-out infinite alternate;
    border-radius: 50%;
    z-index: 0;
}

@keyframes keyFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-4px) rotate(8deg); }
    75% { transform: translateY(4px) rotate(-8deg); }
}

@keyframes keySparkle {
    from { opacity: 0.15; transform: scale(0.8); }
    to { opacity: 0.4; transform: scale(1.15); }
}

/* ============================================
   PRINCE - The brave hero!
   ============================================ */
#prince {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: left 0.12s ease-out, top 0.12s ease-out;
    pointer-events: none;
}

#prince .material-symbols-rounded {
    font-size: calc(var(--cell-size) * 0.7);
    color: var(--prince-blue);
    filter: drop-shadow(0 2px 6px var(--prince-glow))
            drop-shadow(0 0 3px rgba(25, 118, 210, 0.3));
    animation: princeIdle 2s ease-in-out infinite;
}

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

#prince.hit .material-symbols-rounded {
    animation: princeHurt 0.5s;
    color: var(--heart-red);
}

@keyframes princeHurt {
    0% { transform: scale(1); }
    20% { transform: scale(0.65) rotate(-15deg); }
    40% { transform: scale(1.25); filter: brightness(1.8); }
    60% { transform: scale(0.85); }
    100% { transform: scale(1); }
}

/* ============================================
   MOBILE CONTROLS
   ============================================ */
#mobile-controls {
    padding: 10px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 5;
}

.control-row {
    display: flex;
    gap: 4px;
}

.control-btn {
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(6px);
    color: var(--text-mid);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.95);
    transform: scale(0.9);
}

.control-btn .material-symbols-rounded {
    font-size: 30px;
}

/* ============================================
   OVERLAY SCREENS
   ============================================ */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(225, 245, 254, 0.88);
    backdrop-filter: blur(10px);
    z-index: 50;
    animation: fadeIn 0.4s ease-out;
}

.overlay.hidden { display: none; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.overlay-box {
    background: linear-gradient(160deg, #ffffff, #fafafa);
    border: 2px solid rgba(0, 0, 0, 0.05);
    border-radius: 28px;
    padding: 36px 32px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.1),
        0 4px 16px rgba(0, 0, 0, 0.06);
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.overlay-icon {
    font-size: 72px !important;
    display: block;
    margin-bottom: 12px;
}

.princess-icon {
    color: var(--princess-pink);
    filter: drop-shadow(0 3px 8px rgba(216, 27, 96, 0.3));
    animation: princessWave 2.5s ease-in-out infinite;
}

.gameover-icon {
    color: var(--heart-red);
    animation: heartBreak 1s ease-out;
}

@keyframes heartBreak {
    0% { transform: scale(1); }
    30% { transform: scale(1.3); }
    60% { transform: scale(0.8); }
    100% { transform: scale(1); }
}

.complete-icon {
    color: var(--star-gold);
    filter: drop-shadow(0 3px 8px rgba(255, 193, 7, 0.5));
    animation: trophySpin 1s ease-out;
}

@keyframes trophySpin {
    0% { transform: scale(0) rotate(-180deg); }
    70% { transform: scale(1.2) rotate(10deg); }
    100% { transform: scale(1) rotate(0); }
}

.overlay-box h2 {
    font-family: 'Fredoka One', cursive;
    font-size: 1.9em;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.win-box h2 {
    background: linear-gradient(135deg, #ffc107, #ff6f00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gameover-box h2 {
    background: linear-gradient(135deg, #e53935, #ff6d00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.complete-box h2 {
    background: linear-gradient(135deg, #ffc107, #ff8f00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-box p {
    color: var(--text-mid);
    margin-bottom: 8px;
}

.level-name {
    font-family: 'Fredoka One', cursive;
    font-size: 1.15em !important;
    color: #2e7d32 !important;
}

.level-desc { font-style: italic; }

.controls-help {
    margin: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.help-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    color: var(--text-mid);
    font-size: 0.9em;
}

.help-row .material-symbols-rounded {
    font-size: 20px;
    color: var(--prince-blue);
}

/* Stars */
.stars-display {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
}

.star-icon {
    font-size: 50px !important;
    color: #e0e0e0;
    transition: color 0.3s, transform 0.5s;
}

.star-icon.earned {
    color: var(--star-gold);
    filter: drop-shadow(0 2px 8px rgba(255, 193, 7, 0.5));
    animation: starPop 0.5s ease-out;
}

@keyframes starPop {
    0% { transform: scale(0) rotate(-45deg); }
    70% { transform: scale(1.3) rotate(10deg); }
    100% { transform: scale(1) rotate(0); }
}

.win-stats {
    font-weight: 700;
    color: var(--text-dark) !important;
}

.final-stars {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 16px 0;
    flex-wrap: wrap;
}

.final-star-group {
    display: flex;
    gap: 2px;
    margin: 0 6px;
}

.final-star-group .material-symbols-rounded { font-size: 20px; }
.final-star-group .star-earned { color: var(--star-gold); }
.final-star-group .star-empty { color: #e0e0e0; }

/* ====== BUTTONS ====== */
.game-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 32px;
    border: none;
    border-radius: 18px;
    font-family: 'Fredoka One', cursive;
    font-size: 1.15em;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
    margin-top: 8px;
}

.game-btn:hover { transform: translateY(-2px); }
.game-btn:active { transform: translateY(0); }

.primary-btn {
    background: linear-gradient(135deg, #43a047, #66bb6a);
    color: white;
    box-shadow: 0 4px 18px rgba(67, 160, 71, 0.4);
}

.primary-btn:hover {
    box-shadow: 0 6px 24px rgba(67, 160, 71, 0.55);
}

.secondary-btn {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-mid);
}

.complete-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

/* ====== EFFECTS ====== */
.shake {
    animation: screenShake 0.4s ease-out;
}

@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-5px, -2px); }
    20% { transform: translate(5px, 3px); }
    30% { transform: translate(-4px, 1px); }
    40% { transform: translate(4px, -2px); }
    50% { transform: translate(-2px, 2px); }
    60% { transform: translate(3px, -1px); }
}

.red-flash::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(229, 57, 53, 0.25);
    pointer-events: none;
    z-index: 40;
    animation: flashOut 0.4s ease-out forwards;
    border-radius: 12px;
}

@keyframes flashOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ====== PARTICLES ====== */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    animation: particleBurst var(--duration) ease-out forwards;
}

.particle.petal {
    border-radius: 50% 0 50% 0;
}

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

/* ====== RESPONSIVE ====== */
@media (hover: none) and (pointer: coarse) {
    #mobile-controls { display: flex; }
}

@media (max-width: 480px) {
    :root { --cell-size: 28px; }
    #hud { padding: 4px 8px; }
    .hud-title h1 { font-size: 1em; }
    .hud-stats { gap: 10px; font-size: 0.85em; padding: 4px 12px; }
    .overlay-box { padding: 24px 20px; }
    .overlay-box h2 { font-size: 1.4em; }
    .control-btn { width: 52px; height: 52px; }
    #mobile-controls { display: flex; }
    .sun { width: 45px; height: 45px; top: 12px; right: 25px; }
    .castle-bg { transform: translateX(-50%) scale(0.6); }
}

@media (min-width: 481px) and (max-width: 768px) {
    :root { --cell-size: 34px; }
    #mobile-controls { display: flex; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    :root { --cell-size: 40px; }
}

@media (min-width: 1025px) {
    :root { --cell-size: 48px; }
}

@media (max-height: 500px) and (orientation: landscape) {
    :root { --cell-size: 26px; }
    #hud { padding: 2px 8px; }
    .hud-title h1 { font-size: 0.9em; }
    #mobile-controls { position: fixed; right: 10px; bottom: 10px; }
    .control-btn { width: 44px; height: 44px; }
}

/* Hero credit badge - stylish pink banner */
.created-by {
    text-align: center;
    font-family: 'Fredoka One', cursive;
    font-size: 1.2em;
    margin: 12px auto;
    padding: 10px 28px;
    color: #fff;
    background: linear-gradient(135deg, #E91E63, #FF4081, #F50057);
    border-radius: 30px;
    display: block;
    width: fit-content;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(233, 30, 99, 0.4);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    z-index: 4;
    position: relative;
    animation: createdByGlow 2s ease-in-out infinite alternate;
}

@keyframes createdByGlow {
    from { box-shadow: 0 4px 15px rgba(233, 30, 99, 0.4); }
    to   { box-shadow: 0 4px 25px rgba(233, 30, 99, 0.7), 0 0 40px rgba(255, 64, 129, 0.3); }
}
