/* --- DUEL FIELD SIMULATOR STYLES --- */
.duel-board-wrapper {
    position: relative;
    margin-bottom: 2rem;
}

.duel-board {
    position: relative;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    height: 680px;
    background: linear-gradient(135deg, #1a4d6d 0%, #0d2838 100%);
    border: 3px solid #2563eb;
    border-radius: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    user-select: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), inset 0 0 80px rgba(0, 0, 0, 0.4);
    font-family: 'Inter', sans-serif;
}

/* Grid Layout - Matching Official Yu-Gi-Oh! Field */
.field-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 110px 1fr 110px;
    grid-template-rows: 120px 160px 160px;
    gap: 8px;
    padding: 15px;
    grid-template-areas:
        "corner-tl  extra-monsters  banished"
        "field      main-monsters   gy       "
        "extra-deck spell-traps     deck     ";
}

/* Empty corners */
.empty-corner {
    background: transparent;
}

/* Zone Styling */
.zone {
    border: 2px solid #3b82f6;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.4) 0%, rgba(17, 24, 39, 0.6) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

.zone:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3) 0%, rgba(30, 64, 175, 0.4) 100%);
    border-color: #60a5fa;
}

.zone::after {
    content: attr(data-label);
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.45rem;
    color: rgba(191, 219, 254, 0.6);
    font-weight: 700;
    text-transform: uppercase;
    pointer-events: none;
    letter-spacing: 0.05em;
    text-align: center;
    white-space: nowrap;
}

/* Top Row - Extra Monster Zones */
.extra-monster-zones {
    grid-area: extra-monsters;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 80px;
}

.extra-monster-zone {
    width: 100px;
    height: 115px;
    border: 3px solid #60a5fa;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.3) 0%, rgba(29, 78, 216, 0.5) 100%);
}

.extra-monster-zone::after {
    font-size: 0.4rem;
}

/* Middle Row - Field, Main Monster Zones, GY */
.field-zone {
    grid-area: field;
    border-color: #10b981;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.3) 100%);
}

.field-zone::after {
    color: rgba(167, 243, 208, 0.7);
}

.main-monster-zones {
    grid-area: main-monsters;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.main-monster-zone {
    min-height: 140px;
    border: 2px solid #60a5fa;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.3) 100%);
}

.main-monster-zone::after {
    font-size: 0.4rem;
}

.gy-zone {
    grid-area: gy;
    border-color: #8b5cf6;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(109, 40, 217, 0.3) 100%);
}

.gy-zone::after {
    color: rgba(221, 214, 254, 0.7);
}

.banished-zone {
    grid-area: banished;
    border: 2px solid #f97316;
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.2) 0%, rgba(194, 65, 12, 0.3) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

.banished-zone:hover {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.3) 0%, rgba(194, 65, 12, 0.4) 100%);
    border-color: #fb923c;
}

.banished-zone::after {
    content: 'BANISHED';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.45rem;
    color: rgba(253, 186, 116, 0.7);
    font-weight: 700;
    text-transform: uppercase;
    pointer-events: none;
    letter-spacing: 0.05em;
    text-align: center;
    white-space: nowrap;
}

/* Bottom Row - Extra Deck, Spell/Trap Zones, Deck */
.extra-deck-zone {
    grid-area: extra-deck;
    border-color: #3b82f6;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.25) 0%, rgba(37, 99, 235, 0.35) 100%);
}

.extra-deck-zone::after {
    color: rgba(147, 197, 253, 0.7);
}

.spell-trap-zones {
    grid-area: spell-traps;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.spell-trap-zone {
    min-height: 140px;
    border: 2px solid #14b8a6;
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.2) 0%, rgba(13, 148, 136, 0.3) 100%);
    position: relative;
}

.spell-trap-zone::after {
    font-size: 0.4rem;
    color: rgba(153, 246, 228, 0.7);
}

