/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height - better for mobile */
    overflow: hidden;
    font-family: Arial, sans-serif;
}

#renderDiv {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height - better for mobile */
    overflow: hidden;
    background: #111;
}

/* Video element */
#videoElement {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh; /* Use dynamic viewport height */
    object-fit: cover;
    transform: scaleX(-1);
    z-index: 0;
}

/* Start screen overlay */
#startScreenOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    z-index: 30;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    text-align: left;
    margin: 0 auto;
    backdrop-filter: blur(3px);
}

#startScreenOverlay .text-container {
    background-color: rgba(0, 0, 0, 0.7);
    padding: 20px;
    /* border-radius: 10px; */
    border: 1px solid gray;
    max-width: 75%;
    margin: 0 auto;
    text-align: left;
    /* box-shadow: 5px 5px 0px rgb(255, 238, 177); */
}

#startScreenOverlay h1 {
    font-size: clamp(28px, 6vw, 50px);
    margin-bottom: 20px;
    color: #00ffa2;
    text-align: center;
}

#startScreenOverlay p {
    font-size: clamp(14px, 3vw, 20px);
    line-height: 1.5;
    margin-bottom: 30px;
    color: #ccc;
}

#loadingText {
    font-size: clamp(14px, 3vw, 20px);
    font-style: italic;
    margin-top: 10px;
    color: #999;
}

#startButton {
    /* margin-top: 20px; */
    padding: 15px;
    font-size: clamp(16px, 4vw, 24px);
    font-family: Arial, sans-serif;
    font-weight: bold;
    color: #fff;
    background-color: #0022ff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    display: none;
    text-align: center;
    margin: 0 auto;
}

/* Exercise and Animal selection dropdowns */
.exercise-selection, .animal-selection {
    margin: 20px 0;
    text-align: center;
}

.exercise-selection label, .animal-selection label {
    display: block;
    font-size: clamp(16px, 3vw, 22px);
    color: #ffffff;
    margin-bottom: 10px;
    font-weight: bold;
}

#exerciseSelect, #animalSelect {
    padding: 10px 15px;
    font-size: clamp(16px, 3vw, 20px);
    font-family: Arial, sans-serif;
    color: #fff;
    background-color: #333;
    border: 2px solid #555;
    border-radius: 5px;
    cursor: pointer;
    min-width: 200px;
    outline: none;
    margin: 5px;
    text-align: center;
}

#exerciseSelect:hover, #animalSelect:hover {
    border-color: #00ffa2;
    background-color: #444;
}

#exerciseSelect:focus, #animalSelect:focus {
    border-color: #00ffa2;
    box-shadow: 0 0 5px rgba(0, 255, 162, 0.3);
}

#exerciseSelect option, #animalSelect option {
    background-color: #333;
    color: #fff;
    padding: 5px;
}

#startButton:hover {
    background-color: #00eeff;
}

#startButton:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Counter UI */
#counterContainer {
    position: absolute;
    top: 2px;
    left: 2px;
    z-index: 20;
    display: none;
    text-align: center;
}

#counterDisplay.flash {
    animation: colorFlash 1.2s ease-in-out;
}

#counterDisplay {
    font-size: clamp(24px, 7vw, 60px);
    font-weight: bold;
    /* margin-bottom: 5px; */
    color: rgb(23, 31, 255);
    transition: color 0.3s ease-out;
}

#stateDisplay {
    font-size: clamp(14px, 3vw, 20px);
    font-weight: normal;
    opacity: 0.8;
    color: black;
    font-style: italic;
}

/* Game over / status container */
#gameOverContainer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    display: none;
    pointer-events: none;
    text-align: center;
    color: white;
    text-shadow: 2px 2px 4px black;
}

#gameOverText {
    font-size: clamp(24px, 8vw, 48px);
    font-weight: bold;
    margin-bottom: 10px;
}

#restartHintText {
    font-size: clamp(14px, 3vw, 20px);
    font-weight: normal;
    opacity: 0.8;
}

/* House image */
#houseImage {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 15;
    width: clamp(150px, 20vw, 300px);
    height: auto;
    pointer-events: none;
}

/* Fire images container */
#fireContainer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 210px;
    z-index: 5;
    pointer-events: none;
    display: flex;
    align-items: flex-end;
    overflow: hidden;
}

.fire-image {
    height: 180px;
    width: auto;
    flex-shrink: 0;
    transform-origin: bottom center;
}

/* Multiple fire animation variants for variety */
.fire-image:nth-child(3n+1) {
    animation: fireFlicker1 0.4s ease-in-out infinite alternate;
}

.fire-image:nth-child(3n+2) {
    animation: fireFlicker2 0.6s ease-in-out infinite alternate;
}

.fire-image:nth-child(3n+3) {
    animation: fireFlicker3 0.5s ease-in-out infinite alternate;
}

@keyframes fireFlicker1 {
    0% { 
        opacity: 0.6;
        transform: scaleY(0.8) scaleX(0.95);
        filter: hue-rotate(0deg) brightness(0.9);
    }
    25% {
        opacity: 0.9;
        transform: scaleY(1.2) scaleX(1.05);
        filter: hue-rotate(10deg) brightness(1.1);
    }
    50% {
        opacity: 0.7;
        transform: scaleY(0.9) scaleX(0.98);
        filter: hue-rotate(-5deg) brightness(0.95);
    }
    75% {
        opacity: 1;
        transform: scaleY(1.3) scaleX(1.08);
        filter: hue-rotate(15deg) brightness(1.2);
    }
    100% { 
        opacity: 0.8;
        transform: scaleY(1.1) scaleX(1.02);
        filter: hue-rotate(5deg) brightness(1.05);
    }
}

