* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a472a 0%, #2d5a3d 50%, #1a472a 100%);
    min-height: 100vh;
    overflow-x: hidden;
    color: #fff;
}

#app {
    max-width: 1300px;
    margin: 0 auto;
    padding: 6px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== HEADER ========== */
header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    margin-bottom: 6px;
}

header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
}

#controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

#score-display, #moves-display {
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 8px;
    border-radius: 5px;
    white-space: nowrap;
}

button {
    padding: 5px 12px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    background: #4a90d9;
    color: #fff;
}

button:hover {
    filter: brightness(1.15);
}

button:active {
    transform: scale(0.97);
}

#new-game-btn {
    background: #e67e22;
}

#undo-btn {
    background: #7f8c8d;
}

/* ========== GAME LAYOUT ========== */
#game-layout {
    display: flex;
    flex: 1;
    gap: 6px;
}

/* Left panel - completed sets */
#left-panel {
    width: 90px;
    min-width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    padding: 6px 4px;
}

#left-panel .panel-label {
    font-size: 0.65rem;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Right panel - stock */
#right-panel {
    width: 100px;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    padding: 8px 6px;
}

#stock-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#stock-label {
    font-size: 0.65rem;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.г {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 0;
    border-radius: 8px;
    transition: background 0.2s;
    min-height: 100px;
    position: relative;
    overflow: visible;
    width: 60px;
}

.stock-pile {
    position: relative;
    min-height: 84px;
}

.stock-pile:hover {
    background: rgba(255, 255, 255, 0.2);
}

.stock-pile .card.back {
    width: 60px;
    height: 84px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

#stock-count,
#foundation-count {
    font-size: 1rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 10px;
    border-radius: 5px;
    min-width: 30px;
    text-align: center;
    margin-top: 6px;
}

/* ========== TABLEAU ========== */
#tableau {
    display: flex;
    gap: 3px;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

.column {
    flex: 1;
    max-width: 95px;
    min-width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-height: 150px;
    border-radius: 6px;
    transition: background 0.2s;
}

.column.highlight {
    background: rgba(255, 255, 255, 0.1);
    outline: 2px solid rgba(241, 196, 15, 0.5);
}

/* ========== CARDS ========== */
.card {
    border-radius: 5px;
    position: absolute;
    cursor: pointer;
    transition: none;
    background: #fff;
    border: 1px solid #ccc;
}

.card.front {
    width: 100%;
    aspect-ratio: 5 / 7;
    max-width: 85px;
    min-width: 38px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: #222;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    backface-visibility: hidden;
    overflow: hidden;
}

.card.front.red {
    color: #d32f2f;
}

.card.front .rank {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 1.3rem;
    line-height: 1;
    font-weight: 800;
    z-index: 2;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}

.card.front .suit-corner {
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 1.3rem;
    line-height: 1;
    font-weight: 800;
    z-index: 2;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}

.card.front .suit-icon {
    font-size: 5rem;
    pointer-events: none;
}

.card.front.blocked {
    background: #d0d0d0;
    border-color: #aaa;
    color: #555;
    opacity: 1;
}
.card.front.blocked .rank,
.card.front.blocked .suit-corner {
    color: #555;
}
.card.front.blocked .suit-icon {
    color: #999;
    opacity: 0.85;
}
.card.front.blocked.red {
    color: #c07070;
}
.card.front.blocked.red .rank,
.card.front.blocked.red .suit-corner {
    color: #c07070;
}
.card.front.blocked.red .suit-icon {
    color: #c07070;
    opacity: 0.85;
}

.card.back {
    width: 100%;
    aspect-ratio: 5 / 7;
    max-width: 85px;
    min-width: 38px;
    background: linear-gradient(135deg, #2980b9, #3498db);
    border: 1px solid #2471a3;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    overflow: hidden;
}

.card-placeholder {
    width: 100%;
    max-width: 85px;
    min-width: 38px;
    aspect-ratio: 5 / 7;
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 5px;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

/* ========== FOUNDATION (completed sets) ========== */
#foundation-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.foundation-pile {
    position: relative;
    width: 100%;
    overflow: hidden;
    min-height: 96px;
}

.card.foundation-card {
    width: 60px !important;
    height: 84px !important;
    font-size: 0.8rem;
    border-radius: 4px;
    flex-shrink: 0;
    left: 50%;
    transform: translateX(-50%);
}

.card.foundation-card .suit-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 1.5rem;
}

/* ========== DRAG GHOST ========== */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    opacity: 0.9;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.drag-ghost .card {
    position: absolute !important;
    left: 0 !important;
    width: 80px !important;
    height: 112px !important;
    flex-shrink: 0;
    transform: none !important;
    transition: none !important;
    margin-bottom: 0 !important;
}

/* ========== WIN OVERLAY ========== */
#win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

