:root {
    /* --- Light Theme (Default) --- */
    --bg-gradient-start: #87CEEB;
    /* Sunny Sky Blue */
    --bg-gradient-end: #E0F7FA;
    --text-color: #333333;
    --ui-text-color: #ffffff;
    --primary-color: #FF7043;
    /* Deep Orange */
    --primary-hover: #F4511E;
    --secondary-color: #7CB342;
    /* Light Green */
    --secondary-hover: #558B2F;
    --overlay-bg: rgba(0, 0, 0, 0.6);
    --modal-bg: #ffffff;
    --modal-text: #333333;

    /* Font Families */
    --font-heading: 'Fredoka One', cursive;
    --font-body: 'Bubblegum Sans', cursive;

    /* Transition */
    --theme-transition: background 0.5s ease, color 0.5s ease;
}

/* --- Dark Theme --- */
body.dark-mode {
    --bg-gradient-start: #1a237e;
    /* Midnight Blue */
    --bg-gradient-end: #000000;
    --text-color: #eeeeee;
    --modal-bg: #263238;
    --modal-text: #ffffff;
    --primary-color: #FFAB40;
    /* Orange Accent */
    --primary-hover: #FF6D00;
}

/* --- Global Reset & Basics --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body,
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Prevent scrolling */
    font-family: var(--font-body);
    user-select: none;
    -webkit-user-select: none;
    background: #333;
    /* Fallback */
}

/* --- Game Container --- */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, var(--bg-gradient-start), var(--bg-gradient-end));
    transition: var(--theme-transition);
    overflow: hidden;
}

/* Enhancing background with a subtle pattern overlay */
#game-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    /* Double width for animation */
    height: 100%;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.2) 20%, transparent 20%),
        radial-gradient(rgba(255, 255, 255, 0.1) 20%, transparent 20%);
    background-size: 50px 50px, 80px 80px;
    background-position: 0 0, 25px 25px;
    animation: bg-scroll 60s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes bg-scroll {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(-50%);
    }
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 1;
    /* Above background pattern */
}

/* --- UI Layer --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas when possible */
    z-index: 10;
}

/* Helper Class: .screen */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    /* Enable clicks on UI screens */
    transition: opacity 0.3s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    /* Ensure it's not focusable */
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

/* --- Typography --- */
h1,
h2 {
    font-family: var(--font-heading);
    color: var(--ui-text-color);
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.3);
    margin-bottom: 20px;
    text-align: center;
}

h1.game-title {
    font-size: 3.5rem;
    color: #ffffff;
    -webkit-text-stroke: 2px #333;
    animation: bounce 2s infinite ease-in-out;
}

h2 {
    font-size: 2.5rem;
}

/* --- Buttons --- */
button {
    font-family: var(--font-heading);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 12px 30px;
    margin: 10px;
    transition: transform 0.1s, box-shadow 0.1s;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

.btn-icon {
    background: none;
    box-shadow: none;
    font-size: 2rem;
    padding: 0;
    margin: 0;
}

.btn-icon:hover {
    transform: scale(1.1);
}

.btn-icon:active {
    transform: scale(0.9);
}

/* --- Persistent Controls (Top Right) --- */
#persistent-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 15px;
    z-index: 20;
    pointer-events: auto;
}

.btn-icon-small {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(4px);
}

.btn-icon-small:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* --- Game HUD --- */
#game-hud {
    justify-content: flex-start;
    /* Align to top */
    pointer-events: none;
}

.hud-top {
    width: 100%;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
}

.score-container {
    background: rgba(255, 255, 255, 0.4);
    padding: 5px 20px;
    border-radius: 30px;
    backdrop-filter: blur(5px);
    border: 2px solid rgba(255, 255, 255, 0.6);
}

#score-display {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.stage-indicator {
    font-family: var(--font-heading);
    color: white;
    font-size: 1.2rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 15px;
    border-radius: 20px;
}

/* --- Screens --- */
.bird-mascot-menu {
    font-size: 5rem;
    margin: 20px;
    animation: float 3s ease-in-out infinite;
}

.overlay-dark {
    background: var(--overlay-bg);
    backdrop-filter: blur(3px);
}

.overlay-blur {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
}

/* --- Game Over --- */
.final-score-box {
    background: #fff;
    padding: 20px 40px;
    border-radius: 20px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    color: #333;
}

.big-number {
    font-family: var(--font-heading);
    font-size: 4rem;
    color: var(--primary-color);
}

.score-label {
    font-size: 0.9rem;
    color: #666;
    letter-spacing: 2px;
}

.celebration {
    color: #FFD700;
    font-weight: bold;
    font-size: 1.2rem;
    animation: pulse 1s infinite;
    margin-top: 5px;
}

/* --- Modal --- */
.modal-content {
    background: var(--modal-bg);
    color: var(--modal-text);
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    padding: 25px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.btn-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #999;
    box-shadow: none;
    cursor: pointer;
}

.help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
    text-align: left;
}

.help-item {
    background: rgba(0, 0, 0, 0.05);
    padding: 10px;
    border-radius: 10px;
    font-size: 0.9rem;
}

.help-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 5px;
}

/* --- Animations --- */
@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0) rotate(5deg);
    }

    50% {
        transform: translateY(-20px) rotate(-5deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* --- Particles --- */
#particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* --- Responsive --- */
@media (max-width: 480px) {
    h1.game-title {
        font-size: 2.5rem;
    }

    h2 {
        font-size: 2rem;
    }

    .help-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Particles --- */
.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 999;
}

@keyframes particle-explode {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}