* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Desktop: allow scrolling but optimize for one screen */
html, body {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    /* Background will be set dynamically by JavaScript */
    min-height: 100vh;
    color: #fff;
    overflow-x: hidden;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: contain;
    position: relative;
    transition: background 2s ease-in-out; /* Smooth background transitions */
    /* Very shallow perspective for subtle depth only */
    perspective: 2000px;
    perspective-origin: 50% 50%;
}

/* Random background color schemes */
.body-theme-purple {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

.body-theme-blue {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 50%, #667eea 100%);
}

.body-theme-red {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 50%, #f093fb 100%);
}

.body-theme-green {
    background: linear-gradient(135deg, #30cfd0 0%, #330867 50%, #4facfe 100%);
}

.body-theme-orange {
    background: linear-gradient(135deg, #fad961 0%, #f76b1c 50%, #fa709a 100%);
}

.body-theme-dark {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 50%, #7f8c8d 100%);
}

/* Animated background aura/smoke effects */
body::before,
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.3;
}

/* Aura colors will be set dynamically based on theme */
body::before {
    animation: auraMove1 20s ease-in-out infinite alternate;
}

body::after {
    animation: auraMove2 25s ease-in-out infinite alternate-reverse;
}

/* Purple theme aura */
.body-theme-purple::before {
    background: radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(240, 147, 251, 0.3) 0%, transparent 50%);
}

.body-theme-purple::after {
    background: radial-gradient(circle at 60% 30%, rgba(240, 147, 251, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 30% 70%, rgba(102, 126, 234, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 90% 50%, rgba(118, 75, 162, 0.4) 0%, transparent 50%);
}

/* Blue theme aura */
.body-theme-blue::before {
    background: radial-gradient(circle at 20% 50%, rgba(79, 172, 254, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(0, 242, 254, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(102, 126, 234, 0.3) 0%, transparent 50%);
}

.body-theme-blue::after {
    background: radial-gradient(circle at 60% 30%, rgba(102, 126, 234, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 30% 70%, rgba(79, 172, 254, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 90% 50%, rgba(0, 242, 254, 0.4) 0%, transparent 50%);
}

/* Red theme aura */
.body-theme-red::before {
    background: radial-gradient(circle at 20% 50%, rgba(250, 112, 154, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(254, 225, 64, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(240, 147, 251, 0.3) 0%, transparent 50%);
}

.body-theme-red::after {
    background: radial-gradient(circle at 60% 30%, rgba(240, 147, 251, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 30% 70%, rgba(250, 112, 154, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 90% 50%, rgba(254, 225, 64, 0.4) 0%, transparent 50%);
}

/* Green theme aura */
.body-theme-green::before {
    background: radial-gradient(circle at 20% 50%, rgba(48, 207, 208, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(51, 8, 103, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(79, 172, 254, 0.3) 0%, transparent 50%);
}

.body-theme-green::after {
    background: radial-gradient(circle at 60% 30%, rgba(79, 172, 254, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 30% 70%, rgba(48, 207, 208, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 90% 50%, rgba(51, 8, 103, 0.4) 0%, transparent 50%);
}

/* Orange theme aura */
.body-theme-orange::before {
    background: radial-gradient(circle at 20% 50%, rgba(250, 217, 97, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(247, 107, 28, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(250, 112, 154, 0.3) 0%, transparent 50%);
}

.body-theme-orange::after {
    background: radial-gradient(circle at 60% 30%, rgba(250, 112, 154, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 30% 70%, rgba(250, 217, 97, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 90% 50%, rgba(247, 107, 28, 0.4) 0%, transparent 50%);
}

/* Dark theme aura */
.body-theme-dark::before {
    background: radial-gradient(circle at 20% 50%, rgba(44, 62, 80, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(52, 73, 94, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 40% 20%, rgba(127, 140, 141, 0.3) 0%, transparent 50%);
}

.body-theme-dark::after {
    background: radial-gradient(circle at 60% 30%, rgba(127, 140, 141, 0.4) 0%, transparent 50%),
                radial-gradient(circle at 30% 70%, rgba(44, 62, 80, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 90% 50%, rgba(52, 73, 94, 0.4) 0%, transparent 50%);
}

@keyframes auraMove1 {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    50% {
        transform: translate(10%, -5%) scale(1.1);
        opacity: 0.4;
    }
    100% {
        transform: translate(-5%, 10%) scale(0.9);
        opacity: 0.3;
    }
}

@keyframes auraMove2 {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    50% {
        transform: translate(-8%, 8%) scale(1.15);
        opacity: 0.4;
    }
    100% {
        transform: translate(12%, -8%) scale(0.95);
        opacity: 0.3;
    }
}

/* Floating particles/smoke effects */
.background-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    filter: blur(20px);
    opacity: 0.4;
}

.particle-1 {
    width: 200px;
    height: 200px;
    top: 10%;
    left: 10%;
    animation: float1 15s ease-in-out infinite;
}

.particle-2 {
    width: 150px;
    height: 150px;
    top: 60%;
    left: 20%;
    animation: float2 18s ease-in-out infinite;
}

.particle-3 {
    width: 180px;
    height: 180px;
    top: 30%;
    right: 15%;
    animation: float3 20s ease-in-out infinite;
}

.particle-4 {
    width: 120px;
    height: 120px;
    bottom: 20%;
    right: 25%;
    animation: float4 16s ease-in-out infinite;
}

.particle-5 {
    width: 160px;
    height: 160px;
    top: 50%;
    left: 50%;
    animation: float5 22s ease-in-out infinite;
}

.particle-6 {
    width: 140px;
    height: 140px;
    bottom: 30%;
    left: 30%;
    animation: float6 17s ease-in-out infinite;
}

@keyframes float1 {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    33% {
        transform: translate(30px, -40px) scale(1.2);
        opacity: 0.5;
    }
    66% {
        transform: translate(-20px, 30px) scale(0.9);
        opacity: 0.4;
    }
}

@keyframes float2 {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.4;
    }
    33% {
        transform: translate(-25px, 35px) scale(1.1);
        opacity: 0.5;
    }
    66% {
        transform: translate(40px, -25px) scale(0.95);
        opacity: 0.3;
    }
}

@keyframes float3 {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    33% {
        transform: translate(35px, 25px) scale(1.15);
        opacity: 0.5;
    }
    66% {
        transform: translate(-30px, -35px) scale(0.9);
        opacity: 0.4;
    }
}

@keyframes float4 {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.4;
    }
    33% {
        transform: translate(-35px, -30px) scale(1.1);
        opacity: 0.5;
    }
    66% {
        transform: translate(25px, 40px) scale(0.95);
        opacity: 0.3;
    }
}

@keyframes float5 {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    33% {
        transform: translate(40px, -30px) scale(1.2);
        opacity: 0.5;
    }
    66% {
        transform: translate(-35px, 35px) scale(0.9);
        opacity: 0.4;
    }
}

@keyframes float6 {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.4;
    }
    33% {
        transform: translate(-30px, 40px) scale(1.1);
        opacity: 0.5;
    }
    66% {
        transform: translate(30px, -25px) scale(0.95);
        opacity: 0.3;
    }
}

/* Reduce particle effects on mobile for performance */
@media (max-width: 768px) {
    .particle {
        opacity: 0.2; /* More subtle on mobile */
        filter: blur(15px);
    }
    
    body::before,
    body::after {
        opacity: 0.2; /* More subtle aura on mobile */
    }
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1; /* Above background effects */
    /* Very subtle tilt for esports-style flat layout */
    transform: rotateX(5deg);
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
}

.game-header {
    text-align: center;
    margin-bottom: 10px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    flex-shrink: 0; /* Don't shrink header */
    border: 1px solid rgba(255, 255, 255, 0.1);
    /* Flat esports-style depth */
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transform: translateZ(0);
}

.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    font-size: 1.2em;
    flex-wrap: wrap;
}

.currency-display {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-left: auto;
    margin-right: 10px;
}

.currency-item {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
}

.currency-icon {
    font-size: 1.1em;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.currency-value {
    font-weight: bold;
    color: #ffd700;
    font-size: 1em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.currency-item:first-child .currency-value {
    color: #ffd700; /* Gold color */
}

.currency-item:last-child .currency-value {
    color: #9b59b6; /* Purple/magical color for Arcana */
}

.settings-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s;
    color: #fff;
    touch-action: manipulation;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.settings-btn:active {
    transform: scale(0.95);
}

.turn-indicator {
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.player-area {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    padding: 20px;
    margin: 10px 0;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0; /* Don't shrink player areas */
    position: relative;
    z-index: 1; /* Above background effects */
    /* Flat esports-style depth with shadows and glow */
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(102, 126, 234, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    /* Add padding to prevent character icon from overlapping content */
    padding-right: 160px; /* Space for character icon on right side (player 1) */
    transform: translateZ(0); /* Flat layering */
}

/* Opponent area needs padding on left for character icon */
.opponent-area {
    padding-left: 160px; /* Space for character icon on left side (player 2) */
    padding-right: 20px; /* Reset right padding for opponent */
}

/* Opponent area - no rotation so monster fields face each other */

.player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    position: relative;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-area {
    position: relative;
}

.character-icon {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.4);
    overflow: visible; /* Changed to visible to show chat bubble */
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    position: fixed;
    z-index: 1;
    pointer-events: none;
    transition: transform 0.3s ease;
}

/* Avatar shake animation when fort is attacked */
.character-icon.avatar-shake {
    animation: avatarShake 0.5s ease-in-out;
}

@keyframes avatarShake {
    0%, 100% {
        transform: translate(0, 0) rotate(0deg);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translate(-8px, -8px) rotate(-5deg);
    }
    20%, 40%, 60%, 80% {
        transform: translate(8px, 8px) rotate(5deg);
    }
}

/* Chat bubble for avatar */
.chat-bubble {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 71, 87, 0.95);
    color: #fff;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.9em;
    font-weight: bold;
    white-space: nowrap;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 0 20px rgba(255, 71, 87, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.3);
    z-index: 1000;
    pointer-events: none;
    animation: chatBubblePop 0.5s ease-out;
}

/* Speech bubble tail */
.chat-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgba(255, 71, 87, 0.95);
}

@keyframes chatBubblePop {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px) scale(0.8);
    }
    50% {
        transform: translateX(-50%) translateY(-5px) scale(1.1);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

/* Player 1 avatar - bottom right corner, but avoid HP area */
.player-area.player-area .character-icon {
    bottom: 10px;
    right: 10px;
    /* Position it lower to avoid overlapping with player-header/HP area */
    /* The HP is in the player-header at the top of the player area */
}

/* Player 2 (opponent) avatar - top left corner, but avoid HP area */
.opponent-area .character-icon {
    top: 60px; /* Move down from top to avoid player-header with HP */
    left: 10px;
}

.character-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.character-icon-placeholder {
    font-size: 4em;
    color: rgba(255, 255, 255, 0.6);
}

.player-name {
    font-size: 1.5em;
    font-weight: bold;
}

.player-stats {
    display: flex;
    gap: 20px;
}

.stat {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-label {
    font-weight: bold;
}

.stat-value {
    font-size: 1.2em;
    color: #ffd700;
}

.fort-hp {
    transition: all 0.3s;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 1.4em;
    color: #ff4757;
    text-shadow: 
        0 0 10px rgba(255, 71, 87, 0.8),
        0 0 20px rgba(255, 71, 87, 0.5),
        0 2px 5px rgba(0, 0, 0, 0.8);
    position: relative;
    padding: 8px 15px;
    border: 2px solid rgba(255, 71, 87, 0.6);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.7) 0%, rgba(20, 0, 0, 0.8) 100%);
    box-shadow: 
        inset 0 0 20px rgba(255, 71, 87, 0.2),
        0 0 15px rgba(255, 71, 87, 0.4),
        0 2px 10px rgba(0, 0, 0, 0.5);
    display: inline-block;
    min-width: 60px;
    text-align: center;
}

/* Progress bar for HP - using parent container */
.player-stats {
    position: relative;
}

.player-stats::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, rgba(255, 71, 87, 0.3) 0%, rgba(255, 71, 87, 0.1) 100%);
    border-radius: 2px;
    pointer-events: none;
}

/* HP Progress bar for Player 1 (red) */
.player-area .fort-hp::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: var(--hp-percentage, 100%);
    height: 4px;
    background: linear-gradient(90deg, #ff4757 0%, #ff6b6b 50%, #ff4757 100%);
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(255, 71, 87, 0.8);
    transition: width 0.5s ease;
    animation: pulseGlow 2s ease-in-out infinite;
}

/* HP Progress bar for Player 2 (blue) */
.opponent-area .fort-hp::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: var(--hp-percentage, 100%);
    height: 4px;
    background: linear-gradient(90deg, #4facfe 0%, #00f2fe 50%, #4facfe 100%);
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(79, 172, 254, 0.8);
    transition: width 0.5s ease;
    animation: pulseGlowBlue 2s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 10px rgba(255, 71, 87, 0.8);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 71, 87, 1), 0 0 30px rgba(255, 71, 87, 0.6);
    }
}

@keyframes pulseGlowBlue {
    0%, 100% {
        box-shadow: 0 0 10px rgba(79, 172, 254, 0.8);
    }
    50% {
        box-shadow: 0 0 20px rgba(79, 172, 254, 1), 0 0 30px rgba(79, 172, 254, 0.6);
    }
}

/* Player 2 HP (blue theme) */
.opponent-area .fort-hp {
    color: #4facfe;
    border-color: rgba(79, 172, 254, 0.6);
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.7) 0%, rgba(0, 10, 30, 0.8) 100%);
    box-shadow: 
        inset 0 0 20px rgba(79, 172, 254, 0.2),
        0 0 15px rgba(79, 172, 254, 0.4),
        0 2px 10px rgba(0, 0, 0, 0.5);
    text-shadow: 
        0 0 10px rgba(79, 172, 254, 0.8),
        0 0 20px rgba(79, 172, 254, 0.5),
        0 2px 5px rgba(0, 0, 0, 0.8);
}

.fort-hp[style*="cursor: pointer"] {
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.8);
}

.fort-hp[style*="cursor: pointer"]:hover {
    transform: scale(1.1);
    color: #ff4757 !important;
}

.monster-field {
    min-height: 200px;
    margin: 15px 0;
    padding: 15px;
    /* Clean esports-style field with subtle depth */
    background: 
        /* Subtle scanline overlay */
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 255, 255, 0.02) 2px,
            rgba(0, 255, 255, 0.02) 4px
        ),
        /* Subtle grid lines */
        linear-gradient(rgba(0, 200, 255, 0.15) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 200, 255, 0.15) 1px, transparent 1px),
        /* Dark base */
        linear-gradient(135deg, rgba(0, 0, 20, 0.85) 0%, rgba(0, 10, 30, 0.9) 100%);
    background-size: 100% 100%, 20px 20px, 20px 20px, 100% 100%;
    border-radius: 10px;
    border: 1px solid rgba(0, 200, 255, 0.3);
    /* Flat depth with subtle shadows and glow */
    box-shadow: 
        inset 0 0 30px rgba(0, 200, 255, 0.1),
        0 2px 10px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(0, 200, 255, 0.2);
    position: relative;
    overflow: hidden;
    transform: translateZ(0); /* Flat layering */
}

/* Animated scanline effect */
.monster-field::after {
    content: '';
    position: absolute;
    top: -100%;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(0, 255, 255, 0.1) 50%,
        transparent 100%
    );
    animation: scanline 3s linear infinite;
    pointer-events: none;
    z-index: 2;
}

@keyframes scanline {
    0% {
        top: -100%;
    }
    100% {
        top: 100%;
    }
}

/* Add a subtle glow effect to the field */
.monster-field::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, rgba(102, 126, 234, 0.1) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.monster-field > * {
    position: relative;
    z-index: 1;
}

.monster-slots {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-top: 10px;
    position: relative;
    z-index: 1;
}

.monster-card {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.8) 0%, rgba(118, 75, 162, 0.9) 100%);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    touch-action: manipulation;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        0 0 10px rgba(102, 126, 234, 0.3);
    backdrop-filter: blur(5px);
    /* Cards stay front-facing with minimal rotation */
    transform: rotateX(-5deg);
    transform-style: preserve-3d;
    /* Subtle depth with shadows instead of heavy 3D */
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        0 0 10px rgba(102, 126, 234, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Card summon animation - subtle scale and fade */
.monster-card.card-summoning {
    animation: cardSummon 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    /* Ensure card is visible during and after animation */
    visibility: visible !important;
    display: flex !important;
}

@keyframes cardSummon {
    0% {
        transform: rotateX(-5deg) scale(0.8);
        opacity: 0.5;
    }
    100% {
        transform: rotateX(-5deg) scale(1);
        opacity: 1;
    }
}

/* Remove animation class after it completes */
.monster-card.card-summoning {
    animation-fill-mode: forwards;
}

/* Ensure monster cards are always visible */
.monster-card:not(.empty) {
    visibility: visible !important;
    display: flex !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 2 !important;
}

/* Ensure monster slots container doesn't hide cards */
.monster-slots {
    position: relative;
    z-index: 1;
    display: grid !important;
    visibility: visible !important;
}

/* Subtle slot highlight effect for card summon - no full-screen flash */
.monster-card.slot-highlight {
    animation: slotHighlight 0.6s ease-out forwards;
}

@keyframes slotHighlight {
    0% {
        box-shadow: 
            0 0 0 rgba(102, 126, 234, 0),
            0 0 0 rgba(255, 215, 0, 0),
            inset 0 0 0 rgba(102, 126, 234, 0);
        border-color: rgba(255, 255, 255, 0.4);
    }
    50% {
        box-shadow: 
            0 0 20px rgba(102, 126, 234, 0.8),
            0 0 30px rgba(255, 215, 0, 0.6),
            inset 0 0 15px rgba(102, 126, 234, 0.4);
        border-color: rgba(255, 215, 0, 0.8);
    }
    100% {
        box-shadow: 
            0 4px 15px rgba(0, 0, 0, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.2),
            0 0 10px rgba(102, 126, 234, 0.3),
            0 2px 8px rgba(0, 0, 0, 0.3);
        border-color: rgba(255, 255, 255, 0.4);
    }
}

/* Add a subtle inner glow */
.monster-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at top, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    pointer-events: none;
    border-radius: 10px;
}

.monster-image {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.monster-card:hover {
    transform: rotateX(-5deg) translateY(-3px) scale(1.01);
    box-shadow: 
        0 6px 20px rgba(255, 255, 255, 0.3),
        0 0 15px rgba(255, 215, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.4);
    border-color: #ffd700;
    z-index: 10;
}

.monster-card.empty {
    background: 
        /* Grid pattern for empty slots */
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        /* Base */
        rgba(0, 0, 0, 0.3);
    background-size: 15px 15px, 15px 15px, 100% 100%;
    border: 2px dashed rgba(255, 255, 255, 0.25);
    cursor: default;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.3),
        0 2px 5px rgba(0, 0, 0, 0.2);
}

.monster-card.empty:hover {
    transform: none;
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.3),
        0 2px 5px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    background: 
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        rgba(0, 0, 0, 0.35);
    background-size: 15px 15px, 15px 15px, 100% 100%;
}

.monster-card.empty::before {
    display: none; /* Remove glow effect for empty slots */
}

.monster-name {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 5px;
    text-align: center;
}

.monster-stats {
    display: flex;
    justify-content: space-around;
    font-size: 0.9em;
    margin: 5px 0;
}

.monster-stat {
    text-align: center;
}

.monster-stat-label {
    font-size: 0.8em;
    opacity: 0.8;
}

.monster-stat-value {
    font-weight: bold;
    font-size: 1.1em;
}

.monster-level {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.5);
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.8em;
}

.monster-equipment {
    font-size: 0.75em;
    margin-top: 5px;
    opacity: 0.9;
}

.spell-trap-zone {
    min-height: 100px;
    min-width: 300px;
    flex: 1;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    display: flex;
    gap: 10px;
    flex-wrap: wrap; /* Wrap on desktop */
    flex-direction: row; /* Explicit row direction */
}

.empty-slot {
    background: rgba(0, 0, 0, 0.3) !important;
    border: 2px dashed rgba(255, 255, 255, 0.2) !important;
    min-width: 80px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
}

.spell-card {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 100px;
    text-align: center;
    color: #ffffff;
}

.spell-card.trap-card {
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    border-color: #5f3dc4;
}

.spell-card .card-name {
    color: #ffffff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8), 0 0 4px rgba(0, 0, 0, 0.5);
}

.spell-card {
    /* Flat front-facing spell cards */
    transform: translateZ(0);
    transform-style: flat;
}

.spell-card:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 3px 12px rgba(255, 255, 255, 0.25),
        0 1px 5px rgba(0, 0, 0, 0.3);
}

.zone-label {
    font-size: 0.9em;
    opacity: 0.7;
    margin-bottom: 10px;
    text-align: center;
}

.game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 10px 0;
    gap: 5px;
    flex-shrink: 0; /* Don't shrink center area */
}

.battle-log-toggle {
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: #fff;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
}

.battle-log-toggle:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.battle-zone {
    width: 100%;
    max-width: 600px;
    min-height: 200px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
}

.spell-trap-row {
    display: flex;
    gap: 10px;
    margin: 15px 0;
    align-items: flex-start;
}

.graveyard {
    min-width: 100px;
    min-height: 100px;
    padding: 10px;
    transform: translateZ(0);
    /* Flat esports-style depth */
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    border: 2px solid rgba(139, 0, 0, 0.5);
    flex-shrink: 0;
}

.battle-log {
    height: 100%;
}

.log-header {
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
}

.log-content {
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.9em;
    line-height: 1.6;
}

.log-entry {
    margin: 5px 0;
    padding: 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
}

.bottom-panel {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    /* Flat esports-style depth */
    box-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.4),
        0 0 15px rgba(102, 126, 234, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transform: translateZ(0);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    flex-shrink: 0; /* Don't shrink bottom panel */
    overflow: hidden; /* Prevent overflow */
}

.hand-container {
    flex: 1;
    transform: translateZ(0);
}

.hand-label {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1.1em;
    transform: translateZ(0);
}

.hand {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 150px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.hand-card {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    /* Flat front-facing cards */
    transform: translateZ(0);
    transform-style: flat;
    transition: all 0.3s;
    min-width: 120px;
    max-width: 150px;
    text-align: center;
    position: relative;
    overflow: hidden;
    color: #ffffff;
    touch-action: manipulation;
}

.card-image {
    width: 100%;
    height: auto;
    max-height: 150px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.hand-card.monster .card-image {
    max-height: 120px;
}

.hand-card.spell .card-image {
    max-height: 100px;
}

.hand-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 
        0 4px 15px rgba(255, 255, 255, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

.hand-card.monster {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.hand-card.spell {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.hand-card.trap {
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    border-color: #5f3dc4;
}

.card-cost {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.6);
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: bold;
    color: #ffd700;
}

.card-name {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 1em;
    color: #ffffff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8), 0 0 4px rgba(0, 0, 0, 0.5);
}

.card-stats {
    font-size: 0.85em;
    margin-top: 5px;
    color: #ffffff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8), 0 0 3px rgba(0, 0, 0, 0.5);
    line-height: 1.4;
}

.action-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 200px;
    transform: translateZ(0);
}

.action-panel .btn {
    /* Flat esports-style buttons */
    transform: translateZ(0);
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.action-panel .btn:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 4px 10px rgba(0, 0, 0, 0.4),
        0 0 10px rgba(102, 126, 234, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    color: #fff;
    touch-action: manipulation;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(240, 147, 251, 0.5);
}

.btn-secondary:active {
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(240, 147, 251, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.upgrade-options {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 10px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 10000; /* Very high z-index to ensure visibility */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85); /* Darker for better visibility */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Disable backdrop-filter on mobile for performance */
@media (min-width: 769px) {
    .modal {
        backdrop-filter: blur(5px);
    }
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 5% auto;
    padding: 30px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.win-modal {
    text-align: center;
}

/* Yu-Gi-Oh style defeat screen */
.defeat-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.5s ease-in;
    pointer-events: none;
}

.defeat-screen.show {
    opacity: 1;
    pointer-events: all;
}

.defeat-screen.fade-out {
    opacity: 0;
    transition: opacity 1.5s ease-out;
}

.defeat-face-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
}

.defeat-face {
    width: 400px;
    height: 400px;
    object-fit: cover;
    border-radius: 20px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    box-shadow: 
        0 0 50px rgba(255, 71, 87, 0.8),
        0 0 100px rgba(255, 71, 87, 0.5),
        inset 0 0 30px rgba(0, 0, 0, 0.5);
    animation: faceAppear 0.8s ease-out;
    transform: scale(0.8);
}

.defeat-screen.show .defeat-face {
    transform: scale(1);
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.defeat-message {
    font-size: 4em;
    font-weight: bold;
    color: #fff;
    text-shadow: 
        0 0 20px rgba(255, 71, 87, 1),
        0 0 40px rgba(255, 71, 87, 0.8),
        0 0 60px rgba(255, 71, 87, 0.6),
        0 4px 10px rgba(0, 0, 0, 0.8);
    font-family: 'Orbitron', monospace;
    letter-spacing: 8px;
    animation: messageAppear 1s ease-out 0.3s both;
    text-transform: uppercase;
}

@keyframes faceAppear {
    0% {
        opacity: 0;
        transform: scale(0.5) translateY(50px);
        filter: blur(20px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
        filter: blur(0);
    }
}

@keyframes messageAppear {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.8);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Mobile adjustments for defeat screen */
@media (max-width: 768px) {
    .defeat-face {
        width: 250px;
        height: 250px;
    }
    
    .defeat-message {
        font-size: 2.5em;
        letter-spacing: 4px;
    }
}

.close {
    color: #fff;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: 10px;
}

.close:hover {
    color: #ffd700;
}

#winTitle {
    font-size: 2.5em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#winMessage {
    font-size: 1.3em;
    margin-bottom: 30px;
}

/* Battle Animations */
@keyframes damageFloat {
    0% {
        transform: translateY(0) scale(1);
        opacity: 0.7;
    }
    100% {
        transform: translateY(-30px) scale(1.2);
        opacity: 0;
    }
}

.damage-effect {
    animation: damageFloat 1s ease-out forwards;
}

.monster-card.attacking {
    animation: attackPulse 0.3s ease;
    /* Subtle highlight instead of flash */
    box-shadow: 
        0 0 10px rgba(255, 215, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 215, 0, 0.6);
}

.monster-card.taking-damage {
    animation: damageShake 0.3s ease;
    /* Subtle red border highlight */
    border-color: rgba(255, 71, 87, 0.6);
    box-shadow: 
        0 0 8px rgba(255, 71, 87, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.3);
}

.monster-card.destroyed {
    animation: destroyAnimation 0.5s ease forwards;
}

.fort-hp.fort-hit {
    animation: fortHit 0.8s ease;
}

.card-played {
    animation: cardPlayAnimation 0.3s ease;
    /* Subtle animation - no flashing */
}

@keyframes cardPlayAnimation {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes attackPulse {
    0%, 100% {
        transform: rotateX(-5deg) scale(1);
    }
    50% {
        transform: rotateX(-5deg) scale(1.05);
    }
}

@keyframes damageShake {
    0%, 100% {
        transform: rotateX(-5deg) translateX(0);
    }
    25% {
        transform: rotateX(-5deg) translateX(-3px);
    }
    75% {
        transform: rotateX(-5deg) translateX(3px);
    }
}

@keyframes destroyAnimation {
    0% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: scale(0) rotate(360deg);
    }
}

@keyframes fortHit {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
        color: #ff4757;
    }
}

@keyframes cardPlayAnimation {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
}

.win-animation {
    animation: winPulse 0.5s ease;
}

@keyframes winPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* Battle Intro Screen - Overlay on game */
.battle-intro-modal {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(3px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

/* Hide audio element */
#introVoiceAudio {
    display: none;
}

.battle-intro-content {
    text-align: center;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.battle-intro-title {
    font-size: 4em;
    font-weight: 900;
    color: #ffd700;
    text-shadow: 
        0 0 10px rgba(255, 215, 0, 0.8),
        0 0 20px rgba(255, 215, 0, 0.6),
        0 0 30px rgba(255, 215, 0, 0.4),
        4px 4px 0px rgba(0, 0, 0, 0.8);
    letter-spacing: 8px;
    margin-bottom: 30px;
    animation: titleSlideIn 0.8s ease-out;
    transform: translateY(-100px);
    opacity: 0;
}

.battle-intro-subtitle {
    font-size: 1.5em;
    color: #ffffff;
    text-shadow: 
        0 0 10px rgba(255, 255, 255, 0.5),
        2px 2px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 50px;
    animation: subtitleSlideIn 2.5s ease-in-out 0.5s forwards;
    opacity: 0;
    line-height: 1.4;
    white-space: nowrap;
    position: absolute;
    left: 50%;
    transform: translateX(calc(50vw + 100%));
}

.battle-intro-narrator {
    font-size: 1.8em;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 
        0 0 10px rgba(255, 255, 255, 0.6),
        0 0 20px rgba(255, 255, 255, 0.4),
        2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 3px;
    animation: narratorFadeIn 0.6s ease-out 1s forwards, narratorFadeOut 0.6s ease-out 2.5s forwards;
    opacity: 0;
    font-style: italic;
    text-align: center;
    max-width: 90%;
    margin: 20px 0;
    line-height: 1.4;
}

.battle-intro-commence {
    font-size: 5em;
    font-weight: 700;
    color: #ffd700;
    text-shadow: 
        0 0 15px rgba(255, 215, 0, 0.6),
        0 0 30px rgba(255, 215, 0, 0.4),
        3px 3px 0px rgba(0, 0, 0, 0.8);
    letter-spacing: 10px;
    animation: commenceFadeIn 0.8s ease-out 2.8s forwards;
    opacity: 0;
    font-style: italic;
}

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

@keyframes subtitleSlideIn {
    0% {
        opacity: 0;
        transform: translateX(calc(50vw + 100%));
    }
    20% {
        opacity: 1;
    }
    50% {
        opacity: 1;
        transform: translateX(-50%);
    }
    80% {
        opacity: 1;
        transform: translateX(-50%);
    }
    100% {
        opacity: 0;
        transform: translateX(calc(-50vw - 100%));
    }
}

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

@keyframes narratorFadeOut {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}

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

/* Mobile adjustments for battle intro */
@media (max-width: 768px) {
    /* Modal optimizations for mobile */
    .modal {
        background-color: rgba(0, 0, 0, 0.9); /* Even darker on mobile */
    }
    
    .modal-content {
        margin: 10% auto;
        padding: 25px 20px;
        width: 95%;
        max-width: none;
        border-radius: 12px;
    }
    
    .modal-content h2 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }
    
    .modal-content p {
        font-size: 1em;
        margin: 15px 0;
    }
    
    .modal-content .btn {
        font-size: 1.2em;
        padding: 18px 20px;
        min-height: 60px; /* Larger touch target */
        margin-bottom: 15px;
        border-radius: 10px;
        font-weight: bold;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.3);
        touch-action: manipulation;
    }
    
    /* Ensure all buttons are touch-friendly on mobile */
    .btn {
        min-height: 48px;
        padding: 12px 20px;
        font-size: 1em;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.2);
    }
    
    /* Disable hover effects on mobile (they can stick) */
    .btn:hover {
        transform: none;
    }
    
    .hand-card:hover {
        transform: none;
    }
    
    .battle-intro-title {
        font-size: 2.5em;
        letter-spacing: 4px;
        margin-bottom: 20px;
    }

    .battle-intro-subtitle {
        font-size: 1.2em;
        margin-bottom: 30px;
    }

    .battle-intro-narrator {
        font-size: 1.4em;
        letter-spacing: 2px;
    }

    .battle-intro-commence {
        font-size: 3em;
        letter-spacing: 6px;
    }
}

@media (max-width: 480px) {
    .battle-intro-title {
        font-size: 2em;
        letter-spacing: 3px;
    }

    .battle-intro-subtitle {
        font-size: 1em;
    }

    .battle-intro-narrator {
        font-size: 1.2em;
        letter-spacing: 1px;
    }

    .battle-intro-commence {
        font-size: 2.5em;
        letter-spacing: 4px;
    }
}

/* Debug Console Styling */
.debug-entry {
    padding: 3px 5px;
    margin: 2px 0;
    border-left: 3px solid #888;
}

.debug-entry.debug-error {
    color: #ff6b6b;
    border-left-color: #ff4757;
    background: rgba(255, 71, 87, 0.1);
}

.debug-entry.debug-warning {
    color: #ffa502;
    border-left-color: #ffa502;
    background: rgba(255, 165, 2, 0.1);
}

.debug-entry.debug-debug {
    color: #70a1ff;
    border-left-color: #70a1ff;
}

.debug-entry.debug-info {
    color: #fff;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Music Player Controls */
.settings-modal {
    max-width: 500px;
}

.settings-section {
    margin: 20px 0;
}

.settings-section h3 {
    margin-bottom: 15px;
    color: #ffd700;
    font-size: 1.2em;
}

.music-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.music-info {
    font-size: 0.9em;
    color: #ffd700;
    min-width: 120px;
    text-align: center;
}

.music-buttons {
    display: flex;
    gap: 5px;
}

.music-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s;
    color: #fff;
}

.music-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.music-volume-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.volume-slider {
    width: 100px;
    height: 5px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 15px;
    height: 15px;
    background: #ffd700;
    border-radius: 50%;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #ffd700;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.music-select {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    padding: 5px 10px;
    color: #fff;
    font-size: 0.9em;
    cursor: pointer;
    outline: none;
}

.music-select:hover {
    background: rgba(0, 0, 0, 0.7);
}

.music-select option {
    background: #333;
    color: #fff;
}

/* Mobile Responsive Styles */
/* Desktop: allow scrolling */
@media (min-width: 769px) {
    html, body {
        overflow-y: auto;
        position: relative;
    }
    
    .game-container {
        overflow: visible;
    }
}

/* Mobile devices (Android/iOS) - no scrolling, fixed viewport */
@media (max-width: 768px) {
    /* Only apply fixed viewport on actual touch devices */
    @media (hover: none) and (pointer: coarse) {
        html, body {
            height: 100vh;
            height: 100dvh; /* Dynamic viewport height for mobile */
            overflow: hidden;
            position: fixed;
            width: 100%;
        }
        
        .game-container {
            height: 100vh;
            height: 100dvh;
            padding: 5px;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            will-change: auto;
        }
    }
    
    /* Mobile optimizations that apply to all mobile */
    .game-container {
        padding: 5px;
        display: flex;
        flex-direction: column;
        /* Flat on mobile - no 3D */
        transform: none;
    }
    
    /* Flat cards on mobile */
    .monster-card {
        transform: none !important;
    }
    
    .hand-card, .spell-card {
        transform: none !important;
    }
    
    /* Performance optimizations for mobile */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        /* Reduce animations on mobile for better performance */
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Optimize card rendering */
    .hand-card {
        will-change: auto;
        transform: none; /* Disable transforms on mobile for performance */
    }
    
    .monster-card {
        will-change: auto;
    }

    /* Allow text selection in specific areas */
    .log-content, .card-name, .monster-name {
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }

    .game-header {
        padding: 5px;
        margin-bottom: 3px;
    }

    .game-info {
        flex-direction: row;
        gap: 8px;
        font-size: 0.85em;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .currency-display {
        gap: 8px;
        margin-left: 0;
        margin-right: 0;
        order: 3; /* Move to end on mobile */
        width: 100%;
        justify-content: center;
    }
    
    .currency-item {
        padding: 4px 8px;
        font-size: 0.9em;
    }
    
    .currency-icon {
        font-size: 1em;
    }
    
    .currency-value {
        font-size: 0.9em;
    }
    
    /* Settings button on mobile */
    .settings-btn {
        font-size: 1em;
        padding: 6px 10px;
    }

    .music-controls {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }

    .music-info {
        width: 100%;
    }

    .music-buttons {
        justify-content: center;
    }

    .music-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 10px 15px;
        font-size: 1.2em;
    }

    .music-volume-control {
        width: 100%;
        justify-content: center;
    }

    .volume-slider {
        flex: 1;
        max-width: 200px;
        min-height: 44px;
        -webkit-appearance: none;
        appearance: none;
    }

    .volume-slider::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    .volume-slider::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }

    .music-select {
        width: 100%;
        min-height: 44px;
        padding: 10px;
        font-size: 1em;
    }

    /* Mobile: 3 monster slots instead of 4 */
    .monster-slots {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    /* Hide slot 4 on mobile (index 3) */
    .monster-slots .monster-card:nth-child(4) {
        display: none;
    }

    .monster-field {
        min-height: 150px;
        padding: 10px;
        background-size: 15px 15px, 15px 15px, 100% 100%; /* Smaller grid on mobile */
    }

    .monster-card {
        min-height: 140px;
        padding: 12px;
        touch-action: manipulation;
    }

    .monster-image {
        height: 80px;
    }

    .player-area {
        padding: 8px;
        margin: 3px 0;
    }

    .player-header {
        flex-direction: row;
        gap: 8px;
        text-align: left;
        padding: 8px;
        margin-bottom: 5px;
    }
    
    .player-name {
        font-size: 0.9em;
    }
    
    .player-stats {
        font-size: 0.8em;
        gap: 8px;
    }
    
    .stat {
        font-size: 0.85em;
    }

    .player-info {
        justify-content: center;
    }

    .character-icon {
        width: 120px;
        height: 120px;
        border-width: 3px;
    }

    .player-area.player-area .character-icon {
        bottom: 2px;
        right: 2px;
        width: 60px;
        height: 60px;
        border-width: 2px;
    }

    .opponent-area .character-icon {
        top: 50px; /* Move down more on mobile to avoid HP area */
        left: 2px;
        width: 60px;
        height: 60px;
        border-width: 2px;
    }
    
    /* Reduce padding on mobile since icons are smaller */
    .player-area {
        padding-right: 70px; /* Space for smaller character icon on mobile */
    }
    
    .opponent-area {
        padding-left: 70px; /* Space for smaller character icon on mobile */
        padding-right: 8px;
    }

    .player-stats {
        justify-content: center;
        flex-wrap: wrap;
        gap: 15px;
    }

    .stat {
        font-size: 1.1em;
    }

    .game-center {
        flex-direction: column;
        gap: 3px;
        margin: 3px 0;
    }
    
    .battle-log-toggle {
        padding: 5px 10px;
        font-size: 0.75em;
    }

    .spell-trap-row {
        flex-direction: row;
        gap: 3px;
        margin: 3px 0;
        align-items: stretch; /* Make both same height */
    }
    
    .spell-trap-zone {
        min-height: 60px;
        max-height: 60px;
        height: 60px; /* Fixed height to prevent wrapping */
        padding: 3px;
        gap: 3px;
        flex: 1; /* Take available space */
        overflow-x: auto;
        overflow-y: hidden;
        display: flex;
        flex-direction: row; /* Explicitly row direction */
        flex-wrap: nowrap !important; /* Force no wrapping - critical */
        align-items: center; /* Center cards vertically */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        scrollbar-width: thin; /* Thin scrollbar on Firefox */
        scrollbar-color: rgba(255, 255, 255, 0.5) rgba(255, 255, 255, 0.1); /* Custom scrollbar color */
    }
    
    /* Custom scrollbar for webkit browsers (Chrome, Safari) */
    .spell-trap-zone::-webkit-scrollbar {
        height: 4px;
    }
    
    .spell-trap-zone::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .spell-trap-zone::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }
    
    .spell-trap-zone::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.5);
    }
    
    /* Hide zone label on mobile to save space */
    .spell-trap-zone .zone-label {
        display: none;
    }
    
    /* Hide graveyard label on mobile to save space */
    .graveyard .zone-label {
        display: none;
    }
    
    .spell-card, .empty-spell-trap-slot {
        min-width: 50px !important;
        width: 50px !important;
        max-width: 50px !important;
        min-height: 54px !important;
        max-height: 54px !important;
        height: 54px !important;
        font-size: 0.65em;
        padding: 3px;
        flex-shrink: 0 !important; /* Don't shrink cards - critical for scrolling */
        flex-grow: 0 !important; /* Don't grow cards */
    }
    
    /* Show ALL slots on mobile - they're scrollable now, no hiding */
    /* All 5 slots should be visible via horizontal scrolling */
    
    .graveyard {
        min-width: 50px;
        max-width: 50px;
        min-height: 60px;
        max-height: 60px;
        padding: 3px;
        flex-shrink: 0; /* Don't shrink graveyard */
    }

    .spell-zone, .trap-zone {
        min-width: 100%;
    }

    .battle-zone {
        min-height: 100px;
        max-height: 120px;
        padding: 8px;
    }

    .log-content {
        max-height: 80px;
        font-size: 0.75em;
        overflow-y: auto;
    }

    .bottom-panel {
        flex-direction: row;
        padding: 8px;
        gap: 8px;
        margin-top: 5px;
        max-height: 35vh; /* Limit height */
    }
    
    .hand-container {
        flex: 1;
        min-width: 0; /* Allow shrinking */
    }
    
    .hand-label {
        font-size: 0.85em;
        margin-bottom: 5px;
    }

    .hand {
        min-height: 100px;
        max-height: 120px;
        padding: 5px;
        gap: 5px;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap; /* Horizontal scroll on mobile */
    }
    
    .hand-card {
        min-width: 80px;
        max-width: 80px;
        padding: 8px;
        font-size: 0.7em;
        flex-shrink: 0; /* Don't shrink cards */
    }
    
    .card-image {
        max-height: 60px;
    }
    
    .action-panel {
        min-width: 120px;
        flex-shrink: 0;
    }
    
    .action-panel .btn {
        font-size: 0.8em;
        padding: 8px 12px;
        min-height: 40px;
        margin-bottom: 5px;
    }

    .hand-card {
        min-width: 110px;
        max-width: 130px;
        min-height: 160px;
        padding: 12px;
        touch-action: manipulation;
    }

    .card-image {
        max-height: 100px;
    }

    .action-panel {
        width: 100%;
        gap: 12px;
    }

    .btn {
        min-height: 48px;
        padding: 14px 20px;
        font-size: 1.1em;
        touch-action: manipulation;
    }

    .spell-zone, .trap-zone {
        min-height: 90px;
        padding: 12px;
        gap: 8px;
    }

    .spell-card {
        min-width: 90px;
        min-height: 100px;
        padding: 10px;
        touch-action: manipulation;
    }

    .zone-label {
        font-size: 0.85em;
        margin-bottom: 8px;
    }
}

@media (max-width: 480px) {
    .game-header h1 {
        font-size: 1.5em;
    }

    .game-container {
        padding: 8px;
    }

    .monster-card {
        min-height: 130px;
        padding: 10px;
    }

    .monster-name {
        font-size: 0.9em;
    }

    .monster-stats {
        font-size: 0.8em;
    }

    .hand-card {
        min-width: 100px;
        max-width: 110px;
        min-height: 150px;
        padding: 10px;
    }

    .card-name {
        font-size: 0.9em;
    }

    .card-stats {
        font-size: 0.75em;
    }

    .btn {
        min-height: 50px;
        font-size: 1em;
        padding: 12px 18px;
    }

    .player-area {
        padding: 12px;
    }

    .monster-field {
        padding: 5px;
        margin-bottom: 5px;
    }
    
    .zone-label {
        font-size: 0.75em;
        margin-bottom: 3px;
    }

    .monster-slots {
        gap: 4px;
    }
    
    .monster-card {
        min-height: 90px;
        padding: 5px;
        font-size: 0.75em;
    }
    
    .monster-name {
        font-size: 0.85em;
        margin-bottom: 3px;
    }
    
    .monster-stats {
        font-size: 0.7em;
        margin: 3px 0;
    }
}

