html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
}

#battleStage {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 56px;
    padding: 24px 24px 110px;
    background: transparent;
}

#cardA,
#cardB {
    position: relative;
    display: flex;
}

#rollBtn {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 80;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    background: rgba(10, 10, 16, 0.78);
    color: #fff;
    padding: 14px 24px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    backdrop-filter: blur(6px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    transition: background 140ms ease, transform 140ms ease;
}

#rollBtn:hover {
    background: rgba(24, 24, 34, 0.9);
    transform: translateX(-50%) translateY(-1px);
}

#rollBtn:active {
    transform: translateX(-50%) translateY(0);
}

.battle-card {
    --accent: #8b95a7;
    --accent-2: #dce2ea;
    --accent-3: #f6f8fb;
    --trim: rgba(255, 255, 255, 0.9);
    --surface-top: rgba(255, 255, 255, 0.99);
    --surface-bottom: rgba(240, 244, 250, 0.98);
    --ink: #111827;
    --ornament-opacity: 0;
    --sheen-opacity: 0.16;
    --card-cut: polygon(
            4% 0%,
            96% 0%,
            100% 4%,
            100% 96%,
            96% 100%,
            4% 100%,
            0% 96%,
            0% 4%
    );
    position: relative;
    width: 360px;
    transform-origin: center center;
    transition: transform 260ms ease, opacity 260ms ease, filter 260ms ease;
    z-index: 2;
    filter: drop-shadow(0 22px 42px rgba(0, 0, 0, 0.22));
}

.card-frame {
    position: relative;
    z-index: 1;
    overflow: clip;
    border-radius: 0;
    clip-path: var(--card-cut);
    background: linear-gradient(
            180deg,
            var(--surface-top) 0%,
            var(--surface-bottom) 100%
    );
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.55),
    inset 0 0 0 5px var(--trim),
    inset 0 0 0 6px rgba(0, 0, 0, 0.08);
}

.card-frame::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    clip-path: var(--card-cut);
    background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 28%),
    radial-gradient(circle at bottom right, color-mix(in srgb, var(--accent) 18%, transparent), transparent 28%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 44%);
}

.card-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    clip-path: var(--card-cut);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 16%, transparent 84%, rgba(0, 0, 0, 0.05)),
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 12%, transparent), transparent 40%);
}

.rarity-glow {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    clip-path: var(--card-cut);
    border-radius: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    inset 0 0 34px color-mix(in srgb, var(--accent) 18%, transparent),
    0 0 18px color-mix(in srgb, var(--accent) 10%, transparent);
}

.foil-sheen {
    position: absolute;
    inset: 0;
    opacity: var(--sheen-opacity);
    pointer-events: none;
    z-index: 1;
    clip-path: var(--card-cut);
    background: linear-gradient(118deg, transparent 16%, rgba(255, 255, 255, 0.34) 28%, transparent 40%),
    linear-gradient(150deg, transparent 46%, color-mix(in srgb, var(--accent-2) 35%, white) 58%, transparent 70%);
}

.card-crown {
    position: absolute;
    left: 50%;
    width: 176px;
    height: 34px;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 2;
    opacity: var(--ornament-opacity);
}

.crown-top {
    top: 12px;
}

.crown-bottom {
    bottom: 12px;
    transform: translateX(-50%) rotate(180deg);
}

.card-crown::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.95) 0 10%, transparent 11%),
    linear-gradient(90deg, transparent 0%, var(--accent) 18%, var(--accent-2) 50%, var(--accent) 82%, transparent 100%);
    clip-path: polygon(
            0 50%, 8% 50%, 14% 18%, 28% 18%, 34% 0, 50% 30%, 66% 0, 72% 18%, 86% 18%, 92% 50%, 100% 50%,
            92% 50%, 86% 82%, 72% 82%, 66% 100%, 50% 70%, 34% 100%, 28% 82%, 14% 82%, 8% 50%
    );
}

.card-header {
    position: relative;
    z-index: 3;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 18px 20px 12px;
}

.card-name-wrap {
    min-width: 0;
    flex: 1;
    text-align: center;
}

.card-name {
    color: var(--ink);
    font-size: 26px;
    line-height: 1.02;
    font-weight: 900;
    letter-spacing: 0.005em;
    text-transform: uppercase;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.96),
    0 0 10px rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-art {
    position: relative;
    z-index: 2;
    margin: 0 16px;
    height: 300px;
    width: 300px;
    border-radius: 28px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08),
    0 10px 20px rgba(0, 0, 0, 0.18);
    background: linear-gradient(
            135deg,
            color-mix(in srgb, var(--accent) 22%, white),
            color-mix(in srgb, var(--accent-2) 30%, white) 42%,
            color-mix(in srgb, var(--accent-3) 22%, white)
    );
}