@keyframes fireFlicker2 {
    0% { 
        opacity: 0.7;
        transform: scaleY(0.9) scaleX(0.96);
        filter: hue-rotate(-10deg) brightness(0.85);
    }
    20% {
        opacity: 1;
        transform: scaleY(1.4) scaleX(1.1);
        filter: hue-rotate(20deg) brightness(1.3);
    }
    40% {
        opacity: 0.5;
        transform: scaleY(0.7) scaleX(0.92);
        filter: hue-rotate(-15deg) brightness(0.8);
    }
    60% {
        opacity: 0.95;
        transform: scaleY(1.25) scaleX(1.06);
        filter: hue-rotate(8deg) brightness(1.15);
    }
    80% {
        opacity: 0.65;
        transform: scaleY(0.85) scaleX(0.97);
        filter: hue-rotate(-5deg) brightness(0.9);
    }
    100% { 
        opacity: 0.9;
        transform: scaleY(1.15) scaleX(1.03);
        filter: hue-rotate(12deg) brightness(1.1);
    }
}

@keyframes fireFlicker3 {
    0% { 
        opacity: 0.8;
        transform: scaleY(1.0) scaleX(0.98);
        filter: hue-rotate(5deg) brightness(1.0);
    }
    15% {
        opacity: 0.6;
        transform: scaleY(0.75) scaleX(0.94);
        filter: hue-rotate(-8deg) brightness(0.85);
    }
    30% {
        opacity: 1;
        transform: scaleY(1.35) scaleX(1.12);
        filter: hue-rotate(25deg) brightness(1.25);
    }
    45% {
        opacity: 0.75;
        transform: scaleY(0.95) scaleX(0.99);
        filter: hue-rotate(2deg) brightness(0.95);
    }
    60% {
        opacity: 0.55;
        transform: scaleY(0.8) scaleX(0.93);
        filter: hue-rotate(-12deg) brightness(0.8);
    }
    85% {
        opacity: 0.95;
        transform: scaleY(1.2) scaleX(1.07);
        filter: hue-rotate(18deg) brightness(1.2);
    }
    100% { 
        opacity: 0.85;
        transform: scaleY(1.05) scaleX(1.01);
        filter: hue-rotate(7deg) brightness(1.05);
    }
}

.text-box {
    padding: 6px 12px;
    background-color: rgba(255, 255, 255, 0.6);
    color: black;
    font-family: "Arial", "Helvetica Neue", Helvetica, sans-serif;
    border: 2px solid rgb(197, 197, 197);
    /* box-shadow: 3px 3px 0px rgb(255, 200, 0); */
    font-size: clamp(13px, 2vw, 15px);
    text-align: center;
    z-index: 200;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
    max-width: 90%;
    box-sizing: border-box;
    /* border-radius: 6px; */
}

#logo-container {
    position: absolute;
    bottom: 2px;
    left: 2px;
}

#logo {
    font-size: clamp(1.5em, 4vw, 2em);
}

a {
    color: #0000ff !important;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Utility classes */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #startScreenOverlay .text-container {
        padding: 15px 25px;
        margin: 0 10px;
        max-width: 90%;
    }
    
    #startScreenOverlay h1 {
        font-size: clamp(24px, 6vw, 40px);
        margin-bottom: 15px;
    }
    
    .exercise-selection, .animal-selection {
        margin: 15px 0;
    }
    
    #exerciseSelect, #animalSelect {
        min-width: 180px;
        font-size: clamp(14px, 3vw, 18px);
        padding: 8px 12px;
    }
    
    #counterContainer {
        top: 5px;
        left: 5px;
    }
    
    /* Ensure fire container has proper spacing from bottom */
    #fireContainer {
        bottom: 0;
        /* Add some padding to account for mobile browser UI */
        padding-bottom: env(safe-area-inset-bottom, 20px);
        min-height: 100px;
    }
    
    /* Adjust fire image height on mobile */
    .fire-image {
        /* height: 100px; Slightly smaller on mobile */
        width: auto;
        flex-shrink: 0;
        transform-origin: bottom center;
    }
}

/* Fallback for browsers that don't support dvh */
@supports not (height: 100dvh) {
    html, body {
        height: 100vh;
    }
    
    #renderDiv {
        height: 100vh;
    }
    
    #videoElement {
        height: 100vh;
    }
    
    /* On mobile, add extra bottom margin if dvh isn't supported */
    @media (max-width: 768px) and (max-height: 800px) {
        #fireContainer {
            bottom: 60px; /* Add space for mobile browser UI */
        }
    }
}

@keyframes colorFlash {
    0% {
        color: rgb(23, 31, 255); /* Original purple */
    }
    15% {
        color: #14dcff; /* Neon pink */
    }
    40% {
        color: #14ff72; /* Neon pink */
    }
    85% {
        color: rgb(20, 98, 255); /* Stay neon pink */
    }
    100% {
        color:  rgb(23, 31, 255); /* Back to original purple */
    }
}