* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1a1b4b;
    --bg-secondary: #2d2e7a;
    --bg-gradient: linear-gradient(135deg, #1a1b4b 0%, #2d2e7a 50%, #4a2c6a 100%);
    
    --card-white: #fffef5;
    --card-shadow: rgba(0, 0, 0, 0.35);
    
    --suit-red: #ff4757;
    --suit-black: #2f3640;
    --suit-hearts: #ff6b81;
    --suit-diamonds: #ff9f43;
    --suit-spades: #3d3d3d;
    --suit-clubs: #5f6a7d;
    
    --accent-yellow: #ffd32a;
    --accent-pink: #ff6b9d;
    --accent-cyan: #18dcff;
    --accent-green: #7bed9f;
    --accent-purple: #a29bfe;
    
    --text-light: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.6);
    
    --card-width: 70px;
    --card-height: 100px;
    --card-radius: 10px;
    --card-offset: 28px;
    --card-offset-hidden: 8px;
}

body {
    font-family: 'Fredoka', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    overflow: hidden;
    color: var(--text-light);
}

.game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* ========== TITLE SCREEN ========== */
.title-screen {
    position: absolute;
    inset: 0;
    background: var(--bg-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.title-screen.hidden {
    opacity: 0;
    transform: scale(1.1);
    pointer-events: none;
}

.title-content {
    text-align: center;
    z-index: 10;
    position: relative;
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3) translateY(50px);
    }
    50% {
        transform: scale(1.05) translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.logo {
    margin-bottom: 40px;
}

.bouncing-cards {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
    perspective: 1000px;
}

.bounce-card {
    width: 55px;
    height: 75px;
    background: var(--color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    box-shadow: 
        0 8px 25px rgba(0,0,0,0.3),
        inset 0 2px 0 rgba(255,255,255,0.3),
        inset 0 -2px 0 rgba(0,0,0,0.2);
    animation: cardBounce 1.5s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.15s);
    transform-origin: bottom center;
}

.bounce-card:nth-child(1) { background: linear-gradient(135deg, #ff6b6b, #ee5a5a); }
.bounce-card:nth-child(2) { background: linear-gradient(135deg, #ff9ff3, #f368e0); }
.bounce-card:nth-child(3) { background: linear-gradient(135deg, #feca57, #ff9f43); }
.bounce-card:nth-child(4) { background: linear-gradient(135deg, #48dbfb, #0abde3); }
.bounce-card:nth-child(5) { background: linear-gradient(135deg, #1dd1a1, #10ac84); }

@keyframes cardBounce {
    0%, 100% { 
        transform: translateY(0) rotate(0deg) scale(1);
    }
    25% {
        transform: translateY(-20px) rotate(-5deg) scale(1.05);
    }
    50% { 
        transform: translateY(-35px) rotate(5deg) scale(1.1);
    }
    75% {
        transform: translateY(-15px) rotate(-3deg) scale(1.03);
    }
}

/* Card fan fallback for legacy */
.card-fan {
    display: none;
}

.logo h1 {
    font-family: 'Fredoka', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 76px;
    font-weight: 700;
    background: linear-gradient(
        90deg, 
        #ff6b6b, 
        #feca57, 
        #1dd1a1, 
        #48dbfb, 
        #ff9ff3, 
        #ff6b6b
    );
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: var(--accent-yellow);
    letter-spacing: -2px;
    line-height: 1;
    animation: rainbowShift 4s linear infinite;
    text-shadow: none;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

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

.subtitle {
    font-family: 'Patrick Hand', cursive;
    font-size: 26px;
    color: var(--accent-yellow);
    letter-spacing: 3px;
    margin-top: 8px;
    animation: subtitleGlow 2s ease-in-out infinite alternate;
}

@keyframes subtitleGlow {
    from { 
        text-shadow: 0 0 10px rgba(255, 211, 42, 0.5);
        transform: scale(1);
    }
    to { 
        text-shadow: 0 0 20px rgba(255, 211, 42, 0.8), 0 0 30px rgba(255, 107, 157, 0.4);
        transform: scale(1.02);
    }
}

.play-btn {
    position: relative;
    padding: 18px 50px;
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 600;
    color: var(--bg-primary);
    background: linear-gradient(135deg, var(--accent-yellow) 0%, var(--accent-pink) 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55), box-shadow 0.3s ease;
    box-shadow: 0 8px 30px rgba(255, 107, 157, 0.4), 0 4px 0 #e55b8a;
}

.play-btn:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 15px 40px rgba(255, 107, 157, 0.5), 0 6px 0 #e55b8a;
}

.play-btn:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: 0 4px 20px rgba(255, 107, 157, 0.4), 0 2px 0 #e55b8a;
}

.btn-sparkle {
    margin-left: 8px;
    display: inline-block;
    animation: sparkle 1s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(10deg); }
}

.game-features {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 25px;
}

.feature-tag {
    display: inline-block;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    animation: tagFloat 3s ease-in-out infinite;
}

.feature-tag:nth-child(1) {
    animation-delay: 0s;
    border-color: var(--accent-pink);
    background: rgba(255, 107, 157, 0.15);
}

.feature-tag:nth-child(2) {
    animation-delay: 0.3s;
    border-color: var(--accent-cyan);
    background: rgba(24, 220, 255, 0.15);
}

.feature-tag:nth-child(3) {
    animation-delay: 0.6s;
    border-color: var(--accent-yellow);
    background: rgba(255, 211, 42, 0.15);
}

@keyframes tagFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Floating background elements */
.floating-cards {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

.floating-cards::before {
    content: '♠ ♥ ♦ ♣';
    position: absolute;
    top: 8%;
    left: 3%;
    font-size: 40px;
    letter-spacing: 20px;
    opacity: 0.15;
    animation: float1 10s ease-in-out infinite;
    background: linear-gradient(90deg, #ff6b6b, #ff9ff3, #feca57, #48dbfb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.floating-cards::after {
    content: '🌟 ✨ 💫';
    position: absolute;
    bottom: 12%;
    right: 5%;
    font-size: 50px;
    letter-spacing: 15px;
    opacity: 0.2;
    animation: float2 12s ease-in-out infinite;
}

@keyframes float1 {
    0%, 100% { transform: translate(0, 0) rotate(-5deg); }
    33% { transform: translate(30px, -20px) rotate(5deg); }
    66% { transform: translate(-15px, 25px) rotate(-10deg); }
}

@keyframes float2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-30px, -25px) scale(1.1); }
}

/* ========== GAME SCREEN ========== */
.game-screen {
    position: absolute;
    inset: 0;
    background: var(--bg-gradient);
    display: none;
    flex-direction: column;
}

.game-screen.active {
    display: flex;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-left,
.header-right {
    display: flex;
    gap: 10px;
}

.header-center {
    display: flex;
    gap: 30px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-light);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.icon-btn:active {
    transform: scale(0.95);
}

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

.hint-btn {
    background: rgba(255, 211, 42, 0.2);
}

.hint-btn:hover {
    background: rgba(255, 211, 42, 0.3);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-icon {
    font-size: 18px;
}

.stat-value {
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 600;
    min-width: 50px;
}

/* ========== GAME BOARD ========== */
.game-board {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    overflow: hidden;
}

.top-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.stock-waste-area {
    display: flex;
    gap: 15px;
}

.foundations-area {
    display: flex;
    gap: 12px;
}

.tableau-row {
    flex: 1;
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* ========== PILES ========== */
.pile {
    position: relative;
    width: var(--card-width);
    min-height: var(--card-height);
    border-radius: var(--card-radius);
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.15);
    transition: all 0.2s ease;
}

.pile.highlight {
    background: rgba(123, 237, 159, 0.2);
    border-color: var(--accent-green);
    box-shadow: 0 0 20px rgba(123, 237, 159, 0.3);
}

.stock-pile {
    cursor: pointer;
}

.stock-pile:hover {
    border-color: rgba(255, 255, 255, 0.3);
}

.pile-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    opacity: 0.3;
    pointer-events: none;
}

.foundation-pile {
    border-style: solid;
    border-width: 2px;
}

.foundation-suit {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    opacity: 0.15;
    pointer-events: none;
}

#foundation-0 .foundation-suit { color: var(--suit-spades); }
#foundation-1 .foundation-suit { color: var(--suit-hearts); }
#foundation-2 .foundation-suit { color: var(--suit-diamonds); }
#foundation-3 .foundation-suit { color: var(--suit-clubs); }

.tableau-pile {
    flex: 1;
    max-width: var(--card-width);
    min-height: calc(var(--card-height) + 200px);
}

/* ========== CARDS ========== */
.card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    border-radius: var(--card-radius);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    transform-style: preserve-3d;
    user-select: none;
    -webkit-user-select: none;
}

.card.face-down {
    cursor: default;
}

.card:not(.face-down):hover {
    transform: translateY(-4px);
    z-index: 100;
}

.card.dragging {
    cursor: grabbing;
    z-index: 1000 !important;
    transition: none;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.card.hint {
    animation: hintPulse 0.6s ease-in-out infinite;
    z-index: 500;
}

@keyframes hintPulse {
    0%, 100% { 
        box-shadow: 0 0 0 0 rgba(255, 211, 42, 0.7);
    }
    50% { 
        box-shadow: 0 0 0 12px rgba(255, 211, 42, 0);
    }
}

.card-front,
.card-back {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    backface-visibility: hidden;
}

.card-front {
    background: var(--card-white);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 6px;
    box-shadow: 0 4px 15px var(--card-shadow), inset 0 1px 0 rgba(255,255,255,0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.card-back {
    background: 
        radial-gradient(circle at 20% 20%, #ff6b6b 0%, transparent 30%),
        radial-gradient(circle at 80% 20%, #feca57 0%, transparent 30%),
        radial-gradient(circle at 20% 80%, #48dbfb 0%, transparent 30%),
        radial-gradient(circle at 80% 80%, #ff9ff3 0%, transparent 30%),
        radial-gradient(circle at 50% 50%, #1dd1a1 0%, transparent 40%),
        linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    transform: rotateY(180deg);
    box-shadow: 0 4px 15px var(--card-shadow);
    overflow: hidden;
}

.card-back::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    background: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 4px,
            rgba(255, 255, 255, 0.1) 4px,
            rgba(255, 255, 255, 0.1) 8px
        ),
        repeating-linear-gradient(
            -45deg,
            transparent,
            transparent 4px,
            rgba(255, 255, 255, 0.1) 4px,
            rgba(255, 255, 255, 0.1) 8px
        );
}

.card-back::after {
    content: '🌟';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    animation: sparkleRotate 3s ease-in-out infinite;
}

@keyframes sparkleRotate {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: scale(1.2) rotate(180deg); opacity: 1; }
}

.card.face-down .card-front {
    transform: rotateY(180deg);
}

.card.face-down .card-back {
    transform: rotateY(0deg);
}

.card-corner {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.card-corner.bottom {
    align-self: flex-end;
    transform: rotate(180deg);
}

.card-rank {
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    font-weight: 700;
}

.card-suit-small {
    font-size: 14px;
}

.card-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 36px;
}

.card.red .card-rank,
.card.red .card-suit-small,
.card.red .card-center {
    color: var(--suit-red);
}

.card.black .card-rank,
.card.black .card-suit-small,
.card.black .card-center {
    color: var(--suit-black);
}

/* Specific suit colors for more fun */
.card[data-suit="hearts"] .card-center { color: var(--suit-hearts); }
.card[data-suit="diamonds"] .card-center { color: var(--suit-diamonds); }
.card[data-suit="spades"] .card-center { color: var(--suit-spades); }
.card[data-suit="clubs"] .card-center { color: var(--suit-clubs); }

/* ========== WIN SCREEN ========== */
.win-screen {
    position: absolute;
    inset: 0;
    background: rgba(26, 27, 75, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.win-screen.active {
    display: flex;
}

.win-content {
    text-align: center;
    animation: winBounce 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
    z-index: 10;
}

@keyframes winBounce {
    0% {
        opacity: 0;
        transform: scale(0.5) translateY(100px);
    }
    60% {
        transform: scale(1.1) translateY(-20px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.win-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 56px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-yellow) 0%, var(--accent-pink) 50%, var(--accent-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 30px;
    animation: winPulse 1.5s ease-in-out infinite;
}

@keyframes winPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.win-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 40px;
}

.win-stat {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.win-stat-label {
    font-size: 14px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.win-stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-yellow);
}

/* Confetti */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    opacity: 0;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(-100vh) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg);
    }
}

/* ========== MODAL ========== */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 150;
    backdrop-filter: blur(5px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-radius: 24px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalPop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal h3 {
    font-size: 28px;
    margin-bottom: 24px;
    color: var(--accent-yellow);
}

.modal-btn {
    display: block;
    width: 100%;
    padding: 16px 32px;
    margin-bottom: 12px;
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 500;
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent-cyan);
    transform: translateX(5px);
}

.modal-btn:last-child {
    margin-bottom: 0;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    :root {
        --card-width: 50px;
        --card-height: 72px;
        --card-radius: 6px;
        --card-offset: 22px;
        --card-offset-hidden: 6px;
    }
    
    .logo h1 {
        font-size: 48px;
    }
    
    .subtitle {
        font-size: 18px;
    }
    
    .fan-card {
        width: 45px;
        height: 64px;
        font-size: 26px;
        margin: 0 -8px;
    }
    
    .play-btn {
        padding: 14px 36px;
        font-size: 18px;
    }
    
    .game-header {
        padding: 8px 12px;
    }
    
    .header-center {
        gap: 15px;
    }
    
    .stat-value {
        font-size: 14px;
        min-width: 40px;
    }
    
    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    .game-board {
        padding: 10px 8px;
        gap: 15px;
    }
    
    .foundations-area,
    .stock-waste-area {
        gap: 6px;
    }
    
    .tableau-row {
        gap: 5px;
    }
    
    .card-rank {
        font-size: 12px;
    }
    
    .card-suit-small {
        font-size: 10px;
    }
    
    .card-center {
        font-size: 24px;
    }
    
    .win-title {
        font-size: 36px;
    }
    
    .win-stats {
        gap: 20px;
    }
    
    .win-stat-value {
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    :root {
        --card-width: 42px;
        --card-height: 60px;
        --card-offset: 18px;
        --card-offset-hidden: 5px;
    }
    
    .header-center {
        gap: 10px;
    }
    
    .stat-icon {
        display: none;
    }
    
    .card-corner.bottom {
        display: none;
    }
    
    .card-center {
        font-size: 20px;
    }
}

/* Card dealing animation */
@keyframes dealCard {
    from {
        opacity: 0;
        transform: translate(calc(50vw - 50%), calc(-50vh)) rotate(-180deg) scale(0.5);
    }
    to {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }
}

.card.dealing {
    animation: dealCard 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Card flip animation */
@keyframes flipCard {
    0% {
        transform: rotateY(180deg);
    }
    100% {
        transform: rotateY(0deg);
    }
}

.card.flipping {
    animation: flipCard 0.3s ease-out forwards;
}

/* Auto-complete card flight */
@keyframes flyToFoundation {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1) translateY(-20px);
    }
    100% {
        transform: scale(1);
    }
}

.card.flying {
    animation: flyToFoundation 0.3s ease-out;
}