.art-theme-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 22% 20%, rgba(255, 255, 255, 0.42), transparent 24%),
    radial-gradient(circle at 78% 76%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 26%),
    linear-gradient(140deg, color-mix(in srgb, var(--accent) 34%, transparent), transparent 46%),
    repeating-linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.06) 0 12px,
            rgba(255, 255, 255, 0) 12px 24px
    );
    z-index: 0;
}

.card-headshot,
.victory-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-headshot {
    z-index: 1;
    transition: opacity 180ms ease;
}

.card-headshot.hide-for-victory {
    opacity: 0;
}

.victory-video {
    z-index: 2;
    opacity: 0;
    pointer-events: none;
}

.victory-video.show {
    opacity: 1;
}

.art-vignette {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 24%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.2), transparent 34%),
    radial-gradient(circle at center, transparent 42%, rgba(0, 0, 0, 0.13) 100%);
    pointer-events: none;
    z-index: 3;
}

.card-stats {
    position: relative;
    z-index: 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 16px 12px;
}

.stat-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 64px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(17, 24, 39, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 4px 10px rgba(0, 0, 0, 0.08);
}

.attack-chip {
    background: linear-gradient(
            180deg,
            rgba(255, 248, 235, 0.98),
            rgba(255, 236, 195, 0.94)
    );
}

.hp-chip {
    background: linear-gradient(
            180deg,
            rgba(255, 240, 242, 0.98),
            rgba(255, 224, 229, 0.94)
    );
}

.stat-symbol {
    font-size: 28px;
    line-height: 1;
    font-weight: 900;
    color: #111827;
}

.stat-value {
    font-size: 48px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: -0.03em;
}

.attack-value {
    color: #f59e0b;
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.18);
}

.hp-value {
    color: #ef4444;
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.16);
}

.hp-bar {
    position: relative;
    z-index: 3;
    padding: 0 16px 18px;
}

.hp-track {
    height: 20px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(17, 24, 39, 0.16);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.28);
}

.hp-fill {
    height: 100%;
    width: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ff6a6a 0%, #ef4444 50%, #b91c1c 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 0 14px rgba(239, 68, 68, 0.28);
    transition: width 260ms ease;
}

.damage-pop,
.damage-marks,
.damage-mark,
.hit-flash {
    display: none !important;
}

/* clean default */
.battle-card {
    --card-cut: polygon(
            0% 0%,
            100% 0%,
            100% 100%,
            0% 100%
    );
}

/* base (rounded rectangle via clip-path) */
.battle-card[data-damage="0"] {
    --card-cut: polygon(
            4% 0%,
            96% 0%,
            100% 4%,
            100% 96%,
            96% 100%,
            4% 100%,
            0% 96%,
            0% 4%
    );
}

.battle-card[data-damage="1"] {
    --card-cut: polygon(
            4% 0%,
            20% 0%,
            24% 1.6%,
            36% 0%,
            80% 0%,
            96% 0%,
            100% 4%,
            100% 30%,
            98% 34%,
            100% 60%,
            100% 96%,
            96% 100%,
            70% 100%,
            66% 98.5%,
            40% 100%,
            4% 100%,
            0% 96%,
            0% 60%,
            1.5% 56%,
            0% 30%,
            0% 4%
    );
}

.battle-card[data-damage="2"] {
    --card-cut: polygon(
            0% 0%,
            12% 0%,
            16% 1.8%,
            28% 0%,
            46% 0%,
            50% 2.3%,
            64% 0%,
            84% 0%,
            89% 1.8%,
            100% 0%,
            100% 18%,
            98.2% 23%,
            100% 36%,
            100% 57%,
            97.8% 61%,
            100% 78%,
            100% 100%,
            82% 100%,
            77% 98.4%,
            61% 100%,
            38% 100%,
            34% 97.8%,
            16% 100%,
            0% 100%,
            0% 80%,
            1.8% 74%,
            0% 56%,
            0% 32%,
            2% 26%,
            0% 12%
    );
}

.battle-card[data-damage="3"] {
    --card-cut: polygon(
            0% 0%,
            8% 0%,
            13% 2.2%,
            22% 0%,
            34% 0%,
            39% 3.2%,
            51% 0%,
            66% 0%,
            71% 2.4%,
            84% 0%,
            100% 0%,
            100% 10%,
            97.5% 16%,
            100% 28%,
            96.8% 35%,
            100% 48%,
            97.4% 56%,
            100% 70%,
            96.9% 78%,
            100% 90%,
            100% 100%,
            90% 100%,
            84% 97.4%,
            73% 100%,
            56% 100%,
            50% 96.6%,
            34% 100%,
            18% 100%,
            12% 97.2%,
            0% 100%,
            0% 88%,
            2.4% 80%,
            0% 67%,
            3% 58%,
            0% 44%,
            2.2% 32%,
            0% 18%
    );
}

