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

:root {
    --card-width: 100px;
    --card-height: 140px;
    --card-radius: 8px;
    --card-back: #2563eb;
    --felt-green: #1a5c2e;
    --felt-dark: #14492a;
    --text-light: #f0f0f0;
    --red: #dc2626;
    --black: #1f2937;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--felt-dark) 0%, var(--felt-green) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 10px;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

#header h1 {
    color: var(--text-light);
    font-size: 1.4rem;
    font-weight: 700;
}

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

#controls button {
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    background: #3b82f6;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#controls button:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

#controls button:active {
    transform: translateY(0);
}

#move-counter, #timer {
    color: var(--text-light);
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 70px;
}

#board {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#top-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

#top-row .spacer {
    width: var(--card-width);
}

#foundation-area {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

.pile {
    width: var(--card-width);
    height: var(--card-height);
    position: relative;
    border-radius: var(--card-radius);
}

.pile::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px dashed rgba(255, 255, 255, 0.25);
    border-radius: var(--card-radius);
    background: rgba(0, 0, 0, 0.15);
}

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

#tableau-area .pile {
    height: auto;
    min-height: var(--card-height);
    flex: 1;
    max-width: var(--card-width);
}

.card {
    width: 100%;
    height: var(--card-height);
    border-radius: var(--card-radius);
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    padding: 6px 8px;
    font-weight: 700;
    cursor: grab;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: box-shadow 0.15s;
    background: white;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.card.face-down {
    background: var(--card-back);
    cursor: default;
    display: block;
}

.card.face-down::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: calc(var(--card-radius) - 4px);
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 4px,
        rgba(255, 255, 255, 0.1) 4px,
        rgba(255, 255, 255, 0.1) 8px
    );
}

.card.red {
    color: var(--red);
}

.card.black {
    color: var(--black);
}

.card .rank {
    font-size: 1.1rem;
    line-height: 1;
}

.card .suit {
    font-size: 1rem;
    line-height: 1.2;
}

.card .center-suit {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.2rem;
    opacity: 0.8;
}

.card.dragging {
    opacity: 0.7;
    cursor: grabbing;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.pile.drop-target {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
    border-radius: var(--card-radius);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.card.invalid-shake {
    animation: shake 0.4s ease;
}

@keyframes flipIn {
    from { transform: rotateY(90deg); }
    to { transform: rotateY(0deg); }
}

.card.just-flipped {
    animation: flipIn 0.3s ease;
}

#win-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

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

#win-message {
    background: white;
    padding: 40px 60px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#win-message h2 {
    font-size: 2rem;
    margin-bottom: 12px;
    color: #1f2937;
}

#win-message p {
    color: #6b7280;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

#btn-play-again {
    padding: 12px 28px;
    border: none;
    border-radius: 8px;
    background: #22c55e;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#btn-play-again:hover {
    background: #16a34a;
}

/* Responsive adjustments */
@media (max-width: 800px) {
    :root {
        --card-width: 75px;
        --card-height: 105px;
    }
    #top-row {
        gap: 6px;
    }
    #top-row .spacer {
        width: var(--card-width);
    }
    #tableau-area {
        gap: 6px;
    }
    .card .rank {
        font-size: 0.9rem;
    }
    .card .center-suit {
        font-size: 1.6rem;
    }
}

@media (max-width: 500px) {
    :root {
        --card-width: 52px;
        --card-height: 72px;
    }
    #header h1 {
        font-size: 1.1rem;
    }
    #controls button {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    #top-row, #foundation-area {
        gap: 4px;
    }
    #tableau-area {
        gap: 4px;
    }
    .card {
        padding: 3px 4px;
    }
    .card .rank {
        font-size: 0.7rem;
    }
    .card .suit {
        font-size: 0.65rem;
    }
    .card .center-suit {
        font-size: 1.2rem;
    }
}

