body {
    margin: 0;
    padding: 0;
    background-color: #111;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

canvas {
    /* PSX Aesthetic: Sharp pixels */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    
    /* Scale to fit screen while maintaining aspect ratio logic is handled by CSS layout 
       but here we ensure it fills the container */
    width: 100%;
    height: 100%;
    object-fit: contain; 
} 
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to canvas if needed, but we enable pointer-events on buttons */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    box-sizing: border-box;
    font-family: 'Courier New', Courier, monospace;
    text-transform: uppercase;
}

/* --- HUD TOP (Health Bars) --- */
#hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.fighter-hud {
    width: 40%;
    display: flex;
    flex-direction: column;
}

.fighter-name {
    color: #fff;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 4px;
    text-shadow: 2px 2px 0 #000;
}

.p2 .fighter-name {
    text-align: right;
}

.health-track {
    width: 100%;
    height: 20px;
    background: #300; /* Dark red background for empty health */
    border: 2px solid #fff;
    box-shadow: 3px 3px 0 #000;
    position: relative;
    overflow: hidden;
}

.health-ghost {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ff0000; /* Red damage ghost */
    transition: width 0.5s cubic-bezier(0.25, 1, 0.5, 1) 0.8s; /* Delay then slide */
    z-index: 1;
}

.health-fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffcc00; /* Classic yellow health bar */
    transition: width 0.1s linear; /* Instant drop */
    z-index: 2;
}

.health-track.shake {
    animation: healthShake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes healthShake {
    10%, 90% { transform: translate3d(-2px, 1px, 0); }
    20%, 80% { transform: translate3d(2px, -1px, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 2px, 0); }
    40%, 60% { transform: translate3d(4px, -2px, 0); }
}

/* Low health color */
.health-fill.danger {
    background: #ff0000;
}

.timer {
    color: #fff;
    font-size: 32px;
    font-weight: bold;
    text-shadow: 2px 2px 0 #000;
    background: rgba(0,0,0,0.5);
    padding: 0 10px;
    border: 2px solid #fff;
}

/* --- HUD BOTTOM --- */
/* --- HUD BOTTOM --- */
#hud-bottom {
    display: flex;
    flex-direction: column;
align-items: center;
    pointer-events: auto; 
    margin-bottom: 100px; /* Make room for controls */
}

#autopilot-btn {
    background: #000;
    color: #fff;
    border: 2px solid #fff;
    padding: 5px 10px;
    font-family: inherit;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 2px 2px 0 #000;
    margin-bottom: 5px;
    text-align: left;
}

#autopilot-btn:hover { background: #333; }
#autopilot-btn.active {
    background: #004400;
    color: #00ff00;
    border-color: #00ff00;
}

#controls-hint { display: none; } /* Hide keyboard hint for mobile focus */

/* --- MOBILE CONTROLS --- */
#mobile-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px;
    box-sizing: border-box;
    pointer-events: none; /* Let clicks pass through gaps */
    z-index: 20;
}

/* Hide keyboard hint for mobile focus */
@media (hover: hover) and (pointer: fine) {
    #controls-hint { display: block; }
    #mobile-controls { display: none; }
    #hud-bottom { margin-bottom: 0; }
}
@media (hover: none) and (pointer: coarse) {
    #controls-hint { display: none; }
    #mobile-controls { display: flex; }
    #hud-bottom { margin-bottom: 100px; } /* Make room for controls */
}

/* --- JOYSTICK --- */
#joystick-base {
    position: relative;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    margin-bottom: 30px;
    margin-left: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

#joystick-thumb {
    position: absolute;
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transition: transform 0.05s;
}

#joystick-thumb.active {
    background: rgba(255, 255, 255, 0.5);
    border-color: #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
}

.action-area {
    pointer-events: auto;
    display: flex;
    gap: 10px;
    margin-bottom: 40px;
    margin-right: 10px;
}


.dpad-row-top {
    display: flex;
    justify-content: center;
}

.dpad-row-mid {
    display: flex;
    gap: 5px;
}



.control-btn {
    width: 75px;
    height: 65px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 28px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    transition: transform 0.05s, background 0.05s;
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95) translateY(2px);
    border-color: #fff;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.atk-btn {
    width: 90px;
    height: 90px;
    background: rgba(255, 40, 40, 0.2);
    border-color: rgba(255, 80, 80, 0.4);
    border-radius: 50%;
    font-size: 32px;
    color: rgba(255, 200, 200, 0.9);
}

