/* Letterboxed Game Container */
body {
    background: #111;
    margin: 0;
    cursor: crosshair;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

#game-container {
    width: 100vw;
    /* Maintain min height but allow infinite horizontal stretch out to 23.7:10 (1600x675) */
    height: 42.18vw;
    max-width: 237.0vh;
    max-width: 237.0dvh;
    max-height: 100vh;
    max-height: 100dvh;
    margin: auto;
    position: relative;
    /* Anchors the absolute mobile controls strictly inside this box */
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

#game {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Mobile Controls Overlay */
#mobile-controls {
    position: absolute;
    /* Anchored to the bottom of #game-container, NOT the window */
    bottom: 20px;
    left: 0;
    width: 100%;
    height: 120px;
    display: flex;
    justify-content: space-between;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    box-sizing: border-box;
    z-index: 100;
    pointer-events: none;
}

.action-buttons {
    display: flex;
    gap: 10px;
    pointer-events: auto;
    align-items: flex-end;
}

/* Joystick Styles */
#joystick-zone {
    width: 120px;
    height: 120px;
    position: relative;
    pointer-events: auto;
    /* Re-enable clicks on the joystick zone */
}

#joystick-base {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    box-sizing: border-box;
}

#joystick-thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    /* Center it initially */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    /* Let touches pass through to the zone */
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    font-size: 24px;
    font-weight: bold;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    touch-action: manipulation;
    /* Prevent zoom on double tap */
    -webkit-tap-highlight-color: transparent;
    /* Remove blue highlight on iOS */
    backdrop-filter: blur(4px);
    transition: background 0.1s, transform 0.1s;
}

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

/* Specific buttons */
.action-btn {
    font-size: 14px;
    border-radius: 12px;
    width: 60px;
    height: 60px;
}

.attack-btn {
    background: rgba(255, 100, 100, 0.2);
    border-color: rgba(255, 100, 100, 0.5);
    color: #ffcccc;
    font-size: 20px;
}

.attack-btn:active,
.attack-btn.active {
    background: rgba(255, 100, 100, 0.6);
}

.transform-btn {
    background: rgba(255, 215, 0, 0.2);
    /* Gold tint for T */
    border-color: rgba(255, 215, 0, 0.5);
    color: gold;
    font-size: 20px;
    width: 50px;
    height: 50px;
    align-self: flex-start;
    /* Push T button up a bit */
    border-radius: 50%;
}

.transform-btn:active,
.transform-btn.active {
    background: rgba(255, 215, 0, 0.6);
}

/* In-game Fullscreen Toggle */
#btn-fullscreen {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

/* Subtle Music Toggle */
#btn-music-toggle {
    position: absolute;
    top: 20px;
    right: 90px;
    z-index: 1000;
    opacity: 0.5;
    transform: scale(0.85);
    /* Slightly smaller and discreet */
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#btn-music-toggle:active {
    opacity: 1.0;
    transform: scale(0.8);
}

/* Loading Screen Overlay */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    color: white;
    font-family: Arial, sans-serif;
    transition: opacity 0.3s ease;
}

.loading-content {
    text-align: center;
    width: 80%;
    max-width: 600px;
}

.loading-title {
    font-size: 3rem;
    margin-bottom: 20px;
    letter-spacing: 5px;
    color: #ffcc00;
    /* Gold */
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

#loading-text {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #ccc;
    font-family: inherit;
}

.loading-bar-container {
    width: 100%;
    height: 20px;
    background-color: #333;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid #555;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* =========================================
   FULL GAME ARCHITECTURE (Level 1 + UI)
========================================= */

#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 900;
    background-image: url('press start screen/game start.webp');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.blink-text {
    font-size: 36px;
    color: #ffd700;
    text-shadow: 2px 2px 5px #000, 0 0 10px #ff0000;
    animation: blink 1.5s infinite;
    margin-bottom: 20px;
    text-transform: uppercase;
    font-weight: bold;
    width: 100%;
    text-align: center;
}

.copyright-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 30px;
    font-family: monospace;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

#prologue-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 850;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

#prologue-image-container {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    position: absolute;
    top: 0;
    left: 0;
}

.comic-textbox {
    position: absolute;
    bottom: 50px;
    width: 80%;
    max-width: 800px;
    background: rgba(255, 255, 255, 0.95);
    border: 4px solid #000;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.8);
    font-family: 'Verdana', sans-serif;
    color: #000;
    font-size: 22px;
    font-weight: bold;
    text-align: left;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease-out;
}

.comic-textbox.visible {
    transform: translateY(0);
    opacity: 1;
}

.comic-textbox.action-effect {
    background: #000;
    color: #fff;
    border: 4px solid #ff0000;
    box-shadow: 8px 8px 0px rgba(255, 0, 0, 0.6);
    font-family: 'Courier New', Courier, monospace;
    text-align: center;
    font-style: italic;
}

.comic-textbox.epic-effect {
    background: transparent;
    border: none;
    box-shadow: none;
    color: #fff;
    font-size: 48px;
    text-align: center;
    bottom: 40%;
    text-shadow: 3px 3px 10px #000;
}

.click-to-continue {
    display: block;
    text-align: right;
    font-size: 14px;
    color: #555;
    margin-top: 15px;
    animation: blink 2s infinite;
}

.comic-textbox.action-effect .click-to-continue,
.comic-textbox.epic-effect .click-to-continue {
    color: #aaa;
}

/* Player Health Bar - MegaMan X Style */
#health-bar-container {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 20px;
    height: 150px;
    background: rgba(0, 0, 0, 0.5);
    border: 3px solid #ccc;
    display: flex;
    flex-direction: column-reverse;
    /* Stacks from bottom to top */
    padding: 2px;
    z-index: 100;
}

#lives-container {
    position: absolute;
    top: 180px;
    left: 20px;
    color: #fff;
    font-family: monospace;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 2px 2px 4px #000;
    z-index: 100;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 10px;
}

#lives-icon {
    height: 48px;
    width: auto;
    image-rendering: pixelated;
    object-fit: contain;
}

.health-segment {
    width: 100%;
    flex: 1;
    background: #00ff00;
    /* Green */
    margin-top: 2px;
    box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.5);
}

.health-segment.empty {
    background: transparent;
}

#loading-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #ffcc00, #ff9900);
    border-radius: 10px;
    transition: width 0.1s ease-out;
}

/* Mobile Landscape Optimizations for Prologue */
@media (max-height: 500px) {
    .comic-textbox {
        bottom: 15px;
        padding: 10px;
        font-size: 14px;
        border-width: 2px;
    }

    .comic-textbox.epic-effect {
        font-size: 24px;
        bottom: 20%;
    }
}