/* Adapted from the supplied Simey card effects, with local gradient textures. */
@property --pointer-x {
    syntax: "<percentage>";
    inherits: true;
    initial-value: 50%;
}
@property --pointer-y {
    syntax: "<percentage>";
    inherits: true;
    initial-value: 50%;
}
@property --foil-color-opacity {
    syntax: "<number>";
    inherits: true;
    initial-value: .48;
}
@property --foil-pattern-x {
    syntax: "<percentage>";
    inherits: true;
    initial-value: 50%;
}
@property --foil-pattern-y {
    syntax: "<percentage>";
    inherits: true;
    initial-value: 50%;
}
@property --foil-glare-opacity {
    syntax: "<number>";
    inherits: true;
    initial-value: .3;
}
@property --foil-glare-x {
    syntax: "<percentage>";
    inherits: true;
    initial-value: 0%;
}
@property --foil-glare-y {
    syntax: "<percentage>";
    inherits: true;
    initial-value: 0%;
}
:is(#playerHand .game-card, .card-preview)[data-foil] {
    isolation: isolate;
    /* Match the SVG card outline: its 1.5-unit stroke at x/y 1.5 leaves 0.75 of 80×120 units transparent,
       and the outer corner radius is 8.75 units on a 78.5×118.5 unit card. */
    --foil-inset: 0.625% 0.9375%;
    --foil-radius: 11.15% / 7.38%;
    --foil-angle: 133deg;
    --foil-space: 5%;
    --foil-x: calc(50% + (var(--pointer-x, 50%) - 50%) * .8);
    --foil-y: calc(50% + (var(--pointer-y, 50%) - 50%) * .8);
    --foil-spectrum: repeating-linear-gradient(0deg,
        #ff7773 5%, #ffed5f 10%, #a8ff5f 15%, #83fff7 20%,
        #7894ff 25%, #d875ff 30%, #ff7773 35%);
    --foil-texture: repeating-linear-gradient(45deg, #fff3 0 1px, #0002 1px 3px, transparent 3px 7px);
    --foil-bars: repeating-linear-gradient(var(--foil-angle),
        #0e152e 0%, #8faaaa 3.8%, #8fc2c2 4.5%, #8faaaa 5.2%, #0e152e 10% 12%);
    --foil-light: radial-gradient(farthest-corner circle at var(--foil-x) var(--foil-y),
        #fff9 5%, #9995 40%, #000 100%);
    --foil-blend: screen, hue, hard-light;
    --foil-filter: brightness(.8) contrast(2.95) saturate(.5);
    --foil-mix: soft-light;
    --foil-size: 60%, 200% 700%, 300%, 200%;
    --foil-strength: 1;
    --foil-saturation: 1;
}

/* The pixel card style draws square corners. */
:is([data-card-style="pixel"] #playerHand .game-card, #playerHand .game-card[data-card-style="pixel"],
    .card-preview--pixel)[data-foil] {
    --foil-radius: 0;
}

.card-foil-option__select > strong,
.card-style-option__select > strong {
    min-width: 0;
    white-space: normal;
    text-align: right;
}

:is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"])::before {
    position: absolute;
    inset: var(--foil-inset);
    z-index: 1;
    border-radius: var(--foil-radius);
    content: "";
    pointer-events: none;
    background-image: var(--foil-texture), var(--foil-spectrum), var(--foil-bars), var(--foil-light);
    background-size: var(--foil-size);
    background-position: center, 0% var(--foil-y),
        var(--foil-x) var(--foil-y), center;
    background-blend-mode: var(--foil-blend);
    filter: var(--foil-filter) saturate(var(--foil-saturation));
    mix-blend-mode: var(--foil-mix);
    opacity: calc(.48 * var(--foil-strength));
    animation: none;
    transition: opacity 400ms ease, background-position 400ms ease-out;
}

:is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"])::after {
    position: absolute;
    inset: var(--foil-inset);
    z-index: 2;
    border-radius: var(--foil-radius);
    content: "";
    pointer-events: none;
    /* A plain white stand-in for a soft-light glare: within 6 of 255 levels on any colour (perf/foil-model.cjs),
       and it needs no off-screen render pass, so it can drift on the compositor for almost nothing. */
    background: radial-gradient(farthest-corner circle at var(--foil-x) var(--foil-y),
        rgb(255 255 255 / .077) 0%, rgb(255 255 255 / .019) 25%, transparent 65%);
    opacity: calc(.3 * var(--foil-strength));
    transition: opacity 400ms ease;
}

:is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"]).is-tilting::before,
.card-foil-option:hover .card-preview[data-foil]:not([data-foil="none"])::before,
.card-foil-option:focus-visible .card-preview[data-foil]:not([data-foil="none"])::before {
    opacity: calc(.72 * var(--foil-strength));
}

:is(#playerHand .game-card, .card-preview).card-flight[data-foil]:not([data-foil="none"])::before {
    background-position: center, 0% var(--foil-pattern-y),
        var(--foil-pattern-x) var(--foil-pattern-y), center;
    opacity: calc(var(--foil-color-opacity) * var(--foil-strength));
    transition: none;
}
:is(#playerHand .game-card, .card-preview).card-flight[data-foil]:not([data-foil="none"])::after {
    opacity: calc(var(--foil-glare-opacity) * var(--foil-strength));
    translate: var(--foil-glare-x) var(--foil-glare-y);
    transition: none;
}

/* Drag previews receive a JavaScript-eased pattern position instead of restarting a CSS transition every frame. */
:is(#playerHand .game-card, .card-preview).card-drag-preview[data-foil]:not([data-foil="none"])::before {
    background-position: center, 0% var(--foil-pattern-y),
        var(--foil-pattern-x) var(--foil-pattern-y), center;
    transition: opacity 400ms ease;
}
:is(#playerHand .game-card, .card-preview).card-drag-preview.is-returning[data-foil]:not([data-foil="none"])::before {
    transition: opacity 400ms ease, background-position 400ms ease-out;
}

:is(#playerHand .game-card, .card-preview)[data-foil="holo"] {
    --foil-texture: repeating-linear-gradient(90deg, #ff3780 0 2px, #000 2px 4px,
        #56cfff 4px 6px, #000 6px 8px, #eedf10 8px 10px, #000 10px 12px);
    --foil-spectrum: repeating-linear-gradient(90deg, #c929f1, #0dbde9, #21e985, #eedf10, #f80e7b, #c929f1);
    --foil-bars: repeating-linear-gradient(90deg, #0a0a0a 0 24px, #fff9 36px,
        #0a0a0a 42px, #fff9 48px, #0a0a0a 60px 144px);
    --foil-size: 100% 100%, 200% 200%, 237% 237%, 120% 120%;
    --foil-blend: soft-light, screen, overlay;
    --foil-filter: brightness(.75) contrast(3.2) saturate(.66);
}

:is(#playerHand .game-card, .card-preview)[data-foil="galaxy"] {
    --foil-texture: radial-gradient(circle at 20% 30%, #fff 0 1px, transparent 3px),
        radial-gradient(circle at 65% 70%, #ffb9f9 0 2px, transparent 5px);
    --foil-spectrum: repeating-linear-gradient(82deg, #da3832, #dbcc56, #79c73a, #3ac0b7, #4762cf, #aa45d1, #da3832);
    --foil-size: 23px 37px, 41px 53px, 600% 1200%, 200%, 120%;
    --foil-blend: color-dodge, color-burn, saturation, screen;
    --foil-filter: brightness(.75) contrast(1.2) saturate(1.5);
    --foil-mix: color-dodge;
}

:is(#playerHand .game-card, .card-preview)[data-foil="vmax"] {
    --foil-angle: 133deg;
    --foil-texture: repeating-radial-gradient(ellipse at 35% 60%, #fff8 0 1px, #0008 2px 4px, transparent 5px 9px);
    --foil-spectrum: repeating-linear-gradient(-33deg, #ce2a24 6%, #9daedf 12%,
        #2d9992 18%, #1d9724 24%, #b540e4 30%, #ce2a24 36%);
    --foil-blend: color-burn, screen, soft-light;
    --foil-size: 60% 30%, 1100% 1100%, 600% 600%, 200% 200%;
    --foil-filter: brightness(.7) contrast(2.5) saturate(.6);
}

:is(#playerHand .game-card, .card-preview)[data-foil="vstar"] {
    --foil-texture: repeating-conic-gradient(from 45deg at 50% 50%, #fff8 0deg 10deg, #0006 10deg 20deg, transparent 20deg 45deg);
    --foil-size: 30%, 200% 700%, 300%, 200%;
    --foil-blend: soft-light, hue, hard-light;
    --foil-filter: brightness(.8) contrast(2) saturate(.75);
}

:is(#playerHand .game-card, .card-preview)[data-foil="full-art"] {
    --foil-texture: repeating-radial-gradient(ellipse at center, #fff9 0 1px, transparent 2px 5px, #0005 6px 7px);
    --foil-size: 50%, 200% 700%, 300%, 200%;
    --foil-blend: exclusion, hue, hard-light;
    --foil-filter: brightness(.75) contrast(2) saturate(1.5);
}

:is(#playerHand .game-card, .card-preview)[data-foil="trainer-full-art"] {
    --foil-texture: repeating-linear-gradient(30deg, #fff9 0 1px, transparent 2px 6px),
        repeating-linear-gradient(-30deg, #0006 0 1px, transparent 2px 6px);
    --foil-size: 50%, 50%, 200% 700%, 300%, 200%;
    --foil-blend: difference, difference, hue, hard-light;
    --foil-filter: brightness(.75) contrast(2.5) saturate(.75);
}

:is(#playerHand .game-card, .card-preview)[data-foil="rainbow"],
:is(#playerHand .game-card, .card-preview)[data-foil="rainbow-alt"] {
    --foil-angle: 130deg;
    --foil-texture: repeating-radial-gradient(circle at center, #fff6 0 1px, #0004 1px 2px, transparent 2px 4px);
    --foil-spectrum: repeating-linear-gradient(-20deg, #fd4741 7%, #fff397 14%, #a8ff5f 21%,
        #83fff7 28%, #4bc6ff 35%, #ff49f6 42%, #ff3831 49%);
    --foil-blend: color-burn, soft-light, normal;
    --foil-size: 50% 50%, 500% 500%, 1000% 1000%, 200%;
    --foil-filter: brightness(.85) contrast(2) saturate(.95);
}

:is(#playerHand .game-card, .card-preview)[data-foil="rainbow-alt"] {
    --foil-filter: brightness(.85) contrast(3) saturate(.7);
    --foil-mix: exclusion;
}

:is(#playerHand .game-card, .card-preview)[data-foil="gold"] {
    --foil-angle: 110deg;
    --foil-spectrum: repeating-linear-gradient(110deg, #775120 0%, #bfa56e 2.5%,
        #d8b75c 5%, #bfa56e 7.5%, #463719 10% 15%);
    --foil-bars: repeating-linear-gradient(20deg, #fff5 0 1px, #0004 2px 3px, transparent 4px 8px);
    --foil-blend: color-burn, darken, soft-light;
    --foil-filter: brightness(.95) contrast(3) saturate(.66);
}

:is(#playerHand .game-card, .card-preview)[data-foil="radiant"] {
    --foil-spectrum: repeating-linear-gradient(55deg, #ffa19e, #55b2ff, #ffc792, #82ffd5, #fdaaf0, #94f1ff, #ffa19e);
    --foil-texture: repeating-linear-gradient(45deg, #111 0 2px, #555 3px, #aaa 4px, #555 5px, #111 6px 8px);
    --foil-bars: repeating-linear-gradient(-45deg, #111 0 2px, #555 3px, #aaa 4px, #555 5px, #111 6px 8px);
    --foil-size: 100% 100%, 400% 400%, 100% 100%, 200%;
    --foil-blend: screen, difference, soft-light;
    --foil-filter: brightness(.9) contrast(1.8) saturate(.9);
}

:is(#playerHand .game-card, .card-preview)[data-foil="gallery-holo"] {
    --foil-texture: linear-gradient(transparent, transparent);
    --foil-spectrum: repeating-linear-gradient(-22deg, #ae66ca 5%, #e44d48 10%,
        #d8c537 15%, #7cc93e 20%, #50b1aa 25%, #88a0ff 30%, #b069cc 35%);
    --foil-bars: linear-gradient(transparent, transparent);
    --foil-size: 100%, 200% 400%, 100%, 200%;
    --foil-filter: brightness(.8) contrast(2.3) saturate(1.1);
    --foil-mix: hard-light;
}

:is(#playerHand .game-card, .card-preview)[data-foil="gallery-v"] {
    --foil-texture: repeating-radial-gradient(ellipse at 35% 60%, #fff9 0 1px, #0006 2px 3px, transparent 4px 7px);
    --foil-blend: exclusion, hue, hard-light;
    --foil-filter: brightness(.8) contrast(2.5) saturate(1);
}

:is(#playerHand .game-card, .card-preview)[data-foil="gallery-vmax"] {
    --foil-texture: repeating-conic-gradient(from 20deg, #fff9 0deg 8deg, transparent 8deg 15deg, #0006 15deg 20deg, transparent 20deg 30deg);
    --foil-size: 48%, 200% 700%, 300%, 200%;
    --foil-blend: exclusion, hue, hard-light;
    --foil-filter: brightness(.9) contrast(2.5) saturate(1);
}

@keyframes foil-idle-glare {
    0%, 100% { translate: -3.2% -1.6%; }
    50% { translate: 3.2% 1.6%; }
}
/* Behind a dialog's dimmed, blurred backdrop the shimmer is invisible, but every frame would re-blur it.
   A class set by showDialog, because body:has() would re-check this rule on every DOM change. */
body.has-open-dialog :is(#playerHand .game-card, #gameTable .card-preview)::before,
body.has-open-dialog :is(#playerHand .game-card, #gameTable .card-preview)::after {
    animation-play-state: paused !important;
}

/* The blended colour layer stays still at rest, so it is painted once into its card's layer and costs no render pass
   while something else on the page moves. Only the plain glare drifts, and only on cards that nothing covers. */
@media (prefers-reduced-motion: no-preference) {
    :is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"]):not(.is-tilting,
        .card-flight, .card-discard-flight, .is-drag-source, .card-drag-layer *,
        .card-foil-option:is(:hover, :focus-visible) *)::before {
        transition: none;
    }
    /* The drifting glare is inset by its travel distance, so it never extends past the card. */
    :is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"]):not(.is-tilting,
        .card-flight, .card-discard-flight, .is-drag-source, .card-drag-layer *,
        .card-foil-option:is(:hover, :focus-visible) *)::after {
        inset: calc(.625% + 1.6%) calc(.9375% + 3.2%);
        animation: foil-idle-glare 6s steps(45) infinite;
        transition: none;
    }
}

.table-play[data-top-play="false"] .card-preview::after {
    animation: none !important;
}

/* A moving card's foil keeps its own layers, so tilting the card moves them without repainting the gradients. */
:is(.card-drag-preview, .card-flight)[data-foil]:not([data-foil="none"])::before,
:is(.card-drag-preview, .card-flight)[data-foil]:not([data-foil="none"])::after {
    will-change: transform;
}

.is-foil-offscreen[data-foil]::before,
.is-foil-offscreen[data-foil]::after {
    animation-play-state: paused !important;
}

/* At most a tenth of this table card shows (see CardDepth.updateFoilCoverage), so its blended foil layers are skipped. */
.table-play__card.is-foil-covered[data-foil]::before,
.table-play__card.is-foil-covered[data-foil]::after {
    display: none !important;
}

/* The foil and style pickers stay in the DOM while closed. A visibility:hidden element paints nothing, so its
   animation has no compositor layer and would otherwise tick on the main thread every frame. */
.dialog-container:not(.dialog-container--visible) .card-preview::before,
.dialog-container:not(.dialog-container--visible) .card-preview::after {
    animation: none !important;
}

/* English configuration names map to persisted foil IDs without changing player preferences. */
:is(#playerHand .game-card, .card-preview)[data-foil="holo"] { /* stripes */
    --foil-strength: .7; --foil-saturation: .75; --foil-mix: soft-light;
}
:is(#playerHand .game-card, .card-preview)[data-foil="galaxy"] { /* stardust */
    --foil-strength: .7; --foil-saturation: .5;
}
:is(#playerHand .game-card, .card-preview)[data-foil="v"] { /* prism */
    --foil-strength: .8; --foil-saturation: .75;
}
:is(#playerHand .game-card, .card-preview)[data-foil="vstar"] { /* facets */
    --foil-strength: .7; --foil-saturation: .75;
}
:is(#playerHand .game-card, .card-preview)[data-foil="full-art"],
:is(#playerHand .game-card, .card-preview)[data-foil="trainer-full-art"] { /* rings, weave */
    --foil-strength: .8; --foil-saturation: .75;
}
:is(#playerHand .game-card, .card-preview)[data-foil="rainbow"] {
    --foil-strength: .9;
}
:is(#playerHand .game-card, .card-preview)[data-foil="rainbow-alt"],
:is(#playerHand .game-card, .card-preview)[data-foil="gold"],
:is(#playerHand .game-card, .card-preview)[data-foil="gallery-holo"] { /* contrast, gold-sheen, iridescent */
    --foil-strength: .7;
}
:is(#playerHand .game-card, .card-preview)[data-foil="radiant"] { /* grid */
    --foil-strength: .8;
}
:is(#playerHand .game-card, .card-preview)[data-foil="gallery-v"],
:is(#playerHand .game-card, .card-preview)[data-foil="gallery-vmax"] { /* pearlescent, rays */
    --foil-strength: .7; --foil-saturation: .75;
}

@media (prefers-reduced-motion: reduce) {
    :is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"])::before,
    :is(#playerHand .game-card, .card-preview)[data-foil]:not([data-foil="none"])::after {
        background-position: center;
        transition: none;
    }
}
