/* Basic Reset and Container */
.sp-tcg-container {
    --sp-accent: #2a7de1;
    --sp-bg-card: rgba(0, 0, 0, 0.4);
    --sp-text-main: #ededed;
    --sp-text-muted: #aaaaaa;
    --sp-border-color: #444;
    --sp-border: 1px solid var(--sp-border-color);
    --sp-radius: 8px;
    --sp-blur: blur(10px);
    --sp-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);

    font-family: 'Barlow Condensed', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    max-width: 500px;
    margin: 0 auto;
    background: #0a0a0a;
    /* Dark background as base */
    color: var(--sp-text-main);
    border-radius: var(--sp-radius);
    overflow: hidden;
    position: relative;
    height: 100vh;
    height: 100dvh;
    /* Use dynamic viewport height for mobile */
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: all 0.3s ease;
    touch-action: manipulation;
}

/* Prevent double-tap-to-zoom universally inside the game app */
.sp-tcg-container * {
    touch-action: manipulation;
}

/* Faux Fullscreen for iOS (iPhone) or Fallback */
.sp-tcg-container.sp-fullscreen-manual {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    z-index: 2147483647 !important; /* Max possible z-index */
    /* REMOVED background override to allow JS-set images to show */
    border-radius: 0 !important;
    margin: 0 !important;
}

/* QR Scanner Modal */
.sp-qr-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Align from top for better mobile keyboard/button handling */
    padding: 60px 20px 20px 20px;
    box-sizing: border-box;
    animation: spFadeIn 0.3s ease;
}

.sp-qr-video-container {
    position: relative;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--sp-accent);
    box-shadow: 0 0 20px rgba(42, 125, 225, 0.3);
}

#sp-qr-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.sp-qr-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    border: 40px solid rgba(0,0,0,0.3);
    box-sizing: border-box;
}

.sp-qr-laser {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--sp-accent);
    box-shadow: 0 0 10px var(--sp-accent);
    animation: qrLaserAnim 2s infinite linear;
}

@keyframes qrLaserAnim {
    0% { top: 10%; }
    50% { top: 90%; }
    100% { top: 10%; }
}

.sp-tcg-container input,
.sp-tcg-container textarea {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent page scrolling when game is visible */
body:has(#sp-tcg-app:not(.sp-hidden-container)) {
    overflow: hidden !important;
    height: 100vh;
    height: 100dvh;
}

/* Hidden state for [sp_tcg_button] flow */
.sp-hidden-container {
    display: none !important;
}

.sp-tcg-start-wrapper {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

.sp-tcg-main-start-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #1e1e1e 0%, #2a2a2a 100%);
    color: #fff;
    border: 1px solid #444;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    font-family: inherit;
}

.sp-tcg-main-start-btn:hover {
    background: linear-gradient(135deg, #2a7de1 0%, #1e5bb0 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(42, 125, 225, 0.4);
    border-color: #2a7de1;
}

.sp-btn-logo {
    color: #2a7de1;
    transition: color 0.3s ease;
}

.sp-tcg-main-start-btn:hover .sp-btn-logo {
    color: #fff;
}

/* Fullscreen Mode */
.sp-tcg-container:-webkit-full-screen {
    max-width: none;
    min-height: 100vh;
    background: #0a0a0a;
    border-radius: 0;
}

.sp-tcg-container:-ms-fullscreen {
    max-width: none;
    min-height: 100vh;
    background: #0a0a0a;
    border-radius: 0;
}

.sp-tcg-container:fullscreen {
    max-width: none;
    min-height: 100vh;
    min-height: 100dvh;
    background: #0a0a0a;
    border-radius: 0;
}

.sp-fullscreen-btn,
.sp-home-btn,
.sp-audio-btn {
    background: var(--sp-bg-card);
    border: var(--sp-border);
    color: var(--sp-text-main);
    padding: 8px;
    border-radius: var(--sp-radius);
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    backdrop-filter: var(--sp-blur);
    z-index: 10;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
}

.sp-fullscreen-btn svg,
.sp-home-btn svg,
.sp-audio-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    display: block;
}

.sp-fullscreen-btn {
    position: absolute;
    top: 15px;
    right: 15px;
}

.sp-home-btn {
    position: absolute;
    top: 15px;
    left: 15px;
}

.sp-audio-controls {
    position: absolute;
    top: 15px;
    right: 60px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.sp-fullscreen-btn:hover,
.sp-audio-btn:hover {
    background: var(--sp-accent);
    color: #fff;
    border-color: var(--sp-accent);
    transform: scale(1.05);
}


.sp-tcg-loading,
.sp-tcg-error {
    padding: 40px;
    text-align: center;
    font-size: 1.2rem;
}

/* Screens */
.sp-screen {
    display: none;
    flex: 1;
    flex-direction: column;
    padding: 10px 15px;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
}

.sp-screen.active {
    display: flex;
    animation: spFadeIn 0.3s ease;
}

@keyframes spFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================
   END SCREEN
   ============================ */
.sp-end-screen {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    text-align: center;
    padding: 60px 15px 80px 15px; /* Increased top padding for controls, bottom for scroll clearance */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sp-end-content {
    background: rgba(0, 0, 0, 0.5);
    padding: 20px;
    border-radius: var(--sp-radius);
    border: var(--sp-border);
    backdrop-filter: var(--sp-blur);
    width: 100%;
    max-width: 400px;
    margin-top: auto;
    margin-bottom: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* ============================
   MENU SCREEN
   ============================ */
.sp-menu-screen,
.sp-leaderboard-screen,
#sp-collection-screen {
    justify-content: flex-start;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 15px;
    box-sizing: border-box;
    width: 100%;
}

/* Force scroll behavior on mobile for collection */
#sp-collection-screen {
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: contain;
    padding-bottom: 80px !important;
    min-height: 0 !important;
    height: 100% !important;
    align-items: flex-start !important;
}

.sp-menu-content {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding-bottom: 30px;
}

.sp-menu-illustration-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
    padding: 10px 0;
}

.sp-menu-illustration {
    max-width: 90%;
    max-height: 30vh;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 15px rgba(0,0,0,0.5));
}

/* ============================
   VS OVERLAY
   ============================ */
.sp-vs-overlay {
    position: absolute;
    top: 0;
    left: 50%;
    width: 100vw;
    height: 100%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    pointer-events: none;
}

.sp-vs-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sp-vs-avatar {
    width: min(150px, 35vw);
    height: min(150px, 35vw);
    border-radius: 50%;
    border: 4px solid #fff;
    background-size: cover;
    background-position: center;
    position: absolute;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
}

.sp-vs-avatar-player {
    left: -200px;
    border-color: var(--sp-player-color);
    box-shadow: 0 0 40px var(--sp-player-color);
    animation: spVsPlayerIn 0.35s cubic-bezier(0.17, 0.67, 0.83, 0.67) forwards;
}

.sp-vs-avatar-cpu {
    right: -200px;
    border-color: var(--sp-cpu-color);
    box-shadow: 0 0 40px var(--sp-cpu-color);
    animation: spVsCpuIn 0.35s cubic-bezier(0.17, 0.67, 0.83, 0.67) forwards;
}

.sp-vs-text {
    font-size: min(80px, 20vw);
    font-weight: 900;
    font-style: italic;
    color: #fff;
    text-shadow: 0 0 30px #fff, 0 0 60px #fff;
    opacity: 0;
    transform: scale(3);
    z-index: 10;
    animation: spVsTextIn 0.15s 0.35s forwards;
}

.sp-vs-lightning {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300vw;
    height: 300vh;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    z-index: 5;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.8) 0%, transparent 70%);
}

.sp-vs-flash {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300vw;
    height: 300vh;
    transform: translate(-50%, -50%);
    background: #fff;
    opacity: 0;
    z-index: 10000;
    pointer-events: none;
}

.sp-vs-overlay.clashing .sp-vs-flash {
    animation: spVsFlash 0.3s ease-out;
}

.sp-vs-overlay.clashing .sp-vs-lightning {
    opacity: 1;
    animation: spVsLightning 0.5s steps(2) infinite;
}

.sp-vs-overlay.clashing .sp-vs-content {
    animation: spVsShake 0.4s 0.35s;
}

@keyframes spVsPlayerIn {
    0% { left: -200px; transform: scale(1.5); }
    100% { left: calc(50% - min(100px, 25vw)); transform: scale(1) translateX(-50%); }
}

@keyframes spVsCpuIn {
    0% { right: -200px; transform: scale(1.5); }
    100% { right: calc(50% - min(100px, 25vw)); transform: scale(1) translateX(50%); }
}

@keyframes spVsTextIn {
    0% { opacity: 0; transform: scale(3); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes spVsFlash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes spVsLightning {
    0% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: translate(-50%, -50%) scale(1.2) rotate(180deg); opacity: 0.4; }
    100% { transform: translate(-50%, -50%) scale(1.1) rotate(360deg); opacity: 0.8; }
}

@keyframes spVsShake {
    0%, 100% { transform: translate(0, 0); }
    10%, 30%, 50%, 70%, 90% { transform: translate(-10px, -10px); }
    20%, 40%, 60%, 80% { transform: translate(10px, 10px); }
}

.sp-menu-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--sp-text-main);
    text-align: center;
    margin: 10px 0 0 0;
    letter-spacing: 2px;
    text-shadow: 0 0 20px rgba(42, 125, 225, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.6);
}

.sp-menu-section {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border-radius: var(--sp-radius);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 16px 18px;
    backdrop-filter: blur(6px);
}