.pendulum-icon {
    font-size: 2.5rem;
    font-weight: bold;
    pointer-events: none;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.pendulum-icon.blue {
    color: #3b82f6;
}

.pendulum-icon.red {
    color: #ef4444;
}

.deck-zone {
    grid-area: deck;
    border-color: #f59e0b;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(217, 119, 6, 0.3) 100%);
}

.deck-zone::after {
    color: rgba(253, 230, 138, 0.7);
}

/* Hand Area */
.hand-area {
    height: 155px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.5) 100%);
    border-top: 2px solid #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

/* Card Token */
.card-token {
    width: 120px;
    height: 175px;
    background-color: #1e3a8a;
    border: 2px solid #60a5fa;
    border-radius: 4px;
    position: absolute;
    z-index: 10;
    transition: all 0.6s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;

    /* KEY CHANGES FOR QUALITY */

    /* 1. Force GPU to use high-quality resampling */
    image-rendering: -webkit-optimize-contrast;
    /* Best for Chrome/Edge text */
    image-rendering: high-quality;
    /* Standard property */

    /* 2. Force hardware acceleration to unlock better texture filtering */
    transform: translateZ(0);
    backface-visibility: hidden;

    /* 3. "The Blur Hack": A tiny blur removes the jagged aliasing noise */
    filter: contrast(105%) blur(0.2px);
}

.card-token.active-card {
    border-color: #fbbf24;
    box-shadow: 0 0 20px #fbbf24, 0 0 10px #f59e0b;
    z-index: 20;
    transform: scale(1.15);
}

/* Effect Activation Animation */
.card-token.activating-effect {
    z-index: 50;
    animation: effectActivate 0.8s ease-out forwards;
}

.card-token.activating-effect::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    animation: effectRing 0.8s ease-out forwards;
    pointer-events: none;
}

.card-token.activating-effect::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    animation: effectRing 0.8s ease-out 0.15s forwards;
    pointer-events: none;
}

@keyframes effectActivate {
    0% {
        transform: translateZ(0) scale(1);
        filter: contrast(105%) blur(0.2px) brightness(1);
    }
    25% {
        transform: translateZ(0) scale(1.25);
        filter: contrast(105%) blur(0.2px) brightness(1.5);
    }
    50% {
        transform: translateZ(0) scale(1.2);
        filter: contrast(105%) blur(0.2px) brightness(1.3);
    }
    100% {
        transform: translateZ(0) scale(1);
        filter: contrast(105%) blur(0.2px) brightness(1);
    }
}

@keyframes effectRing {
    0% {
        box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.8), 
                    0 0 20px 5px rgba(250, 204, 21, 0.6),
                    inset 0 0 20px rgba(250, 204, 21, 0.4);
        opacity: 1;
    }
    100% {
        box-shadow: 0 0 0 40px rgba(250, 204, 21, 0), 
                    0 0 60px 30px rgba(250, 204, 21, 0),
                    inset 0 0 0 rgba(250, 204, 21, 0);
        opacity: 0;
    }
}

/* Spell Effect (Green glow) */
.card-token.activating-effect.ctype-spell::before,
.card-token.activating-effect.ctype-spell::after {
    animation-name: effectRingSpell;
}

@keyframes effectRingSpell {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.8), 
                    0 0 20px 5px rgba(34, 197, 94, 0.6),
                    inset 0 0 20px rgba(34, 197, 94, 0.4);
        opacity: 1;
    }
    100% {
        box-shadow: 0 0 0 40px rgba(34, 197, 94, 0), 
                    0 0 60px 30px rgba(34, 197, 94, 0),
                    inset 0 0 0 rgba(34, 197, 94, 0);
        opacity: 0;
    }
}

/* Trap Effect (Purple/Pink glow) */
.card-token.activating-effect.ctype-trap::before,
.card-token.activating-effect.ctype-trap::after {
    animation-name: effectRingTrap;
}

@keyframes effectRingTrap {
    0% {
        box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.8), 
                    0 0 20px 5px rgba(168, 85, 247, 0.6),
                    inset 0 0 20px rgba(168, 85, 247, 0.4);
        opacity: 1;
    }
    100% {
        box-shadow: 0 0 0 40px rgba(168, 85, 247, 0), 
                    0 0 60px 30px rgba(168, 85, 247, 0),
                    inset 0 0 0 rgba(168, 85, 247, 0);
        opacity: 0;
    }
}