.atk-btn:active {
    background: rgba(255, 40, 40, 0.5);
    border-color: #ffaaaa;
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.4);

}

.jump-btn {
    background: rgba(40, 40, 255, 0.2);
    border-color: rgba(80, 80, 255, 0.4);
    border-radius: 12px;
    font-size: 28px;
    color: rgba(200, 200, 255, 0.9);
}

.jump-btn:active {
    background: rgba(40, 40, 255, 0.5);
    border-color: #aaaaff;
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(0, 0, 255, 0.4);
}

/* --- GAME OVERLAYS --- */
#message-overlay {
    position: absolute;
    top: 30%;
    left: 0;
    width: 100%;
    text-align: center;
    pointer-events: none;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#big-text {
    font-size: 80px;
    font-weight: 900;
    color: #ffcc00;
    text-shadow: 4px 4px 0 #000, -2px -2px 0 #fff;
    font-style: italic;
    transform: scale(0);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#sub-text {
    font-size: 40px;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
    margin-top: 10px;
    opacity: 0;
    animation: slideUp 0.5s ease-out 0.3s forwards;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
    0% { transform: translateY(20px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* --- COMBO COUNTER --- */
#combo-container {
    position: absolute;
    top: 120px;
    left: 20px;
    display: none;
    flex-direction: column;
    align-items: flex-start;
    pointer-events: none;
    z-index: 40;
    transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: center left;
}

#combo-container.active {
    display: flex;
    /* Animation handled via JS transform now */
}

#combo-count {
    font-size: 60px;
    font-weight: 900;
    color: #ff4400;
    text-shadow: 3px 3px 0 #000;
    line-height: 0.8;
    font-style: italic;
}

#combo-label {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 0 #000;
    margin-left: 5px;
    font-style: italic;
}

@keyframes bump {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* --- SPEED LINES --- */
#speed-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 45; /* Below message overlay, above game */
    background: radial-gradient(circle, transparent 40%, rgba(255, 255, 255, 0.8) 150%),
                repeating-conic-gradient(transparent 0deg, transparent 5deg, rgba(200, 240, 255, 0.15) 5.5deg, transparent 6deg);
    opacity: 0;
    mix-blend-mode: screen;
    display: none;
}

#speed-lines.active {
    display: block;
    animation: speedLineAnim 0.1s infinite alternate;
}

@keyframes speedLineAnim {
    0% { transform: scale(1.0); opacity: 0.8; }
    100% { transform: scale(1.05); opacity: 0.6; }
100% { transform: scale(1.05); opacity: 0.6; }
}

/* --- DOVE TOOLS --- */
#dove-tools-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: #222;
    border: 2px solid #444;
    border-radius: 50%;
    color: #fff;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    transition: transform 0.2s, background 0.2s;
    user-select: none;
    pointer-events: auto;
}

#dove-tools-toggle:hover {
    background: #333;
    transform: scale(1.1);
}

#dove-tools-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: rgba(20, 20, 20, 0.9);
    border-left: 1px solid #444;
    box-shadow: -5px 0 15px rgba(0,0,0,0.5);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    backdrop-filter: blur(4px);
    font-family: 'Consolas', 'Monaco', monospace;
    color: #ddd;
    font-size: 12px;
    pointer-events: auto;
}

#dove-tools-panel.collapsed {
    transform: translateX(100%);
}

/* Mobile Portrait Optimization */
@media (max-width: 600px) {
    #dove-tools-panel {
        width: 100%;
        height: 50%;
        top: auto;
        bottom: 0;
        right: 0;
        border-left: none;
        border-top: 1px solid #444;
        transform: translateY(0);
    }
    
    #dove-tools-panel.collapsed {
        transform: translateY(100%);
    }
}

.dt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #252526;
    border-bottom: 1px solid #3e3e42;
}

.dt-title {
    font-weight: bold;
    color: #fff;
    letter-spacing: 1px;
}

.dt-version {
    font-size: 10px;
    color: #888;
    margin-left: 5px;
}

.dt-icon-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 18px;
    cursor: pointer;
    padding: 0 5px;
}

.dt-icon-btn:hover { color: #fff; }

.dt-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    padding-bottom: 40px; /* Extra padding for mobile touch comfort */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    touch-action: pan-y; /* Explicitly allow vertical scrolling */
}

.dt-section {
    margin-bottom: 20px;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
}

.dt-section:last-child { border-bottom: none; }