.sp-menu-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--sp-text-muted);
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sp-menu-sort-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

.sp-sort-btn,
.sp-sort-dir-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--sp-text-muted);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.sp-sort-btn.active,
.sp-sort-btn:hover,
.sp-sort-dir-btn:hover {
    background: var(--sp-accent);
    color: #fff;
    border-color: var(--sp-accent);
}

.sp-menu-hint {
    font-size: 0.85rem;
    color: var(--sp-text-muted);
    margin: 0;
    opacity: 0.7;
}

.sp-menu-quick-select {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.sp-quick-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--sp-text-main);
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: var(--sp-radius);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    font-family: inherit;
}

.sp-quick-btn:hover {
    background: rgba(42, 125, 225, 0.15);
    border-color: var(--sp-accent);
    transform: translateY(-1px);
}

.sp-quick-btn:active {
    transform: translateY(0);
}

/* Option Button Groups */
.sp-menu-option-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sp-menu-option {
    flex: 1;
    min-width: 100px;
    padding: 10px 14px;
    border-radius: var(--sp-radius);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--sp-text-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
}

.sp-menu-option:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
}

.sp-menu-option.active {
    background: rgba(42, 125, 225, 0.2);
    border-color: var(--sp-accent);
    box-shadow: 0 0 12px rgba(42, 125, 225, 0.3),
        inset 0 0 8px rgba(42, 125, 225, 0.1);
    color: #fff;
}

/* Card Selection Grid */
.sp-card-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--sp-accent) transparent;
}

.sp-card-select-grid::-webkit-scrollbar {
    width: 6px;
}

.sp-card-select-grid::-webkit-scrollbar-thumb {
    background: var(--sp-accent);
    border-radius: 3px;
}

.sp-card-select-item {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
    text-align: center;
}

.sp-card-select-item:hover {
    transform: scale(1.05);
}

.sp-card-select-inner {
    width: 100%;
    aspect-ratio: 2.5 / 3.5;
    border-radius: var(--sp-radius);
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--sp-shadow);
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    transform-style: preserve-3d;
}

.sp-card-select-inner .sp-card-face {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.sp-card-select-inner .sp-card-image-full {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
}

.sp-card-select-inner .sp-card-image-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #555;
    font-size: 1.5rem;
    font-weight: bold;
}

.sp-card-select-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sp-text-main);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-card-select-check {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: transparent;
    transition: all 0.25s ease;
    z-index: 5;
}

/* Selected card state */
.sp-card-select-item.selected .sp-card-select-inner {
    border-color: var(--sp-accent);
    box-shadow: 0 0 15px rgba(42, 125, 225, 0.5),
        0 0 30px rgba(42, 125, 225, 0.2);
}

.sp-card-select-item.selected .sp-card-select-check {
    background: var(--sp-accent);
    border-color: var(--sp-accent);
    color: #fff;
}

/* Menu Start Button Wrapper for Sticky Positioning */
.sp-menu-start-btn-container {
    position: sticky;
    bottom: -30px;
    /* Offset for menu-content padding */
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 20px 0;
    margin-top: 10px;
    z-index: 100;
    background: transparent;
}

.sp-menu-start-btn {
    width: 100%;
    max-width: 320px;
    font-size: 1.35rem;
    padding: 14px 30px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6), 0 0 15px rgba(42, 125, 225, 0.2);
}

.sp-menu-start-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: spMenuBtnShine 3s infinite;
}

@keyframes spMenuBtnShine {
    0% {
        left: -100%;
    }

    100% {
        left: 200%;
    }
}

.sp-menu-start-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

.sp-menu-start-btn:disabled::before {
    animation: none;
}

.sp-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 30px;
    border-radius: var(--sp-radius);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    text-align: center;
    cursor: pointer;
    border: none;
    font-family: 'Barlow Condensed', sans-serif;
    background-color: var(--sp-accent);
    color: #fff;
    box-shadow: 0 4px 15px color-mix(in srgb, var(--sp-accent), transparent 80%);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sp-btn:hover {
    background-color: color-mix(in srgb, var(--sp-accent), #000 10%);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--sp-accent), transparent 70%);
}

.sp-btn:active {
    background-color: color-mix(in srgb, var(--sp-accent), #000 20%);
    transform: translateY(1px);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--sp-accent), transparent 90%);
}

.sp-btn:disabled {
    background: var(--sp-bg-card);
    border: var(--sp-border);
    color: var(--sp-text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Turn Indicator Glow for Active Row */
.sp-card-row {
    position: relative;
    border-radius: var(--sp-radius);
    transition: box-shadow 0.3s ease;
}

#sp-player-stack.active-row .sp-side-stack-avatar img {
    border-color: rgba(42, 125, 225, 0.9);
    animation: spAvatarGlowPlayer 1.5s infinite alternate ease-in-out;
}

@keyframes spAvatarGlowPlayer {
    from {
        box-shadow: 0 0 10px rgba(42, 125, 225, 0.6),
                    0 0 5px rgba(42, 125, 225, 0.4);
    }
    to {
        box-shadow: 0 0 25px rgba(42, 125, 225, 1),
                    0 0 15px rgba(42, 125, 225, 0.8);
    }
}

#sp-cpu-stack.active-row .sp-side-stack-avatar img {
    border-color: rgba(225, 42, 42, 0.9);
    animation: spAvatarGlowCpu 1.5s infinite alternate ease-in-out;
}

@keyframes spAvatarGlowCpu {
    from {
        box-shadow: 0 0 10px rgba(225, 42, 42, 0.6),
                    0 0 5px rgba(225, 42, 42, 0.4);
    }
    to {
        box-shadow: 0 0 25px rgba(225, 42, 42, 1),
                    0 0 15px rgba(225, 42, 42, 0.8);
    }
}


/* Battle Area — always vertical, opponent on top, player on bottom */
.sp-battle-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    align-items: center;
    min-height: 0;
    overflow: visible;
    justify-content: space-between;
}

/* Card Row: card + side stack in horizontal line */
.sp-card-row {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 0;
    flex: 1;
}

/* Inner wrapper for glow bounds */
.sp-card-row-inner {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 20px;
    border-radius: 20px;
    transition: box-shadow 0.3s ease;
    max-width: 100%;
}

/* General card override in battle */
.sp-battle-area .sp-card-wrapper {
    width: auto;
    max-width: 100%;
    max-height: 100%;
}

/* CPU card: smaller + perspective tilt */
#sp-cpu-stack .sp-card {
    width: auto;
    height: 33vh;
    max-height: 33vh;
    aspect-ratio: 2.5 / 3.5;
    transform: perspective(800px) rotateX(3deg) scale(0.92);
    transform-origin: center bottom;
}

#sp-cpu-stack .sp-card.flipped {
    transform: perspective(800px) rotateX(3deg) scale(0.92) rotateY(180deg);
}

/* Player card: full size */
#sp-player-stack .sp-card {
    width: auto;
    height: 40vh;
    max-height: 40vh;
    aspect-ratio: 2.5 / 3.5;
}

.sp-battle-area .sp-player-cards-wrapper {
    width: auto;
    /* Fixes stack distance */
}

/* ============================
   CLASH ANIMATION OVERLAY
   ============================ */
.sp-clash-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    padding: 30px;
    border-radius: 12px;
    border: 2px solid var(--sp-accent);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px var(--sp-accent);
    width: 90%;
    max-width: 350px;
    animation: spClashPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.sp-clash-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 15px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.sp-clash-overlay.player {
    border-color: #2a7de1;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px #2a7de1;
}

.sp-clash-overlay.cpu {
    border-color: #e63946;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px #e63946;
}

.sp-clash-overlay.draw {
    border-color: #fca311;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px #fca311;
}

.sp-clash-stat {
    font-size: 2rem;
    text-transform: uppercase;
    margin-bottom: 12px;
    color: var(--sp-text-main);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.sp-clash-result {
    font-size: 1.5rem;
    font-weight: bold;
}

.sp-clash-result.player {
    color: #2a7de1;
}

.sp-clash-result.cpu {
    color: #e63946;
}

.sp-clash-result.draw {
    color: #fca311;
}

.sp-clash-result small {
    display: block;
    font-size: 1.1rem;
    color: #ccc;
    font-weight: normal;
    margin-top: 8px;
}

@keyframes spClashPop {
    0% {
        transform: translate(-50%, -50%) scale(0.3);
        opacity: 0;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.sp-clash-fadeout {
    animation: spClashOut 0.3s ease forwards;
}

@keyframes spClashOut {
    to {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0;
    }
}

/* ============================
   SIDE STACK (right of card)
   ============================ */
.sp-side-stack-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.sp-side-stack-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    display: block;
}

.sp-side-stack-avatar-name {
    font-size: 0.9rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.sp-side-stack {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sp-side-stack-cards {
    position: relative;
    width: 50px;
    height: 70px;
}

.sp-side-stack-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 50px;
    height: 70px;
    border-radius: 5px;
    background-size: cover;
    background-position: center;
    background-color: #16213e;
    border: 1px solid rgba(42, 125, 225, 0.4);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* CPU side stack: smaller to match perspective */
.sp-side-stack-cpu .sp-side-stack-cards {
    width: 40px;
    height: 56px;
}

.sp-side-stack-cpu .sp-side-stack-card {
    width: 40px;
    height: 56px;
}

.sp-side-stack-count {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.3rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
    z-index: 10;
}

/* 3-Card Special Rule Layout — Fan/Stack */
.sp-battle-area.three-card-mode-player .sp-player-cards-wrapper {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 25px;
    /* More space for the 'centered' focused card */
    position: relative;
}

.three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper {
    flex: none;
    width: 35%; /* Slightly narrower so they don't overlap as aggressively */
    max-width: 200px;
    margin: 0 -4%; /* Less overlap spread */
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275),
        z-index 0.2s;
    position: relative;
}

/* Fan rotation: Dynamic based on how many cards are present */
.three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper:nth-child(1) {
    transform: rotate(-6deg) translateY(-5px);
    z-index: 10;
}

.three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper:nth-child(2) {
    transform: rotate(0deg) translateY(-10px);
    z-index: 11;
}

.three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper:nth-child(3) {
    transform: rotate(6deg) translateY(-5px);
    z-index: 10;
}

/* If only 2 cards: make them more symmetrical */
.three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2):last-child) .sp-card-wrapper:nth-child(1) {
    transform: rotate(-6deg) translateY(-5px) translateX(-15%);
}

.three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2):last-child) .sp-card-wrapper:nth-child(2) {
    transform: rotate(6deg) translateY(-5px) translateX(15%);
}


