/* Spider Solitaire — original card styling (CSS only) */
#spiderGame {
    --sp-cw: 60px;
    --sp-ch: 84px;
    --sp-gap: 6px;
    --sp-fs: 16px;
    --sp-big: 28px;
    --sp-felt1: #1f6b4f;
    --sp-felt2: #134733;
    --sp-face: #fffdf8;
    --sp-edge: rgba(0, 0, 0, .28);
    --sp-black: #1d2329;
    --sp-red: #c62828;
    --sp-green: #1b7a3a;
    --sp-blue: #1b4fa8;
    --sp-back1: #052c65;
    --sp-back2: #0b4596;
    --sp-hint: #ffc107;
}

[data-bs-theme="dark"] #spiderGame {
    --sp-felt1: #164a38;
    --sp-felt2: #0b2a1f;
    --sp-face: #eceae4;
    --sp-edge: rgba(0, 0, 0, .55);
    --sp-red: #b71c1c;
}

.sp-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding-left: .35rem;
    padding-right: .35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .9rem;
}

.sp-actions #spFsBtn { flex: 0 0 auto; }

.sp-hud {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    text-align: center;
}

.sp-hud > div {
    background: var(--bs-tertiary-bg, #f8f9fa);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px;
    padding: 4px 2px;
    line-height: 1.15;
}

.sp-hud-l {
    display: block;
    font-size: .72rem;
    color: var(--bs-secondary-color, #6c757d);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-hud-v {
    display: block;
    font-weight: 700;
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- board */
.sp-board {
    position: relative;
    background: radial-gradient(ellipse at 50% 0%, var(--sp-felt1), var(--sp-felt2));
    border-radius: 12px;
    padding: 10px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overflow: hidden;
    max-width: 100%;
}

.sp-top,
.sp-tableau {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    column-gap: var(--sp-gap);
}

.sp-top { margin-bottom: calc(var(--sp-gap) + 6px); }

.sp-slot {
    position: relative;
    height: var(--sp-ch);
    border-radius: calc(var(--sp-cw) * .1);
    border: 1px dashed rgba(255, 255, 255, .25);
}

.sp-slot-gap { border: 0; }

.sp-slot .sp-card { top: 0; }

.sp-stock {
    cursor: pointer;
    border: 0;
    outline: none;
}

.sp-stock:focus-visible { box-shadow: 0 0 0 3px var(--sp-hint); }

.sp-stock-empty {
    cursor: default;
    border: 1px dashed rgba(255, 255, 255, .25);
}

.sp-badge {
    position: absolute;
    right: -4px;
    bottom: -6px;
    min-width: 1.4em;
    padding: 1px 4px;
    border-radius: 10px;
    background: #fff;
    color: #052c65;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
    z-index: 30;
}

.sp-col {
    position: relative;
    min-height: var(--sp-ch);
    border-radius: calc(var(--sp-cw) * .1);
}

.sp-col.sp-empty { outline: 1px dashed rgba(255, 255, 255, .3); outline-offset: -1px; height: var(--sp-ch); }

.sp-col.sp-target { box-shadow: 0 0 0 3px rgba(255, 255, 255, .55); }

.sp-col.sp-flash { animation: sp-flash .5s 2; }

@keyframes sp-flash {
    50% { background: rgba(255, 80, 80, .45); }
}

/* ---------------------------------------------------------------- cards */
.sp-card {
    position: absolute;
    left: 0;
    width: var(--sp-cw);
    height: var(--sp-ch);
    border-radius: calc(var(--sp-cw) * .09);
    box-shadow: 0 1px 2px var(--sp-edge), 0 0 0 1px var(--sp-edge);
    box-sizing: border-box;
    font-family: Georgia, "Times New Roman", serif;
}

.sp-up {
    background: var(--sp-face);
    color: var(--sp-black);
}

.sp-s1, .sp-s2 { color: var(--sp-red); }

.sp-4color .sp-s3 { color: var(--sp-green); }
.sp-4color .sp-s2 { color: var(--sp-blue); }

.sp-down {
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .13) 0 3px, transparent 3px 7px),
        repeating-linear-gradient(-45deg, rgba(255, 255, 255, .13) 0 3px, transparent 3px 7px),
        linear-gradient(160deg, var(--sp-back2), var(--sp-back1));
    border: 2px solid #f4f1ea;
}

[data-bs-theme="dark"] .sp-down { border-color: #b9c3d1; }

.sp-cn {
    position: absolute;
    top: 1px;
    left: 3px;
    font-size: var(--sp-fs);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -.04em;
    white-space: nowrap;
}

.sp-cn i {
    font-style: normal;
    margin-left: 1px;
}

.sp-br {
    font-size: calc(var(--sp-fs) * .85);
    top: auto;
    left: auto;
    right: 3px;
    bottom: 2px;
    transform: rotate(180deg);
}

.sp-mid {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-38%);
    text-align: center;
    font-size: var(--sp-big);
    line-height: 1;
}

.sp-court {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-weight: 700;
    transform: translateY(-42%);
}

.sp-court span {
    display: inline-block;
    border: 2px solid currentColor;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: calc(var(--sp-big) * .68);
}

.sp-court small { font-size: calc(var(--sp-big) * .55); margin-top: 2px; }

/* narrow phone cards: one corner index + smaller center */
.sp-narrow .sp-cn { left: 2px; }
.sp-narrow .sp-br { display: none; }
.sp-narrow .sp-mid { transform: translateY(-20%); }
.sp-narrow .sp-court span { border-width: 1px; padding: 0 2px; border-radius: 3px; }
.sp-narrow .sp-court small { display: none; }
.sp-narrow .sp-down { border-width: 1px; }

.sp-mv { cursor: grab; touch-action: none; }

.sp-hide { visibility: hidden; }

.sp-ghost {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sp-cw);
    z-index: 2000;
    pointer-events: none;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .35));
}

