/* ── gacha.css — PTCG 抽卡模擬器專用樣式 ──────────────────────────────────── */

/* Page-level dark override */
body.gacha-page {
    background: #080d1a;
    color: #e0e0e0;
    min-height: 100dvh;
    overflow-x: hidden; /* prevent GSAP transforms from enabling horizontal pan */
}

body.gacha-page header {
    background: rgba(8,13,26,0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(252,163,17,0.2);
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
.gacha-main {
    padding-top: 1.5rem;
    padding-bottom: max(3rem, env(safe-area-inset-bottom));
    min-height: calc(100dvh - 70px);
}

.gacha-hero {
    text-align: center;
    padding: 1.5rem 1rem 0.5rem;
}

.gacha-hero h2 {
    font-size: clamp(1.4rem, 4vw, 2rem);
    font-weight: 700;
    color: #fca311;
    letter-spacing: 0.04em;
    margin: 0 0 0.3rem;
}

.gacha-hero p {
    color: rgba(224,224,224,0.6);
    font-size: 0.9rem;
    margin: 0;
}

/* ── Series Swiper ─────────────────────────────────────────────────────────── */
.series-section {
    padding: 1.5rem 0 1rem;
    position: relative;
}

.series-swiper {
    width: 100%;
    padding: 0.5rem 0 1.5rem !important;
    overflow: visible !important;
}

.series-swiper .swiper-wrapper {
    align-items: center;
}

.swiper-slide.series-slide {
    width: 180px;
    flex-shrink: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0.45;
    transform: scale(0.86);
    cursor: pointer;
}

.swiper-slide.series-slide.swiper-slide-active {
    opacity: 1;
    transform: scale(1);
}

.series-card {
    background: rgba(20,33,61,0.7);
    border: 1px solid rgba(252,163,17,0.25);
    border-radius: 14px;
    overflow: hidden;
    text-align: center;
    transition: border-color 0.3s;
}

.swiper-slide-active .series-card {
    border-color: rgba(252,163,17,0.7);
    box-shadow: 0 0 24px rgba(252,163,17,0.2);
}

.series-cover-wrap {
    aspect-ratio: 5 / 7;
    background: #0e1a30;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.series-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.swiper-slide-active .series-cover-img {
    transform: scale(1.04);
}

.series-info {
    padding: 0.6rem 0.5rem 0.8rem;
}

.series-name-zh {
    font-size: 0.72rem;
    font-weight: 600;
    color: #fca311;
    margin: 0 0 0.2rem;
    line-height: 1.3;
}

.series-name-jp {
    font-size: 0.65rem;
    color: rgba(224,224,224,0.5);
    margin: 0 0 0.3rem;
    line-height: 1.3;
}

.series-card-count {
    font-size: 0.62rem;
    color: rgba(224,224,224,0.35);
    margin: 0 0 0.2rem;
}

.series-price {
    font-size: 0.68rem;
    font-weight: 700;
    color: #fca311;
    margin: 0;
    letter-spacing: 0.02em;
}

.series-price--empty {
    color: rgba(224,224,224,0.3);
    font-weight: 400;
}

/* ── Draw Button ────────────────────────────────────────────────────────────── */
.draw-btn-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}

.draw-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: #fca311;
    color: #080d1a;
    border: none;
    border-radius: 9999px;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.85rem 2.8rem;
    cursor: pointer;
    letter-spacing: 0.06em;
    box-shadow: 0 0 28px rgba(252,163,17,0.4);
    transition: box-shadow 0.2s, opacity 0.2s;
    min-width: 160px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.draw-btn:hover:not(:disabled) {
    box-shadow: 0 0 40px rgba(252,163,17,0.6);
}

.draw-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.draw-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}

.draw-btn-spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(8,13,26,0.3);
    border-top-color: #080d1a;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Cards Area ─────────────────────────────────────────────────────────────── */
.cards-section {
    padding: 0 1rem 1.5rem;
}

