body {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height on mobile */
    background-color: #222; /* Slightly darker page background */
    font-family: Arial, sans-serif;
    overflow: hidden;
}

.screen {
    display: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    position: relative;
}

.screen.active {
    display: block;
}

#fight-screen {
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    width: 100vw; /* Full viewport width */
    height: 100vh;
    height: 100dvh; /* dynamic viewport height for mobile toolbars */
    background-color: #454545;
    border: 2px solid black;
    overflow: hidden;
}

.parallax-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-repeat: repeat-x;
    background-position: center bottom; /* Align parallax to bottom, center horizontally if not repeating enough */
    background-size: cover;
    image-rendering: pixelated;
}

/* Specific parallax layers will have their background-image set by game.js from config */
#parallax-layer-1 { z-index: 1; }
#parallax-layer-2 { z-index: 2; }
#parallax-layer-3 { z-index: 3; }
#parallax-layer-4 {
    z-index: 11;
    pointer-events: none;
    background-repeat: no-repeat;
    background-position: center bottom;
    background-size: contain; /* show full width without tiling */
}

.character {
    position: absolute;
    /* width and height will be set by JavaScript */
    bottom: 0px; /* Base, JS will set actual 'bottom' style */
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    z-index: 10;
    image-rendering: pixelated;
    transform-origin: center bottom;
}

/* Player starting X positions are set by JS via player.element.style.left */
/* Player transform for flipping is set by JS */

/* --- New Top UI Area Styling --- */
#top-ui-area {
    position: absolute;
    top: 15px; /* Spacing from the top of the game container */
    left: 15px; /* Spacing from the left */
    right: 15px; /* Spacing from the right */
    height: auto; /* Height will be determined by content */
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Align items to their top edge */
    z-index: 20;
    pointer-events: none; /* Allow clicks to pass through UI elements if needed */
}

.player-ui-info {
    width: 35%; /* Adjust width for P1/P2 info sections */
    display: flex;
    flex-direction: column;
}

#player1-ui-info {
    align-items: flex-start; /* Align content to the left */
}

#player2-ui-info {
    align-items: flex-end; /* Align content to the right */
}

.center-ui-info {
    display: flex;
    flex-direction: column;
    align-items: center; /* Center timer and round info */
    text-align: center;
    color: white;
    text-shadow: 1px 1px 2px black;
}

.health-bar-container {
    position: relative;
    width: 100%; /* Health bar container will take full width of its parent (.player-ui-info) */
    max-width: 40vw; /* Or vw, or keep fixed px if preferred with responsive container */
    height: 32px;
    background-color: #333; /* Default fallback */
    border: 2px solid #111;
    border-radius: 5px;
    padding: 2px;
    margin-top: 5px; /* Space if a player name/icon was above it */
    overflow: hidden;
}

.health-bar {
    position: absolute;
    top: 2px;
    bottom: 2px;
    height: auto;
    width: 100%; /* Default to full health */
    border-radius: 2px;
    transition: width 0.2s ease-in-out;
}

.charge-bar-container {
    position: relative;
    width: 100%;
    max-width: 40vw;
    height: 8px;
    background-color: #222;
    border: 1px solid #111;
    border-radius: 4px;
    margin-top: 2px;
    overflow: hidden;
}

.charge-bar {
    position: absolute;
    top: 1px;
    bottom: 1px;
    width: 0%;
    background-color: #3cf;
    border-radius: 2px;
    transition: width 0.1s linear;
}

.charge-bar.full {
    background-color: #6df;
    box-shadow: 0 0 6px 2px rgba(102, 221, 255, 0.7);
}

#p1-charge-container { background-color: rgba(76,175,80,0.3); }
#p2-charge-container { background-color: rgba(244,67,54,0.3); }

#player1-health { background-color: #4CAF50; left: 2px; /* Green for P1 */ }
#player2-health { background-color: #F44336; right: 2px; /* Red for P2 */ }

#p1-health-container { background-color: rgba(76,175,80,0.5); }
#p2-health-container { background-color: rgba(244,67,54,0.5); }

