/* ===== FX PRIMITIVES ===== */
.fx-spark,
.fx-ring {
    position: fixed;
    pointer-events: none;
    border-radius: 50%;
    z-index: 2;
}

/* Ripples spread out from under the card */
.fx-ring {
    z-index: 0;
    border: 2px solid;
    background: transparent;
}

.fx-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

/* ===== SUMMON CARD (tap to climb, then open) ===== */
.summon-overlay {
    --tier: var(--common);
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 36px;
    background:
        radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--tier) 14%, transparent) 0%, transparent 55%),
        rgba(4, 5, 8, 0.98);
    cursor: pointer;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    animation: overlay-fade-in 0.3s ease-out;
    transition: background 0.4s ease;
}

/* Walkout tease: the room darkens before the legendary flip */
.summon-overlay.charging {
    background: rgba(2, 2, 4, 0.99);
}

.summon-card {
    position: relative;
    z-index: 1;
    width: 200px;
    height: 280px;
    perspective: 1000px;
}

.summon-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.52s cubic-bezier(0.3, 1.25, 0.5, 1);
}

.summon-face {
    --fx: var(--common);
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px 16px;
    text-align: center;
    border-radius: 4px;
    border: 1px solid color-mix(in srgb, var(--fx) 70%, transparent);
    background:
        radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--fx) 22%, transparent) 0%, transparent 65%),
        var(--bg-surface);
    box-shadow: 0 0 30px color-mix(in srgb, var(--fx) 35%, transparent), inset 0 0 24px color-mix(in srgb, var(--fx) 15%, transparent);
}

.summon-face::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid color-mix(in srgb, var(--fx) 30%, transparent);
    border-radius: 2px;
    pointer-events: none;
}

/* A transparent outline gives the rotated edge room to anti-alias instead of stair-stepping */
.summon-face {
    outline: 1px solid transparent;
    transform: translateZ(0.1px);
}

.summon-face-flipped {
    transform: rotateY(180deg) translateZ(0.1px);
}

.summon-face[data-rarity="legendary"]:not(.card-back) {
    animation: choice-legendary-glow 1.6s ease-in-out infinite;
}

/* Buff side of the card packs more content */
.summon-face:has(.summon-face-icon) {
    gap: 6px;
    padding: 22px 18px;
}

.summon-face-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 4px;
    object-fit: contain;
    image-rendering: pixelated;
    filter: drop-shadow(0 0 12px var(--fx));
}

.summon-face-name {
    font-family: var(--font-display);
    font-size: 1.2rem;
    line-height: 1.15;
    font-weight: 600;
    color: var(--fx);
}

.summon-face-effect {
    font-size: 0.8rem;
    line-height: 1.4;
    color: #6abf69;
}