.battle-card[data-damage="4"] {
    --card-cut: polygon(
            4% 0%,
            12% 2.5%,
            22% 0%,
            34% 4%,
            50% 0%,
            70% 3.5%,
            90% 0%,
            96% 0%,
            100% 4%,
            100% 10%,
            96% 18%,
            100% 28%,
            95% 40%,
            100% 55%,
            95% 70%,
            100% 85%,
            100% 96%,
            96% 100%,
            80% 96%,
            70% 100%,
            55% 95%,
            40% 100%,
            25% 96%,
            10% 100%,
            4% 100%,
            0% 96%,
            0% 90%,
            4% 80%,
            0% 65%,
            5% 50%,
            0% 35%,
            4% 20%,
            0% 8%,
            0% 4%
    );
}

/* torn silhouette is now handled by each layer directly; no dark inner silhouette */
.battle-card[data-damage="3"] .card-frame,
.battle-card[data-damage="4"] .card-frame {
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.94),
    inset 0 0 0 4px var(--trim),
    inset 0 0 0 5px rgba(0, 0, 0, 0.06);
}

/* rarity themes from either classes or manifest-driven data-rarity attributes */
.battle-card.rarity-common,
.battle-card[data-rarity="common"] {
    --accent: #97a0ae;
    --accent-2: #dce3eb;
    --accent-3: #f7f9fc;
    --trim: rgba(255, 255, 255, 0.9);
    --surface-top: rgba(255, 255, 255, 0.99);
    --surface-bottom: rgba(240, 244, 250, 0.98);
    --ink: #18202c;
    --ornament-opacity: 0;
    --sheen-opacity: 0.1;
}

.battle-card.rarity-uncommon,
.battle-card[data-rarity="uncommon"] {
    --accent: #28b76b;
    --accent-2: #bcefd1;
    --accent-3: #eefcf4;
    --trim: rgba(222, 255, 233, 0.98);
    --surface-top: rgba(252, 255, 253, 0.995);
    --surface-bottom: rgba(233, 248, 239, 0.985);
    --ink: #0f2617;
    --ornament-opacity: 0.45;
    --sheen-opacity: 0.18;
}

.battle-card.rarity-uncommon .card-frame,
.battle-card[data-rarity="uncommon"] .card-frame {
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.96),
    0 22px 42px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(22, 112, 62, 0.18),
    0 0 18px rgba(40, 183, 107, 0.1);
}

.battle-card.rarity-mythic,
.battle-card[data-rarity="mythic"] {
    --accent: #9b5cff;
    --accent-2: #e6d8ff;
    --accent-3: #faf6ff;
    --trim: rgba(242, 233, 255, 0.99);
    --surface-top: rgba(255, 252, 255, 0.995);
    --surface-bottom: rgba(244, 236, 255, 0.985);
    --ink: #24133d;
    --ornament-opacity: 0.82;
    --sheen-opacity: 0.24;
}

.battle-card.rarity-mythic .card-frame,
.battle-card[data-rarity="mythic"] .card-frame {
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.97),
    inset 0 0 44px rgba(164, 102, 255, 0.08),
    0 22px 42px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(114, 53, 203, 0.2),
    0 0 26px rgba(155, 92, 255, 0.18);
}

.battle-card.rarity-mythic .foil-sheen,
.battle-card[data-rarity="mythic"] .foil-sheen {
    background: linear-gradient(118deg, transparent 14%, rgba(255, 255, 255, 0.44) 28%, transparent 42%),
    linear-gradient(150deg, transparent 46%, rgba(235, 218, 255, 0.42) 58%, transparent 70%),
    radial-gradient(circle at 82% 24%, rgba(255, 255, 255, 0.2), transparent 20%);
}

.battle-card.rarity-legendary,
.battle-card[data-rarity="legendary"] {
    --accent: #ffab2f;
    --accent-2: #ffe1a8;
    --accent-3: #fff8eb;
    --trim: rgba(255, 243, 215, 0.995);
    --surface-top: rgba(255, 253, 248, 0.998);
    --surface-bottom: rgba(255, 241, 214, 0.988);
    --ink: #3a2408;
    --ornament-opacity: 1;
    --sheen-opacity: 0.28;
}

.battle-card.rarity-legendary .card-frame,
.battle-card[data-rarity="legendary"] .card-frame {
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.98),
    inset 0 0 54px rgba(255, 193, 87, 0.1),
    0 22px 40px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(181, 99, 12, 0.24),
    0 0 32px rgba(255, 174, 39, 0.24);
}

.battle-card.rarity-legendary .foil-sheen,
.battle-card[data-rarity="legendary"] .foil-sheen {
    background: linear-gradient(118deg, transparent 12%, rgba(255, 255, 255, 0.46) 26%, transparent 40%),
    linear-gradient(150deg, transparent 42%, rgba(255, 226, 166, 0.42) 58%, transparent 74%),
    repeating-linear-gradient(
            115deg,
            rgba(255, 255, 255, 0.08) 0 8px,
            transparent 8px 16px
    );
}

/* =========================================================
   LEGENDARY EFFECTS
   Fully gold legendary treatment
   - no purple aura
   - strong gold foil, glow, filigree, and particles
   - clearer moving gold flecks
   ========================================================= */

