* {
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

:root {
    --card-width: 70px;
    --card-height: 100px;
    --card-radius: 6px;
    --card-gap: 10px;
    --pile-offset: 25px;
    --pile-offset-hidden: 8px;
}

body {
    margin: 0;
    padding: 10px;
    background: linear-gradient(135deg, #1a5f2a 0%, #0d3d18 100%);
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow-x: hidden;
}

#game-container {
    max-width: 600px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

#new-game-btn {
    background: #2d8a4a;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#new-game-btn:active {
    transform: scale(0.98);
    background: #247a3d;
}

#draw-mode {
    display: flex;
    gap: 15px;
    color: white;
    font-size: 14px;
}

#draw-mode label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

#draw-mode input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

#top-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

#stock-waste {
    display: flex;
    gap: var(--card-gap);
}

#foundations {
    display: flex;
    gap: var(--card-gap);
}

.card-slot {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255,255,255,0.3);
    border-radius: var(--card-radius);
    position: relative;
}

.foundation::before {
    content: attr(data-suit);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    opacity: 0.4;
}

.foundation[data-suit="hearts"]::before { content: "♥"; color: #e74c3c; }
.foundation[data-suit="diamonds"]::before { content: "♦"; color: #e74c3c; }
.foundation[data-suit="clubs"]::before { content: "♣"; color: #2c3e50; }
.foundation[data-suit="spades"]::before { content: "♠"; color: #2c3e50; }

#stock {
    cursor: pointer;
}

#stock.empty {
    border-style: solid;
    border-color: rgba(255,255,255,0.5);
}

#stock.empty::after {
    content: "↻";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    color: rgba(255,255,255,0.6);
}

#tableau {
    display: flex;
    justify-content: space-between;
    gap: 5px;
}

.pile {
    width: var(--card-width);
    min-height: calc(var(--card-height) + 200px);
    position: relative;
}

.card {
    width: var(--card-width);
    height: var(--card-height);
    background: white;
    border-radius: var(--card-radius);
    position: absolute;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4px 6px;
    cursor: grab;
    touch-action: none;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.card.face-down {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 50%, #3498db 100%);
    background-size: 10px 10px;
    cursor: default;
}

.card.face-down::after {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 4px;
}

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

.card.snap-animation {
    transition: left 0.15s ease, top 0.15s ease;
}

.card .top-left,
.card .bottom-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

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

.card .rank {
    font-size: 16px;
    font-weight: bold;
}

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

.card.red {
    color: #e74c3c;
}

.card.black {
    color: #2c3e50;
}

.card.valid-drop {
    box-shadow: 0 0 10px 3px #f1c40f;
}

#stock .card,
#waste .card {
    position: absolute;
    top: 0;
    left: 0;
}

#waste .card {
    cursor: grab;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px 50px;
    border-radius: 15px;
    text-align: center;
}

.modal-content h2 {
    margin: 0 0 20px 0;
    color: #27ae60;
    font-size: 28px;
}

#play-again-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
}

#play-again-btn:active {
    background: #219a52;
}

/* Responsive adjustments */
@media (max-width: 500px) {
    :root {
        --card-width: 48px;
        --card-height: 70px;
        --card-gap: 6px;
        --pile-offset: 18px;
        --pile-offset-hidden: 6px;
    }

    body {
        padding: 8px;
    }

    header {
        margin-bottom: 10px;
    }

    #new-game-btn {
        padding: 8px 16px;
        font-size: 14px;
    }

    #draw-mode {
        font-size: 12px;
        gap: 10px;
    }

    #draw-mode input[type="radio"] {
        width: 16px;
        height: 16px;
    }

    #top-row {
        margin-bottom: 15px;
    }

    .card .rank {
        font-size: 12px;
    }

    .card .suit {
        font-size: 10px;
    }

    .foundation::before {
        font-size: 18px;
    }

    #stock.empty::after {
        font-size: 24px;
    }
}

@media (max-width: 380px) {
    :root {
        --card-width: 42px;
        --card-height: 62px;
        --card-gap: 4px;
        --pile-offset: 15px;
        --pile-offset-hidden: 5px;
    }

    .card .rank {
        font-size: 11px;
    }

    .card .suit {
        font-size: 9px;
    }
}
