/* Core Design System for Malayali Dino */
:root {
    --primary-color: #4CAF50;
    --accent-color: #FFC107;
    --text-color: #FFFFFF;
    --bg-color: #E0F2F1;
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --font-main: 'Outfit', sans-serif;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-color);
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    width: 100%;
    height: 35vh;
    /* Reduced from 50vh for better FOV */
    max-height: 280px;
    /* Reduced to squeeze height on mobile */
    background-color: #87CEEB;
    /* Match the sky to hide gaps */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

/* Loading Screen - Modernized */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #1a2a6c, #000);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.8s;
    pointer-events: auto;
}

#loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

#loading-content {
    text-align: center;
    color: white;
    width: 85%;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#loading-logo {
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 30px;
    letter-spacing: 5px;
    background: linear-gradient(to right, #fff, #8BC34A, #fff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: title-glow 2s ease-in-out infinite alternate;
}

@keyframes title-glow {
    from { filter: drop-shadow(0 0 5px rgba(255,255,255,0.2)); }
    to { filter: drop-shadow(0 0 20px rgba(76, 175, 80, 0.6)); }
}

#loading-bar-container {
    width: 100%;
    height: 4px; /* Sleek thin bar */
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

#loading-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A, #4CAF50);
    background-size: 200% 100%;
    animation: gradient-move 2s linear infinite;
    transition: width 0.4s cubic-bezier(0.1, 0.7, 0.1, 1);
}

@keyframes gradient-move {
    0% { background-position: 100% 0%; }
    100% { background-position: -100% 0%; }
}

#loading-status {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
}

@media (min-width: 600px) {
    #game-container {
        max-width: 800px;
        height: 400px;
        max-height: 400px;
        border-radius: 8px;
    }
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#hud-left {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    z-index: 50;
    pointer-events: none;
}

#score-container {
    font-weight: 700;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    z-index: 5;
    gap: 3px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    padding: 8px 15px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

#stats-main {
    display: flex;
    gap: 15px;
    font-size: 16px;
}

#karikku-container {
    position: absolute;
    top: 10px;
    right: 10px;
    color: #FFC107;
    font-size: 18px;
    font-weight: 800;
    text-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    padding: 8px 15px;
    border-radius: 30px;
    border: 1.5px solid rgba(255, 193, 7, 0.3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#karikku-count {
    font-size: 22px;
    background: linear-gradient(180deg, #FFF, #FFC107);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#karikku-icon {
    width: 24px;
    height: auto;
    filter: drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.5));
}

.bus-mode #score-value {
    color: #FFEB3B;
    text-shadow: 0 0 10px rgba(255, 235, 59, 0.8), 0 0 20px rgba(255, 193, 7, 0.5);
    font-weight: 800;
}

#score-value,
#high-score-value {
    letter-spacing: 2px;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-bg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-color);
    pointer-events: auto;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

h1 {
    font-size: 32px;
}

p {
    font-size: 16px;
    margin-bottom: 20px;
}

@media (min-width: 600px) {
    h1 {
        font-size: 48px;
        margin-bottom: 10px;
        letter-spacing: 4px;
        text-transform: uppercase;
    }

    p {
        font-size: 18px;
        margin-bottom: 30px;
    }

    #score-container {
        padding: 20px;
        font-size: 20px;
    }
}

#external-controls {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 20px;
}

#external-controls {
    pointer-events: none;
}

#pause-button,
#fire-button {
    pointer-events: auto;
    position: fixed;
    z-index: 1000;
}

#fire-button {
    bottom: 20px;
    left: 20px;
    padding: 25px 50px;
    background-color: #FF5252;
    /* Bright Red for firing */
    color: #fff;
    font-size: 24px;
    box-shadow: 0 4px 0 #D32F2F;
}

#pause-button {
    position: absolute;
    top: 65px;
    /* Increased space below Karikku on Desktop */
    right: 10px;
    left: auto;
    padding: 6px 18px;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.hidden {
    display: none !important;
}

button {
    padding: 12px 30px;
    font-size: 20px;
    font-family: var(--font-main);
    font-weight: 700;
    background-color: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 0 #2E7D32;
}

button:hover {
    transform: translateY(-2px);
    background-color: #66BB6A;
}

button:active {
    transform: translateY(2px);
    box-shadow: none;
}

#dino-health-ui {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 2px 0;
    background-color: transparent;
    border: none;
    z-index: 20;
    backdrop-filter: none;
}