.battle-card.rarity-legendary,
.battle-card[data-rarity="legendary"] {
    --accent: #ffab2f;
    --accent-2: #ffe1a8;
    --accent-3: #fff8eb;
    --trim: rgba(255, 243, 215, 0.995);
    --surface-top: rgba(255, 253, 248, 0.998);
    --surface-bottom: rgba(255, 241, 214, 0.988);
    --ink: #3a2408;
    --ornament-opacity: 1;
    --sheen-opacity: 0.34;

    --legend-gold-1: rgba(255, 248, 229, 0.98);
    --legend-gold-2: rgba(255, 236, 184, 0.94);
    --legend-gold-3: rgba(255, 214, 102, 0.9);
    --legend-gold-4: rgba(255, 188, 58, 0.82);
    --legend-gold-5: rgba(214, 132, 22, 0.44);
    --legend-gold-6: rgba(255, 255, 255, 0.82);
}

.battle-card.rarity-legendary,
.battle-card[data-rarity="legendary"] {
    filter: drop-shadow(0 22px 40px rgba(0, 0, 0, 0.3)) drop-shadow(0 0 12px rgba(255, 196, 82, 0.26)) drop-shadow(0 0 26px rgba(255, 170, 39, 0.2));
}

.battle-card.rarity-legendary .card-frame,
.battle-card[data-rarity="legendary"] .card-frame {
    position: relative;
    overflow: clip;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.98),
    inset 0 0 54px rgba(255, 199, 87, 0.12),
    inset 0 0 0 1px rgba(181, 99, 12, 0.24),
    0 22px 40px rgba(0, 0, 0, 0.32),
    0 0 30px rgba(255, 182, 43, 0.2);
}

.battle-card.rarity-legendary .card-frame::before,
.battle-card[data-rarity="legendary"] .card-frame::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(circle at 18% 8.5%, var(--legend-gold-1) 0 6px, transparent 7px),
    radial-gradient(circle at 82% 8.5%, var(--legend-gold-1) 0 6px, transparent 7px),
    linear-gradient(
            90deg,
            transparent 0%,
            rgba(255, 197, 82, 0) 7%,
            rgba(255, 197, 82, 0.52) 18%,
            rgba(255, 232, 168, 0.96) 50%,
            rgba(255, 197, 82, 0.52) 82%,
            rgba(255, 197, 82, 0) 93%,
            transparent 100%
    ),
    radial-gradient(ellipse at 50% 9%, rgba(255, 224, 145, 0.24), transparent 52%),
    radial-gradient(ellipse at 30% 9.5%, rgba(255, 192, 76, 0.26) 0 18%, transparent 19%),
    radial-gradient(ellipse at 70% 9.5%, rgba(255, 192, 76, 0.26) 0 18%, transparent 19%);
    background-repeat: no-repeat;
    background-size: auto,
    auto,
    60% 2px,
    56% 34px,
    18% 24px,
    18% 24px;
    background-position: 18% 8.5%,
    82% 8.5%,
    50% 9%,
    50% 7%,
    30% 9.5%,
    70% 9.5%;
    animation: legendaryFiligreeGlowTop 4s ease-in-out infinite;
}

.battle-card.rarity-legendary .card-frame::after,
.battle-card[data-rarity="legendary"] .card-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(circle at 20% 93%, var(--legend-gold-1) 0 5px, transparent 6px),
    radial-gradient(circle at 80% 93%, var(--legend-gold-1) 0 5px, transparent 6px),
    linear-gradient(
            90deg,
            transparent 0%,
            rgba(255, 197, 82, 0) 8%,
            rgba(255, 197, 82, 0.42) 18%,
            rgba(255, 232, 168, 0.84) 50%,
            rgba(255, 197, 82, 0.42) 82%,
            rgba(255, 197, 82, 0) 92%,
            transparent 100%
    ),
    radial-gradient(ellipse at 50% 92%, rgba(255, 224, 145, 0.2), transparent 50%),
    radial-gradient(ellipse at 32% 92%, rgba(255, 192, 76, 0.22) 0 18%, transparent 19%),
    radial-gradient(ellipse at 68% 92%, rgba(255, 192, 76, 0.22) 0 18%, transparent 19%);
    background-repeat: no-repeat;
    background-size: auto,
    auto,
    56% 2px,
    50% 26px,
    16% 20px,
    16% 20px;
    background-position: 20% 93%,
    80% 93%,
    50% 92%,
    50% 92%,
    32% 92%,
    68% 92%;
    animation: legendaryFiligreeGlowBottom 4.8s ease-in-out infinite;
}

