/* ----------------------------------------------------------------------------------------------- */
/* Game widget: toolbar, felt table, cards, status bar, win dialog. Loaded on game pages only.        */
/* ----------------------------------------------------------------------------------------------- */

/* Toolbar: flat buttons that light up like the toolbar of a Windows 9x program. */

.game {
    -webkit-user-select: none;
    user-select: none;
}

.game__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 10px;
    padding: 4px 1px;
}

.game__modes,
.game__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.btn--tool {
    min-block-size: 24px;
    padding: 2px 8px;
    background: none;
    border-color: transparent;
    box-shadow: none;
    font-size: 12px;
}

.btn--tool:not([aria-current="page"]):not(:active):hover {
    background: var(--c-silver-light);
    border-color: var(--bevel-out-border);
    box-shadow: var(--bevel-out-inner);
}

.btn--tool[aria-current="page"] {
    font-weight: bold;
}

/* Table */

.game__frame {
    border: 2px solid;
    border-color: var(--bevel-in-border);
    background: var(--c-felt);
}

.game__table {
    --cw: 71px;
    --ch: 96px;

    position: relative;
    block-size: clamp(380px, 68vh, 640px);
    overflow: hidden;
    background: var(--c-felt);
    touch-action: pan-y; /* the felt between the cards still scrolls the page */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.game__nojs {
    margin: 0;
    padding: 24px;
    color: var(--c-white);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    text-shadow: 1px 1px 0 var(--c-black);
}

.card-sprite {
    position: absolute;
    inline-size: 0;
    block-size: 0;
    overflow: hidden;
}

/* Empty piles: a faint card-shaped hollow. The deck's place is a ring, as in the original game. */

.slot {
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 0;
    z-index: 0;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.5);
    background: rgba(0, 0, 0, 0.12);
    box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.14);
}

.slot--stock {
    appearance: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
}

.slot--stock:not(:disabled) {
    background: radial-gradient(circle, transparent 0 71%, rgba(0, 0, 0, 0.45) 72% 84%, transparent 85%);
    cursor: pointer;
}

/* Cards: a positioned box around an <svg><use> that points at its face in the sprite. */

.card {
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 0;
    inline-size: var(--cw);
    block-size: var(--ch);
    border-radius: calc(var(--cw) * 0.049);
    box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.42);
    transition: transform 260ms ease-out;
    touch-action: none; /* a finger on a card drags it; scrolling starts from the felt */
    -webkit-tap-highlight-color: transparent;
}

.card__face {
    display: block;
    inline-size: 100%;
    block-size: 100%;
}

.card[aria-disabled="false"] {
    cursor: pointer;
}

.card:focus-visible {
    outline: 2px solid #ff0;
    outline-offset: 2px;
}

.card--dragging {
    transition: none;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
    cursor: grabbing;
}

.game__table--instant .card {
    transition: none;
}

@keyframes card-flip {
    from {
        transform: scaleX(0.1);
    }

    to {
        transform: scaleX(1);
    }
}

.card--flip .card__face {
    animation: card-flip 340ms ease-out;
}

@keyframes card-shake {
    0%,
    100% {
        translate: 0 0;
    }

    25% {
        translate: -3px 0;
    }

    75% {
        translate: 3px 0;
    }
}

.card--shake {
    animation: card-shake 180ms ease-in-out 2;
}

@keyframes hint-pulse {
    from {
        outline-color: #ff0;
    }

    to {
        outline-color: #fff;
    }
}

.card.is-hinted,
.card.is-hinted-target {
    outline: 2px solid #ff0;
    outline-offset: 2px;
    animation: hint-pulse 600ms ease-in-out 4 alternate;
}

.slot.is-hinted,
.slot.is-hinted-target {
    border-radius: 6px;
    outline: 2px dashed #ff0;
    outline-offset: 3px;
    animation: hint-pulse 600ms ease-in-out 4 alternate;
}

/* The win animation paints over the table. */

.game-canvas {
    position: absolute;
    inset: 0;
    z-index: 5000;
    inline-size: 100%;
    block-size: 100%;
    cursor: pointer;
}

/* Status bar */

.game__status {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-block-start: 4px;
    font: 12px/1.3 var(--font-ui);
}

.game__cell {
    padding: 2px 7px;
    border: 1px solid;
    border-color: var(--bevel-in-border);
    background: var(--c-silver);
    white-space: nowrap;
}

.game__cell b {
    color: var(--c-navy);
}

.game__cell--last {
    flex: 1 1 0;
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game__cell.is-flash {
    color: var(--c-navy);
    font-weight: bold;
}

/* Retro dialog (a window that happens to be modal). */

.game-dialog {
    inline-size: min(26rem, calc(100vw - 32px));
    margin: auto;
    color: var(--c-black);
}

.game-dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.game-dialog__body {
    margin-block-start: 3px;
    padding: 14px 12px 4px;
    font-size: 13px;
    line-height: 1.5;
}

.game-dialog__body p {
    margin: 0;
}

.game-dialog__stats {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 18px;
    margin: 0;
}

.game-dialog__stats div {
    display: contents;
}

.game-dialog__stats dt {
    color: var(--c-muted);
}

.game-dialog__stats dd {
    margin: 0;
    color: var(--c-navy);
    font-weight: bold;
}

.game-dialog__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 12px 12px 10px;
}

/* Whole screen: the Fullscreen API, or an overlay where the browser has none (iPhone Safari). */

.game.is-expanded,
.game:fullscreen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.game.is-expanded .game__frame,
.game:fullscreen .game__frame {
    display: flex;
    flex: 1;
    min-block-size: 0;
}

.game.is-expanded .game__table,
.game:fullscreen .game__table {
    flex: 1;
    block-size: auto;
}

html.is-game-expanded,
html.is-game-expanded body {
    overflow: hidden;
}

/* Touch screens: larger buttons come from style.css, the toolbar only needs to wrap neatly. */

@media (pointer: coarse) {
    .btn--tool {
        min-block-size: 36px;
        padding: 6px 12px;
        font-size: 13px;
    }
}

@media (max-width: 640px) {
    .game__modes {
        inline-size: 100%;
    }

    .game__toolbar {
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .card {
        transition: none;
    }

    .card--flip .card__face,
    .card--shake,
    .card.is-hinted,
    .card.is-hinted-target,
    .slot.is-hinted,
    .slot.is-hinted-target {
        animation: none;
    }
}

@media print {
    .game__toolbar,
    .game__frame,
    .game__status {
        display: none !important;
    }
}