/* ===== ACTIONS (under the opened card) ===== */
.summon-actions {
    position: relative;
    z-index: 2;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: -14px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.summon-actions.shown {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s ease;
}

/* Full-width and tall so it's easy to hit on a phone; keeps its height without the
   "Requires patronage" line */
.summon-ability {
    min-height: 66px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Repick: a text ability button with just its name, plus what it requires when locked */
.summon-ability {
    gap: 2px;
    padding: 12px;
    background: var(--bg-deep);
    border: 1px solid rgba(179, 150, 64, 0.5);
    border-radius: 2px;
    cursor: pointer;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.summon-ability:hover:not(.locked):not(.spent),
.summon-ability:focus-visible {
    outline: none;
    border-color: var(--accent-light);
    box-shadow: 0 0 12px rgba(212, 182, 88, 0.3);
}

.ability-name {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent-light);
}

/* Clearly unavailable: greyed out with a dashed outline */
.summon-ability.locked,
.summon-ability.spent {
    cursor: not-allowed;
    background: transparent;
    border-style: dashed;
    border-color: rgba(110, 106, 94, 0.6);
}

.summon-ability.locked .ability-name,
.summon-ability.spent .ability-name {
    color: var(--text-dim);
}

.ability-note {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-style: italic;
    color: var(--text-dim);
}

.summon-ability:not(.locked) .ability-note {
    display: none;
}

.summon-card.charging {
    animation: summon-charge 0.07s linear infinite;
}

@keyframes summon-charge {
    0% { translate: -3px 2px; }
    25% { translate: 3px -2px; }
    50% { translate: -2px -3px; }
    75% { translate: 2px 3px; }
    100% { translate: -3px 2px; }
}

/* Mirrors the Repick button below the card: same width, height and gap, so both texts
   sit the same distance from the card. Also the "Tap to confirm" tap target. */
.summon-hint {
    width: 200px;
    min-height: 66px;
    margin-bottom: -14px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* One centred line even where the text (~198px) is wider than the box (180px on
       phones); flex centring lets it overflow evenly on both sides */
    text-align: center;
    white-space: nowrap;
    font-family: var(--font-display);
    font-size: 1.2rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--accent-light);
    animation: summon-hint-pulse 1.4s ease-in-out infinite;
    transition: opacity 0.3s ease;
}

.summon-hint.confirm {
    cursor: pointer;
}

.summon-hint.hidden {
    opacity: 0;
    animation: none;
}

@keyframes summon-hint-pulse {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

/* ===== REVEAL PAYOFF (around the revealed card) ===== */
.reveal-backdrop {
    --fx: var(--common);
    position: fixed;
    width: 0;
    height: 0;
    z-index: 0;
    pointer-events: none;
}

.reveal-backdrop > * {
    position: absolute;
    left: 0;
    top: 0;
    translate: -50% -50%;
}

.reveal-glow {
    width: 560px;
    height: 560px;
    max-width: 150vw;
    max-height: 150vw;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--fx) 45%, transparent) 0%, transparent 65%);
    animation: reveal-glow-in 0.6s ease-out;
}

@keyframes reveal-glow-in {
    from { transform: scale(0.2); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* God-rays for rare and above */
.reveal-rays {
    width: 160vmax;
    height: 160vmax;
    background: repeating-conic-gradient(
        from 0deg,
        color-mix(in srgb, var(--fx) 28%, transparent) 0deg 6deg,
        transparent 6deg 18deg
    );
    mask-image: radial-gradient(circle, #000 0%, transparent 45%);
    -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 45%);
    animation: reveal-rays-spin 14s linear infinite, reveal-glow-in 0.8s ease-out;
}

.reveal-rays.legendary {
    background: repeating-conic-gradient(
        from 0deg,
        color-mix(in srgb, var(--fx) 45%, transparent) 0deg 5deg,
        transparent 5deg 12deg
    );
    animation-duration: 8s, 0.8s;
}

@keyframes reveal-rays-spin {
    to { rotate: 360deg; }
}

/* Moves the 250%-wide gradient by exactly one tile so the loop is seamless */
@keyframes reveal-foil {
    from { background-position: 0% 0; }
    to { background-position: -166.667% 0; }
}

/* "Legendary" slams in above the card */
.reveal-stamp {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 18px);
    translate: -50% 0;
    white-space: nowrap;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: #fff4d6;
    text-shadow: 0 0 12px var(--fx), 0 0 30px var(--fx);
    pointer-events: none;
    animation: reveal-stamp-slam 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) 0.15s both;
}

@keyframes reveal-stamp-slam {
    from { transform: scale(2.6); opacity: 0; letter-spacing: 1em; }
    to { transform: scale(1); opacity: 1; letter-spacing: 0.4em; }
}

/* ===== CARD BACK (summon rarity climb) ===== */
.card-back {
    gap: 14px;
    background: var(--bg-surface);
    border: 1px solid color-mix(in srgb, var(--fx) 70%, transparent);
    box-shadow: none;
    animation: none;
    transition: box-shadow 0.08s ease-out;
}

.card-back::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid color-mix(in srgb, var(--fx) 30%, transparent);
    border-radius: 2px;
    pointer-events: none;
}

.card-back > :not(.card-back-bg):not(.card-shine) { position: relative; }

/* About to tap: a quick inner vignette in the rarity colour */
.summon-card:hover .card-back {
    box-shadow: inset 0 0 42px color-mix(in srgb, var(--fx) 32%, transparent);
}