.flip-hint {
    text-align: center;
    color: rgba(224,224,224,0.5);
    font-size: 0.85rem;
    margin: 0 0 1rem;
    letter-spacing: 0.03em;
    animation: hint-pulse 2s ease-in-out infinite;
}

@keyframes hint-pulse {
    0%, 100% { opacity: 0.5; }
    50%       { opacity: 1; }
}

/* Desktop: 5-card row */
.cards-grid {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: nowrap;
}

/* Mobile: 3 per row, last 2 auto-centred via flex */
@media (max-width: 767px) {
    .cards-grid {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        max-width: min(300px, 100vw - 2rem);
        margin: 0 auto;
    }

    .cards-grid .card-flip {
        width: calc((100% - 16px) / 3); /* 3 cols, 2 gaps of 8px */
        flex-shrink: 0;
    }
}

/* ── Bottom actions area (全部翻開 ↔ 再抽一包) ────────────────────────────── */
.bottom-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 0 0;
    flex-wrap: wrap;
}

.open-all-btn {
    background: rgba(252,163,17,0.12);
    border: 1.5px solid rgba(252,163,17,0.55);
    color: #fca311;
    border-radius: 9999px;
    font-size: 0.88rem;
    font-weight: 700;
    padding: 0.38rem 1.3rem;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.open-all-btn:hover:not(:disabled) {
    background: rgba(252,163,17,0.22);
    border-color: #fca311;
}

.open-all-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.open-all-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Card Flip ──────────────────────────────────────────────────────────────── */
.card-flip {
    position: relative;
    flex-shrink: 0;
    width: 120px;
    aspect-ratio: 5 / 7;
    border-radius: 10px;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* .card-flip mobile width is set inside .cards-grid @media block above */

.card-flip:focus-visible {
    box-shadow: 0 0 0 3px #fca311;
}

.card-face {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

/* Card back — real PTCG card back image */
.card-back-face {
    background: url('../img/ptcg-card-back.webp') center / cover no-repeat, #0e1a30;
    border: none;
}

.card-front-face {
    background: #0e1a30;
}

.card-front-face img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 10px;
}

/* Skeleton shimmer */
.card-shimmer .card-back-face {
    background: linear-gradient(
        90deg,
        #1a2540 25%,
        #253060 50%,
        #1a2540 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-color: transparent;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Rarity Effects ─────────────────────────────────────────────────────────── */

/* R — silver glow */
.rarity-R .card-front-face {
    box-shadow: 0 0 12px 2px rgba(192,192,192,0.5);
    border: 1.5px solid rgba(192,192,192,0.6);
}

/* RR — gold glow */
.rarity-RR .card-front-face {
    box-shadow: 0 0 18px 4px rgba(212,175,55,0.6);
    border: 1.5px solid rgba(212,175,55,0.7);
}

/* AR — rainbow animated border */
.rarity-AR .card-front-face {
    border: 2px solid hsl(0,80%,60%);
    animation: rainbow-border 2s linear infinite;
    box-shadow: 0 0 16px 2px rgba(255,100,100,0.4);
}

@keyframes rainbow-border {
    0%   { border-color: hsl(0,80%,60%);   box-shadow: 0 0 16px 2px hsla(0,80%,60%,0.4); }
    25%  { border-color: hsl(90,80%,50%);  box-shadow: 0 0 16px 2px hsla(90,80%,50%,0.4); }
    50%  { border-color: hsl(200,80%,60%); box-shadow: 0 0 16px 2px hsla(200,80%,60%,0.4); }
    75%  { border-color: hsl(280,80%,65%); box-shadow: 0 0 16px 2px hsla(280,80%,65%,0.4); }
    100% { border-color: hsl(360,80%,60%); box-shadow: 0 0 16px 2px hsla(0,80%,60%,0.4); }
}

/* SR — blue-purple glow + shimmer */
.rarity-SR .card-front-face {
    border: 2px solid #7b2fff;
    box-shadow: 0 0 22px 6px rgba(123,47,255,0.55);
    animation: sr-pulse 1.8s ease-in-out infinite;
}

@keyframes sr-pulse {
    0%, 100% { box-shadow: 0 0 22px 6px rgba(123,47,255,0.55); }
    50%       { box-shadow: 0 0 36px 10px rgba(123,47,255,0.8); }
}

/* SAR — full-card rainbow holo overlay */
.rarity-SAR .card-front-face {
    border: 2.5px solid #fff;
    animation: rainbow-border 1.6s linear infinite;
    position: relative;
}

.rarity-SAR .card-front-face::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 9px;
    background: linear-gradient(
        135deg,
        hsla(0,100%,70%,0.18),
        hsla(60,100%,70%,0.18),
        hsla(120,100%,70%,0.18),
        hsla(200,100%,70%,0.18),
        hsla(280,100%,70%,0.18),
        hsla(340,100%,70%,0.18)
    );
    background-size: 300% 300%;
    mix-blend-mode: color-dodge;
    animation: holo-shift 3s linear infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes holo-shift {
    0%   { background-position: 0% 0%; }
    50%  { background-position: 100% 100%; }
    100% { background-position: 0% 0%; }
}

/* UR — gold pulse + border */
.rarity-UR .card-front-face {
    border: 3px solid #ffd700;
    animation: ur-pulse 1.4s ease-in-out infinite;
    position: relative;
}

.rarity-UR .card-front-face::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(255,215,0,0.22), transparent 60%, rgba(255,215,0,0.12));
    mix-blend-mode: screen;
    pointer-events: none;
    z-index: 1;
}

@keyframes ur-pulse {
    0%, 100% { box-shadow: 0 0 20px 6px rgba(255,215,0,0.55); }
    50%       { box-shadow: 0 0 44px 16px rgba(255,215,0,0.85); }
}

/* ── Rarity Badge ───────────────────────────────────────────────────────────── */
.rarity-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 2;
    pointer-events: none;
    letter-spacing: 0.04em;
}

.badge-C  { background: rgba(0,0,0,0.55); color: #aaa; }
.badge-U  { background: rgba(0,0,0,0.55); color: #6ab0de; }
.badge-R  { background: rgba(30,30,30,0.75); color: #c0c0c0; }
.badge-RR { background: rgba(30,20,0,0.75); color: #d4af37; }
.badge-AR { background: rgba(30,0,0,0.75); color: #ff9999; }
.badge-SR { background: rgba(20,0,40,0.75); color: #bb88ff; }
.badge-SAR{ background: rgba(20,0,40,0.85); color: #ffbbff; }
.badge-UR { background: rgba(30,25,0,0.85); color: #ffd700; }

/* ── Screen Flash (SR/SAR/UR reveal) ──────────────────────────────────────── */
.screen-flash {
    position: fixed;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
}

/* ── Error State ─────────────────────────────────────────────────────────────*/
.draw-error {
    text-align: center;
    color: #ff6b6b;
    padding: 1rem;
}

.draw-error .retry-btn {
    margin-top: 0.5rem;
    background: transparent;
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
    border-radius: 6px;
    padding: 0.4rem 1.2rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.draw-error .retry-btn:hover {
    background: rgba(255,107,107,0.15);
}

/* ── Re-draw button ──────────────────────────────────────────────────────────*/
.redraw-btn {
    background: transparent;
    border: 1.5px solid rgba(252,163,17,0.6);
    color: #fca311;
    border-radius: 9999px;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.6rem 2rem;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: background 0.2s, border-color 0.2s;
    touch-action: manipulation;
}

.redraw-btn:hover {
    background: rgba(252,163,17,0.1);
    border-color: #fca311;
}

/* ── Card title tooltip (desktop hover, only after flip) ────────────────────*/
.card-flip[data-flipped="1"] {
    position: relative;
}

.card-flip[data-flipped="1"][data-name]:hover::after {
    content: attr(data-name);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.88);
    color: #e0e0e0;
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 5px;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 10;
    pointer-events: none;
}

/* ── Jackpot Banner (SR/SAR/UR big win) ──────────────────────────────────── */
.jackpot-banner {
    position: relative;
    margin: 1rem auto 0;
    max-width: 480px;
    border-radius: 16px;
    padding: 1.2rem 1.4rem;
    text-align: center;
    border: 2px solid rgba(252,163,17,0.5);
    background: rgba(8,13,26,0.85);
    overflow: hidden;
}

.jackpot-banner.jk-SR {
    border-color: #7b2fff;
    background: rgba(60,0,120,0.35);
    box-shadow: 0 0 40px rgba(123,47,255,0.4);
}

.jackpot-banner.jk-SAR {
    border-color: #ffbbff;
    background: rgba(80,0,80,0.35);
    box-shadow: 0 0 50px rgba(255,187,255,0.4);
    animation: jk-sar-border 2s linear infinite;
}

@keyframes jk-sar-border {
    0%   { border-color: hsl(0,90%,80%); }
    25%  { border-color: hsl(90,90%,70%); }
    50%  { border-color: hsl(200,90%,75%); }
    75%  { border-color: hsl(280,90%,80%); }
    100% { border-color: hsl(360,90%,80%); }
}

.jackpot-banner.jk-UR {
    border-color: #ffd700;
    background: rgba(60,45,0,0.4);
    box-shadow: 0 0 60px rgba(255,215,0,0.5);
}

.jackpot-rarity-text {
    display: block;
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    margin-bottom: 0.4rem;
}

.jk-SR  .jackpot-rarity-text { color: #bb88ff; text-shadow: 0 0 12px rgba(123,47,255,0.9); }
.jk-SAR .jackpot-rarity-text { color: #ffbbff; text-shadow: 0 0 16px rgba(255,100,255,0.9); }
.jk-UR  .jackpot-rarity-text { color: #ffd700; text-shadow: 0 0 20px rgba(255,215,0,1); }

.jackpot-name {
    font-size: 1rem;
    font-weight: 600;
    color: #e0e0e0;
    margin: 0.2rem 0 0.6rem;
    line-height: 1.4;
}

.jackpot-psa10-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.2rem auto 0.7rem;
    padding: 0.35rem 0.9rem;
    background: rgba(0,0,0,0.4);
    border-radius: 8px;
    width: fit-content;
}

.jackpot-psa10-label {
    font-size: 0.75rem;
    color: rgba(224,224,224,0.55);
}

.jackpot-psa10-val {
    font-size: 0.85rem;
    font-weight: 700;
    color: #fca311;
}

.jackpot-close {
    background: transparent;
    border: 1px solid rgba(224,224,224,0.25);
    color: rgba(224,224,224,0.5);
    border-radius: 6px;
    padding: 0.28rem 1rem;
    cursor: pointer;
    font-size: 0.78rem;
    transition: border-color 0.2s, color 0.2s;
    touch-action: manipulation;
}

.jackpot-close:hover {
    border-color: rgba(224,224,224,0.5);
    color: rgba(224,224,224,0.8);
}

/* Sparkle particles */
.sparkle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    animation: sparkle-float 1.5s ease-in-out infinite alternate;
    opacity: 0.9;
}

@keyframes sparkle-float {
    0%   { transform: translateY(0) scale(1);    opacity: 0.9; }
    100% { transform: translateY(-18px) scale(0.3); opacity: 0; }
}

.sparkle--diamond {
    border-radius: 2px;
    animation: sparkle-diamond 1.5s ease-in-out infinite alternate;
}

@keyframes sparkle-diamond {
    0%   { transform: rotate(45deg) translateY(0) scale(1);     opacity: 0.9; }
    100% { transform: rotate(45deg) translateY(-18px) scale(0.3); opacity: 0; }
}

/* ── reduced-motion: strip all animations ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .draw-btn-spinner,
    .flip-hint,
    .card-shimmer .card-back-face,
    .rarity-AR .card-front-face,
    .rarity-SR .card-front-face,
    .rarity-SAR .card-front-face,
    .rarity-SAR .card-front-face::before,
    .rarity-UR .card-front-face,
    .jackpot-banner.jk-SAR,
    .sparkle,
    .sparkle--diamond {
        animation: none !important;
    }
}
