:root {
    /* Fonts */
    --font-heading: 'Fredoka One', cursive;
    --font-body: 'Baloo 2', cursive;

    /* Global Colors (Initial - Default Meadow) */
    --bg-gradient: linear-gradient(180deg, #4facfe 0%, #00f2fe 100%);
    --bg-ground: #76c95d;
    --text-color: #2D3436;
    --accent-color: #FF9F43;

    /* UI Colors */
    --ui-btn-primary: #FF6B6B;
    --ui-btn-primary-shadow: #c94040;
    --ui-btn-secondary: #48DBFB;
    --ui-btn-secondary-shadow: #2babd1;
    --ui-panel-bg: rgba(255, 255, 255, 0.95);

    /* Functional */
    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-hard: 0 6px 0 rgba(0, 0, 0, 0.2);

    /* Dimensions */
    --header-height: 70px;
}

/* --- THEMES --- */

/* Theme 1: Sunny Meadow (Levels 1-3) */
body[data-stage-theme="meadow"] {
    --bg-gradient: linear-gradient(180deg, #89f7fe 0%, #66a6ff 100%);
    --bg-ground: #6ab04c;
    --accent-color: #f9ca24;
}

/* Theme 2: Sandy Beach (Levels 4-6) */
body[data-stage-theme="beach"] {
    --bg-gradient: linear-gradient(180deg, #4facfe 0%, #00f2fe 100%);
    --bg-ground: #f6e58d;
    /* Sand */
    --accent-color: #ffbe76;
}

/* Theme 3: Candy Land (Levels 7-9) */
body[data-stage-theme="candy"] {
    --bg-gradient: linear-gradient(180deg, #a18cd1 0%, #fbc2eb 100%);
    --bg-ground: #ff9ff3;
    --accent-color: #f368e0;
}

/* Theme 4: Night Sky (Levels 10-12) */
body[data-stage-theme="night"] {
    --bg-gradient: linear-gradient(180deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    --bg-ground: #2d3436;
    --accent-color: #feca57;
    --text-color: #dfe6e9;
    /* Light text for dark bg */
}

/* Theme 5: Space Station (Levels 13-15) */
body[data-stage-theme="space"] {
    --bg-gradient: linear-gradient(180deg, #000000 0%, #434343 100%);
    --bg-ground: #636e72;
    /* Metal grey */
    --accent-color: #00cec9;
    --text-color: #dfe6e9;
}


/* Dark Mode Overrides for UI */
[data-theme="dark"] {
    --ui-panel-bg: rgba(30, 39, 46, 0.95);
    --text-color: #dcdde1;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    font-family: var(--font-body);
    background: var(--bg-gradient);
    color: var(--text-color);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    transition: background 1s ease;
}

/* Container */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
}

/* --- UI ELEMENTS --- */

/* Buttons */
button {
    font-family: var(--font-heading);
    border: none;
    cursor: pointer;
    border-radius: 20px;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.1s;
    position: relative;
    top: 0;
}

button:active {
    top: 4px;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2) !important;
}

.btn-primary {
    background-color: var(--ui-btn-primary);
    color: white;
    font-size: 1.8rem;
    padding: 15px 50px;
    box-shadow: 0 6px 0 var(--ui-btn-primary-shadow);
    margin: 10px;
    min-width: 200px;
}

.btn-secondary {
    background-color: var(--ui-btn-secondary);
    color: #2d3436;
    font-size: 1.2rem;
    padding: 12px 30px;
    box-shadow: 0 5px 0 var(--ui-btn-secondary-shadow);
    margin: 10px;
}

.btn-danger {
    background-color: #ff4757;
    color: white;
    font-size: 1.2rem;
    padding: 12px 30px;
    box-shadow: 0 5px 0 #bf3542;
}

.icon-btn {
    background: white;
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    box-shadow: 0 4px 0 #bdc3c7;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2d3436;
}

.icon-btn:active {
    box-shadow: 0 1px 0 #bdc3c7 !important;
    top: 3px;
}

/* Global Controls */
#global-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 2000;
    /* Higher than HUD */
    pointer-events: auto;
    /* Ensure clickable */
}

/* Rotate Overlay */
#rotate-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #2d3436;
    color: white;
    z-index: 9999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#rotate-overlay .rotate-icon {
    font-size: 4rem;
    animation: rotate-phone 2s infinite;
    margin-bottom: 20px;
}

#rotate-overlay p {
    font-family: var(--font-heading);
    font-size: 1.5rem;
}

@keyframes rotate-phone {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(90deg);
    }

    50% {
        transform: rotate(90deg);
    }

    75% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

/* Responsive Rules */
/* Show overlay only on Portrait Mobile/Tablet */
@media screen and (orientation: portrait) and (max-width: 1024px) {
    #rotate-overlay {
        display: flex;
    }

    /* Hide game content to prevent interaction */
    #game-container> :not(#rotate-overlay) {
        display: none !important;
    }
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
    z-index: 0;
}

/* Main Menu */
#screen-menu .title {
    font-family: var(--font-heading);
    font-size: 4rem;
    color: white;
    text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
    margin-bottom: 50px;
    text-align: center;
    line-height: 1.1;
}

/* Level Select */
#screen-levels {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.screen-header {
    width: 100%;
    max-width: 800px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    margin-bottom: 20px;
}

.screen-header h2 {
    font-family: var(--font-heading);
    color: white;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    font-size: 2rem;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    max-width: 800px;
    width: 90%;
    padding: 20px;
    overflow-y: auto;
    max-height: 70vh;
}

.level-btn {
    aspect-ratio: 1;
    background: var(--ui-panel-bg);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-color);
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
    cursor: pointer;
    position: relative;
}

.level-btn.locked {
    background: rgba(0, 0, 0, 0.2);
    color: rgba(255, 255, 255, 0.5);
    box-shadow: none;
    cursor: not-allowed;
}

.level-btn.locked::after {
    content: "🔒";
    font-size: 1.5rem;
}

.level-btn .stars {
    font-size: 0.8rem;
    margin-top: 5px;
}

/* Gameplay HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 20;
}

.hud-top,
.hud-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
}

.level-indicator,
.score-display {
    background: var(--ui-panel-bg);
    padding: 8px 20px;
    border-radius: 30px;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    box-shadow: var(--shadow-soft);
    color: var(--text-color);
}

.shots-display {
    background: linear-gradient(135deg, #ff9f43, #ff6b6b);
    color: white;
    padding: 10px 25px;
    border-radius: 50px;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    border: 3px solid white;
}

/* Modals */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

#modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.popup {
    background: white;
    padding: 30px;
    border-radius: 25px;
    text-align: center;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    width: 400px;
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: #2D3436;
}

.popup.hidden {
    display: none !important;
}

#modal-overlay.active .popup {
    transform: scale(1);
}

.popup h2 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    margin-bottom: 20px;
    color: var(--ui-btn-primary);
}

.stars-result {
    font-size: 3rem;
    margin: 10px 0 20px;
    letter-spacing: 5px;
}

/* Animations */
@keyframes bounce-in {
    0% {
        transform: scale(0);
    }

    60% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.btn-primary.pulse {
    animation: float 2s ease-in-out infinite;
}

/* Responsive */
@media (max-width: 600px) {
    .level-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .btn-primary {
        width: 100%;
        margin: 10px 0;
    }

    #screen-menu .title {
        font-size: 3rem;
    }
}