/* Fine diagonal foil grain, faintly tinted, fading out towards the edges */
.card-back-bg {
    position: absolute;
    inset: 10px;
    pointer-events: none;
    background:
        repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.045) 0 2px, transparent 2px 5px),
        repeating-linear-gradient(115deg, transparent 0 1px, color-mix(in srgb, var(--fx) 8%, transparent) 1px 2px, transparent 2px 5px);
    -webkit-mask-image: radial-gradient(ellipse at 50% 45%, #000 30%, transparent 75%);
    mask-image: radial-gradient(ellipse at 50% 45%, #000 30%, transparent 75%);
}

.card-back-icon {
    width: 72px;
    height: 72px;
    image-rendering: pixelated;
}

.card-back-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 10px;
    color: var(--fx);
}

.card-back-divider span {
    width: 34px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--fx));
}

.card-back-divider span:last-child {
    background: linear-gradient(90deg, var(--fx), transparent);
}

.card-back-label {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--fx);
    text-shadow: 0 0 12px color-mix(in srgb, var(--fx) 60%, transparent);
}

/* Shine on both faces: none for common to rare, Foil Catch for epic, Holographic for legendary */
.card-shine {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 4px;
    pointer-events: none;
    z-index: 2;
}

.card-shine::after {
    content: '';
    position: absolute;
    inset: 0;
}

.summon-face[data-rarity="epic"] .card-shine::after,
.shelf-card[data-rarity="epic"] .card-shine::after {
    background: repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.4) 0 2px, transparent 2px 5px);
    -webkit-mask: linear-gradient(115deg, transparent 38%, #000 50%, transparent 62%) 0 0 / 250% 100%;
    mask: linear-gradient(115deg, transparent 38%, #000 50%, transparent 62%) 0 0 / 250% 100%;
    animation: card-back-mask-sweep 2.8s linear infinite;
}

.summon-face[data-rarity="legendary"] .card-shine::after,
.shelf-card[data-rarity="legendary"] .card-shine::after {
    background: linear-gradient(115deg, transparent 41%, rgba(255, 120, 200, 0.22) 45%, rgba(255, 240, 200, 0.32) 50%, rgba(120, 230, 255, 0.22) 55%, transparent 59%) 0 0 / 250% 100%;
    mix-blend-mode: plus-lighter;
    animation: reveal-foil 2.6s linear infinite;
}

/* ===== SHELF CARDS: the top shelf's buffs as mini card backs ===== */
/* Same look as the summon card back in each rarity (border, inner line, foil, shine),
   holding the buff's own icon, with the remaining duration as a fill rising from the bottom */
.buffs-shelf .buff .shelf-card {
    width: 40px;
    height: 56px;
    border-radius: 3px;
    background: var(--bg-surface);
    /* Inner border line, like the card back's */
    box-shadow: inset 0 0 0 3px var(--bg-surface), inset 0 0 0 4px color-mix(in srgb, var(--fx) 30%, transparent);
}

/* Outer border; also carries the focused pulse */
.buffs-shelf .buff .shelf-card::before {
    border-radius: 3px;
    border: 1px solid color-mix(in srgb, var(--fx) 70%, transparent);
    box-shadow: none;
}

/* Duration fill */
.buffs-shelf .buff .shelf-card::after {
    border-radius: 2px;
}

.shelf-card .card-back-bg {
    inset: 4px;
}

.shelf-card .card-shine {
    border-radius: 3px;
}

@media (max-width: 600px) {
    .buffs-shelf .buff .shelf-card {
        width: 32px;
        height: 45px;
    }
}

/* Pulsing glow on the legendary buff face */
@keyframes choice-legendary-glow {
    0%, 100% { box-shadow: 0 0 18px color-mix(in srgb, var(--fx) 25%, transparent); }
    50% { box-shadow: 0 0 36px color-mix(in srgb, var(--fx) 60%, transparent); }
}

/* Moves a 250%-wide mask by exactly one tile so the loop is seamless */
@keyframes card-back-mask-sweep {
    from { -webkit-mask-position: 0% 0; mask-position: 0% 0; }
    to { -webkit-mask-position: -166.667% 0; mask-position: -166.667% 0; }
}

@media (max-width: 600px) {
    .summon-card {
        width: 180px;
        height: 252px;
    }

    .summon-actions,
    .summon-hint {
        width: 180px;
    }
}
