:root {
    --primary-color: #0ff;
    --secondary-color: #f0f;
    --bg-color: #050510;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-color: #fff;
    --accent-color: #ffe600;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Prevent text selection during fast clicks */
}

body {
    font-family: 'Orbitron', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Background Animation */
.stars-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
    perspective: 1000px; /* Enable 3D perspective */
}

/* Retro Wave Grid */
.stars-container::after {
    content: '';
    position: absolute;
    bottom: -50%;
    left: -50%;
    width: 200%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(255, 0, 255, 0.3) 2px, transparent 2px),
        linear-gradient(90deg, rgba(255, 0, 255, 0.3) 2px, transparent 2px);
    background-size: 100px 100px;
    transform: rotateX(60deg);
    animation: gridMove 20s linear infinite;
    z-index: -1;
    opacity: 0.3;
}

@keyframes gridMove {
    0% { transform: rotateX(60deg) translateY(0); }
    100% { transform: rotateX(60deg) translateY(100px); }
}

/* CRT Scanline Effect */
body::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 10000;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    opacity: 0.6;
}

.stars, .stars2, .stars3 {
    width: 2px;
    height: 2px;
    background: transparent;
    box-shadow: 100px 200px #fff, 400px 300px #fff, 800px 100px #fff; 
    animation: animStar 50s linear infinite;
}

.stars2 {
    width: 3px;
    height: 3px;
    animation-duration: 100s;
}

.stars3 {
    width: 1px;
    height: 1px;
    animation-duration: 150s;
}

@keyframes animStar {
    from { transform: translateY(0px); }
    to { transform: translateY(-2000px); }
}

/* Game Container */
.game-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

/* Setup Screen */
#setup-screen {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 1rem;
    text-align: center;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
    z-index: 10;
    position: relative;
    overflow: hidden;
}

#setup-screen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 5px;
    background: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-color);
    opacity: 0.5;
    animation: scannerMove 3s linear infinite;
}

@keyframes scannerMove {
    0% { top: -10%; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 110%; opacity: 0; }
}

.game-title {
    font-size: 3rem;
    margin-bottom: 2rem;
    text-shadow: 0 0 10px var(--primary-color);
    color: var(--primary-color);
    position: relative;
    animation: glitchText 3s infinite;
}

@keyframes glitchText {
    0%, 90% { transform: translate(0); }
    92% { transform: translate(-3px, 3px); text-shadow: 3px -3px 0 #f0f; }
    94% { transform: translate(3px, -3px); text-shadow: -3px 3px 0 #0ff; }
    96% { transform: translate(-3px, 0); }
    98% { transform: translate(3px, 0); }
    100% { transform: translate(0); }
}

.setup-grid {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.setup-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--primary-color);
    color: #fff;
    padding: 1rem;
    border-radius: 4px;
    font-family: 'Orbitron', sans-serif;
    text-align: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    width: 100%;
}

input:focus {
    outline: none;
    box-shadow: 0 0 15px var(--primary-color);
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.02);
}

button {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 1rem 3rem;
    font-size: 1.5rem;
    font-family: 'Orbitron', sans-serif;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s;
    text-transform: uppercase;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    margin-top: 1rem;
}

button:hover {
    background: var(--primary-color);
    color: #000;
    box-shadow: 0 0 30px var(--primary-color);
    transform: translateY(-2px);
}

/* Arena */
#arena-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background-image: 
        linear-gradient(rgba(0, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
}

.vs {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.03);
    z-index: 0;
    pointer-events: none;
    font-family: sans-serif;
}

.vs-small {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-color);
}

#match-title {
    position: absolute;
    top: 20px;
    width: 100%;
    text-align: center;
    font-size: 2rem;
    text-shadow: 0 0 10px #fff;
    z-index: 5;
    pointer-events: none;
}

