/* ── Reset & Base ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --clr-bg: #0b1120;
    --clr-felt: #0d6b3d;
    --clr-felt-dark: #094a2a;
    --clr-accent: #f0c040;
    --clr-accent-glow: rgba(240, 192, 64, .35);
    --clr-red: #ef4444;
    --clr-black: #1e293b;
    --clr-card-bg: #fffdf7;
    --clr-card-border: #d4d0c8;
    --clr-glass: rgba(255, 255, 255, .06);
    --card-w: 100px;
    --card-h: 142px;
    --card-radius: 10px;
    --pile-gap: 18px;
    --tableau-offset: 28px;
    --shadow-card: 0 2px 6px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.15);
    --shadow-card-hover: 0 8px 24px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.2);
    --transition: .22s cubic-bezier(.4,0,.2,1);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--clr-bg);
    min-height: 100vh;
    padding: 16px;
    color: #e2e8f0;
    overflow-x: hidden;
}

/* ── Particles ── */
.particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}
.particle {
    position: absolute;
    border-radius: 50%;
    background: rgba(240, 192, 64, .12);
    animation: float linear infinite;
}
@keyframes float {
    0%   { transform: translateY(100vh) scale(0); opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}

/* ── Container ── */
.container {
    max-width: 1100px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* ── Header ── */
header {
    background: var(--clr-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,.08);
    padding: 16px 24px;
    border-radius: 16px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

h1 {
    font-size: 1.6em;
    font-weight: 800;
    letter-spacing: -.02em;
    background: linear-gradient(135deg, var(--clr-accent), #fde68a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-icon {
    font-size: 1.1em;
    -webkit-text-fill-color: var(--clr-accent);
}

.subtitle {
    font-size: .8em;
    font-weight: 500;
    color: rgba(255,255,255,.35);
    text-transform: uppercase;
    letter-spacing: .08em;
}

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    padding: 9px 18px;
    border-radius: 10px;
    font-family: inherit;
    font-size: .85em;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--clr-accent);
    color: #1a1a2e;
    box-shadow: 0 0 20px var(--clr-accent-glow);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px var(--clr-accent-glow), 0 6px 16px rgba(0,0,0,.3);
    filter: brightness(1.1);
}

.btn-ghost {
    background: rgba(255,255,255,.08);
    color: #cbd5e1;
    border: 1px solid rgba(255,255,255,.1);
}
.btn-ghost:hover {
    background: rgba(255,255,255,.14);
    transform: translateY(-2px);
}

.btn-accent {
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    box-shadow: 0 0 16px rgba(16,185,129,.3);
}
.btn-accent:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 26px rgba(16,185,129,.45);
}

.btn:active { transform: translateY(0) !important; }
.btn-large { padding: 14px 32px; font-size: 1.05em; }

/* ── Stats bar ── */
.stats-bar {
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,.3);
    border-radius: 12px;
    padding: 4px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 18px;
    border-radius: 10px;
    transition: var(--transition);
}
.stat:hover { background: rgba(255,255,255,.06); }

.stat-label {
    font-size: .65em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255,255,255,.4);
}
.stat-value {
    font-size: 1.15em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--clr-accent);
}
.stat-value-best {
    color: #a78bfa;
}
.stat-value.score-pop {
    animation: scorePop .32s ease;
}
@keyframes scorePop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.3); color: #fff; }
    100% { transform: scale(1); }
}

/* ── Game Board (Felt) ── */
.game-board {
    background:
        radial-gradient(ellipse at 50% 30%, rgba(16,120,60,.35) 0%, transparent 70%),
        linear-gradient(180deg, var(--clr-felt) 0%, var(--clr-felt-dark) 100%);
    border: 2px solid rgba(255,255,255,.07);
    padding: 28px 24px;
    border-radius: 20px;
    box-shadow:
        inset 0 2px 40px rgba(0,0,0,.2),
        0 4px 30px rgba(0,0,0,.4);
    position: relative;
    overflow: hidden;
}

.game-board::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000' fill-opacity='.06'%3E%3Ccircle cx='1' cy='1' r='.6'/%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
    border-radius: 20px;
}

.top-section {
    display: flex;
    justify-content: space-between;
    margin-bottom: 32px;
    gap: 20px;
    position: relative;
    z-index: 1;
}

.stock-section { display: flex; gap: var(--pile-gap); }
.foundation-section { display: flex; gap: var(--pile-gap); }