.battle-card.rarity-legendary .foil-sheen,
.battle-card[data-rarity="legendary"] .foil-sheen {
    opacity: 0.58;
    background: linear-gradient(
            115deg,
            transparent 0%,
            transparent 24%,
            rgba(255, 255, 255, 0.14) 30%,
            rgba(255, 231, 160, 0.38) 36%,
            rgba(255, 255, 255, 0.16) 42%,
            transparent 50%,
            transparent 100%
    ),
    linear-gradient(
            145deg,
            transparent 0%,
            transparent 50%,
            rgba(255, 214, 102, 0.22) 58%,
            transparent 72%,
            transparent 100%
    ),
    repeating-linear-gradient(
            115deg,
            rgba(255, 255, 255, 0.05) 0 8px,
            transparent 8px 18px
    );
    background-size: 240% 240%, 180% 180%, auto;
    animation: legendaryFoilSweep 4.8s linear infinite;
}

.battle-card.rarity-legendary .stat-chip,
.battle-card[data-rarity="legendary"] .stat-chip {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92),
    inset 0 0 0 1px rgba(181, 99, 12, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.08),
    0 0 12px rgba(255, 193, 87, 0.12);
}

.battle-card.rarity-legendary .legendary-particles,
.battle-card[data-rarity="legendary"] .legendary-particles {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    overflow: hidden;
}

.battle-card.rarity-legendary .legendary-particles::before,
.battle-card[data-rarity="legendary"] .legendary-particles::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.95;
    background: radial-gradient(circle at 10% 78%, rgba(255, 241, 204, 0.96) 0 2px, transparent 3.2px),
    radial-gradient(circle at 14% 36%, rgba(255, 214, 102, 0.95) 0 2.5px, transparent 3.9px),
    radial-gradient(circle at 18% 18%, rgba(255, 232, 168, 0.92) 0 1.9px, transparent 3px),
    radial-gradient(circle at 24% 58%, rgba(255, 201, 77, 0.9) 0 2.5px, transparent 3.9px),
    radial-gradient(circle at 28% 84%, rgba(255, 244, 214, 0.94) 0 1.8px, transparent 2.9px),
    radial-gradient(circle at 34% 26%, rgba(255, 214, 102, 0.93) 0 2.4px, transparent 3.8px),
    radial-gradient(circle at 40% 70%, rgba(255, 238, 184, 0.9) 0 2px, transparent 3.2px),
    radial-gradient(circle at 46% 14%, rgba(255, 200, 90, 0.88) 0 2.35px, transparent 3.7px),
    radial-gradient(circle at 52% 88%, rgba(255, 241, 204, 0.96) 0 1.9px, transparent 3px),
    radial-gradient(circle at 58% 42%, rgba(255, 214, 102, 0.93) 0 2.45px, transparent 3.8px),
    radial-gradient(circle at 64% 20%, rgba(255, 232, 168, 0.9) 0 1.9px, transparent 3px),
    radial-gradient(circle at 70% 76%, rgba(255, 201, 77, 0.88) 0 2.4px, transparent 3.8px),
    radial-gradient(circle at 76% 30%, rgba(255, 244, 214, 0.94) 0 1.85px, transparent 2.95px),
    radial-gradient(circle at 82% 62%, rgba(255, 214, 102, 0.92) 0 2.4px, transparent 3.8px),
    radial-gradient(circle at 88% 16%, rgba(255, 238, 184, 0.88) 0 2px, transparent 3.2px),
    radial-gradient(circle at 92% 84%, rgba(255, 200, 90, 0.86) 0 2.35px, transparent 3.7px);
    filter: drop-shadow(0 0 4px rgba(255, 223, 154, 0.45)) drop-shadow(0 0 8px rgba(255, 170, 39, 0.22));
    animation: legendaryParticleDrift 4.8s ease-in-out infinite,
    legendaryTwinkle 2.7s ease-in-out infinite;
}

.battle-card.rarity-legendary .legendary-particles::after,
.battle-card[data-rarity="legendary"] .legendary-particles::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.92;
    background: radial-gradient(circle at 18% 24%, rgba(255, 255, 255, 1) 0 1.2px, transparent 2.2px),
    linear-gradient(rgba(255, 239, 184, 0.96), rgba(255, 239, 184, 0.96)),
    linear-gradient(90deg, rgba(255, 239, 184, 0.96), rgba(255, 239, 184, 0.96)),
    radial-gradient(circle at 74% 28%, rgba(255, 255, 255, 1) 0 1.2px, transparent 2.2px),
    linear-gradient(rgba(255, 214, 102, 0.92), rgba(255, 214, 102, 0.92)),
    linear-gradient(90deg, rgba(255, 214, 102, 0.92), rgba(255, 214, 102, 0.92)),
    radial-gradient(circle at 30% 72%, rgba(255, 255, 255, 0.96) 0 1.1px, transparent 2.1px),
    linear-gradient(rgba(255, 230, 160, 0.88), rgba(255, 230, 160, 0.88)),
    linear-gradient(90deg, rgba(255, 230, 160, 0.88), rgba(255, 230, 160, 0.88)),
    radial-gradient(circle at 84% 70%, rgba(255, 255, 255, 0.95) 0 1.1px, transparent 2px),
    linear-gradient(rgba(255, 208, 120, 0.84), rgba(255, 208, 120, 0.84)),
    linear-gradient(90deg, rgba(255, 208, 120, 0.84), rgba(255, 208, 120, 0.84));
    background-size: 10px 10px, 2px 18px, 18px 2px,
    10px 10px, 2px 16px, 16px 2px,
    9px 9px, 2px 14px, 14px 2px,
    9px 9px, 2px 14px, 14px 2px;
    background-repeat: no-repeat;
    background-position: 18% 24%, calc(18% + 4px) calc(24% - 4px), calc(18% - 4px) calc(24% + 4px),
    74% 28%, calc(74% + 4px) calc(28% - 3px), calc(74% - 3px) calc(28% + 4px),
    30% 72%, calc(30% + 3px) calc(72% - 3px), calc(30% - 3px) calc(72% + 3px),
    84% 70%, calc(84% + 3px) calc(70% - 3px), calc(84% - 3px) calc(70% + 3px);
    filter: drop-shadow(0 0 5px rgba(255, 228, 168, 0.34));
    animation: legendaryTwinkle 2.9s ease-in-out infinite;
}