#timer {
    font-size: 24px;
    font-weight: bold;
    padding: 2px 10px;
    background-color: rgba(0,0,0,0.6);
    border-radius: 4px;
    margin-bottom: 3px;
}

#round-info {
    font-size: 16px;
    padding: 2px 8px;
    background-color: rgba(0,0,0,0.5);
    border-radius: 4px;
}
#win-info {
    font-size: 16px;
    padding: 2px 8px;
    background-color: rgba(0,0,0,0.5);
    border-radius: 4px;
    margin-top: 3px;
}

.player-name,
.projectile-list {
    color: white;
    text-shadow: 1px 1px 2px black;
    pointer-events: none;
    font-size: 14px;
    margin-top: 2px;
}

.projectile-list { font-size: 12px; display: flex; gap: 4px; }

.projectile-item {
    display: flex;
    align-items: center;
    gap: 2px;
}

.projectile-icon {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}
/* --- End Top UI Area Styling --- */


#gameOverMessage {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #FFCC00; /* Yellowish game over text */
    font-size: 42px;
    font-weight: bold;
    text-align: center;
    background-color: rgba(0,0,0,0.75);
    padding: 25px;
    border-radius: 10px;
    border: 2px solid #FFCC00;
    z-index: 100;
}

.round-announcement {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 64px;
    font-weight: bold;
    text-shadow: 2px 2px 4px #000;
    pointer-events: none;
    opacity: 0;
    z-index: 80;
}

.round-announcement.animate {
    animation: fadeScale 1s forwards;
}

.keys-preview {
    position: absolute;
    bottom: 10px;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 6px;
    border-radius: 4px;
    pointer-events: auto; /* allow clicking/tapping preview keys */
    z-index: 30;
}

.keys-preview.connected::after {
    content: "🎮";
    position: absolute;
    right: -1.2em;
    bottom: 0;
    font-size: 1.4rem;
}

.key-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 2px;
}

.key-grid kbd {
    cursor: pointer;
    display: inline-block;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid #999;
    background: linear-gradient(#eee, #ccc);
    box-shadow: 0 2px 0 #666;
    font-size: 12px;
    text-align: center;
    aspect-ratio: 1/1;
    pointer-events: auto; /* allow clicks even if parent disables events */
    touch-action: none;
    user-select: none;
    color: #222;
}

.key-grid kbd[data-key=" "],
.key-preview[data-key=" "],
.key-grid kbd[data-key="space"],
.key-preview[data-key="space"],
.key-grid kbd[data-key="spacebar"],
.key-preview[data-key="spacebar"] {
    aspect-ratio: 2/1;
    grid-column: span 2;
}

.key-grid kbd.main-key {
    background: linear-gradient(#fff, #ddd);
    font-weight: bold;
}

.key-grid kbd.aux-key {
    background: linear-gradient(#aaa, #666);
}

#p1-keys-preview {
    left: 10px;
    text-align: left;
}
#p2-keys-preview {
    right: 10px;
    text-align: right;
}
#p1-nav-preview {
    left: 10px;
    text-align: left;
}
#p2-nav-preview {
    right: 10px;
    text-align: right;
}

.key-grid kbd.disabled {
    opacity: 0.2;
    pointer-events: none;
}

.debug-box {
    position: absolute;
    border: 1px dashed red;
    pointer-events: none;
    z-index: 999;
}

.debug-grid {
    position: absolute;
    pointer-events: none;
    z-index: 998;
}

.debug-grid-cell {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid rgba(0,255,0,0.4);
    background-color: transparent;
}

.debug-center-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: magenta;
    pointer-events: none;
    z-index: 997;
}

@keyframes fadeScale {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    10% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    90% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes damageFlash {
    0% { filter: none; }
    50% { filter: brightness(2); }
    100% { filter: none; }
}

.character.damage-flash {
    animation: damageFlash 0.2s;
}

.projectile { position: absolute; z-index: 12; pointer-events: none; background-size: cover; background-repeat: no-repeat; image-rendering: pixelated; }
.particle-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 13;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: yellow;
    pointer-events: none;
    z-index: 13;
}