/* Mobile HUD Layout (Symmetrical & Compact) */
@media (max-width: 600px) {
    #score-container {
        padding: 2px 8px;
        /* Tighter padding */
        font-size: 8px;
        /* Everything at 8px for extreme compact look */
        background: rgba(0, 0, 0, 0.4);
        border-radius: 4px;
        /* Sharper corners for a smaller box */
        backdrop-filter: blur(4px);
    }

    #stats-main {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 3px;
    }

    #score-label,
    #high-score-label {
        font-size: 6.5px;
        /* Micro labels */
        opacity: 0.6;
    }

    #dino-health-ui {
        padding: 2px 4px;
        transform: scale(0.65);
        /* Extra small */
        transform-origin: top left;
    }

    #karikku-container {
        font-size: 14px;
        top: 8px;
        right: 8px;
        /* Karikku on the top right */
        padding: 4px 10px;
        background: rgba(0, 0, 0, 0.4);
        border-radius: 6px;
        /* Matching Score Container! */
    }

    #karikku-count {
        font-size: 18px;
    }

    #karikku-icon {
        width: 18px;
    }

    #boss-ui {
        transform: scale(0.85);
        transform-origin: top right;
        top: 8px;
        right: 8px;
        width: 130px;
    }

    #pause-button {
        display: block;
        position: absolute;
        top: 50px;
        /* Fine-tuned "sweet spot" position */
        right: 8px;
        left: auto;
        transform: scale(0.75);
        transform-origin: top right;
        margin: 0;
        padding: 6px 16px;
        background: rgba(0, 0, 0, 0.4);
        border: 1px solid rgba(255, 255, 255, 0.1);
        font-size: 11px;
        border-radius: 4px;
        z-index: 100;
        width: auto;
    }

    #fire-button {
        bottom: 10px;
        padding: 15px 35px;
        font-size: 16px;
        border-radius: 40px;
    }

    #loading-logo {
        font-size: 1.8rem;
        margin-bottom: 20px;
    }

    .overlay h1 {
        font-size: 24px;
    }
}


#hearts-wrapper {
    display: flex;
    gap: 6px;
    font-size: 16px;
}

#dino-name {
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.heart {
    filter: drop-shadow(0 0 5px rgba(255, 0, 0, 0.5));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.heart.lost {
    opacity: 0.3;
    transform: scale(0.5);
    filter: grayscale(1);
}

.dino-hit {
    animation: damage-flash 0.15s linear infinite;
    filter: drop-shadow(0 0 5px rgba(255, 0, 0, 0.8));
}

@keyframes damage-flash {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

#game-container.dino-hit-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 0, 0, 0.2);
    pointer-events: none;
    z-index: 99;
    animation: overlay-pulse 0.15s infinite;
}

@keyframes overlay-pulse {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* Boss UI Styles */
#boss-ui {
    position: absolute;
    top: 10px;
    /* Top right corner */
    right: 10px;
    width: 180px;
    /* Resized smaller */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background-color: rgba(0, 0, 0, 0.5);
    /* Matching container! */
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    z-index: 20;
    backdrop-filter: blur(2px);
}

#boss-name {
    font-weight: 700;
    color: #fff;
    /* Changed from #FF5252 to white */
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    font-size: 11px;
    /* Smaller font */
    letter-spacing: 1px;
}

#boss-health-container {
    width: 100%;
    height: 12px;
    background-color: rgba(0, 0, 0, 0.3);
    border: 2px solid #444;
    border-radius: 10px;
    overflow: hidden;
}

#boss-health-bar {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, #f44336, #ff5252);
    transition: width 0.2s ease-out;
}

#boss-health-bar.hit-splash {
    animation: bar-white-splash 0.15s linear;
}

@keyframes bar-white-splash {
    0% {
        background: #fff !important;
        filter: brightness(2);
    }

    100% {
        background: linear-gradient(to right, #f44336, #ff5252);
        filter: brightness(1);
    }
}

#resume-overlay {
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: none !important; /* Forces removal of inherited blur from .overlay */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#resume-button-central {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    outline: none;
    padding: 0;
}

#resume-button-central:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6);
}

#resume-button-central:active {
    transform: scale(0.9);
}

.play-icon {
    font-size: 45px;
    color: #fff;
    margin-left: 8px; /* Offset to center the triangle icon visually */
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.6);
}

@media (max-width: 600px) {
    #resume-button-central {
        width: 80px;
        height: 80px;
    }
    .play-icon {
        font-size: 35px;
    }
}