.arena {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Fighter Containers */
.fighter-container {
    position: absolute; /* Controlled by JS via top/left/transform */
    min-width: 150px;
    width: auto;
    height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s linear; /* Smooth movement */
    z-index: 10;
    top: 0;
    left: 0;
    padding: 0 20px;
}

/* Pulsing Fighter Aura */
.fighter-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120%;
    height: 120%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    border-radius: 20px;
    animation: auraPulse 2s infinite ease-in-out;
    z-index: -1;
}

@keyframes auraPulse {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.2; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
}

.fighter {
    font-size: 5rem;
    font-weight: 900;
    display: flex;
    flex-direction: row;
    white-space: nowrap;
    gap: 5px;
    text-shadow: 
        0 0 10px currentColor,
        0 0 20px currentColor,
        0 0 40px currentColor;
    transition: transform 0.1s;
    /* Default fighter color fallback */
    color: #fff; 
}

/* Responsive Design */
@media (max-width: 768px) {
    .setup-grid {
        flex-direction: column;
    }
    /* Transform is handled in JS renderLoop to avoid conflict */
    /* .fighter-container { transform: scale(0.7); } */ 
    
    .game-title {
        font-size: 2rem;
    }
    #match-title {
        font-size: 1.5rem;
    }
    .fighter {
        font-size: 3rem;
    }
    #setup-screen {
        padding: 1rem;
        width: 95%;
    }
    .vs {
        font-size: 5rem;
    }
    .finish-text {
        font-size: 4rem; /* Smaller for mobile */
    }
    #game-over-message {
        font-size: 2rem;
    }
    .ult-overlay {
        font-size: 2rem;
    }
}

/* HUD elements inside fighter container */
.hud {
    position: absolute;
    top: -40px;
    width: 120%;
    text-align: center;
    pointer-events: none;
}

.hp-percent {
    font-size: 1rem;
    color: #fff;
    font-weight: bold;
    margin-bottom: 2px;
}

.skill-label {
    font-size: 0.8rem;
    color: #aaa;
    margin-top: 2px;
}

/* Game Over Overlay */
#game-over-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 3rem;
    border: 2px solid var(--primary-color);
    border-radius: 1rem;
    text-align: center;
    z-index: 2000;
    box-shadow: 0 0 50px rgba(0,0,0,0.8);
}

#game-over-message {
    font-size: 3rem;
    margin-bottom: 2rem;
    color: var(--primary-color);
}

/* Health Bar Styles */
.health-bar-container {
    width: 120px;
    height: 12px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    margin: 5px auto;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.health-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #e74c3c, #c0392b);
    transition: width 0.2s ease-out;
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.7);
}

.hp-percent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 2px #000;
    pointer-events: none;
    z-index: 2;
}

/* Ultimate Meter Styles */
.ult-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}

.ult-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #f1c40f, #e67e22);
    box-shadow: 0 0 10px #f1c40f;
    transition: width 0.2s ease-out;
}

.ult-ready .ult-bar-fill {
    background: linear-gradient(90deg, #ff00cc, #3333ff);
    animation: ult-pulse 0.5s infinite alternate;
    box-shadow: 0 0 15px #ff00cc;
}

@keyframes ult-pulse {
    0% { filter: brightness(1); }
    100% { filter: brightness(1.5); }
}

.ultimate-active .game-container {
    filter: brightness(0.4) contrast(1.2);
}

.ultimate-active .fighter-container.casting-ult {
    filter: brightness(1.5) drop-shadow(0 0 20px gold);
    z-index: 1000;
}

.ult-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 20px #ff00cc;
    z-index: 2000;
    pointer-events: none;
    white-space: nowrap;
    animation: ult-text-anim 2s ease-out forwards;
}

@keyframes ult-text-anim {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    10% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); filter: blur(10px); }
}

/* Cinematic Lines for Ultimate */
.cinematic-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        90deg,
        transparent 0,
        transparent 50px,
        rgba(255, 255, 255, 0.1) 50px,
        rgba(255, 255, 255, 0.1) 52px
    );
    z-index: 900;
    pointer-events: none;
    animation: cinematic-pan 0.2s linear infinite;
    opacity: 0;
    transition: opacity 0.3s;
}