.battle-card.rarity-legendary .card-art::before,
.battle-card[data-rarity="legendary"] .card-art::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    opacity: 0.74;
    background: radial-gradient(circle at 16% 78%, rgba(255, 239, 184, 0.84) 0 1.3px, transparent 2.1px),
    radial-gradient(circle at 25% 24%, rgba(255, 214, 102, 0.84) 0 1.45px, transparent 2.2px),
    radial-gradient(circle at 40% 65%, rgba(255, 232, 168, 0.82) 0 1.1px, transparent 1.9px),
    radial-gradient(circle at 61% 16%, rgba(255, 201, 77, 0.8) 0 1.4px, transparent 2.1px),
    radial-gradient(circle at 72% 74%, rgba(255, 244, 214, 0.86) 0 1.1px, transparent 1.8px),
    radial-gradient(circle at 84% 33%, rgba(255, 214, 102, 0.82) 0 1.35px, transparent 2.1px);
    animation: legendaryArtSparkle 5.8s ease-in-out infinite;
}

.battle-card.rarity-legendary.winner .card-frame,
.battle-card[data-rarity="legendary"].winner .card-frame {
    animation: legendaryWinnerMajesty 2.6s ease-in-out infinite;
}

@keyframes legendaryFiligreeGlowTop {
    0%, 100% {
        opacity: 0.82;
        filter: drop-shadow(0 0 2px rgba(255, 232, 168, 0.34));
    }
    50% {
        opacity: 1;
        filter: drop-shadow(0 0 7px rgba(255, 192, 76, 0.42));
    }
}

@keyframes legendaryFiligreeGlowBottom {
    0%, 100% {
        opacity: 0.74;
        filter: drop-shadow(0 0 2px rgba(255, 232, 168, 0.28));
    }
    50% {
        opacity: 0.98;
        filter: drop-shadow(0 0 6px rgba(255, 192, 76, 0.36));
    }
}

@keyframes legendaryFoilSweep {
    0% {
        background-position: -170% -140%, 0% 0%, 0 0;
    }
    100% {
        background-position: 180% 150%, 0% 0%, 0 0;
    }
}

@keyframes legendaryParticleDrift {
    0%, 100% {
        transform: translate3d(0, 0, 0) scale(1);
    }
    20% {
        transform: translate3d(-4px, -6px, 0) scale(1.02);
    }
    40% {
        transform: translate3d(3px, -11px, 0) scale(1.05);
    }
    60% {
        transform: translate3d(6px, -7px, 0) scale(1.03);
    }
    80% {
        transform: translate3d(-2px, -3px, 0) scale(1.01);
    }
}

@keyframes legendaryTwinkle {
    0%, 100% {
        opacity: 0.64;
        filter: brightness(0.98);
    }
    20% {
        opacity: 0.88;
        filter: brightness(1.08);
    }
    50% {
        opacity: 1;
        filter: brightness(1.28);
    }
    75% {
        opacity: 0.86;
        filter: brightness(1.12);
    }
}

@keyframes legendaryArtSparkle {
    0%, 100% {
        opacity: 0.46;
        transform: translate3d(0, 0, 0);
    }
    50% {
        opacity: 0.78;
        transform: translate3d(0, -2px, 0);
    }
}

@keyframes legendaryWinnerMajesty {
    0%, 100% {
        transform: translateY(0) scale(1);
        filter: brightness(1);
    }
    50% {
        transform: translateY(-2px) scale(1.012);
        filter: brightness(1.05);
    }
}

.battle-card.attack-left {
    animation: attackLeftLunge 1.08s cubic-bezier(0.2, 0.78, 0.12, 1);
    z-index: 20;
}

.battle-card.attack-right {
    animation: attackRightLunge 1.08s cubic-bezier(0.2, 0.78, 0.12, 1);
    z-index: 20;
}