/* Hover/Tap: Bring card to front and center it */
.three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper.sp-card-focus {
    z-index: 100 !important;
    filter: drop-shadow(0 15px 35px rgba(0, 0, 0, 0.8)) drop-shadow(0 0 15px rgba(42, 125, 225, 0.6));
}

/* On Mobile: More pronounced centering for the focused card */
@media (max-width: 767px) {
    .three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper.sp-card-focus {
        transform: rotate(0deg) translateY(-60px) scale(1.30) !important;
        z-index: 999 !important;
    }

    /* If it's the 1st of 3, shift slightly right to center it in the screen */
    .three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper:nth-child(1):not(:last-child).sp-card-focus {
        transform: rotate(0deg) translateX(40%) translateY(-60px) scale(1.30) !important;
    }

    /* If it's the 3rd card, shift slightly left to center it */
    .three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper:nth-child(3).sp-card-focus {
        transform: rotate(0deg) translateX(-40%) translateY(-60px) scale(1.30) !important;
    }

    /* If only 2 cards exist, both need slight offsets to center when focused */
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2):last-child) .sp-card-wrapper:nth-child(1).sp-card-focus {
        transform: rotate(0deg) translateX(30%) translateY(-60px) scale(1.30) !important;
    }

    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2):last-child) .sp-card-wrapper:nth-child(2).sp-card-focus {
        transform: rotate(0deg) translateX(-30%) translateY(-60px) scale(1.30) !important;
    }

    /* PART THE SEA for 3 Cards - when one is focused, push the others out of the way! */
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(1).sp-card-focus) .sp-card-wrapper:nth-child(2):not(.sp-card-focus) {
        transform: rotate(8deg) translateX(30%) translateY(-5px) !important;
    }
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(1).sp-card-focus) .sp-card-wrapper:nth-child(3):not(.sp-card-focus) {
        transform: rotate(14deg) translateX(40%) translateY(-5px) !important;
    }

    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2).sp-card-focus) .sp-card-wrapper:nth-child(1):not(.sp-card-focus) {
        transform: rotate(-12deg) translateX(-30%) translateY(-5px) !important;
    }
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2).sp-card-focus) .sp-card-wrapper:nth-child(3):not(.sp-card-focus) {
        transform: rotate(12deg) translateX(30%) translateY(-5px) !important;
    }

    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(3).sp-card-focus) .sp-card-wrapper:nth-child(1):not(.sp-card-focus) {
        transform: rotate(-14deg) translateX(-40%) translateY(-5px) !important;
    }
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(3).sp-card-focus) .sp-card-wrapper:nth-child(2):not(.sp-card-focus) {
        transform: rotate(-8deg) translateX(-30%) translateY(-5px) !important;
    }

    /* PART THE SEA for 2 Cards */
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2):last-child):has(.sp-card-wrapper:nth-child(1).sp-card-focus) .sp-card-wrapper:nth-child(2):not(.sp-card-focus) {
        transform: rotate(10deg) translateX(30%) translateY(-5px) !important;
    }
    .three-card-mode-player .sp-player-cards-wrapper:has(.sp-card-wrapper:nth-child(2):last-child):has(.sp-card-wrapper:nth-child(2).sp-card-focus) .sp-card-wrapper:nth-child(1):not(.sp-card-focus) {
        transform: rotate(-10deg) translateX(-30%) translateY(-5px) !important;
    }
}

/* Desktop Hover: Subtle lift and center when hovering in 3-card mode */
@media (min-width: 768px) {
    .three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper:hover {
        z-index: 150 !important;
        transform: rotate(0deg) translateY(-20px) scale(1.08) !important;
        filter: drop-shadow(0 15px 35px rgba(0,0,0,0.8)) drop-shadow(0 0 15px rgba(42,125,225,0.4));
    }
    
    /* Ensure focused card stays prominent if also hovered */
    .three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper.sp-card-focus:hover {
        transform: rotate(0deg) translateY(-25px) scale(1.12) !important;
    }
}


/* Disable picking-stat zoom in 3-card mode (fan layout handles it) */
.three-card-mode-player .sp-card-wrapper.picking-stat {
    transform: none;
    z-index: auto;
}

/* CPU 3-Card Mode - Stacked closer together */
.sp-battle-area.three-card-mode-cpu .sp-cpu-cards-wrapper {
    display: flex;
    flex-direction: row;
    justify-content: center;
    position: relative;
    padding-top: 5px;
}

.three-card-mode-cpu .sp-cpu-cards-wrapper .sp-card-wrapper {
    flex: none;
    width: 25%;
    max-width: 140px;
    margin: 0 -5%;
    /* Closer together */
    transition: transform 0.3s ease;
}

.three-card-mode-cpu .sp-cpu-cards-wrapper .sp-card-wrapper:nth-child(1) {
    z-index: 1;
    transform: rotate(-3deg);
}

.three-card-mode-cpu .sp-cpu-cards-wrapper .sp-card-wrapper:nth-child(2) {
    z-index: 2;
    transform: translateY(-5px);
}

.three-card-mode-cpu .sp-cpu-cards-wrapper .sp-card-wrapper:nth-child(3) {
    z-index: 1;
    transform: rotate(3deg);
}

/* Ensure the ACTIVE card of CPU is always on top of the face-down cards */
.three-card-mode-cpu .sp-cpu-cards-wrapper .sp-card-wrapper.active-cpu-card {
    z-index: 100 !important;
    transform: rotate(0deg) translateY(0) !important;
}

/* Card Styling */
.sp-card-wrapper {
    perspective: 1000px;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    transform: scale(1);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.sp-player-cards-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 100;
    touch-action: pan-y;
}

.sp-card {
    position: relative;
    width: 100%;
    aspect-ratio: 2.5/3.5;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    cursor: pointer;
}

.sp-card.flipped {
    transform: rotateY(180deg);
}

.sp-card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--sp-radius);
    overflow: hidden;
    box-shadow: var(--sp-shadow);
    background: var(--sp-bg-card);
    display: flex;
    flex-direction: column;
    border: var(--sp-border);
    backdrop-filter: var(--sp-blur);
}

.sp-card-back {
    background-size: cover;
    background-position: center;
    background-color: #0a0a0a;
    /* No rotation: the back is the default visible face */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Fallback if no custom image is set */
.sp-card-back.sp-default-back {
    background: repeating-linear-gradient(45deg,
            rgba(0, 0, 0, 0.4),
            rgba(0, 0, 0, 0.4) 10px,
            rgba(0, 0, 0, 0.2) 10px,
            rgba(0, 0, 0, 0.2) 20px);
    backdrop-filter: var(--sp-blur);
}

.sp-card-back.sp-default-back::after {
    content: "SP";
    font-size: 4rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.2);
}

.sp-card-image-full {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-color: var(--sp-bg-card);
    z-index: 1;
}

/* Glossy Effect & Cardboard Texture Overlay */
.sp-card-gloss {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
    background: 
        /* The Glossy Reflection - Subtle hotspot */
        radial-gradient(
            circle at var(--gloss-x, 50%) var(--gloss-y, 50%),
            rgba(255, 255, 255, calc(var(--gloss-opacity, 0) * 0.8)) 0%,
            rgba(255, 255, 255, calc(var(--gloss-opacity, 0) * 0.4)) 25%,
            rgba(255, 255, 255, calc(var(--gloss-opacity, 0) * 0.1)) 50%,
            transparent 80%
        ),
        /* Cardboard Texture Overlay - Very subtle */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    opacity: 0.4; /* Controlled overall intensity */
    mix-blend-mode: overlay;
    transition: opacity 0.3s ease;
}

/* Base values for the reflection */
.sp-card-wrapper .sp-card-gloss {
    --gloss-opacity: 0.15;
}

/* Interaction intensity */
.sp-card-wrapper:hover .sp-card-gloss,
.sp-card-wrapper.picking-stat .sp-card-gloss {
    --gloss-opacity: 0.45;
}