/* Extra Deck Effect (Blue glow) */
.card-token.activating-effect.ctype-extra::before,
.card-token.activating-effect.ctype-extra::after {
    animation-name: effectRingExtra;
}

@keyframes effectRingExtra {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.8), 
                    0 0 20px 5px rgba(99, 102, 241, 0.6),
                    inset 0 0 20px rgba(99, 102, 241, 0.4);
        opacity: 1;
    }
    100% {
        box-shadow: 0 0 0 40px rgba(99, 102, 241, 0), 
                    0 0 60px 30px rgba(99, 102, 241, 0),
                    inset 0 0 0 rgba(99, 102, 241, 0);
        opacity: 0;
    }
}

/* ============================================
   EXTRA DECK SUMMON ANIMATIONS
   ============================================ */

/* --- XYZ SUMMON (Black/Gold Galaxy Spiral) --- */
.card-token.xyz-summoning {
    z-index: 100;
    animation: xyzSummonCard 1.2s ease-out forwards;
}

.card-token.xyz-summoning::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    transform: translate(-50%, -50%);
    background: conic-gradient(from 0deg, 
        transparent 0deg, 
        rgba(0, 0, 0, 0.8) 60deg,
        rgba(255, 215, 0, 0.6) 120deg,
        transparent 180deg,
        rgba(0, 0, 0, 0.8) 240deg,
        rgba(255, 215, 0, 0.6) 300deg,
        transparent 360deg);
    border-radius: 50%;
    animation: xyzSpiral 1.2s ease-out forwards;
    pointer-events: none;
}

.card-token.xyz-summoning::after {
    content: '★';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 60px;
    color: #ffd700;
    text-shadow: 0 0 20px #ffd700, 0 0 40px #ff8c00, 0 0 60px #000;
    animation: xyzStar 1.2s ease-out forwards;
    pointer-events: none;
    z-index: 10;
}

@keyframes xyzSummonCard {
    0% { transform: translateZ(0) scale(0.3) rotateY(180deg); filter: brightness(0.5); opacity: 0; }
    30% { transform: translateZ(0) scale(1.3) rotateY(90deg); filter: brightness(2); opacity: 1; }
    60% { transform: translateZ(0) scale(1.4) rotateY(0deg); filter: brightness(1.5); }
    100% { transform: translateZ(0) scale(1) rotateY(0deg); filter: brightness(1); }
}

@keyframes xyzSpiral {
    0% { transform: translate(-50%, -50%) rotate(0deg) scale(0); opacity: 1; }
    50% { transform: translate(-50%, -50%) rotate(360deg) scale(1.5); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) rotate(720deg) scale(2); opacity: 0; }
}

@keyframes xyzStar {
    0% { transform: translate(-50%, -50%) scale(0) rotate(-180deg); opacity: 0; }
    40% { transform: translate(-50%, -50%) scale(1.5) rotate(0deg); opacity: 1; }
    70% { transform: translate(-50%, -50%) scale(1.2) rotate(20deg); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(0) rotate(45deg); opacity: 0; }
}

/* --- SYNCHRO SUMMON (White/Green Rings) --- */
.card-token.synchro-summoning {
    z-index: 100;
    animation: synchroSummonCard 1.1s ease-out forwards;
}

.card-token.synchro-summoning::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 150%;
    transform: translate(-50%, -50%);
    border: 4px solid rgba(144, 238, 144, 0.8);
    border-radius: 50%;
    box-shadow: 0 0 30px rgba(144, 238, 144, 0.6), 
                inset 0 0 30px rgba(255, 255, 255, 0.4);
    animation: synchroRing1 1.1s ease-out forwards;
    pointer-events: none;
}

.card-token.synchro-summoning::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    transform: translate(-50%, -50%);
    border: 3px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    animation: synchroRing2 1.1s ease-out 0.15s forwards;
    pointer-events: none;
}