.tableau-section {
    display: flex;
    gap: var(--pile-gap);
    justify-content: center;
    position: relative;
    z-index: 1;
}

/* ── Piles ── */
.pile {
    width: var(--card-w);
    min-height: var(--card-h);
    border: 2px dashed rgba(255,255,255,.15);
    border-radius: var(--card-radius);
    position: relative;
    transition: var(--transition);
}

.pile.drag-over,
.pile.click-target {
    background: rgba(240, 192, 64, .12);
    border-color: var(--clr-accent);
    border-style: solid;
    box-shadow: 0 0 20px var(--clr-accent-glow);
    transform: scale(1.03);
}

.tableau-pile { min-height: 420px; }

/* ── Foundation piles ── */
.foundation-pile { background: rgba(0,0,0,.12); }
.foundation-pile::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.8em;
    opacity: .18;
    pointer-events: none;
}
.foundation-pile[data-suit="hearts"]::before   { content: '♥'; color: var(--clr-red); }
.foundation-pile[data-suit="diamonds"]::before  { content: '♦'; color: var(--clr-red); }
.foundation-pile[data-suit="clubs"]::before     { content: '♣'; color: #cbd5e1; }
.foundation-pile[data-suit="spades"]::before    { content: '♠'; color: #cbd5e1; }

.foundation-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(0deg, rgba(240,192,64,.15), transparent);
    border-radius: 0 0 var(--card-radius) var(--card-radius);
    transition: height .4s ease;
    pointer-events: none;
}

/* ── Stock pile ── */
.stock-pile {
    cursor: pointer;
    background: rgba(0,0,0,.1);
}
.stock-pile:hover { background: rgba(0,0,0,.18); }

.stock-counter {
    position: absolute;
    bottom: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: .65em;
    font-weight: 700;
    color: rgba(255,255,255,.35);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    pointer-events: none;
}

.stock-pile.empty { cursor: pointer; border-style: solid; border-color: rgba(255,255,255,.12); }
.stock-pile.empty::after {
    content: '↻';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.4em;
    opacity: .35;
    color: #fff;
    transition: var(--transition);
}
.stock-pile.empty:hover::after {
    opacity: .6;
    transform: translate(-50%, -50%) rotate(180deg);
}

/* ── Cards ── */
.card {
    width: var(--card-w);
    height: var(--card-h);
    background: var(--clr-card-bg);
    border: 1.5px solid var(--clr-card-border);
    border-radius: var(--card-radius);
    position: absolute;
    cursor: grab;
    user-select: none;
    transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 7px 9px;
    font-size: 1em;
    font-weight: 700;
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-card-hover);
    z-index: 100 !important;
}

.card.selected {
    box-shadow: 0 0 0 3px var(--clr-accent), 0 0 24px var(--clr-accent-glow);
    transform: translateY(-8px);
    z-index: 101 !important;
}

.card.dragging {
    opacity: .6;
    cursor: grabbing;
    transform: scale(1.06) rotate(2deg);
    box-shadow: 0 16px 48px rgba(0,0,0,.4);
}

.card.card-dealing {
    animation: dealCard .4s cubic-bezier(.4,0,.2,1) both;
}
@keyframes dealCard {
    0%   { opacity: 0; transform: translate(-200%, -100%) rotate(-15deg) scale(.7); }
    100% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
}

.card.card-flip {
    animation: cardFlip .4s ease;
}
@keyframes cardFlip {
    0%   { transform: rotateY(0deg) scale(1); }
    50%  { transform: rotateY(90deg) scale(1.05); }
    100% { transform: rotateY(0deg) scale(1); }
}

.card.card-shake {
    animation: cardShake .4s ease;
}
@keyframes cardShake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-6px) rotate(-2deg); }
    40%      { transform: translateX(6px) rotate(2deg); }
    60%      { transform: translateX(-4px) rotate(-1deg); }
    80%      { transform: translateX(4px) rotate(1deg); }
}