/* Fallback Design Classes */
.sp-card-image-fallback {
    width: 100%;
    height: 45%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    font-size: 3rem;
    font-weight: bold;
    background: repeating-linear-gradient(45deg, #1a1a1a, #1a1a1a 10px, #2a2a2a 10px, #2a2a2a 20px);
    border-bottom: var(--sp-border);
}

.sp-card-content {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sp-card-title {
    font-size: 1.3rem;
    font-weight: 800;
    margin: 0 0 10px 0;
    text-align: center;
    color: var(--sp-text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.5px;
}

.sp-stats-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.sp-stat-row.sp-fallback-row {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-left: 3px solid transparent;
    cursor: default;
    justify-content: space-between;
}

.sp-card-wrapper[data-interactive="true"] .sp-stat-row.sp-fallback-row {
    cursor: pointer;
}

.sp-card-wrapper[data-interactive="true"] .sp-stat-row.sp-fallback-row:hover {
    background: rgba(255, 255, 255, 0.1);
    border-left-color: var(--sp-accent);
}

.sp-stat-label {
    font-weight: 500;
}

.sp-stat-value {
    font-weight: bold;
}

/* Invisible interaction grid over the stats column.
   Measured from Tim's card (360x504px):
   - Stats start at y=310 (61.5% from top = 38.5% from bottom)
   - Stats end at y=452 (89.7% from top = 10.3% from bottom)
   - Right column from x=182 to x=350 (49% width, 2.8% from right) */
.sp-card-interaction-grid {
    position: absolute;
    bottom: 8%;
    right: 0;
    width: 49%;
    height: 27%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Help Icon & Rules Modal */
.sp-help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--sp-text-main);
    font-size: 14px;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s ease;
    vertical-align: middle;
}

.sp-help-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--sp-accent);
    transform: scale(1.1);
}

.sp-rules-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sp-rules-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sp-rules-modal {
    background: var(--sp-bg-dark);
    border: 2px solid var(--sp-accent);
    border-radius: var(--sp-radius);
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 80%;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(252, 163, 17, 0.1);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.sp-rules-modal-overlay.active .sp-rules-modal {
    transform: translateY(0);
}

.sp-rules-modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.sp-rules-modal-close:hover {
    opacity: 1;
}

.sp-rules-title {
    margin-top: 0;
    color: var(--sp-accent);
    font-size: 1.8rem;
    margin-bottom: 20px;
    text-align: center;
}

.sp-rules-content {
    line-height: 1.6;
    font-size: 1.05rem;
    color: #eee;
}

.sp-rules-content b, .sp-rules-content strong {
    color: var(--sp-accent);
}

/* DEBUG helper: uncomment to inspect the grid position visually (in browser console: document.querySelector('.sp-tcg-container').classList.add('sp-debug')) 
.sp-debug .sp-card-interaction-grid { outline: 2px solid red; }
.sp-debug .sp-stat-row { outline: 1px solid yellow; background: rgba(255,255,0,0.1) !important; }
*/

.sp-stat-row {
    flex: 1;
    display: flex;
    cursor: default;
    background: rgba(255, 255, 255, 0);
    /* Invisible by default */
    border: 2px solid transparent;
    border-radius: 3px;
    margin-bottom: 0;
    /* No margin — let flex handle spacing evenly */
    transition: all 0.2s ease;
}

/* Interactive Stats */
.sp-card-wrapper[data-interactive="true"] .sp-stat-row {
    cursor: pointer;
}

.sp-card-wrapper[data-interactive="true"] .sp-stat-row:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.02);
}

.sp-stat-row.selected {
    background: rgba(42, 125, 225, 0.4) !important;
    border-color: var(--sp-accent);
    transform: scale(1.02);
}

.sp-stat-row.winner {
    background: rgba(40, 167, 69, 0.5) !important;
    border-color: #28a745;
}

.sp-stat-row.loser {
    background: rgba(230, 57, 70, 0.5) !important;
    border-color: #e63946;
}

/* Middle Pot */
.sp-pot-info {
    text-align: center;
    font-size: 0.9rem;
    color: #fca311;
    font-weight: bold;
    padding: 10px;
    background: rgba(252, 163, 17, 0.1);
    border-radius: 8px;
    margin: 10px 0;
}

/* Action Log / Result Text — centered overlay */
.sp-action-log {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--sp-text-main);
    z-index: 50;
    background: rgba(0, 0, 0, 0.85);
    padding: 15px 30px;
    border-radius: 12px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: none;
    min-width: 200px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    white-space: pre-wrap;
    line-height: 1.4;
}

.sp-action-log:empty {
    display: none;
}

.sp-action-log.win {
    color: #28a745;
    border-color: rgba(40, 167, 69, 0.4);
}

.sp-action-log.loss {
    color: #e63946;
    border-color: rgba(230, 57, 70, 0.4);
}

.sp-action-log.draw {
    color: #fca311;
    border-color: rgba(252, 163, 17, 0.4);
}




.sp-end-content {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
}

.sp-end-screen h2 {
    font-size: 3rem;
    text-align: center;
    margin: 20px 0 10px 0;
    text-transform: uppercase;
}

@media (max-width: 480px) {
    .sp-end-screen h2 {
        font-size: 2.2rem;
        margin: 15px 0 5px 0;
    }
    
    .sp-end-content {
        gap: 15px;
        padding: 15px;
        margin-top: 20px; /* Reset auto margin to ensure it starts near top */
        margin-bottom: 20px;
    }
    
    .sp-end-screen {
        padding-top: 70px; /* Extra space for music/fullscreen buttons */
    }
    
    .sp-end-cpu-message {
        margin: 10px 0;
        gap: 15px;
    }
    
    .sp-cpu-avatar-small {
        width: 50px;
        height: 50px;
    }
    
    .sp-speech-bubble {
        font-size: 0.9rem;
        padding: 10px 14px;
    }
}

.sp-end-screen.victory h2 {
    color: #28a745;
}

.sp-end-screen.defeat h2 {
    color: #e63946;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .sp-tcg-container {
        max-width: 500px;
    }

    .sp-card-wrapper {
        margin: 0;
    }

    /* Bigger side stacks on desktop */
    .sp-side-stack-cards {
        width: 70px;
        height: 98px;
    }

    .sp-side-stack-card {
        width: 70px;
        height: 98px;
    }

    .sp-side-stack-cpu .sp-side-stack-cards {
        width: 55px;
        height: 77px;
    }

    .sp-side-stack-cpu .sp-side-stack-card {
        width: 55px;
        height: 77px;
    }

    .sp-side-stack-count {
        font-size: 1.6rem;
    }

    .sp-battle-area.three-card-mode-player .sp-player-cards-wrapper {
        justify-content: center;
    }

    .three-card-mode-player .sp-player-cards-wrapper .sp-card-wrapper {
        width: 220px;
        max-width: 220px;
        margin: 0 -25px;
    }

    .three-card-mode-cpu .sp-cpu-cards-wrapper .sp-card-wrapper {
        flex: 0 0 140px;
        max-width: 140px;
    }
}

/* ============================
   CARD STACK VISUAL
   Shows layered card backs behind the active card
   ============================ */
.sp-card-stack-container {
    position: relative;
    margin: 0 auto;
}

.sp-card-stack-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    aspect-ratio: 2.5/3.5;
    border-radius: var(--sp-radius);
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid rgba(42, 125, 225, 0.5);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    transition: all 0.4s ease;
    pointer-events: none;
    /* Stack layers must not block clicks */
}

/* Real card-back layers — fully visible edges peeking out */
.sp-card-stack-layer:nth-child(1) {
    transform: translate(5px, 5px);
    z-index: -1;
    opacity: 0.95;
}

.sp-card-stack-layer:nth-child(2) {
    transform: translate(10px, 10px);
    z-index: -2;
    opacity: 0.85;
}

.sp-card-stack-layer:nth-child(3) {
    transform: translate(15px, 15px);
    z-index: -3;
    opacity: 0.7;
}

/* The actual card wrapper AND player-cards-wrapper sit on top of the stack */
.sp-card-stack-container>.sp-card-wrapper,
.sp-card-stack-container>.sp-player-cards-wrapper {
    position: relative;
    z-index: 5;
}

/* ============================
   BATTLE ANIMATIONS
   ============================ */

/* Winner card: Punches hard toward the loser */
@keyframes spPunchLeft {
    0% {
        transform: translateX(0) scale(1);
    }

    20% {
        transform: translateX(10px) scale(1.05);
    }

    /* Wind-up */
    50% {
        transform: translateX(-60px) scale(1.08);
    }

    /* Slam! */
    70% {
        transform: translateX(-30px) scale(1.03);
    }

    100% {
        transform: translateX(0) scale(1);
    }
}

@keyframes spPunchRight {
    0% {
        transform: translateX(0) scale(1);
    }

    20% {
        transform: translateX(-10px) scale(1.05);
    }

    50% {
        transform: translateX(60px) scale(1.08);
    }

    70% {
        transform: translateX(30px) scale(1.03);
    }

    100% {
        transform: translateX(0) scale(1);
    }
}

/* Loser card: Gets smashed out with dramatic rotation */
@keyframes spFlyOutLeft {
    0% {
        transform: translateX(0) rotate(0deg) scale(1);
        opacity: 1;
    }

    15% {
        transform: translateX(10px) rotate(2deg) scale(0.98);
        opacity: 1;
    }

    /* Recoil */
    100% {
        transform: translateX(-400px) rotate(-35deg) scale(0.7);
        opacity: 0;
    }
}

@keyframes spFlyOutRight {
    0% {
        transform: translateX(0) rotate(0deg) scale(1);
        opacity: 1;
    }

    15% {
        transform: translateX(-10px) rotate(-2deg) scale(0.98);
        opacity: 1;
    }

    100% {
        transform: translateX(400px) rotate(35deg) scale(0.7);
        opacity: 0;
    }
}