.dt-section-header {
    font-size: 11px;
    font-weight: bold;
    color: #569cd6;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.dt-row {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
}

.dt-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.dt-checkbox input { margin-right: 8px; }
.dt-label-text { color: #ccc; }

.dt-control-group {
    margin-bottom: 10px;
}

.dt-control-group label {
    display: block;
    margin-bottom: 5px;
    color: #aaa;
}

.dt-select {
    width: 100%;
    background: #3c3c3c;
    border: 1px solid #555;
    color: #fff;
    padding: 5px;
    font-family: inherit;
    font-size: 11px;
}

.dt-playback-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.dt-btn {
    flex: 1;
    background: #3c3c3c;
    border: 1px solid #555;
    color: #eee;
    padding: 5px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    transition: background 0.1s;
}

.dt-btn:hover { background: #505050; }
.dt-btn:active { background: #2a2d2e; }

.dt-btn-full {
    width: 100%;
    margin-top: 5px;
    margin-bottom: 5px;
}

.dt-btn-primary {
    background: #0e639c;
    border-color: #1177bb;
}

.dt-btn-primary:hover { background: #1177bb; }

.dt-scrubber-wrapper {
    background: #252526;
    padding: 8px;
    border-radius: 4px;
}

.dt-slider {
    width: 100%;
    margin-bottom: 5px;
    cursor: pointer;
}

.dt-time-display {
    text-align: right;
    color: #888;
    font-size: 10px;
}

.dt-list {
    margin-bottom: 10px;
}

.dt-empty-state {
    color: #666;
    font-style: italic;
    text-align: center;
    padding: 10px;
    border: 1px dashed #444;
}

/* Hitbox Item Styling (for dynamic JS generation) */
.dt-hitbox-item {
    background: #2d2d30;
    border: 1px solid #3e3e42;
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 3px;
}

.dt-hitbox-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    color: #dcdcaa;
}

.dt-field-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.dt-field-row label { 
    color: #9cdcfe; 
    width: 60px; 
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Scrubber Styles */
.dt-scrubber-control {
    display: flex;
    align-items: center;
    flex: 1;
    margin-left: 5px;
    background: #222;
    border-radius: 3px;
    padding: 1px;
}

.dt-scrubber-label {
    color: #aaa;
    font-size: 10px;
    padding: 0 4px;
    cursor: ew-resize;
    user-select: none;
    font-weight: bold;
    width: 15px;
    text-align: center;
}

.dt-scrubber-label:hover { color: #fff; background: #444; }
.dt-scrubber-label.x { color: #ff5555; }
.dt-scrubber-label.y { color: #55ff55; }
.dt-scrubber-label.z { color: #5555ff; }

.dt-input-sm {
    width: 40px;
    background: transparent;
    border: none;
    color: #fff;
    padding: 2px;
    text-align: right;
    font-family: monospace;
    font-size: 11px;
}
.dt-input-sm:focus { background: #333; outline: none; }

.dt-hitbox-item.selected {
    border-color: #dcdcaa;
    background: #3e3e42;
}
/* --- FLOATING TEXT FX --- */
.floating-text {
    position: absolute;
    color: #00ff00;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    font-size: 24px;
    text-shadow: 2px 2px 0 #000;
    pointer-events: none;
    z-index: 60;
    transform: translate(-50%, -50%);
    animation: floatUp 0.8s ease-out forwards;
}

.floating-text.perfect {
    color: #00ffff;
    font-size: 32px;
    text-shadow: 0 0 10px #00ffff;
text-shadow: 0 0 10px #00ffff;
}

.floating-text.counter {
    color: #ffaa00; /* Orange/Gold */
    font-size: 40px;
    font-style: italic;
    text-shadow: 3px 3px 0 #880000;
    animation: popInText 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popInText {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.0); opacity: 0; }

@keyframes floatUp {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    20% { transform: translate(-50%, -100%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -250%) scale(1.0); opacity: 0; }
/* --- TABS --- */
.dt-tabs {
    display: flex;
    background: #252526;
    border-bottom: 1px solid #3e3e42;
}

.dt-tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: #888;
    padding: 8px 0;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: background 0.1s, color 0.1s;
}

.dt-tab-btn:hover {
    color: #ddd;
    background: #2d2d30;
}

.dt-tab-btn.active {
    color: #fff;
    border-bottom-color: #0e639c;
    background: #1e1e1e;
}

.dt-tab-content {
    display: none;
}

.dt-tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}