.card.hint-glow {
    animation: hintPulse 1s ease 3;
    z-index: 102 !important;
}
@keyframes hintPulse {
    0%, 100% { box-shadow: var(--shadow-card); }
    50%      { box-shadow: 0 0 0 4px #3b82f6, 0 0 20px rgba(59,130,246,.5); transform: translateY(-8px); }
}

/* Face-down cards */
.card.face-down {
    background:
        repeating-conic-gradient(#1e3a5f 0% 25%, #1a3050 25% 50%) 50% / 10px 10px;
    border: 2px solid #2a5080;
    cursor: pointer;
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.card.face-down::before {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 6px;
    border: 1.5px solid rgba(255,255,255,.08);
    background:
        radial-gradient(ellipse at 50% 30%, rgba(100,160,255,.12), transparent 60%),
        linear-gradient(135deg, #1a3a6a, #0f2540);
    pointer-events: none;
}

.card.face-down::after {
    content: '♠';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2em;
    color: rgba(120,180,255,.15);
    pointer-events: none;
}

.card.face-down:hover {
    transform: none;
    border-color: #3a6fa0;
}

/* Card faces */
.card-value { text-align: left; line-height: 1; }
.card-suit  { text-align: right; line-height: 1; transform: rotate(180deg); }

.card-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.2em;
    opacity: .12;
    pointer-events: none;
}

.card.red   { color: var(--clr-red); }
.card.black { color: var(--clr-black); }

.card.highlight-valid {
    box-shadow: 0 0 0 3px var(--clr-accent), var(--shadow-card-hover);
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30, 41, 59, .95);
    backdrop-filter: blur(12px);
    color: #e2e8f0;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: .9em;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,.1);
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
    z-index: 999;
    opacity: 0;
    transition: all .3s cubic-bezier(.4,0,.2,1);
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }

/* ── Win Message ── */
.win-message {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .75);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn .35s ease;
}
.win-message.hidden { display: none; }

.win-content {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 1px solid rgba(240,192,64,.2);
    padding: 48px 56px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 0 60px rgba(240,192,64,.15), 0 20px 60px rgba(0,0,0,.6);
    animation: winSlide .5s cubic-bezier(.4,0,.2,1);
    max-width: 440px;
    width: 90%;
}

.win-icon {
    font-size: 4em;
    margin-bottom: 12px;
    animation: winBounce 1s ease infinite;
}
@keyframes winBounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-14px); }
}

.win-content h2 {
    font-size: 2.2em;
    font-weight: 800;
    background: linear-gradient(135deg, var(--clr-accent), #fde68a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.win-subtitle {
    font-size: 1em;
    color: rgba(255,255,255,.5);
    margin-bottom: 28px !important;
}

.win-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 24px;
}

.win-stat { display: flex; flex-direction: column; align-items: center; }
.win-stat-value {
    font-size: 1.8em;
    font-weight: 800;
    color: var(--clr-accent);
}
.win-stat-label {
    font-size: .7em;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255,255,255,.4);
    margin-top: 2px;
}

.new-best {
    font-size: 1.1em;
    font-weight: 700;
    color: #a78bfa;
    margin-bottom: 24px;
    animation: bestPulse 1.2s ease infinite;
}
.new-best.hidden { display: none; }
@keyframes bestPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .7; transform: scale(1.08); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes winSlide {
    from { transform: translateY(40px) scale(.9); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

#confettiCanvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1001;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
    :root {
        --card-w: 82px;
        --card-h: 116px;
        --pile-gap: 12px;
        --tableau-offset: 24px;
    }
    .game-board { padding: 20px 16px; }
}

@media (max-width: 800px) {
    :root {
        --card-w: 62px;
        --card-h: 88px;
        --pile-gap: 8px;
        --tableau-offset: 20px;
        --card-radius: 7px;
    }
    body { padding: 8px; }
    header {
        flex-direction: column;
        text-align: center;
        padding: 12px 16px;
        gap: 8px;
    }
    .controls { justify-content: center; }
    .stats-bar { align-self: stretch; justify-content: center; }
    .game-board { padding: 14px 8px; border-radius: 14px; }
    .top-section { flex-direction: column; align-items: center; }
    .stock-section, .foundation-section { justify-content: center; }
    .card { font-size: .8em; padding: 4px 6px; }
    h1 { font-size: 1.2em; }
    .btn { padding: 7px 14px; font-size: .8em; }
}

@media (max-width: 520px) {
    :root {
        --card-w: 46px;
        --card-h: 66px;
        --pile-gap: 5px;
        --tableau-offset: 16px;
        --card-radius: 5px;
    }
    .card { font-size: .65em; padding: 3px 4px; }
    .foundation-pile::before { font-size: 1.6em; }
    .card.face-down::after { font-size: 1.2em; }
    .stock-counter { font-size: .55em; bottom: -18px; }
    .stats-bar { gap: 2px; }
    .stat { padding: 4px 10px; }
}