@keyframes spFlyOutUp {
    0% {
        transform: translateY(0) translateX(0) rotateX(0deg) scale(1);
        opacity: 1;
    }

    10% {
        transform: translateY(30px) translateX(0) rotateX(15deg) scale(1);
        opacity: 1;
        z-index: 1000;
    }

    40% {
        transform: translateY(30px) translateX(0) rotateX(15deg) scale(1);
        opacity: 1;
        z-index: 1000;
    }

    65% {
        transform: translateY(400px) translateX(50px) rotateX(65deg) scale(1);
        opacity: 0.8;
    }

    /* Thrown DOWN */
    100% {
        transform: translateY(-700px) translateX(350px) rotateX(60deg) scale(0.05);
        opacity: 0;
    }
}

@keyframes spFlyOutDown {
    0% {
        transform: translateY(0) translateX(0) rotateX(0deg) scale(1);
        opacity: 1;
    }

    10% {
        transform: translateY(-30px) translateX(0) rotateX(-15deg) scale(1);
        opacity: 1;
        z-index: 1000;
    }

    40% {
        transform: translateY(-30px) translateX(0) rotateX(-15deg) scale(1);
        opacity: 1;
        z-index: 1000;
    }

    65% {
        transform: translateY(-400px) translateX(50px) rotateX(-65deg) scale(1);
        opacity: 0.8;
    }

    /* Thrown UP */
    100% {
        transform: translateY(700px) translateX(350px) rotateX(-60deg) scale(0.05);
        opacity: 0;
    }
}

/* Draw: Both cards shimmer */
@keyframes spDrawShake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Enlarge player card when picking stat */
.sp-card-wrapper.picking-stat {
    transform: scale(1.2);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    /* Ensure it's above log and other cards */
}

@media (max-width: 767px) {
    .sp-card-wrapper.picking-stat {
        transform: scale(1.3) translateY(-15px);
    }
}

/* Action Log Mitteilung */
.sp-action-log {
    z-index: 1000;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(10, 10, 10, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: white;
    pointer-events: none;
    /* Let clicks pass through to the cards below */
    max-width: 90%;
}

/* Pot Info Badge */
.sp-pot-info {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #d49c00 0%, #ffcc33 100%);
    color: #000;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 15px rgba(212, 156, 0, 0.4);
    z-index: 1100;
    pointer-events: none;
    text-shadow: none;
    animation: spPulsePot 2s infinite ease-in-out;
}

@keyframes spPulsePot {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.05);
    }
}

.sp-action-log:empty {
    display: none;
}

.sp-log-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.sp-log-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

/* Card Draw entrance animations */
.sp-anim-draw-enter-player {
    animation: spDrawEnterPlayer 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    will-change: transform, opacity;
}

@keyframes spDrawEnterPlayer {
    0% {
        transform: translate(100px, 0) scale(0.3);
        opacity: 0;
    }

    100% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
}

.sp-anim-draw-enter-cpu {
    animation: spDrawEnterCPU 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    will-change: transform, opacity;
}

@keyframes spDrawEnterCPU {
    0% {
        transform: translate(100px, 0) scale(0.3);
        opacity: 0;
    }

    100% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
}

/* Animation classes applied by JS */
.sp-anim-punch-left {
    animation: spPunchLeft 0.6s ease forwards;
}

.sp-anim-punch-right {
    animation: spPunchRight 0.6s ease forwards;
}

.sp-anim-punch-up {
    animation: spPunchUp 0.6s ease forwards;
    z-index: 1001 !important;
    will-change: transform;
}

.sp-anim-punch-down {
    animation: spPunchDown 0.6s ease forwards;
    z-index: 1001 !important;
    will-change: transform;
}

/* Vertical punch animations (always used in vertical layout) */
@keyframes spPunchUp {
    0% {
        transform: translateY(0) scale(1);
    }

    20% {
        transform: translateY(15px) scale(1.05);
    }

    50% {
        transform: translateY(-60px) scale(1.08);
    }

    70% {
        transform: translateY(-25px) scale(1.03);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}

@keyframes spPunchDown {
    0% {
        transform: translateY(0) scale(1);
    }

    20% {
        transform: translateY(-15px) scale(1.05);
    }

    50% {
        transform: translateY(60px) scale(1.08);
    }

    70% {
        transform: translateY(25px) scale(1.03);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}

.sp-anim-punch-up {
    animation: spPunchUp 0.6s ease forwards;
}

.sp-anim-punch-down {
    animation: spPunchDown 0.6s ease forwards;
}

.sp-anim-fly-left {
    animation: spFlyOutLeft 0.7s ease forwards;
}

.sp-anim-fly-right {
    animation: spFlyOutRight 0.7s ease forwards;
}

.sp-anim-fly-up {
    animation: spFlyOutUp 1.2s cubic-bezier(0.15, 0, 0.15, 1) forwards;
    will-change: transform, opacity;
}

.sp-anim-fly-down {
    animation: spFlyOutDown 1.2s cubic-bezier(0.15, 0, 0.15, 1) forwards;
    will-change: transform, opacity;
}

.sp-anim-draw {
    animation: spDrawShake 0.4s ease 3;
}

@keyframes spDrawShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px) rotate(-1deg); }
    75% { transform: translateX(5px) rotate(1deg); }
}


/* Thematic Winner glow effects using stat themes */
.sp-card-wrapper.sp-theme-jedi-power.sp-winner-glow-player .sp-card,
.sp-card-wrapper.sp-theme-jedi-power.sp-winner-glow-cpu .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(42, 125, 225, 0.7),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(42, 125, 225, 0.4),
        0 0 calc(80px * var(--sp-glow-scale, 1)) rgba(42, 125, 225, 0.2);
}

.sp-card-wrapper.sp-theme-dunkle-seite.sp-winner-glow-player .sp-card,
.sp-card-wrapper.sp-theme-dunkle-seite.sp-winner-glow-cpu .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(255, 0, 0, 0.8),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(255, 0, 0, 0.5),
        0 0 calc(80px * var(--sp-glow-scale, 1)) rgba(255, 0, 0, 0.3);
}

.sp-card-wrapper.sp-theme-trainingspower.sp-winner-glow-player .sp-card,
.sp-card-wrapper.sp-theme-trainingspower.sp-winner-glow-cpu .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(0, 255, 0, 0.7),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(0, 255, 0, 0.4);
}

.sp-card-wrapper.sp-theme-ausdauer.sp-winner-glow-player .sp-card,
.sp-card-wrapper.sp-theme-ausdauer.sp-winner-glow-cpu .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(255, 165, 0, 0.7),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(255, 165, 0, 0.4);
}

.sp-card-wrapper.sp-theme-geburtsjahr.sp-winner-glow-player .sp-card,
.sp-card-wrapper.sp-theme-geburtsjahr.sp-winner-glow-cpu .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(196, 87, 255, 0.8),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(196, 87, 255, 0.5),
        0 0 calc(80px * var(--sp-glow-scale, 1)) rgba(196, 87, 255, 0.3);
}

/* Fallback / Generic */
.sp-card-wrapper.sp-winner-glow-player .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(42, 125, 225, 0.7),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(42, 125, 225, 0.4);
    transition: box-shadow 0.3s ease;
}

.sp-card-wrapper.sp-winner-glow-cpu .sp-card {
    box-shadow:
        0 0 calc(25px * var(--sp-glow-scale, 1)) rgba(230, 57, 70, 0.7),
        0 0 calc(50px * var(--sp-glow-scale, 1)) rgba(230, 57, 70, 0.4);
    transition: box-shadow 0.3s ease;
}