@keyframes synchroSummonCard {
    0% { transform: translateZ(0) scale(0.2) translateY(-50px); filter: brightness(3) saturate(0); opacity: 0; }
    40% { transform: translateZ(0) scale(1.3) translateY(0); filter: brightness(2) saturate(0.5); opacity: 1; }
    70% { transform: translateZ(0) scale(1.2) translateY(0); filter: brightness(1.3) saturate(1); }
    100% { transform: translateZ(0) scale(1) translateY(0); filter: brightness(1) saturate(1); }
}

@keyframes synchroRing1 {
    0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; border-width: 8px; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; border-width: 4px; }
    100% { transform: translate(-50%, -50%) scale(2); opacity: 0; border-width: 1px; }
}

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

/* --- FUSION SUMMON (Purple/Orange Swirl) --- */
.card-token.fusion-summoning {
    z-index: 100;
    animation: fusionSummonCard 1.3s ease-out forwards;
}

.card-token.fusion-summoning::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 180%;
    height: 180%;
    transform: translate(-50%, -50%);
    background: radial-gradient(ellipse at center,
        rgba(147, 51, 234, 0.8) 0%,
        rgba(255, 140, 0, 0.6) 30%,
        rgba(147, 51, 234, 0.4) 60%,
        transparent 80%);
    border-radius: 50%;
    animation: fusionSwirl 1.3s ease-out forwards;
    pointer-events: none;
}

.card-token.fusion-summoning::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    background: linear-gradient(45deg, 
        rgba(147, 51, 234, 0.5) 0%,
        rgba(255, 140, 0, 0.5) 50%,
        rgba(147, 51, 234, 0.5) 100%);
    border-radius: 8px;
    animation: fusionFlash 1.3s ease-out forwards;
    pointer-events: none;
}

@keyframes fusionSummonCard {
    0% { transform: translateZ(0) scale(0) rotate(-180deg); filter: brightness(0) hue-rotate(0deg); opacity: 0; }
    30% { transform: translateZ(0) scale(0.8) rotate(-90deg); filter: brightness(1.5) hue-rotate(45deg); opacity: 1; }
    60% { transform: translateZ(0) scale(1.4) rotate(0deg); filter: brightness(2) hue-rotate(90deg); }
    80% { transform: translateZ(0) scale(1.2) rotate(10deg); filter: brightness(1.3) hue-rotate(45deg); }
    100% { transform: translateZ(0) scale(1) rotate(0deg); filter: brightness(1) hue-rotate(0deg); }
}

@keyframes fusionSwirl {
    0% { transform: translate(-50%, -50%) rotate(0deg) scale(0); opacity: 1; }
    50% { transform: translate(-50%, -50%) rotate(180deg) scale(1.2); opacity: 0.9; }
    100% { transform: translate(-50%, -50%) rotate(360deg) scale(1.8); opacity: 0; }
}

@keyframes fusionFlash {
    0% { opacity: 0; }
    30% { opacity: 0.8; }
    60% { opacity: 0.4; }
    100% { opacity: 0; }
}

/* --- LINK SUMMON (Blue Circuit/Digital) --- */
.card-token.link-summoning {
    z-index: 100;
    animation: linkSummonCard 1s ease-out forwards;
}

.card-token.link-summoning::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    transform: translate(-50%, -50%);
    background: 
        linear-gradient(0deg, transparent 48%, rgba(0, 191, 255, 0.8) 49%, rgba(0, 191, 255, 0.8) 51%, transparent 52%),
        linear-gradient(90deg, transparent 48%, rgba(0, 191, 255, 0.8) 49%, rgba(0, 191, 255, 0.8) 51%, transparent 52%),
        linear-gradient(45deg, transparent 48%, rgba(0, 191, 255, 0.4) 49%, rgba(0, 191, 255, 0.4) 51%, transparent 52%),
        linear-gradient(-45deg, transparent 48%, rgba(0, 191, 255, 0.4) 49%, rgba(0, 191, 255, 0.4) 51%, transparent 52%);
    animation: linkCircuit 1s ease-out forwards;
    pointer-events: none;
}

.card-token.link-summoning::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 140%;
    height: 140%;
    transform: translate(-50%, -50%);
    border: 3px solid rgba(0, 191, 255, 0.9);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    box-shadow: 0 0 20px rgba(0, 191, 255, 0.8), inset 0 0 20px rgba(0, 191, 255, 0.3);
    animation: linkHexagon 1s ease-out forwards;
    pointer-events: none;
}