#win-overlay.hidden {
    display: none;
}

#win-modal {
    background: linear-gradient(135deg, #2d5a3d, #1a472a);
    padding: 25px 35px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2);
}

#win-modal h2 {
    font-size: 1.8rem;
    margin-bottom: 12px;
}

#win-modal p {
    font-size: 1.1rem;
    margin-bottom: 6px;
}

#play-again-btn {
    margin-top: 16px;
    padding: 10px 28px;
    font-size: 1rem;
    background: #e67e22;
}

/* ========== DIFFICULTY MODAL ========== */
#difficulty-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

#difficulty-overlay.hidden {
    display: none;
}

#difficulty-modal {
    background: linear-gradient(135deg, #2d5a3d, #1a472a);
    padding: 30px 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2);
    max-width: 380px;
}

#difficulty-close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    opacity: 0.8;
}

#difficulty-close-btn:hover {
    background: rgba(255,255,255,0.15);
    opacity: 1;
}

#difficulty-modal {
    position: relative;
}

#difficulty-modal h2 {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

#difficulty-modal p {
    font-size: 1rem;
    margin-bottom: 20px;
    opacity: 0.8;
}

#difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.diff-btn {
    padding: 14px 20px;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
    background: rgba(255,255,255,0.08);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.diff-btn:hover {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.4);
    filter: brightness(1.1);
}

.diff-btn:active {
    transform: scale(0.97);
}

.diff-btn .diff-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.diff-btn .diff-desc {
    font-size: 0.85rem;
    opacity: 0.7;
}

/* ========== MOBILE ========== */
@media (max-width: 700px) {
    #app {
        padding: 3px;
    }

    header {
        padding: 4px 6px;
        gap: 3px;
    }

    header h1 {
        font-size: 0.85rem;
    }

    #controls {
        gap: 3px;
    }

    #score-display, #moves-display {
        font-size: 0.65rem;
        padding: 2px 5px;
    }

    button {
        padding: 3px 8px;
        font-size: 0.65rem;
    }

    #game-layout {
        gap: 3px;
        overflow: hidden;
    }

    #left-panel {
        width: 52px;
        min-width: 42px;
        padding: 4px 2px;
    }

    #right-panel {
        width: 55px;
        min-width: 45px;
        padding: 4px 3px;
    }

    .stock-pile .card.back {
        width: 42px;
        height: 59px;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    #stock-count,
    #foundation-count {
        font-size: 0.75rem;
        padding: 2px 6px;
    }

    #stock-label,
    #left-panel .panel-label {
        font-size: 0.5rem;
    }

    .column {
        max-width: 52px;
        min-width: 18px;
    }

    .card.front {
        max-width: 48px;
        min-width: 20px;
        font-size: 0.65rem;
    }

    .card.front .rank {
        font-size: 0.7rem;
        top: 1px;
        left: 2px;
        line-height: 0.9;
    }

    .card.front .suit-corner {
        font-size: 0.7rem;
        top: 1px;
        right: 2px;
        line-height: 0.9;
    }

    .card.front .suit-icon {
        font-size: 1.3rem;
        height: 100%;
        display: flex;
        align-items: flex-end;
        justify-content: center;
        padding-bottom: 4px;
    }

    .card.back {
        max-width: 48px;
        min-width: 20px;
    }

    .card-placeholder {
        max-width: 48px;
        min-width: 20px;
    }

    .card.foundation-card {
        width: 38px !important;
        height: 53px !important;
        font-size: 0.7rem;
    }

    .card.foundation-card .suit-icon {
        font-size: 1.2rem;
    }

    #win-modal {
        padding: 18px 22px;
    }

    #win-modal h2 {
        font-size: 1.2rem;
    }

    .drag-ghost .card {
        width: 48px !important;
        height: 67px !important;
    }
}

@media (max-width: 400px) {
    .column {
        max-width: 38px;
        min-width: 14px;
    }

    .card.front {
        max-width: 34px;
        min-width: 12px;
        font-size: 0.45rem;
    }

    .card.front .rank {
        font-size: 0.65rem;
        top: 0px;
        left: 1px;
    }

    .card.front .suit-corner {
        font-size: 0.65rem;
        top: 0px;
        right: 1px;
    }

    .card.front .suit-icon {
        font-size: 1.2rem;
        height: 100%;
        display: flex;
        align-items: flex-end;
        justify-content: center;
        padding-bottom: 3px;
    }

    .card.back {
        max-width: 34px;
        min-width: 12px;
    }

    #left-panel {
        width: 38px;
        min-width: 30px;
    }

    #right-panel {
        width: 42px;
        min-width: 35px;
    }

    .stock-pile .card.back {
        width: 28px;
        height: 39px;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    .card.foundation-card {
        width: 28px !important;
        height: 39px !important;
        font-size: 0.4rem;
    }

    .card.foundation-card .suit-icon {
        font-size: 0.8rem;
    }

    .drag-ghost .card {
        width: 38px !important;
        height: 53px !important;
    }
}