.sp-ghost .sp-card { cursor: grabbing; }

.sp-hint-src { box-shadow: 0 0 0 3px var(--sp-hint), 0 0 12px var(--sp-hint); z-index: 5; }
.sp-hint-dst { box-shadow: 0 0 0 3px var(--sp-hint), 0 0 14px var(--sp-hint); border-radius: calc(var(--sp-cw) * .1); }

/* ------------------------------------------------------------ animations */
.sp-dealt { animation: sp-deal .28s ease-out both; }

@keyframes sp-deal {
    from { opacity: 0; transform: translateY(-40px) scale(.9); }
    to { opacity: 1; transform: none; }
}

.sp-moved { animation: sp-moved .16s ease-out; }

@keyframes sp-moved {
    from { transform: scale(1.05); }
    to { transform: none; }
}

.sp-flip { animation: sp-flip .3s ease-out; }

@keyframes sp-flip {
    from { transform: rotateY(90deg); }
    to { transform: none; }
}

.sp-pop { animation: sp-pop .5s ease-out; }

@keyframes sp-pop {
    0% { transform: scale(.4); opacity: 0; }
    70% { transform: scale(1.12); opacity: 1; }
    100% { transform: none; }
}

.sp-shake { animation: sp-shake .3s; }

@keyframes sp-shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
    .sp-dealt, .sp-moved, .sp-flip, .sp-pop, .sp-shake, .sp-col.sp-flash { animation: none; }
}

/* ------------------------------------------------------------------ win */
.sp-win {
    position: absolute;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    overflow: hidden;
}

.sp-fly { top: 0; left: 0; }

.sp-win-box {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, .95);
    color: #052c65;
    border-radius: 12px;
    padding: 14px 20px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
    pointer-events: auto;
    z-index: 2;
    width: max-content;
    max-width: 92%;
    animation: sp-fade .6s ease-out;
}

@keyframes sp-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

[data-bs-theme="dark"] .sp-win-box { background: rgba(33, 37, 41, .96); color: #e9ecef; }

.sp-win-title { font-size: 1.5rem; font-weight: 800; }
.sp-win-line { font-size: .9rem; }
.sp-win-best { color: #b8860b; font-weight: 700; margin-top: 2px; }

.sp-status { min-height: 1.3em; color: var(--bs-secondary-color, #6c757d); }

.sp-check { cursor: pointer; display: inline-flex; align-items: center; }

.sp-stats td:first-child { text-align: left; white-space: nowrap; }

/* ----------------------------------------------------------- fullscreen */
#spiderGame.sp-fs {
    position: fixed;
    inset: 0;
    z-index: 1080;
    overflow: auto;
    padding: 8px;
    background: var(--bs-body-bg, #fff);
}

#spiderGame:fullscreen { background: var(--bs-body-bg, #fff); padding: 8px; overflow: auto; }

#spiderGame.sp-fs .sp-controls,
#spiderGame:fullscreen .sp-controls { margin-bottom: .5rem !important; }

#spiderGame.sp-fs .sp-controls .card-body { padding: .5rem; }

html.sp-fs-page, html.sp-fs-page body { overflow: hidden !important; }

@media (max-width: 575.98px) {
    .sp-board { padding: 6px 4px; border-radius: 8px; }
    .sp-actions .btn { font-size: .8rem; padding-left: .2rem; padding-right: .2rem; }
    .sp-actions .btn:not(#spFsBtn) img, .sp-deal-c { display: none; }
    .sp-hud-v { font-size: .95rem; }
    .sp-badge { font-size: 10px; right: -2px; }
}