@keyframes linkSummonCard {
    0% { transform: translateZ(0) scale(0.1); filter: brightness(3) contrast(2); opacity: 0; }
    30% { transform: translateZ(0) scale(1.2); filter: brightness(2) contrast(1.5); opacity: 1; }
    60% { transform: translateZ(0) scale(1.15); filter: brightness(1.5) contrast(1.2); }
    100% { transform: translateZ(0) scale(1); filter: brightness(1) contrast(1); }
}

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

@keyframes linkHexagon {
    0% { transform: translate(-50%, -50%) scale(0) rotate(-60deg); opacity: 0; }
    40% { transform: translate(-50%, -50%) scale(1.2) rotate(0deg); opacity: 1; }
    70% { transform: translate(-50%, -50%) scale(1.1) rotate(10deg); opacity: 0.7; }
    100% { transform: translate(-50%, -50%) scale(1.5) rotate(0deg); opacity: 0; }
}

/* --- CONTACT FUSION (Special Purple/Gold Merge) --- */
.card-token.contact-fusion-summoning {
    z-index: 100;
    animation: contactFusionCard 1.2s ease-out forwards;
}

.card-token.contact-fusion-summoning::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    transform: translate(-50%, -50%);
    background: conic-gradient(from 0deg,
        rgba(147, 51, 234, 0.7) 0deg,
        rgba(255, 215, 0, 0.7) 90deg,
        rgba(147, 51, 234, 0.7) 180deg,
        rgba(255, 215, 0, 0.7) 270deg,
        rgba(147, 51, 234, 0.7) 360deg);
    border-radius: 50%;
    animation: contactFusionVortex 1.2s ease-out forwards;
    pointer-events: none;
}

.card-token.contact-fusion-summoning::after {
    content: '⚡';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 50px;
    color: #ffd700;
    text-shadow: 0 0 15px #9333ea, 0 0 30px #ffd700;
    animation: contactFusionBolt 1.2s ease-out forwards;
    pointer-events: none;
    z-index: 10;
}

@keyframes contactFusionCard {
    0% { transform: translateZ(0) scale(0.5); filter: brightness(0.5) saturate(2); opacity: 0; }
    40% { transform: translateZ(0) scale(1.35); filter: brightness(2) saturate(1.5); opacity: 1; }
    70% { transform: translateZ(0) scale(1.2); filter: brightness(1.5) saturate(1.2); }
    100% { transform: translateZ(0) scale(1); filter: brightness(1) saturate(1); }
}

@keyframes contactFusionVortex {
    0% { transform: translate(-50%, -50%) rotate(0deg) scale(0); opacity: 1; }
    50% { transform: translate(-50%, -50%) rotate(270deg) scale(1.3); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) rotate(540deg) scale(1.8); opacity: 0; }
}

@keyframes contactFusionBolt {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
    60% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
}

/* Card Types Colors (fallback if no image) */
.ctype-monster {
    background-color: #d97706;
}

.ctype-spell {
    background-color: #059669;
}

.ctype-trap {
    background-color: #db2777;
}

.ctype-extra {
    background-color: #4f46e5;
}

.ctype-synchro {
    background-color: #f1f5f9;
    border-color: #94a3b8;
}