/* ========== SHIRT SELECTOR ========== */
#shirt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

#shirt-overlay.hidden {
    display: none;
}

#shirt-modal {
    background: linear-gradient(135deg, #2d5a3d, #1a472a);
    padding: 25px 30px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2);
    max-width: 520px;
    width: calc(100% - 30px);
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

#shirt-close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    opacity: 0.8;
}

#shirt-close-btn:hover {
    background: rgba(255,255,255,0.15);
    opacity: 1;
}

#shirt-modal h2 {
    font-size: 1.6rem;
    margin-bottom: 8px;
    padding-right: 36px;
}

#shirt-modal > p {
    font-size: 0.95rem;
    margin-bottom: 16px;
    opacity: 0.8;
}

#shirt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}

.shirt-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.2s;
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.shirt-btn:hover {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.4);
    filter: brightness(1.1);
}

.shirt-btn:active {
    transform: scale(0.97);
}

.shirt-preview {
    width: 60px;
    height: 84px;
    border-radius: 5px;
    border: 1px solid rgba(0,0,0,0.2);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1), 0 2px 4px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
}

.shirt-name {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* Shirt 0: Classic blue */
.shirt-0 {
    background: linear-gradient(135deg, #2471a3 0%, #3498db 50%, #2980b9 100%);
}

/* Shirt 1: Emerald */
.shirt-1 {
    background: linear-gradient(135deg, #0e6655 0%, #148f77 50%, #1abc9c 100%);
}

/* Shirt 2: Ruby */
.shirt-2 {
    background: linear-gradient(135deg, #922b21 0%, #c0392b 50%, #e74c3c 100%);
}

/* Shirt 3: Sapphire */
.shirt-3 {
    background: linear-gradient(135deg, #1a5276 0%, #2980b9 50%, #5dade2 100%);
}

/* Shirt 4: Amethyst */
.shirt-4 {
    background: linear-gradient(135deg, #6c3483 0%, #8e44ad 50%, #af7ac5 100%);
}

/* Shirt 5: Citron */
.shirt-5 {
    background: linear-gradient(135deg, #9a7d0a 0%, #b7950b 50%, #f1c40f 100%);
}

/* Shirt 6: Burgundy */
.shirt-6 {
    background: linear-gradient(135deg, #641e16 0%, #922b21 50%, #b03a2e 100%);
}

/* Shirt 7: Teal */
.shirt-7 {
    background: linear-gradient(135deg, #117a65 0%, #17a589 50%, #48c9b0 100%);
}

/* Shirt 8: Wheat */
.shirt-8 {
    background: linear-gradient(135deg, #7d6608 0%, #b9770e 50%, #f0b27a 100%);
}

/* Shirt 9: Checkered dark */
.shirt-9 {
    background: repeating-linear-gradient(90deg, #5d4037 0px, #5d4037 12px, #795548 12px, #795548 24px);
}

/* Shirt 10: Dark */
.shirt-10 {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 50%, #7f8c8d 100%);
}

/* Shirt 11: Rainbow */
.shirt-11 {
    background: conic-gradient(from 45deg, #e74c3c, #f1c40f, #2ecc71, #3498db, #9b59b6, #e74c3c);
}

/* Shirt 12: French */
.shirt-12 {
    background: repeating-linear-gradient(90deg, #c0392b 0px, #c0392b 8px, #ecf0f1 8px, #ecf0f1 16px);
}

/* Shirt 13: Emerald green */
.shirt-13 {
    background: linear-gradient(135deg, #16a085 0%, #2ecc71 100%);
}

/* Shirt 14: Polka dots */
.shirt-14 {
    background: repeating-conic-gradient(#8e44ad 0% 25%, #af7ac5 0% 50%);
}

/* Shirt 15: Orange */
.shirt-15 {
    background: linear-gradient(135deg, #d35400 0%, #e67e22 50%, #f39c12 100%);
}

/* Shirt 16: Army */
.shirt-16 {
    background: repeating-linear-gradient(45deg, #2c3e50 0px, #2c3e50 10px, #34495e 10px, #34495e 20px);
}

/* Shirt 17: Sun */
.shirt-17 {
    background: radial-gradient(circle at 30% 30%, #f1c40f 0%, #e67e22 50%, #d35400 100%);
}

/* Shirt 18: Lime */
.shirt-18 {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 50%, #58d68d 100%);
}

/* Shirt 19: Diagonal stripes */
.shirt-19 {
    background: repeating-linear-gradient(135deg, #2980b9 0px, #2980b9 6px, #3498db 6px, #3498db 12px);
}