/* Massive Impact Flash */
.sp-impact-flash {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 450px;
    height: 450px;
    background: radial-gradient(circle, #fff 15%, rgba(255, 234, 0, 1) 45%, transparent 80%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    filter: blur(5px);
    animation: spImpactFlashAnim 0.6s cubic-bezier(0.15, 0, 0.15, 1) forwards;
}

/* Thematic Impact Colors */
.sp-impact-theme-jedi-power {
    background: radial-gradient(circle, #fff 15%, rgba(42, 125, 225, 0.9) 45%, transparent 80%);
}

.sp-impact-theme-dunkle-seite {
    background: radial-gradient(circle, #fff 15%, rgba(255, 0, 0, 0.9) 45%, transparent 80%);
}

.sp-impact-theme-trainingspower {
    background: radial-gradient(circle, #fff 15%, rgba(0, 255, 0, 0.9) 45%, transparent 80%);
}

.sp-impact-theme-ausdauer {
    background: radial-gradient(circle, #fff 15%, rgba(255, 165, 0, 0.9) 45%, transparent 80%);
}

.sp-impact-theme-geburtsjahr {
    background: radial-gradient(circle, #fff 15%, rgba(196, 87, 255, 0.9) 45%, transparent 80%);
}

@keyframes spImpactFlashAnim {
    0% {
        transform: translate(-50%, -50%) scale(0.1);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    40% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    /* Peak Brightness */
    100% {
        transform: translate(-50%, -50%) scale(4);
        opacity: 0;
    }
}

@keyframes spScreenShake {

    0%,
    100% {
        transform: translate(0, 0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translate(calc(var(--sp-shake-dist, 8px) * -1), calc(var(--sp-shake-dist, 8px) * -1));
    }

    20%,
    40%,
    60%,
    80% {
        transform: translate(var(--sp-shake-dist, 8px), var(--sp-shake-dist, 8px));
    }
}

.sp-battle-shake {
    animation: spScreenShake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}

/* ============================
   SPARK / PARTICLE EFFECTS
   ============================ */
.sp-spark-container {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 100;
    pointer-events: none;
}

.sp-spark {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fca311;
    box-shadow: 0 0 6px #fca311, 0 0 12px rgba(252, 163, 17, 0.5);
    animation: spSparkFly var(--spark-duration, 0.6s) ease-out forwards;
}

@keyframes spSparkFly {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--spark-x, 50px), var(--spark-y, -30px)) scale(0);
        opacity: 0;
    }
}


/* ============================
   CLICK SPARK EFFECTS
   ============================ */
.sp-click-spark-container {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
}

@keyframes spClickSparkAnim {
    0% {
        transform: translate(0, 0) scale(1.5);
        opacity: 1;
    }

    100% {
        transform: translate(var(--spark-x), var(--spark-y)) scale(0);
        opacity: 0;
    }
}

.sp-click-flash {
    position: absolute;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, #fff 0%, rgba(255, 234, 0, 0.8) 40%, transparent 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    animation: spClickFlashAnim 0.3s ease-out forwards;
    pointer-events: none;
}

@keyframes spClickFlashAnim {
    0% {
        transform: translate(-50%, -50%) scale(0.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }
}

.sp-click-spark {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px #ffea00, 0 0 20px #ff9d00, 0 0 30px #ffffff;
    top: -2px;
    left: -2px;
    opacity: 1;
    animation: spClickSparkAnim 0.6s ease-out forwards;
}

/* ============================
   CLICK SPARK THEMES
   ============================ */

/* Jedi-Power (Blue) */
.sp-theme-jedi-power .sp-click-spark {
    box-shadow: 0 0 10px rgba(42, 125, 225, 1), 0 0 20px rgba(42, 125, 225, 0.8), 0 0 30px rgba(42, 125, 225, 0.5);
}

.sp-theme-jedi-power .sp-click-flash {
    background: radial-gradient(circle, #fff 0%, rgba(42, 125, 225, 1) 40%, transparent 70%);
}

/* Dunkle Seite (Red) */
.sp-theme-dunkle-seite .sp-click-spark {
    box-shadow: 0 0 10px #ff0000, 0 0 20px #a30000, 0 0 30px rgba(255, 0, 0, 0.5);
}

.sp-theme-dunkle-seite .sp-click-flash {
    background: radial-gradient(circle, #fff 0%, rgba(255, 0, 0, 1) 40%, transparent 70%);
}

/* Trainingsdauer (Green/Cyan) */
.sp-theme-trainingspower .sp-click-spark {
    box-shadow: 0 0 10px rgba(0, 255, 0, 1), 0 0 20px rgba(0, 255, 0, 0.8), 0 0 30px rgba(0, 255, 0, 0.5);
}

.sp-theme-trainingspower .sp-click-flash {
    background: radial-gradient(circle, #fff 0%, rgba(0, 255, 0, 1) 40%, transparent 70%);
}

/* Ausdauer (Orange/Yellow) */
.sp-theme-ausdauer .sp-click-spark {
    box-shadow: 0 0 10px rgba(255, 165, 0, 1), 0 0 20px rgba(255, 165, 0, 0.8), 0 0 30px rgba(255, 165, 0, 0.5);
}

.sp-theme-ausdauer .sp-click-flash {
    background: radial-gradient(circle, #fff 0%, rgba(255, 165, 0, 1) 40%, transparent 70%);
}

/* Geburtsjahr (Purple/Cosmic) */
.sp-theme-geburtsjahr .sp-click-spark {
    box-shadow: 0 0 10px rgba(196, 87, 255, 1), 0 0 20px rgba(196, 87, 255, 0.8), 0 0 30px rgba(196, 87, 255, 0.5);
}

.sp-theme-geburtsjahr .sp-click-flash {
    background: radial-gradient(circle, #fff 0%, rgba(196, 87, 255, 1) 40%, transparent 70%);
}

/* ============================
   THEMATIC IMPACT ANIMATIONS
   ============================ */

/* 1. Saber Slash (Jedi Power) */
.sp-saber-slash {
    position: absolute;
    top: 50%;
    left: 0;
    width: 200%;
    height: 30px;
    /* Thicker */
    background: linear-gradient(90deg, transparent, #fff 10%, #fff 90%, transparent);
    box-shadow:
        0 0 20px rgba(42, 125, 225, 1),
        0 0 40px rgba(42, 125, 225, 0.8),
        0 0 60px rgba(42, 125, 225, 0.6),
        inset 0 0 10px #fff;
    /* White core */
    transform: translate(-35%, -50%) rotate(-35deg) scaleX(0);
    z-index: 1001;
    pointer-events: none;
    animation: spSaberSlashAnim 0.3s cubic-bezier(0.2, 0, 0.2, 1) forwards;
}

@keyframes spSaberSlashAnim {
    0% {
        transform: translate(-35%, -50%) rotate(35deg) scaleX(0);
        opacity: 0;
    }

    /* TR -> BL */
    10% {
        opacity: 1;
    }

    100% {
        transform: translate(-30%, -50%) rotate(35deg) scaleX(1.1);
        opacity: 0;
    }
}

@keyframes spSaberSlashAnimRev {
    0% {
        transform: translate(-35%, -50%) rotate(-35deg) scaleX(0);
        opacity: 0;
        filter: brightness(1);
    }

    /* TL -> BR */
    10% {
        opacity: 1;
        filter: brightness(1.8);
    }

    100% {
        transform: translate(-30%, -50%) rotate(-35deg) scaleX(1.1);
        opacity: 0;
        filter: brightness(1);
    }
}

/* 2. Lightning (Dark Side) */
.sp-lightning-bolt {
    position: absolute;
    background: #fff;
    box-shadow: 0 0 15px #ff0000, 0 0 30px #ff0000;
    width: 5px;
    /* Thicker */
    z-index: 1001;
    pointer-events: none;
    animation: spLightningAnim 0.25s steps(3) forwards;
}

/* Impact flash for the card itself */
.sp-card-flash-red {
    animation: spFlashRed 0.3s ease-out;
}

@keyframes spFlashRed {
    0% {
        filter: brightness(1) drop-shadow(0 0 0 red);
    }

    20% {
        filter: brightness(4) drop-shadow(0 0 30px red);
    }

    100% {
        filter: brightness(1) drop-shadow(0 0 0 red);
    }
}

@keyframes spLightningAnim {
    0% {
        transform: scaleY(0.2) rotate(var(--rot));
        opacity: 1;
    }

    50% {
        transform: scaleY(1.5) rotate(var(--rot)) translateX(5px);
        filter: brightness(2);
    }

    100% {
        transform: scaleY(1) rotate(var(--rot));
        opacity: 0;
    }
}

/* 3. Wind Vortex (Training) */
.sp-wind-line {
    position: absolute;
    top: 50%;
    left: 50%;
    border: 6px solid rgba(0, 255, 0, 0.7);
    /* Thicker */
    border-radius: 50%;
    z-index: 1001;
    pointer-events: none;
    animation: spWindVortex 0.6s ease-out forwards;
}

@keyframes spWindVortex {
    0% {
        width: 10px;
        height: 10px;
        opacity: 1;
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        width: 700px;
        height: 300px;
        opacity: 0;
        transform: translate(-50%, -50%) rotate(320deg);
    }

    /* Much larger */
}

/* 4. Heavy Slam (Endurance) */
.sp-slam-wave {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 6px solid rgba(255, 165, 0, 0.9);
    border-radius: 50%;
    z-index: 1001;
    pointer-events: none;
    animation: spSlamWaveAnim 0.5s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes spSlamWaveAnim {
    0% {
        width: 0;
        height: 0;
        border-width: 20px;
        opacity: 1;
        filter: blur(0);
    }

    100% {
        width: 600px;
        height: 600px;
        border-width: 1px;
        opacity: 0;
        filter: blur(15px);
    }
}

.sp-shake-heavy {
    animation: spHeavyShake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes spHeavyShake {

    10%,
    90% {
        transform: translate3d(-3px, 3px, 0);
    }

    20%,
    80% {
        transform: translate3d(5px, -5px, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-8px, 8px, 0);
    }

    40%,
    60% {
        transform: translate3d(8px, -8px, 0);
    }
}

/* 5. Fireworks (Birth Year / Alter) */
.sp-firework-particle {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    z-index: 1001;
    pointer-events: none;
    background: #fff;
    box-shadow: 0 0 12px var(--color), 0 0 24px var(--color), 0 0 35px #fff;
    animation: spFireworkBurst 0.6s cubic-bezier(0, 0, 0.2, 1) forwards;
}

@keyframes spFireworkBurst {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* 5. Sand of Time (Birth Year) */
.sp-sand-particle {
    position: absolute;
    width: 2px;
    /* Fine sand */
    height: 3px;
    background: #fff;
    box-shadow: 0 0 4px rgba(196, 87, 255, 1);
    border-radius: 1px;
    z-index: 1001;
    pointer-events: none;
    animation: spSandTrickleSway 2.2s linear forwards;
}

@keyframes spSandTrickleSway {
    0% {
        transform: translateY(0) translateX(0) scale(1.5);
        opacity: 0;
    }

    5% {
        opacity: 1;
    }

    25% {
        transform: translateY(112px) translateX(var(--drift-1)) scale(1.2);
    }

    50% {
        transform: translateY(225px) translateX(var(--drift-2)) scale(1);
    }

    75% {
        transform: translateY(337px) translateX(var(--drift-1)) scale(0.8);
    }

    100% {
        transform: translateY(500px) translateX(var(--drift-2)) scale(0.5);
        opacity: 0;
    }
}

@keyframes spSandFall {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    40% {
        transform: translate(var(--side), 30px) scale(1.3);
        opacity: 1;
    }

    100% {
        transform: translate(var(--side-end), 200px) scale(0);
        opacity: 0;
    }
}

/* Thematic Battle Sparks (Impacts) */
.sp-spark-container.sp-theme-jedi-power .sp-spark {
    box-shadow: 0 0 8px rgba(42, 125, 225, 1);
}

.sp-spark-container.sp-theme-dunkle-seite .sp-spark {
    box-shadow: 0 0 8px rgba(255, 0, 0, 1);
}

.sp-spark-container.sp-theme-trainingspower .sp-spark {
    box-shadow: 0 0 8px rgba(0, 255, 0, 1);
}

.sp-spark-container.sp-theme-ausdauer .sp-spark {
    box-shadow: 0 0 8px rgba(255, 165, 0, 1);
}

.sp-spark-container.sp-theme-geburtsjahr .sp-spark {
    box-shadow: 0 0 8px rgba(196, 87, 255, 1);
}

/* Avatar Menu */
.sp-avatar-menu-wrapper {
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sp-avatar-menu {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    background: rgba(15, 15, 15, 0.95);
    border: 1px solid var(--sp-accent);
    border-radius: var(--sp-radius);
    padding: 8px 0;
    min-width: 180px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: none;
    animation: spMenuSlide 0.3s ease;
}

.sp-avatar-menu.active {
    display: block;
}

/* Special rule for 3-card mode ONLY on mobile: Move player avatar to the corner to avoid overlap */
@media (max-width: 767px) {
    .sp-battle-area.three-card-mode-player #sp-player-avatar-wrapper {
        position: absolute;
        bottom: 10px;
        right: 5px;
        z-index: 2000;
    }

    .three-card-mode-player #sp-player-avatar-wrapper .sp-avatar-menu {
        bottom: calc(100% + 15px);
        right: 0;
    }
}

/* Ensure avatar stays visible on desktop too even if not in corner */
.three-card-mode-player #sp-player-avatar-wrapper {
    z-index: 2000;
}

@keyframes spMenuSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sp-avatar-menu-item {
    padding: 10px 20px;
    color: var(--sp-text-main);
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    text-align: left;
    width: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.sp-avatar-menu-item:hover {
    background: var(--sp-accent);
    color: #fff;
}

/* Custom Confirm Modal */
.sp-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sp-modal-overlay.active {
    display: flex;
    opacity: 1;
}

.sp-modal-content {
    background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
    border: 1px solid var(--sp-accent);
    border-radius: 12px;
    padding: 30px;
    max-width: 320px;
    width: 85%;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.9), 0 0 20px rgba(42, 125, 225, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.sp-modal-overlay.active .sp-modal-content {
    transform: scale(1);
}

.sp-modal-message {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 25px;
    color: #fff;
    text-transform: uppercase;
    line-height: 1.4;
}

.sp-modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.sp-modal-btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    transition: all 0.2s ease;
    flex: 1;
    outline: none;
}

.sp-modal-btn-confirm {
    background: var(--sp-accent);
    color: #fff;
    border: 1px solid var(--sp-accent);
}

.sp-modal-btn-cancel {
    background: transparent;
    color: #aaa;
    border: 1px solid #444;
}

.sp-modal-btn-confirm:hover {
    filter: brightness(1.2);
    box-shadow: 0 0 15px rgba(42, 125, 225, 0.5);
}

.sp-modal-btn-cancel:hover {
    color: #fff;
    border-color: #666;
}

/* ============================
   ROUND COUNTER & TIMER
   ============================ */
.sp-timer-circle {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: 2px solid var(--sp-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.95rem;
    color: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 10;
}

.sp-round-counter {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px); /* Standard gap to avatar */
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10; /* Lower z-index so it doesn't overlap cards/overlays */
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    width: 80px;
}

/* Position round counter to the left when cards shift right (3 or fewer cards) */
.three-card-mode-player #sp-player-avatar-wrapper .sp-round-counter {
    left: auto;
    right: calc(100% + 8px);
    bottom: 2px; /* Center circle vertically relative to avatar */
    transform: none;
}

.sp-round-counter.active {
    opacity: 1;
    visibility: visible;
}

.sp-round-svg {
    width: 60px;
    height: 25px;
    margin-bottom: -20px; /* Pull the number tighter into the curve */
    overflow: visible;
}

.sp-round-label-svg {
    font-size: 8px;
    font-weight: 800;
    fill: var(--sp-text-muted);
    letter-spacing: 1.5px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.sp-round-number {
    width: 42px;
    height: 42px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: 2px solid var(--sp-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 900;
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 0 0 10px rgba(42, 125, 225, 0.3);
    perspective: 1000px;
    z-index: 2;
}

/* Number Change Animation */
.sp-anim-next {
    animation: spRoundFlip 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes spRoundFlip {
    0% {
        transform: rotateX(0deg) scale(1);
        border-color: var(--sp-accent);
    }
    50% {
        transform: rotateX(90deg) scale(1.1);
        border-color: #fff;
        background: var(--sp-accent);
    }
    100% {
        transform: rotateX(0deg) scale(1);
        border-color: var(--sp-accent);
    }
}

@media (max-width: 767px) {
    .sp-round-number {
        width: 38px;
        height: 38px;
        font-size: 1.2rem;
    }
}

/* Variant Selection Modal */
.sp-variant-modal {
    max-width: 600px;
    width: 90%;
}

.sp-variant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 15px;
    margin-top: 20px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 10px;
}

.sp-variant-option {
    aspect-ratio: 2/3;
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.sp-variant-option:hover {
    border-color: var(--sp-accent);
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(42, 125, 225, 0.4);
}

.sp-variant-option.selected {
    border-color: var(--sp-accent);
    box-shadow: 0 0 15px var(--sp-accent);
}

/* Archived Cards */
.sp-card-select-item.sp-card-archived {
    filter: grayscale(1) opacity(0.6);
    cursor: pointer; /* Keep pointer so they can be clicked for the message */
}

.sp-card-select-item.sp-card-archived:hover .sp-card-select-inner {
    transform: none !important; /* Disable 3D tilt for archived */
}

.sp-card-select-item.sp-card-archived .sp-card-select-check {
    display: none !important; /* Hide checkmark */
}

/* CPU End message */
.sp-end-cpu-message {
    display: flex;
    align-items: center;
    gap: 20px;
    margin: 20px 0 30px;
    background: rgba(42, 125, 225, 0.1);
    padding: 15px;
    border-radius: var(--sp-radius);
    border: 1px solid rgba(42, 125, 225, 0.3);
    animation: spFadeInUp 0.6s ease-out forwards;
}

.sp-cpu-avatar-small {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 2px solid var(--sp-accent);
    flex-shrink: 0;
    box-shadow: 0 0 15px rgba(42, 125, 225, 0.4);
}

.sp-speech-bubble {
    position: relative;
    background: rgba(255, 255, 255, 0.08);
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--sp-text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: pre-wrap;
    text-align: left;
    max-width: 100%;
    word-break: break-word;
}

.sp-speech-bubble::after {
    content: "";
    position: absolute;
    top: 22px;
    left: -10px;
    border-width: 10px 10px 10px 0;
    border-style: solid;
    border-color: transparent rgba(255, 255, 255, 0.1) transparent transparent;
}

@keyframes spFadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Keyboard Fix: Move content up when keyboard is visible */
.sp-end-screen .sp-end-content {
    transition: transform 0.3s ease-out;
}

@media (max-width: 600px) {
    .sp-end-screen {
        padding-bottom: 250px; /* Add extra scrolling space for keyboard */
    }

    .sp-end-screen.sp-input-focused .sp-end-content {
        transform: translateY(-160px); /* Applied only on mobile now */
    }
}

@media (max-width: 480px) {
    .sp-end-screen.sp-input-focused h2 {
        font-size: 2rem;
        margin-top: 10px;
    }
}

/* ============================
   HERO SECTION & FLOATING CARDS
   ============================ */
@keyframes spNebulaPulse {
    0% { transform: scale(1) translate(0, 0); opacity: 0.4; }
    50% { transform: scale(1.2) translate(5%, 2%); opacity: 0.6; }
    100% { transform: scale(1) translate(0, 0); opacity: 0.4; }
}

@keyframes spNebulaRotate {
    from { transform: rotate(0deg) scale(1.5); }
    to { transform: rotate(360deg) scale(1.5); }
}

.sp-tcg-hero-section {
    position: relative;
    width: 100%;
    height: 400px;
    /* Deep space base gradient */
    background: radial-gradient(circle at 30% 30%, #1a1a3a 0%, #050510 100%);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    margin: 20px 0;
    box-shadow: inset 0 0 80px rgba(0,0,0,0.9), 0 10px 30px rgba(0,0,0,0.5);
}

/* Starfield Layer */
.sp-tcg-hero-section::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: 
        radial-gradient(1px 1px at 10% 20%, #fff 100%, transparent 0),
        radial-gradient(1px 1px at 40% 70%, #fff 100%, transparent 0),
        radial-gradient(2px 2px at 20% 90%, #fff 100%, transparent 0),
        radial-gradient(1px 1px at 80% 40%, #fff 100%, transparent 0),
        radial-gradient(1px 1px at 60% 10%, #fff 100%, transparent 0),
        radial-gradient(2px 2px at 70% 80%, #fff 100%, transparent 0);
    background-size: 200px 200px;
    opacity: 0.15;
    z-index: 0;
    pointer-events: none;
    animation: spNebulaRotate 120s linear infinite;
}

/* Nebula Layer */
.sp-tcg-hero-section::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 30%, rgba(42, 125, 225, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(30, 91, 176, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(10, 10, 30, 0) 0%, rgba(0,0,0,0.4) 100%);
    z-index: 0;
    pointer-events: none;
    animation: spNebulaPulse 15s ease-in-out infinite;
}

@keyframes spSparkle {
    0%, 100% { 
        opacity: 0.2; 
        filter: brightness(1) blur(0px);
    }
    50% { 
        opacity: 0.8; 
        filter: brightness(2) blur(1.5px); /* The "Corona" halo effect */
    }
}

.sp-hero-cards-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* Fixed Sparkling Star Layer with Corona */
.sp-hero-cards-layer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(1.5px 1.5px at 15% 15%, #fff 100%, transparent 0),
        radial-gradient(2px 2px at 35% 25%, #fff 100%, transparent 0),
        radial-gradient(1.5px 1.5px at 55% 55%, #fff 100%, transparent 0),
        radial-gradient(2.5px 2.5px at 75% 85%, #fff 100%, transparent 0),
        radial-gradient(1.5px 1.5px at 85% 35%, #fff 100%, transparent 0),
        radial-gradient(1.5px 1.5px at 95% 15%, #fff 100%, transparent 0);
    background-size: 400px 400px;
    opacity: 0.3;
    z-index: 0;
    pointer-events: none;
    animation: spSparkle 3s ease-in-out infinite alternate;
}

/* New structure: Container handles the CSS floating animation */
.sp-hero-card-container {
    position: absolute;
    width: 90px;
    height: auto;
    aspect-ratio: 2.5/3.5;
    pointer-events: none;
    animation: spHeroFloat 12s ease-in-out infinite alternate;
    will-change: transform;
}

/* The card itself handles the JS-based mouse interaction */
.sp-hero-card {
    position: relative;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    opacity: 1;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
    image-rendering: auto;
}

/* Depth classes for 3D feel */
.sp-hero-card.depth-far {
    filter: blur(1.5px) brightness(0.7);
    opacity: 0.6;
}

.sp-hero-card.depth-mid {
    filter: blur(0.4px) brightness(0.9);
    opacity: 0.9;
}

.sp-hero-card.depth-near {
    filter: none;
    opacity: 1;
    box-shadow: 0 15px 30px rgba(0,0,0,0.7);
}

.sp-hero-card-gloss {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0) 100%);
    background-size: 200% 200%;
    border-radius: inherit;
    animation: spHeroShine 8s linear infinite;
    pointer-events: none;
}

@keyframes spHeroFloat {
    0% { transform: translateY(0) rotate(var(--base-rot, 0deg)); }
    100% { transform: translateY(-40px) rotate(calc(var(--base-rot, 0deg) + 10deg)); }
}

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

.sp-tcg-hero-section .sp-tcg-start-wrapper {
    position: relative;
    z-index: 2; /* Above all cards (z-index 1) but below sticky navigation */
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    padding: 15px 30px;
    border-radius: 50px;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}


@media (max-width: 600px) {
    .sp-tcg-hero-section {
        height: 300px;
    }
    .sp-hero-card-container {
        width: 70px;
    }
}

/* Cheat Mode: Deck Preview */
.sp-deck-preview-modal {
    max-width: 500px !important;
    width: 90% !important;
}

.sp-deck-preview-title {
    color: #fca311;
    font-size: 1.4rem;
    margin-bottom: 5px;
    text-shadow: 0 0 10px rgba(252,163,17,0.4);
}

.sp-deck-preview-subtitle {
    font-size: 0.85rem;
    color: #aaa;
    margin-bottom: 20px;
}

.sp-deck-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 5px;
    margin-bottom: 20px;
    mask-image: linear-gradient(to bottom, black 90%, transparent 100%);
}

.sp-deck-preview-item {
    background: rgba(40,40,40,0.8);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.sp-deck-preview-item:hover {
    transform: translateY(-2px);
    border-color: #fca311;
}

.sp-preview-index {
    position: absolute;
    top: -5px;
    left: -5px;
    background: #fca311;
    color: #000;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    z-index: 2;
}

.sp-preview-img {
    width: 100%;
    aspect-ratio: 2.5/3.5;
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.sp-preview-name {
    font-size: 0.75rem;
    font-weight: bold;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.sp-side-stack.cheat-active {
    cursor: pointer;
    filter: drop-shadow(0 0 5px rgba(252,163,17,0.5));
    transition: transform 0.2s ease, filter 0.2s ease;
}

.sp-side-stack.cheat-active:hover {
    transform: scale(1.05);
    filter: drop-shadow(0 0 12px rgba(252,163,17,0.8));
}

.sp-side-stack.cheat-active::after {
    content: '👁️';
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 1.2rem;
    background: rgba(0,0,0,0.8);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #fca311;
    z-index: 10;
}

#sp-round-counter.cheat-active {
    transition: transform 0.2s ease, filter 0.2s ease;
}

.sp-round-cheat-controls {
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    width: auto;
    height: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-left: 8px; /* Reduced from 15px */
    pointer-events: none;
    z-index: 30;
}

/* Mobile: Keep buttons on the right but even closer to avoid screen edge cutoff */
@media (max-width: 767px) {
    .sp-round-cheat-controls {
        padding-left: 2px;
    }
}

.sp-round-cheat-btn {
    pointer-events: all;
    background: #fca311;
    color: #000;
    border: 2px solid #000;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
    transition: transform 0.2s ease, background 0.2s ease;
    padding: 0;
    line-height: 1;
}

.sp-round-cheat-btn:hover {
    transform: scale(1.2);
    background: #fff;
    filter: brightness(1.2);
}

.sp-round-cheat-btn:active {
    transform: scale(0.9);
}

/* Epic Card Unlock Animation */
.sp-epic-unlock-container {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 999999;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.85);
    transition: background 0.5s ease;
}

/* Blue pulsing glow behind the card */
.sp-sparks {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 120vw;
    height: 120vh;
    background: radial-gradient(circle, rgba(42,125,225,0.35) 0%, rgba(0,60,180,0) 55%);
    opacity: 0;
    z-index: 0;
    animation: sp-pulse-sparks 1s alternate infinite;
    mix-blend-mode: screen;
    pointer-events: none;
}

@keyframes sp-pulse-sparks {
    0%   { transform: translate(-50%,-50%) scale(0.6); opacity: 0.4; }
    100% { transform: translate(-50%,-50%) scale(1.1); opacity: 0.9; }
}

/* ============================
   BONUS FEATURE
   ============================ */

.sp-bonus-btn {
    background: linear-gradient(135deg, #ffd700 0%, #b8860b 100%) !important;
    color: #000 !important;
    font-weight: 800 !important;
    border: 2px solid #fff !important;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    animation: spBonusGlow 2s infinite alternate;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.sp-bonus-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.9);
}

/* Bonus Glow (Gold) */
@keyframes spBonusGlow {
    0% {
        box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
        filter: brightness(1);
    }
    100% {
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
        filter: brightness(1.2);
    }
}

/* Challenge Pulse (Blue) */
@keyframes spChallengePulseGlow {
    0% {
        box-shadow: 0 0 10px rgba(42, 125, 225, 0.4);
        filter: brightness(1);
    }
    100% {
        box-shadow: 0 0 30px rgba(42, 125, 225, 0.8);
        filter: brightness(1.2);
    }
}

.sp-challenge-banner {
    cursor: pointer;
    transition: transform 0.2s ease;
    animation: spChallengePulseGlow 2s infinite alternate;
}

.sp-challenge-banner:hover {
    transform: scale(1.02);
}

/* Start Screen Challenge Promotion (Integrated into Button) */
.sp-tcg-main-start-btn.challenge-active {
    position: relative;
    border: 2px solid var(--sp-accent);
    padding: 12px 20px;
    height: auto;
    width: auto;
    min-width: 200px;
    max-width: 260px;
    justify-content: center;
    background-color: #000;
    overflow: hidden;
    animation: spStartChallengePulse 3s infinite alternate;
    border-radius: 20px;
}

.sp-tcg-main-start-btn.challenge-active::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7));
    z-index: 1;
}

.sp-tcg-main-start-btn.challenge-active:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 8px 30px rgba(42, 125, 225, 0.6);
    filter: brightness(1.2);
}

.sp-tcg-main-start-btn.challenge-active > * {
    position: relative;
    z-index: 2;
}

@keyframes spStartChallengePulse {
    0% { box-shadow: 0 0 15px rgba(42, 125, 225, 0.3); }
    100% { box-shadow: 0 0 30px rgba(42, 125, 225, 0.7); }
}

.sp-start-challenge-tag {
    color: var(--sp-accent);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 0 0 2px 0;
    font-weight: 800;
    text-shadow: 0 0 10px rgba(42, 125, 225, 0.8);
}

.sp-start-challenge-name {
    color: #fff;
    font-size: 1.15rem;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,1);
    font-weight: 500;
    line-height: 1.1;
}

.sp-rules-modal.sp-bonus-modal .sp-rules-title {
    color: #ffd700 !important;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5) !important;
}

.sp-bonus-video-container iframe {
    border-radius: 8px;
    background: #000;
}

/* Responsive adjustments for the bonus video on small screens */
@media (max-height: 600px) {
    .sp-bonus-modal {
        padding: 15px !important;
    }
    .sp-bonus-video-container {
        margin-top: 10px !important;
    }
}