/* Controls */
.sim-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.sim-btn {
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-weight: bold;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.sim-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.sim-btn-play {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    width: 9rem;
}

.sim-btn-play:hover {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.sim-btn-play.paused {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.sim-btn-nav {
    background: linear-gradient(135deg, #475569 0%, #334155 100%);
}

.sim-btn-nav:hover {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
}

/* Log */
.sim-log {
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.6);
    padding: 1rem;
    border-radius: 0.5rem;
    height: 100px;
    overflow-y: auto;
    border: 2px solid #1e3a8a;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #93c5fd;
}

.log-entry {
    margin-bottom: 0.25rem;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* Popup */
.sim-popup {
    position: fixed;
    display: none;
    opacity: 0;
    padding: 0.75rem;
    background-color: rgba(15, 23, 42, 0.97);
    border: 3px solid #3b82f6;
    border-radius: 0.75rem;
    color: #e0f2fe;
    width: 270px;
    z-index: 9999;
    pointer-events: none;
    transition: opacity 0.15s ease-out;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
}

/* --- REPLACED RESPONSIVE DESIGN SECTION --- */

/* Scrollbar Styling for the wrapper */
.duel-board-wrapper::-webkit-scrollbar {
    height: 8px;
}

.duel-board-wrapper::-webkit-scrollbar-track {
    background: #0f172a;
    border-radius: 4px;
}

.duel-board-wrapper::-webkit-scrollbar-thumb {
    background: #3b82f6;
    border-radius: 4px;
}

.duel-board-wrapper::-webkit-scrollbar-thumb:hover {
    background: #60a5fa;
}

@media (max-width: 1024px) {
    .duel-board {
        max-width: 900px;
        height: 520px;
        /* Slightly taller to accommodate cards */
    }

    .field-grid {
        grid-template-columns: 90px 1fr 90px;
        grid-template-rows: 100px 140px 140px;
        gap: 6px;
    }
}

/* --- MOBILE PORTRAIT LAYOUT (No Side Scroll) --- */
@media (max-width: 768px) {
    .duel-board-wrapper {
        width: 100%;
        overflow: visible;
        /* Disable scroll container */
    }

    .duel-board {
        width: 100%;
        max-width: 100%;
        height: auto;
        /* Allow board to grow vertically */
        min-height: 550px;
        /* Remove fixed aspect ratio, let it be a tall container */
    }

    /* COMPLETE GRID RE-ARRANGEMENT */
    .field-grid {
        display: grid;
        /* Create a 4-column grid for the utility row at bottom */
        grid-template-columns: 1fr 1fr 1fr 1fr;
        /* Rows: EMZ | Monsters | Spells | Utility (Deck/GY/etc) */
        grid-template-rows: 100px 100px 100px 90px;
        gap: 8px;
        padding: 10px 5px;

        /* Re-map the areas to a vertical stack */
        grid-template-areas:
            "extra-monsters extra-monsters extra-monsters banished"
            "main-monsters  main-monsters  main-monsters  main-monsters"
            "spell-traps    spell-traps    spell-traps    spell-traps"
            "field          extra-deck     gy             deck";
    }

    /* --- 1. Extra Monster Zones (Top) --- */
    .extra-monster-zones {
        grid-area: extra-monsters;
        gap: 30px;
        /* Bring them closer */
        align-items: flex-end;
        /* Align to bottom of their row */
    }

    .extra-monster-zone {
        width: 60px;
        height: 88px;
    }

    /* --- 2. Main Monster & Spell Zones (Middle) --- */
    /* We force these containers to span the full width */
    .main-monster-zones,
    .spell-trap-zones {
        display: grid;
        /* 5 Equal columns for the 5 cards */
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
        /* Tight gap to fit 5 cards on phone screen */
        width: 100%;
    }

    .main-monster-zone,
    .spell-trap-zone {
        min-height: 0;
        /* Allow shrinking */
        height: 100%;
        /* Fill the grid row */
        border-width: 1px;
        /* Thinner borders for cleanliness */
    }

    /* Hide the "Main Monster Zone" text on mobile to save visual noise */
    .zone::after {
        display: none;
    }

    /* Optional: Show tiny labels for Deck/GY only */
    .gy-zone::after,
    .deck-zone::after,
    .field-zone::after {
        display: block;
        font-size: 0.5rem;
        bottom: 2px;
    }

    /* --- 3. Utility Zones (Bottom Row) --- */
    /* These now sit side-by-side at the bottom */
    .field-zone {
        grid-area: field;
    }

    .extra-deck-zone {
        grid-area: extra-deck;
    }

    .gy-zone {
        grid-area: gy;
    }

    .deck-zone {
        grid-area: deck;
    }

    .banished-zone {
        grid-area: banished;
    }

    /* --- 4. Hand Area (Fixed at bottom) --- */
    .hand-area {
        height: 100px;
        border-top: 1px solid #3b82f6;
    }

    /* --- 5. Card Tokens (Resized for 5-column layout) --- */
    .card-token {
        /* Calculated: (Screen Width ~360 - Gaps) / 5 */
        width: 62px;
        height: 90px;
        border-width: 1px;
        border-radius: 3px;
    }

    /* Adjust active glow to not be too huge on small cards */
    .card-token.active-card {
        transform: scale(1.1);
        box-shadow: 0 0 10px #fbbf24;
    }

    /* Mobile-friendly effect activation animation */
    .card-token.activating-effect {
        animation: effectActivateMobile 0.8s ease-out forwards;
    }

    @keyframes effectActivateMobile {
        0% {
            transform: translateZ(0) scale(1);
            filter: contrast(105%) blur(0.2px) brightness(1);
        }
        25% {
            transform: translateZ(0) scale(1.15);
            filter: contrast(105%) blur(0.2px) brightness(1.4);
        }
        50% {
            transform: translateZ(0) scale(1.12);
            filter: contrast(105%) blur(0.2px) brightness(1.2);
        }
        100% {
            transform: translateZ(0) scale(1);
            filter: contrast(105%) blur(0.2px) brightness(1);
        }
    }

    /* Smaller rings for mobile */
    @keyframes effectRing {
        0% {
            box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.8), 
                        0 0 10px 3px rgba(250, 204, 21, 0.6),
                        inset 0 0 10px rgba(250, 204, 21, 0.4);
            opacity: 1;
        }
        100% {
            box-shadow: 0 0 0 20px rgba(250, 204, 21, 0), 
                        0 0 30px 15px rgba(250, 204, 21, 0),
                        inset 0 0 0 rgba(250, 204, 21, 0);
            opacity: 0;
        }
    }

    /* --- Mobile Extra Deck Summon Animations (Scaled Down) --- */

    /* Xyz Summon - Mobile */
    .card-token.xyz-summoning::before {
        width: 150%;
        height: 150%;
    }
    .card-token.xyz-summoning::after {
        font-size: 35px;
    }
    @keyframes xyzSpiral {
        0% { transform: translate(-50%, -50%) rotate(0deg) scale(0); opacity: 1; }
        50% { transform: translate(-50%, -50%) rotate(360deg) scale(1); opacity: 0.8; }
        100% { transform: translate(-50%, -50%) rotate(720deg) scale(1.3); opacity: 0; }
    }

    /* Synchro Summon - Mobile */
    .card-token.synchro-summoning::before {
        width: 120%;
        height: 120%;
        border-width: 3px;
    }
    .card-token.synchro-summoning::after {
        width: 100%;
        height: 100%;
        border-width: 2px;
    }

    /* Fusion Summon - Mobile */
    .card-token.fusion-summoning::before {
        width: 140%;
        height: 140%;
    }

    /* Link Summon - Mobile */
    .card-token.link-summoning::before {
        width: 150%;
        height: 150%;
    }
    .card-token.link-summoning::after {
        width: 110%;
        height: 110%;
        border-width: 2px;
    }

    /* Contact Fusion - Mobile */
    .card-token.contact-fusion-summoning::before {
        width: 150%;
        height: 150%;
    }
    .card-token.contact-fusion-summoning::after {
        font-size: 30px;
    }

    /* --- Controls Responsive Adjustments --- */
    .sim-controls {
        gap: 0.4rem;
        flex-wrap: wrap;
        margin-top: 1rem;
    }

    .sim-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
        flex: 1 1 auto; /* Allow buttons to grow/shrink */
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0; /* Allow shrinking below content size if needed */
    }

    .sim-btn i {
        margin-right: 0.3rem;
    }

    .sim-btn-play {
        width: 100%; /* Play button takes full width on new line if wrapped, or just flexes */
        order: -1; /* Keep play button first or adjust as needed */
        flex-basis: 100%; /* Force play button to take full width on very small screens */
        margin-bottom: 0.5rem;
    }
    
    /* Adjust other buttons to share space */
    .btn-reset, .btn-prev, .btn-next, .btn-gy, .btn-banish {
        flex: 1;
    }
}