.ultimate-active .cinematic-lines {
    opacity: 1;
}

@keyframes cinematic-pan {
    0% { background-position: 0 0; }
    100% { background-position: 100px 0; }
}

/* --- Dynamic Game Elements & Animations --- */

/* Damage Text */
.damage-text {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    color: #e74c3c;
    font-weight: bold;
    text-shadow: 0 0 5px #000;
    animation: floatUp 1s ease-out forwards;
    pointer-events: none;
    white-space: nowrap;
}

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

/* Skill Popup */
.skill-popup {
    position: absolute;
    font-size: 1.5rem;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 100;
    animation: popupAnim 1.2s ease-out forwards;
}

@keyframes popupAnim {
    0% { opacity: 0; transform: scale(0.5) translateY(0); }
    20% { opacity: 1; transform: scale(1.2) translateY(-20px); }
    100% { opacity: 0; transform: scale(1) translateY(-60px); }
}

/* Skill Cast Overhead */
.skill-cast {
    /* Styles are mostly inline in JS, but adding fallback/base */
    font-family: 'Orbitron', sans-serif;
}

/* Projectiles */
.projectile {
    position: absolute;
    font-size: 2rem;
    font-weight: bold;
    color: #fff !important; /* Force white core for contrast */
    text-shadow: 
        0 0 10px var(--primary-color),
        0 0 20px var(--primary-color),
        0 0 40px var(--primary-color);
    z-index: 50;
    pointer-events: none;
    filter: brightness(2);
    animation: projectileSpin 0.5s linear infinite;
}

@keyframes projectileSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Trail Ghost */
.trail-ghost {
    position: absolute;
    font-size: 4rem; /* Match fighter size */
    font-weight: bold;
    opacity: 0.5;
    pointer-events: none;
    animation: fadeOut 0.4s linear forwards;
    z-index: 5;
}

@keyframes fadeOut {
    to { opacity: 0; transform: scale(0.9); }
}

/* Particles */
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 60;
    animation: particleExplode 0.6s ease-out forwards;
}

@keyframes particleExplode {
    0% { transform: translate(0, 0); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)); opacity: 0; }
}

/* Shockwave ASCII */
.shockwave-char {
    position: absolute;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.5rem;
    pointer-events: none;
    z-index: 55;
    animation: shockwaveMove 0.8s ease-out forwards;
}

@keyframes shockwaveMove {
    0% { transform: translate(0, 0) scale(0.5); opacity: 1; }
    100% { transform: translate(var(--sx), var(--sy)) scale(2); opacity: 0; }
}

/* Screen Flash */
.screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    opacity: 0.8;
    z-index: 9999;
    animation: flashFade 0.5s ease-out forwards;
    pointer-events: none;
}

@keyframes flashFade {
    to { opacity: 0; }
}

/* Fighter States */
.low-hp-glitch {
    animation: glitch 0.3s infinite;
}

@keyframes glitch {
    0% { transform: translate(0); }
    20% { transform: translate(-2px, 2px); }
    40% { transform: translate(-2px, -2px); }
    60% { transform: translate(2px, 2px); }
    80% { transform: translate(2px, -2px); }
    100% { transform: translate(0); }
}

.damaged .fighter {
    color: #ff4444; /* Tint red when damaged container */
}

/* Impact Sensation Enhancements */
.impact-flash {
    animation: chromaticFlash 0.2s ease-out forwards;
}