/* stronger outer separation for all cards */
.battle-card {
    filter: drop-shadow(0 0 0.5px rgba(0, 0, 0, 0.95)) drop-shadow(0 0 2px rgba(0, 0, 0, 0.45)) drop-shadow(0 22px 42px rgba(0, 0, 0, 0.22));
}

.battle-card.rarity-common .card-frame,
.battle-card[data-rarity="common"] .card-frame {
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.58),
    inset 0 0 0 4px rgba(245, 247, 250, 0.88),
    inset 0 0 0 5px rgba(0, 0, 0, 0.06);
}

@keyframes attackLeftLunge {
    0% {
        transform: translateX(0) scale(1) rotate(0deg);
    }
    24% {
        transform: translateX(28px) scale(1.025) rotate(-1deg);
    }
    62% {
        transform: translateX(190px) scale(1.055) rotate(-2deg);
    }
    100% {
        transform: translateX(0) scale(1) rotate(0deg);
    }
}

@keyframes attackRightLunge {
    0% {
        transform: translateX(0) scale(1) rotate(0deg);
    }
    24% {
        transform: translateX(-28px) scale(1.025) rotate(1deg);
    }
    62% {
        transform: translateX(-190px) scale(1.055) rotate(2deg);
    }
    100% {
        transform: translateX(0) scale(1) rotate(0deg);
    }
}

.battle-card.taking-hit {
    animation: takeHit 0.7s ease;
}

@keyframes takeHit {
    0% {
        transform: translateX(0) scale(1);
    }
    16% {
        transform: translateX(28px) scale(0.985);
    }
    34% {
        transform: translateX(-18px) scale(0.99);
    }
    52% {
        transform: translateX(12px) scale(0.995);
    }
    100% {
        transform: translateX(0) scale(1);
    }
}

.battle-card.winner {
    z-index: 40;
}

.battle-card.winner .card-frame {
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.96),
    0 28px 48px rgba(0, 0, 0, 0.34),
    0 0 36px color-mix(in srgb, var(--accent) 40%, transparent);
}

.battle-card.winner::after {
    content: "";
    position: absolute;
    inset: -14px;
    border-radius: 46px;
    background: radial-gradient(
            circle at center,
            color-mix(in srgb, var(--accent) 20%, transparent),
            transparent 70%
    );
    z-index: -1;
    pointer-events: none;
}

.battle-card.winner-over-left {
    transform: translateX(180px) scale(1.08);
    z-index: 60;
}

.battle-card.winner-over-right {
    transform: translateX(-180px) scale(1.08);
    z-index: 60;
}

.battle-card.loser {
    opacity: 0.66;
    transform: scale(0.96);
    z-index: 10;
}

/* picker intro */
#battleStage.is-picking #cardA,
#battleStage.is-picking #cardB {
    opacity: 0.18;
    transform: scale(0.96);
}

.battle-picker-overlay {
    position: absolute;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 1;
    transition: opacity 220ms ease, transform 220ms ease;
}

.battle-picker-overlay.leaving {
    opacity: 0;
    transform: scale(1.02);
}

.picker-board {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    max-width: 500px;
    width: 100%;
}

.picker-column {
    display: flex;
    align-items: center;
    gap: 12px;
}

.picker-wheel-window {
    width: 180px;
    height: 180px;
    overflow: hidden;
    border-radius: 36px;
    background: rgba(255, 255, 255, 0.82);
    border: 3px solid rgba(255, 255, 255, 0.92);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.18),
    inset 0 2px 0 rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(8px);
}

.picker-wheel-strip {
    will-change: transform;
}

.picker-item {
    width: 180px;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-sizing: border-box;
}

.picker-headshot {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: 28px;
    display: block;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18),
    inset 0 0 0 2px rgba(255, 255, 255, 0.3);
}

/* hands doubled */
.picker-hand {
    width: 144px;
    height: 144px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 88px;
    line-height: 1;
    background: rgba(255, 255, 255, 0.88);
    border: 4px solid rgba(255, 255, 255, 0.94);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.18),
    inset 0 2px 0 rgba(255, 255, 255, 0.7);
    color: #111827;
    transform-origin: center;
}

.picker-hand.spinning {
    animation: pickerHandSpin 260ms linear infinite;
}

.picker-hand.landed {
    animation: none;
    transform: scale(1.08);
}

@keyframes pickerHandSpin {
    0% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(180deg) scale(0.92);
    }
    100% {
        transform: rotate(360deg) scale(1);
    }
}