/* All tableau coordinates are relative to their pile, never document flow. */
:root { --face-step: 32px; }
.card { touch-action: none; }
.card.selected { outline: 3px solid #fbbf24; outline-offset: -3px; }
.corner { display: flex; flex-direction: column; align-items: center; align-self: flex-start; }
.corner.bottom { position: absolute; bottom: 6px; right: 8px; transform: rotate(180deg); }
.pips { position: absolute; inset: 24px 24px; display: grid; grid-template-columns: repeat(2, 1fr); align-items: center; justify-items: center; font-size: 1.4rem; }
.pips-3 > :last-child, .pips-5 > :last-child, .pips-7 > :last-child, .pips-9 > :last-child { grid-column: span 2; }
#top-row { display: grid; grid-template-columns: repeat(7, var(--card-width)); justify-content: space-between; }
#foundation-area { grid-column: 4 / 8; width: 100%; justify-content: space-between; }
#top-row .spacer { display: none; }
@media (max-width: 800px) { :root { --face-step: 28px; } .pips { inset: 20px 16px; font-size: 1rem; } }
@media (max-width: 500px) {
    :root { --card-width: calc((100vw - 44px) / 7); --card-height: calc((100vw - 44px) / 5); --face-step: 23px; }
    .corner.bottom { bottom: 3px; right: 4px; }
    .pips { inset: 17px 11px; font-size: .65rem; }
}
.pips { grid-auto-rows: minmax(0, 1fr); line-height: 1; }
@media (max-width: 500px) { .pips { inset: 17px 11px; font-size: .55rem; } }
#instructions { color: var(--text-light); font-size: .8rem; line-height: 1.4; padding: 0 4px; }

/* A quiet club-table palette, with gold reserved for actions and focus. */
:root { --card-back: #224c61; --red: #b53646; --waste-step: 22px; }
body { background: radial-gradient(ellipse at 50% 10%, #23594e, #102e2a 85%); color: #f5eedb; padding-top: 28px; }
#app { gap: 16px; }
#header { background: #0b2524aa; border: 1px solid #c9b57b33; padding: 18px 22px; }
.eyebrow { font-size: .58rem; letter-spacing: .22em; color: #d0bb88; }
#header h1 { font-family: Georgia, serif; font-size: 1.9rem; font-weight: 400; }
#header h1 span { color: #d0bb88; font-size: 1.3rem; }
#controls button { background: #294c48; border: 1px solid #ffffff25; min-height: 36px; }
#controls #btn-new-game { background: #d4bd84; color: #182e29; }
#controls button:hover { background: #42645a; }
#controls button:disabled { opacity: .45; cursor: default; }
.mode-choice { font-size: .75rem; color: #d0bb88; display: flex; align-items: center; gap: 8px; }
select { background: #193c36; color: #fff3d3; border: 1px solid #c9b57b88; padding: 8px; border-radius: 6px; font: inherit; }
#instructions { color: #c9d8ce; }
#deal-status { color: #e0cb9d; font-size: .76rem; letter-spacing: .03em; }
#board { gap: 34px; padding-top: 8px; }
.card { background: #fffdf6; border: 1px solid #132e2922; }
.pile::before { border: 1px solid #c8d6bc40; background: #082b2633; }
[data-area="foundation"]::before { content: '♠'; display: grid; place-items: center; font-size: 2rem; color: #c9b57b66; }
.pile[data-area="foundation"][data-suit="hearts"]::before { content: '♥'; }
.pile[data-area="foundation"][data-suit="diamonds"]::before { content: '♦'; }
.pile[data-area="foundation"][data-suit="clubs"]::before { content: '♣'; }
#waste-area { grid-column: 2 / 4; }
#waste-area .card { width: var(--card-width); }
:focus-visible { outline: 3px solid #f2d28b; outline-offset: 3px; }
@media (max-width: 800px) { :root { --waste-step: 16px; } }
@media (max-width: 500px) {
    :root { --waste-step: 12px; }
    body { padding-top: 10px; }
    #header { padding: 12px; }
    #header h1 { font-size: 1.5rem; }
    #controls { gap: 6px; }
    #controls button { min-height: 34px; }
    #app { gap: 12px; }
    #board { gap: 26px; }
    #deal-status { font-size: .68rem; }
    .mode-choice { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Expose rank and suit together above the next tableau card. */
.corner:not(.bottom) { flex-direction: row; gap: 3px; align-items: baseline; }
/* The waste fans horizontally, so its labels use the exposed vertical strip. */
#waste-area .corner:not(.bottom) { flex-direction: column; gap: 0; align-items: center; }
:root { --waste-step: 30px; }
@media (max-width: 800px) { :root { --waste-step: 26px; } }
@media (max-width: 500px) { :root { --waste-step: 20px; } }