/* Character selection overlay */
#character-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    color: white;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

#character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 150px);
    gap: 20px;
    margin-bottom: 20px;
}

#character-select kbd {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #999;
    background: linear-gradient(#eee, #ccc);
    box-shadow: 0 2px 0 #666;
    font-size: 12px;
    user-select: none;
    color: #222;
}


.key-preview {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #999;
    background: linear-gradient(#eee, #ccc);
    box-shadow: 0 2px 0 #666;
    font-size: 12px;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    color: #222;
    aspect-ratio: 1/1;
}

.key-preview[data-active="true"],
.key-grid kbd[data-active="true"] {
    background: linear-gradient(#ddd, #bbb);
    box-shadow: 0 1px 0 #444 inset;
    transform: translateY(1px);
}

.character-option {
    width: 150px;
    height: 150px;
    background-size: cover;
    background-position: center;
    position: relative;
    image-rendering: pixelated;
}
.character-option.locked {
    opacity: 0.7;
}

.character-option.p1-selected::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    box-sizing: border-box;
    border: 3px dotted rgba(76, 175, 80, 0.5);
}

.character-option.p2-selected::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    box-sizing: border-box;
    border: 3px dashed rgba(244, 67, 54, 0.5);
}

/* Network connection popup */
.network-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #fff;
    z-index: 250;
    text-align: center;
}

.network-popup button {
    margin: 5px;
    padding: 6px 12px;
    cursor: pointer;
}

.network-popup kbd {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #999;
    background: linear-gradient(#eee, #ccc);
    box-shadow: 0 2px 0 #666;
    font-size: 12px;
    user-select: none;
    color: #222;
}

/* Settings popup */
.settings-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #fff;
    z-index: 250;
    text-align: center;
}

.settings-popup label {
    display: block;
    margin-bottom: 8px;
}

.settings-popup button {
    margin-top: 10px;
    padding: 6px 12px;
    cursor: pointer;
}

.settings-popup table {
    margin-top: 10px;
    width: 100%;
}
.settings-popup th,
.settings-popup td {
    padding: 2px 4px;
}
.settings-popup input[type="text"] {
    width: 60px;
    text-align: center;
}

/* Start screen */
#start-menu {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: white;
    z-index: 100;
}

#start-icon {
    width: 128px;
    height: 128px;
    margin-bottom: 10px;
}

#start-desc {
    max-width: 320px;
    margin: 0 auto 20px;
}

#main-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-item {
    margin: 6px 0;
    padding: 8px 20px;
    border: 2px solid #fff;
    border-radius: 6px;
    cursor: pointer;
}

.menu-item.selected {
    background: rgba(255, 255, 255, 0.2);
}

#menu-hint {
    margin-top: 10px;
}

#menu-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #999;
    background: linear-gradient(#eee, #ccc);
    box-shadow: 0 2px 0 #666;
    font-size: 12px;
    user-select: none;
    color: #222;
}

#debug-console {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 30%;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.8);
    color: #0f0;
    font-family: monospace;
    font-size: 12px;
    padding: 4px;
    z-index: 10000;
}

#debug-console-close {
    position: absolute;
    top: 0;
    right: 0;
    cursor: pointer;
    padding: 2px 6px;
    color: #f55;
    font-weight: bold;
}

#debug-console .debug-warn { color: #ff0; }
#debug-console .debug-error { color: #f55; }

#sync-log {
    width: 100%;
    height: 50vh;
    overflow-y: auto;
    resize: none;
    font-family: monospace;
}


#konami-message {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    background: rgba(0,0,0,0.8);
    padding: 10px 20px;
    border: 2px solid #fff;
    border-radius: 8px;
    z-index: 10000;
    font-size: 24px;
    display: none;
    text-align: center;
}

.sc-instrument {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sc-mute {
    position: sticky;
    left: 0;
    z-index: 2;
}

#sc-mute-buttons {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.sc-track-mute {
    pointer-events: auto;
    z-index: 3;
    width: 24px;
    line-height: 20px;
    text-align: center;
    padding: 0;
}