@media (max-height: 950px), (max-width: 1500px) {
    #battleStage {
        gap: 38px;
        padding: 18px 18px 96px;
    }

    .battle-card {
        width: 300px;
    }

    .card-frame {
        border-radius: 0;
        overflow: clip;
    }

    .card-header {
        padding: 16px 16px 10px;
    }

    .card-name {
        font-size: 22px;
    }

    .card-art {
        margin: 0 14px;
        height: 280px;
        width: 272px;
        border-radius: 24px;
    }

    .card-stats {
        padding: 14px 14px 10px;
    }

    .stat-chip {
        min-height: 56px;
    }

    .stat-symbol {
        font-size: 24px;
    }

    .stat-value {
        font-size: 40px;
    }

    .hp-bar {
        padding: 0 14px 16px;
    }

    .hp-track {
        height: 18px;
    }

    .battle-card.winner-over-left {
        transform: translateX(150px) scale(1.07);
    }

    .battle-card.winner-over-right {
        transform: translateX(-150px) scale(1.07);
    }

    #rollBtn {
        font-size: 17px;
        padding: 11px 18px;
    }
}

/* =========================================================
   RARITY HEADSHOT BORDER
   New block: inset/thickness treatment for all rarity types
   Uses each rarity's existing color theme
   ========================================================= */

.battle-card.rarity-common .card-art,
.battle-card[data-rarity="common"] .card-art,
.battle-card.rarity-uncommon .card-art,
.battle-card[data-rarity="uncommon"] .card-art,
.battle-card.rarity-mythic .card-art,
.battle-card[data-rarity="mythic"] .card-art,
.battle-card.rarity-legendary .card-art,
.battle-card[data-rarity="legendary"] .card-art {
    --rarity-headshot-border: 8px;
    position: relative;
    padding: 0;
    border: 0;
    border-radius: 30px;
    overflow: hidden;
    background: linear-gradient(
            135deg,
            color-mix(in srgb, var(--accent-3) 82%, white 18%) 0%,
            color-mix(in srgb, var(--accent-2) 78%, white 22%) 18%,
            color-mix(in srgb, var(--accent) 68%, var(--accent-2) 32%) 36%,
            color-mix(in srgb, var(--accent) 84%, black 16%) 52%,
            color-mix(in srgb, var(--accent-2) 76%, var(--accent-3) 24%) 68%,
            color-mix(in srgb, var(--accent) 72%, var(--accent-2) 28%) 84%,
            color-mix(in srgb, var(--accent-3) 82%, white 18%) 100%
    );
    background-size: 220% 220%;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--trim) 72%, white 28%),
    0 0 0 1px color-mix(in srgb, var(--accent) 38%, rgba(0, 0, 0, 0.12) 62%),
    0 0 18px color-mix(in srgb, var(--accent) 22%, transparent 78%),
    0 10px 24px rgba(0, 0, 0, 0.18);
    animation: rarityHeadshotBorderShift 4.5s linear infinite;
}

.battle-card.rarity-common .art-theme-bg,
.battle-card[data-rarity="common"] .art-theme-bg,
.battle-card.rarity-common .card-headshot,
.battle-card[data-rarity="common"] .card-headshot,
.battle-card.rarity-common .victory-video,
.battle-card[data-rarity="common"] .victory-video,
.battle-card.rarity-common .art-vignette,
.battle-card[data-rarity="common"] .art-vignette,
.battle-card.rarity-uncommon .art-theme-bg,
.battle-card[data-rarity="uncommon"] .art-theme-bg,
.battle-card.rarity-uncommon .card-headshot,
.battle-card[data-rarity="uncommon"] .card-headshot,
.battle-card.rarity-uncommon .victory-video,
.battle-card[data-rarity="uncommon"] .victory-video,
.battle-card.rarity-uncommon .art-vignette,
.battle-card[data-rarity="uncommon"] .art-vignette,
.battle-card.rarity-mythic .art-theme-bg,
.battle-card[data-rarity="mythic"] .art-theme-bg,
.battle-card.rarity-mythic .card-headshot,
.battle-card[data-rarity="mythic"] .card-headshot,
.battle-card.rarity-mythic .victory-video,
.battle-card[data-rarity="mythic"] .victory-video,
.battle-card.rarity-mythic .art-vignette,
.battle-card[data-rarity="mythic"] .art-vignette,
.battle-card.rarity-legendary .art-theme-bg,
.battle-card[data-rarity="legendary"] .art-theme-bg,
.battle-card.rarity-legendary .card-headshot,
.battle-card[data-rarity="legendary"] .card-headshot,
.battle-card.rarity-legendary .victory-video,
.battle-card[data-rarity="legendary"] .victory-video,
.battle-card.rarity-legendary .art-vignette,
.battle-card[data-rarity="legendary"] .art-vignette {
    top: var(--rarity-headshot-border);
    right: var(--rarity-headshot-border);
    bottom: var(--rarity-headshot-border);
    left: var(--rarity-headshot-border);
    width: calc(100% - (var(--rarity-headshot-border) * 2));
    height: calc(100% - (var(--rarity-headshot-border) * 2));
    border-radius: 22px;
}

@keyframes rarityHeadshotBorderShift {
    0% {
        background-position: 0% 50%;
        filter: brightness(0.98) saturate(1);
    }
    50% {
        background-position: 100% 50%;
        filter: brightness(1.08) saturate(1.12);
    }
    100% {
        background-position: 0% 50%;
        filter: brightness(0.98) saturate(1);
    }
}