@keyframes chromaticFlash {
    0% { filter: contrast(2) brightness(1.5) drop-shadow(2px 0 0 #f0f) drop-shadow(-2px 0 0 #0ff); }
    100% { filter: contrast(1) brightness(1); }
}

.impact-frame {
    animation: whiteFlash 0.1s steps(2) forwards;
}

@keyframes whiteFlash {
    0% { filter: brightness(10) contrast(10); }
    100% { filter: brightness(1) contrast(1); }
}

.slow-mo {
    transition: filter 0.5s ease;
    filter: saturate(0.5) contrast(1.2) brightness(0.8);
}

.finish-text {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(5);
    font-size: 8rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 50px #f00;
    z-index: 5000;
    opacity: 0;
    pointer-events: none;
    animation: finishAnim 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes finishAnim {
    0% { transform: translate(-50%, -50%) scale(10); opacity: 0; filter: blur(20px); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; filter: blur(0); }
}

/* Fighter knockback/squash handled by JS transform */

/* Hit Reactions */
.hit {
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
    filter: brightness(2) sepia(1) hue-rotate(-50deg);
}

.critical-hit {
    animation: shakeHard 0.5s cubic-bezier(.36,.07,.19,.97) both;
    filter: brightness(3) contrast(1.5);
    transform: scale(1.2) !important;
}

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

@keyframes shakeHard {
    0% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(-10px, -10px) scale(1.2); }
    50% { transform: translate(10px, 10px) scale(1.1); }
    75% { transform: translate(-10px, 10px) scale(1.2); }
    100% { transform: translate(0, 0) scale(1); }
}

/* Combat Actions */
.defending .fighter {
    filter: drop-shadow(0 0 10px #3498db);
    transform: scale(0.9);
}

.fast-move {
    filter: blur(2px);
    opacity: 0.8;
}

.feint {
    opacity: 0.5;
}

.anticipate .fighter {
    transform: scale(0.8) rotate(-10deg);
    filter: brightness(0.7);
    transition: transform 0.2s;
}

.morph-attack .fighter {
    transform: scale(1.3) rotate(15deg);
    filter: brightness(1.3);
    transition: transform 0.1s;
}

.block-flash {
    animation: shieldFlash 0.3s ease-out;
}

@keyframes shieldFlash {
    0% { filter: drop-shadow(0 0 2px #fff); }
    50% { filter: drop-shadow(0 0 30px #3498db); }
    100% { filter: drop-shadow(0 0 2px #fff); }
}

.fast-recoil {
    transition: transform 0.1s ease-out;
}

/* Elemental Interactions */
.elemental-advantage {
    animation: advantagePulse 0.5s ease-in-out;
    box-shadow: 0 0 30px gold;
}

.elemental-weakness {
    animation: weaknessShake 0.5s ease-in-out;
    opacity: 0.7;
}

@keyframes advantagePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); filter: brightness(1.5); }
    100% { transform: scale(1); }
}

@keyframes weaknessShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Misc Skill Effects */
.skill-void { filter: grayscale(1) invert(1); }
.skill-frozen { filter: brightness(1.5) hue-rotate(180deg); }
.skill-stunned { animation: shake 0.5s infinite; }
.skill-burn { filter: sepia(1) hue-rotate(-50deg) saturate(3); }

/* Screen Shake Animation */
@keyframes screen-shake {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-5px, 5px); }
    50% { transform: translate(5px, -5px); }
    75% { transform: translate(-5px, -5px); }
    100% { transform: translate(0, 0); }
}

/* Speed Lines for Fast Moves */
.speeding {
    background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(255,255,255,0.05) 50%, rgba(0,0,0,0) 100%);
    background-size: 200% 100%;
    animation: speedBg 0.2s linear infinite;
}

@keyframes speedBg {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

/* Animations for advanced particles */
@keyframes advanced-particle {
    0% { 
        transform: translate(0, 0) scale(1); 
        opacity: 1; 
    }
    100% { 
        transform: translate(calc(cos(var(--angle)) * var(--velocity)), calc(sin(var(--angle)) * var(--velocity))) scale(0); 
        opacity: 0; 
    }
}

@keyframes energy-wave {
    0% { transform: scale(0.5); opacity: 1; border-width: 5px; }
    100% { transform: scale(4); opacity: 0; border-width: 0px; }
}

@keyframes elemental-particle {
    to { transform: translate(var(--dx, 0), var(--dy, -50px)); opacity: 0; }
}