/* =============================================================================
   PASJANS / KLONDIKE SOLITAIRE — game-specific styles.
   Shared section chrome lives in games.css; site tokens come from style.css.
   Board is a neutral gray (site look), suits use site red / near-black.
   Card size is computed by JS into --pj-card-w / --pj-card-h on .pj-board.
   ============================================================================= */

.pj-board {
    --pj-card-w: 80px;
    --pj-card-h: 116px;
    background: var(--color-gray-100);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

/* ---------------- Top row: stock, waste, foundations ---------------- */

.pj-top {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.pj-top-spacer {
    flex-grow: 1;
}

.pj-foundations {
    display: flex;
    gap: 0.6rem;
}

.pj-slot {
    position: relative;
    width: var(--pj-card-w);
    height: var(--pj-card-h);
    border: 2px dashed var(--color-gray-300);
    border-radius: var(--border-radius-sm);
    background: transparent;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.pj-slot-suit {
    font-size: calc(var(--pj-card-w) * 0.45);
    opacity: 0.35;
    line-height: 1;
}

/* Stock is a real button */
.pj-stock {
    cursor: pointer;
    font-family: var(--font-family);
}

.pj-stock.pj-has-cards {
    border-style: solid;
    border-color: var(--color-gray-300);
}

.pj-stock[disabled] {
    cursor: default;
    opacity: 0.6;
}

.pj-stock .pj-stock-back {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.pj-stock-count {
    position: absolute;
    bottom: 4px;
    right: 5px;
    z-index: 2;
    background: var(--color-white);
    color: var(--color-gray-700);
    border-radius: var(--border-radius-full, 999px);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    box-shadow: var(--shadow-sm);
    pointer-events: none;
}

.pj-recycle-icon {
    font-size: calc(var(--pj-card-w) * 0.5);
    color: var(--color-gray-500);
    line-height: 1;
}

.pj-stock.pj-recycle:hover .pj-recycle-icon,
.pj-stock.pj-recycle:focus-visible .pj-recycle-icon {
    color: var(--color-primary);
}

/* Waste: fanned cards positioned by JS (style.left) */
.pj-waste {
    border: none;
    justify-content: flex-start;
    min-width: var(--pj-card-w);
}

.pj-waste .pj-card {
    position: absolute;
    top: 0;
}

/* Foundation shows its top card filling the slot */
.pj-foundation .pj-card {
    position: absolute;
    inset: -2px;
    width: var(--pj-card-w);
    height: var(--pj-card-h);
}

/* ---------------- Tableau ---------------- */

.pj-tableau {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
}

.pj-pile {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: var(--pj-card-h);
    border-radius: var(--border-radius-sm);
}

/* Empty pile shows a drop outline */
.pj-pile:empty {
    border: 2px dashed var(--color-gray-300);
}

.pj-pile .pj-card {
    position: absolute;
    left: 0;
    right: 0;
}

/* ---------------- Cards ---------------- */

.pj-card {
    display: block;
    box-sizing: border-box;
    width: var(--pj-card-w);
    height: var(--pj-card-h);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-gray-300);
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    padding: 0;
    margin: 0;
    font-family: var(--font-family);
    line-height: 1;
    touch-action: none;
}

.pj-card.pj-up {
    cursor: pointer;
}

.pj-card.pj-up:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 1px;
    z-index: 3;
}

.pj-red   { color: var(--color-primary); }
.pj-black { color: var(--color-gray-900); }

.pj-corner {
    position: absolute;
    top: 3px;
    left: 5px;
    font-size: clamp(0.72rem, calc(var(--pj-card-w) * 0.24), 1.25rem);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 1px;
}

.pj-corner i {
    font-style: normal;
}

.pj-corner--br {
    top: auto;
    left: auto;
    bottom: 3px;
    right: 5px;
    transform: rotate(180deg);
}

.pj-center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--pj-card-w) * 0.55);
    opacity: 0.9;
    pointer-events: none;
}

/* Face-down back: site-red with a simple woven pattern (pure CSS) */
.pj-card.pj-down {
    background:
        repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.16) 0 4px,
            transparent 4px 9px),
        repeating-linear-gradient(-45deg,
            rgba(255, 255, 255, 0.16) 0 4px,
            transparent 4px 9px),
        var(--color-primary);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm), inset 0 0 0 3px rgba(255, 255, 255, 0.35);
}

/* Inert copies (drag layer, waste fan, foundation top) don't take input */
.pj-inert {
    pointer-events: none;
}

/* Source cards while their run is being dragged */
.pj-drag-src {
    opacity: 0.35;
}

/* ---------------- Drag layer ---------------- */

.pj-drag-layer {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    pointer-events: none;
    will-change: transform;
}

.pj-drag-layer .pj-card {
    position: absolute;
    left: 0;
    box-shadow: var(--shadow-md);
}

.pj-drag-return {
    transition: transform 0.2s ease;
}

/* ---------------- Feedback ---------------- */

.pj-flash {
    animation: pj-flash-anim 0.45s ease;
}

@keyframes pj-flash-anim {
    0%   { box-shadow: 0 0 0 4px var(--color-success); }
    100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}

.pj-deny {
    animation: pj-deny-anim 0.35s ease;
}

@keyframes pj-deny-anim {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-5px); }
    75%      { transform: translateX(5px); }
}

/* ---------------- Toolbar extras / stats modal ---------------- */

.pj-auto-btn {
    margin-left: auto;
}

.pj-best-title {
    margin-top: 1rem;
    font-weight: 700;
    color: var(--color-gray-900);
    font-size: 0.95rem;
}

.pj-best-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    color: var(--color-gray-600);
    font-size: 0.92rem;
}

.pj-best-list li {
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--color-gray-200);
}

.pj-best-list li:last-child {
    border-bottom: none;
}

/* ---------------- Screen-reader live region ---------------- */

.pj-sr-live {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------- Motion & responsive ---------------- */

@media (prefers-reduced-motion: reduce) {
    .pj-drag-return { transition: none; }
    .pj-flash,
    .pj-deny { animation: none; }
}

@media (max-width: 600px) {
    .pj-board {
        padding: 0.4rem;
    }

    .pj-top,
    .pj-tableau,
    .pj-foundations {
        gap: 0.25rem;
    }

    .pj-top {
        margin-bottom: 0.6rem;
    }

    .pj-slot {
        border-width: 1px;
    }

    .pj-corner {
        top: 2px;
        left: 3px;
    }

    .pj-corner--br {
        display: none;
    }

    .pj-stock-count {
        bottom: 2px;
        right: 2px;
        font-size: 0.62rem;
        padding: 0.05rem 0.3rem;
    }
}
