:root {
    --felt-deep: #0f4f30;
    --felt-mid: #1f754a;
    --felt-light: #3b9966;
    --gold-bright: #e3c877;
    --gold-mid: #c7a74b;
    --gold-shadow: #84651f;
    --ivory: #f6edd7;
    --ink: #1f1a14;
    --wine: #8a2134;
    --charcoal: #1f2530;
    --art-dionysus: url("resources/dionysus.jpg");
    --art-laurel: url("resources/laurel.webp");
    --art-temple: url("resources/temple_gold.jpg");
    --art-nymph-blonde: url("resources/nymph_blonde.jpg");
    --art-nymph-brunette: url("resources/nymph_brunette.jpg");
    --art-coin: url("resources/coin.webp");
    --art-temple-with-coin: url("resources/temple_with_coin.jpg");
    /* Height over width of temple_gold.jpg; the masks size their fade to it. */
    --temple-ratio: calc(661 / 533);

    --slate-light: #5c6a60;
    --slate-mid: #3c453e;
    --slate-deep: #232824;

    /* feTurbulence grain as a matched light+dark pair, in sRGB space so
       the matrix math matches the rendered pixels: each rect's alpha is
       the noise's deviation from a fixed threshold, clamped to zero on one
       side, so the texture adds variance on both a light face and a dark
       back without dragging either surface's mean luminance up or down.
       Darkening has less headroom on a dark back than lightening has on a
       light face, so the dark gain (0.225) outweighs the light gain (0.10)
       to net near zero on both. The gains hold alpha to the settled 6%
       ceiling, bar a stray tile pixel, which keeps the grain felt and never
       seen as a pattern. */
    --grain-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cfilter id='w' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0.10 0 0 -0.0419'/%3E%3C/filter%3E%3Cfilter id='b' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.225 0 0 0.0943'/%3E%3C/filter%3E%3Crect width='24' height='24' filter='url(%23w)'/%3E%3Crect width='24' height='24' filter='url(%23b)'/%3E%3C/svg%3E");
    --grain-size: 12px 12px;

    /* Nine-slice meander tile: four corner turns plus one repeat unit per
       edge, so border-image tiles a genuine key pattern, not a stretch. */
    --meander-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3E%3Cg fill='none' stroke='%23e3c877' stroke-width='2' stroke-linecap='square' stroke-linejoin='miter'%3E%3Cpath transform='translate(0,0)' d='M10,7 H7 V3 H3 V10'/%3E%3Cpath transform='translate(10,0)' d='M-1,7 H3 V3 H7 V7 H11'/%3E%3Cpath transform='translate(20,0)' d='M0,7 H3 V3 H7 V10'/%3E%3Cpath transform='translate(0,10)' d='M3,-1 V3 H7 V7 H3 V11'/%3E%3Cpath transform='translate(20,10)' d='M7,-1 V3 H3 V7 H7 V11'/%3E%3Cpath transform='translate(0,20)' d='M3,0 V3 H7 V7 H10'/%3E%3Cpath transform='translate(10,20)' d='M-1,7 H3 V3 H7 V7 H11'/%3E%3Cpath transform='translate(20,20)' d='M7,0 V3 H3 V7 H0'/%3E%3C/g%3E%3C/svg%3E");

    --body-pad: clamp(8px, 2vw, 24px);
    --shell-pad: clamp(10px, 1.6vw, 22px);
    --shell-border: 2px;
    --pile-gap: clamp(6px, 1vw, 14px);

    /* Seven columns plus gaps must fit the shell's content box down to a
       360px viewport; the fit formula floors at 38px and caps at 102px. */
    --card-w: clamp(
        38px,
        calc(
            (
                    100vw - (var(--body-pad) * 2) - (var(--shell-border) * 2) -
                        (var(--shell-pad) * 2) - (var(--pile-gap) * 6)
                ) / 7
        ),
        102px
    );
    --card-h: calc(var(--card-w) * 1.42);

    --corner-gap: clamp(4px, calc(var(--card-w) * 0.06), 8px);
    --corner-font: clamp(12px, calc(var(--card-w) * 0.16), 17px);
    --corner-line: calc(var(--corner-font) * 1.2);
    /* The face-up fan step must clear the corner's own height so a fanned
       card never hides the rank/suit of the card beneath it. */
    --fan-up: max(calc(var(--card-h) * 0.2), calc(var(--corner-gap) + var(--corner-line)));
    --fan-down: calc(var(--card-h) * 0.09);

    /* Band plus inset must clear --fan-down (0.1278 * card-w) at its own
       worst case (ink at the band's outer edge) or a fanned-down back
       shows no gold at all, or a sliver too thin to read as one. */
    --meander-w: clamp(2px, calc(var(--card-w) * 0.065), 7px);
    --meander-inset: clamp(1px, calc(var(--card-w) * 0.025), 3px);

    font-family: "Palatino Linotype", "Book Antiqua", Palatino, Garamond, serif;
}

* {
    box-sizing: border-box;
}

html {
    touch-action: manipulation;
}

body {
    margin: 0;
    min-height: 100dvh;
    padding: calc(var(--body-pad) + env(safe-area-inset-top))
        calc(var(--body-pad) + env(safe-area-inset-right))
        calc(var(--body-pad) + env(safe-area-inset-bottom))
        calc(var(--body-pad) + env(safe-area-inset-left));
    color: #f9f3df;
    background:
        radial-gradient(circle at 18% 14%, rgba(236, 217, 155, 0.2), transparent 40%),
        radial-gradient(circle at 82% 86%, rgba(236, 217, 155, 0.14), transparent 44%),
        linear-gradient(135deg, #173522 0%, #203d2e 35%, #102219 100%);
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(25deg, rgba(255, 255, 255, 0.03) 8%, transparent 8%),
        linear-gradient(-25deg, rgba(255, 255, 255, 0.03) 8%, transparent 8%);
    background-size: 34px 34px;
    opacity: 0.45;
}

.app-shell {
    width: min(1240px, 100%);
    border-radius: 24px;
    border: var(--shell-border) solid rgba(227, 200, 119, 0.65);
    background:
        radial-gradient(circle at 50% -20%, rgba(255, 255, 255, 0.18), transparent 60%),
        radial-gradient(circle at 45% 18%, var(--felt-light), var(--felt-mid) 48%, var(--felt-deep) 100%);
    box-shadow:
        0 30px 50px rgba(0, 0, 0, 0.35),
        inset 0 0 0 2px rgba(46, 105, 68, 0.75),
        inset 0 0 26px rgba(0, 0, 0, 0.25);
    padding: var(--shell-pad);
    position: relative;
    overflow: hidden;
}

.app-shell::before {
    content: "";
    position: absolute;
    inset: 8px;
    border: 1px solid rgba(227, 200, 119, 0.32);
    border-radius: 18px;
    pointer-events: none;
}

.app-shell::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(circle at 8% 10%, rgba(222, 209, 142, 0.2), transparent 18%),
        radial-gradient(circle at 93% 12%, rgba(222, 209, 142, 0.2), transparent 16%),
        radial-gradient(circle at 6% 90%, rgba(222, 209, 142, 0.18), transparent 16%),
        radial-gradient(circle at 94% 90%, rgba(222, 209, 142, 0.18), transparent 16%);
}

.felt-art {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    /* Query-container so ::after's mask-size can derive its height from
       cqw: a mask-image gradient has no intrinsic ratio, so a plain
       percentage height falls back to the full box instead of the
       painting's own aspect ratio, leaving the fade short of the edge. */
    container-type: inline-size;
    background-image:
        radial-gradient(circle at 35% 12%, rgba(255, 245, 203, 0.14), transparent 28%),
        var(--art-laurel);
    background-size: auto, 34% auto;
    background-position: center top, 2% 42%;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.35s ease;
}

/* mask-image tracks each selector's own background-image/-size/-position
   (full-bleed on .felt-art::after, a side band on .top-board::after) so
   the temple fades at the painting's edges, not the box's. */
.felt-art::after,
.top-board::after {
    content: "";
    position: absolute;
    z-index: 0;
    pointer-events: none;
    background-image: var(--art-temple);
    background-repeat: no-repeat;
    mask-image: radial-gradient(ellipse farthest-side at center, black 45%, transparent 100%);
    mask-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.35s ease;
}

.felt-art::after {
    inset: 0;
    /* One width drives both sizes so the fade cannot drift from the art. The
       mask height is in cqw, not %, to follow the image's real aspect ratio
       instead of the oversized fallback box. */
    --temple-width: 34cqw;
    background-size: var(--temple-width) auto;
    background-position: 98% 42%;
    mask-size: var(--temple-width) calc(var(--temple-width) * var(--temple-ratio));
    mask-position: 98% 42%;
}

.art-dionysus {
    background-image: var(--art-dionysus);
}

.art-laurel {
    background-image: var(--art-laurel);
}

.art-temple {
    background-image: var(--art-temple);
}

.art-temple-with-coin {
    background-image: var(--art-temple-with-coin);
}

.art-nymph-blonde {
    background-image: var(--art-nymph-blonde);
}

.art-nymph-brunette {
    background-image: var(--art-nymph-brunette);
}

.host-nymphs {
    position: absolute;
    inset: 8px 10px auto;
    height: clamp(96px, 16vw, 190px);
    pointer-events: none;
    z-index: 1;
}

.host-nymph {
    position: absolute;
    top: 0;
    width: clamp(68px, 11vw, 132px);
    border-radius: 16px;
    background-size: cover;
    background-position: center top;
    border: 1px solid rgba(229, 194, 104, 0.52);
    box-shadow:
        0 8px 14px rgba(0, 0, 0, 0.3),
        inset 0 0 0 1px rgba(247, 229, 180, 0.26);
    filter: saturate(1.06) contrast(1.04);
}

.host-nymph.left {
    left: 0;
    aspect-ratio: 480 / 804;
}

.host-nymph.right {
    right: 0;
    aspect-ratio: 502 / 680;
}

.thunder-ended {
    box-shadow:
        0 30px 50px rgba(0, 0, 0, 0.35),
        inset 0 0 0 2px rgba(74, 105, 130, 0.72),
        inset 0 0 26px rgba(0, 0, 0, 0.32);
}

.thunder-ended .status-text {
    background: rgba(28, 36, 54, 0.7);
    border-color: rgba(154, 182, 224, 0.48);
}

.gold-ended .status-text {
    background: rgba(63, 22, 22, 0.74);
    border-color: rgba(214, 132, 109, 0.6);
}

.victory-ended {
    box-shadow:
        0 30px 50px rgba(0, 0, 0, 0.35),
        inset 0 0 0 2px rgba(228, 189, 83, 0.8),
        inset 0 0 30px rgba(192, 142, 27, 0.32);
}

.victory-ended .status-text {
    background: rgba(69, 44, 7, 0.72);
    border-color: rgba(236, 202, 118, 0.62);
}

.ended .felt-art,
.ended .felt-art::after {
    opacity: 0.54;
}

.lost .felt-art,
.lost .felt-art::after {
    opacity: 0.12;
}

.lost .tableau-scroll,
.lost .top-board,
.lost .status-row {
    filter: grayscale(0.55) brightness(0.82);
    transition: filter 0.4s ease;
}

.victory-temple {
    position: absolute;
    left: 50%;
    top: 50%;
    width: clamp(132px, 20vw, 250px);
    aspect-ratio: 499 / 679;
    border-radius: 20px;
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(235, 201, 110, 0.75);
    box-shadow:
        0 14px 24px rgba(0, 0, 0, 0.34),
        inset 0 0 0 2px rgba(251, 235, 182, 0.28);
    opacity: 0;
    transform: translate(-50%, -50%) translateY(18px) scale(0.92);
    pointer-events: none;
    /* Above the flight layer (z-index: 2): the victory art always wins the
       stack once the game has ended. */
    z-index: 3;
}

.victory-ended .victory-temple {
    opacity: 0.9;
    animation: temple-float 3.6s ease-in-out infinite;
}

@keyframes temple-float {
    0% {
        transform: translate(-50%, -50%) translateY(8px) scale(0.95);
    }
    50% {
        transform: translate(-50%, -50%) translateY(-10px) scale(1);
    }
    100% {
        transform: translate(-50%, -50%) translateY(8px) scale(0.95);
    }
}

.victory-coins {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 3;
}

.victory-coin {
    position: absolute;
    top: -18%;
    left: calc((var(--coin-index) * 7%) - 8%);
    width: clamp(28px, 3.4vw, 44px);
    aspect-ratio: 1;
    background-image: var(--art-coin);
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    filter: saturate(1.2) contrast(1.1) drop-shadow(2px 3px 3px rgba(0, 0, 0, 0.35));
    opacity: 0;
    will-change: transform, opacity;
    animation: coin-fall 1.8s linear infinite;
    animation-delay: calc(var(--coin-index) * 70ms);
}

@keyframes coin-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }
    12% {
        opacity: 0.95;
    }
    100% {
        transform: translateY(125vh) rotate(520deg);
        opacity: 0;
    }
}

.title-wrap,
.control-row,
.status-row,
.top-board,
.tableau-scroll,
.help-strip {
    position: relative;
    z-index: 1;
}

.title-wrap {
    text-align: center;
    margin-bottom: 10px;
    padding-inline: clamp(74px, 13vw, 170px);
}

.title-art {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.title-medallion {
    width: clamp(40px, 5vw, 58px);
    aspect-ratio: 1;
    border-radius: 999px;
    border: 1px solid rgba(223, 191, 103, 0.72);
    /* Longhand: the `background` shorthand would reset each medallion's
       own background-image rule (.art-laurel, .art-dionysus, .art-temple). */
    background-color: var(--ivory);
    background-size: cover;
    background-position: center;
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.3),
        inset 0 0 0 2px rgba(246, 223, 161, 0.35);
}

.title-wrap h1 {
    margin: 0;
    font-size: clamp(1.7rem, 2.4vw, 2.5rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #f8e8b8;
    text-shadow:
        0 2px 0 rgba(64, 43, 8, 0.75),
        0 12px 22px rgba(0, 0, 0, 0.28);
}

.title-wrap p {
    margin: 4px 0 0;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    color: rgba(251, 243, 222, 0.9);
    letter-spacing: 0.02em;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 12px 0;
}

.control-row button,
.pile-empty,
.card,
.stock-empty {
    font: inherit;
}

.control-row button {
    border: 1px solid rgba(227, 200, 119, 0.6);
    border-radius: 999px;
    padding: 8px 16px;
    color: var(--ivory);
    background: rgba(15, 79, 48, 0.4);
    font-variant: small-caps;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.help-toggle-btn {
    min-width: 118px;
}

.control-row button:not(:disabled):hover {
    background: rgba(31, 117, 74, 0.5);
    border-color: rgba(227, 200, 119, 0.85);
}

.control-row button:not(:disabled):active {
    background: rgba(15, 79, 48, 0.6);
}

.control-row button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    border-color: rgba(227, 200, 119, 0.3);
    color: rgba(246, 237, 215, 0.55);
}

@media (pointer: coarse) {
    .control-row button {
        min-height: 44px;
    }
}

.status-row {
    display: flex;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.status-pill {
    border-radius: 999px;
    padding: 6px 12px;
    background: rgba(23, 59, 38, 0.75);
    border: 1px solid rgba(233, 209, 129, 0.4);
    font-size: 0.9rem;
    letter-spacing: 0.04em;
}

.status-text {
    flex: 1;
    min-width: 240px;
    padding: 7px 12px;
    border-radius: 10px;
    background: rgba(16, 40, 27, 0.52);
    border: 1px solid rgba(233, 209, 129, 0.25);
    font-size: 0.92rem;
    line-height: 1.25;
}

/* Stock, waste, an empty column, then the four temples share the tableau's
   seven-column grid so the two rows align and both centre as one unit. */
.top-board {
    display: grid;
    grid-template-columns: repeat(7, var(--card-w));
    gap: var(--pile-gap);
    justify-content: center;
    align-items: start;
    /* Query-container so ::after's mask-size can derive its height from
       cqw, matching the temple painting's own aspect ratio. */
    container-type: inline-size;
}

.top-board::before,
.top-board::after {
    inset: -6px 0 auto;
    height: calc(var(--card-h) + 44px);
}

.top-board::before {
    content: "";
    position: absolute;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    background-image: var(--art-laurel);
    background-repeat: no-repeat;
    background-size: 20% auto;
    background-position: left center;
    transition: opacity 0.35s ease;
}

.top-board::after {
    --temple-width: 20cqw;
    background-size: var(--temple-width) auto;
    background-position: right center;
    /* min() caps the mask at the band height: past ~820px the painting is
       taller than the band, and an uncapped cqw height would push the
       fade past the clip edge into a hard line. */
    mask-size: var(--temple-width) min(calc(var(--temple-width) * var(--temple-ratio)), 100%);
    mask-position: right center;
}

.ended .top-board::before,
.ended .top-board::after {
    opacity: 0.22;
}

.top-board > * {
    position: relative;
    z-index: 1;
}

.pile-slot {
    width: var(--card-w);
}

/* Wraps a waste/foundation card with its underlay: the underlay sits
   absolutely beneath the real button, which stays in flow above it. */
.card-frame {
    position: relative;
}

/* Two classes each, to outrank `.card, .pile-empty { position: relative }`
   below regardless of source order: an underlay that stayed in flow would
   push the real button down by its own height instead of sitting beneath
   it. */
.card.pile-underlay,
.pile-empty.pile-underlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.pile-label {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(249, 243, 223, 0.86);
    margin-bottom: 4px;
    text-align: center;
}

.card,
.pile-empty {
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 12px;
    border: 1px solid rgba(73, 56, 27, 0.32);
    background: linear-gradient(165deg, #fff9e8 0%, var(--ivory) 62%, #e6dac1 100%);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2);
    padding: 0;
    position: relative;
    overflow: hidden;
}

.card {
    cursor: pointer;
    user-select: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

/* Only face-up cards can be dragged; html's document-wide
   touch-action: manipulation stays on .card.back so a swipe starting on a
   hidden or stock card still scrolls the page. */
.card.face {
    touch-action: none;
}

@media (hover: hover) {
    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 11px 18px rgba(0, 0, 0, 0.28);
    }
}

.card::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: var(--grain-image);
    background-size: var(--grain-size);
}

.card.selected,
.pile-empty.selected {
    border-color: rgba(73, 56, 27, 0.32);
}

.card.selected {
    transform: translateY(-2px);
    filter: brightness(1.07);
    box-shadow: 0 14px 20px rgba(0, 0, 0, 0.34);
}

.pile-empty.selected {
    filter: brightness(1.07);
    box-shadow: 0 11px 16px rgba(0, 0, 0, 0.28);
}

/* A card on a flight or lifted by a drag: opacity, not visibility or
   display, so it stays hit-testable and clickable mid-flight. `transform:
   none` (three classes, to outrank `.card:hover`/`.card.selected` regardless
   of source order) strips the hover/selected lift, so a flight measuring
   this card's slot reads its flat resting position, not one 2px off from
   that lift. `transition: none` makes that stripping instant: `.card`'s own
   transform transition would otherwise ease from the lift toward `none`,
   and a measurement taken a frame after the class changes would still
   catch it mid-ease — invisible either way, since this card is hidden. */
.card.face.away {
    opacity: 0;
    transform: none;
    transition: none;
}

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

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

.card.zeus-revealed {
    filter: saturate(0.72) brightness(0.9) contrast(0.95);
}

.card.face.zeus-revealed::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* Re-declares the grain layer here so the reveal wash, which replaces
       ::after's background outright, does not erase the paper texture. */
    background-image: linear-gradient(
            180deg,
            rgba(218, 223, 233, 0.14) 0%,
            rgba(116, 124, 140, 0.12) 100%
        ),
        var(--grain-image);
    background-size: auto, var(--grain-size);
}

.card.zeus-revealed.red {
    color: #7a3a45;
}

.card.zeus-revealed.black {
    color: #3f4652;
}

.card.zeus-revealed .motif {
    opacity: 0.78;
}

.card.zeus-revealed.red .center .motif {
    color: rgba(118, 48, 59, 0.88);
}

.card.zeus-revealed.black .center .motif {
    color: rgba(58, 65, 77, 0.88);
}

.card .corner {
    position: absolute;
    left: var(--corner-gap);
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 2px;
    line-height: 1;
    font-weight: 700;
}

.card .corner .rank,
.card .corner .suit {
    font-size: var(--corner-font);
}

.card .corner.top {
    top: var(--corner-gap);
}

.card .corner.bottom {
    bottom: var(--corner-gap);
    transform: rotate(180deg);
}

.card .center {
    position: absolute;
    inset: 26% 10% 26%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 2px;
    border-radius: 10px;
    overflow: hidden;
    isolation: isolate;
}

.card .center .center-art {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.34;
    filter: saturate(0.78) contrast(1.04);
    mix-blend-mode: multiply;
}

.card.court .center .center-art {
    opacity: 0.46;
    background-position: center 20%;
}

.card .center .glyph {
    font-size: 2rem;
    line-height: 1;
    position: relative;
    z-index: 1;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.card .center .motif {
    font-size: 0.58rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(30, 24, 16, 0.86);
    position: relative;
    z-index: 1;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.card.red .center .motif {
    color: rgba(114, 17, 36, 0.9);
}

.card.court .center .glyph {
    font-size: 1.72rem;
}

.card.court .center .motif {
    font-size: 0.65rem;
    letter-spacing: 0.14em;
}

.card.back {
    border-color: rgba(212, 179, 88, 0.7);
    color: #f1d891;
    background: linear-gradient(118deg, transparent 38%, rgba(255, 255, 255, 0.05) 41%, transparent 44%),
        linear-gradient(72deg, transparent 58%, rgba(232, 227, 212, 0.045) 61%, transparent 64%),
        linear-gradient(160deg, var(--slate-light) 0%, var(--slate-mid) 45%, var(--slate-deep) 100%);
}

.card.back::before {
    content: "";
    position: absolute;
    inset: var(--meander-inset);
    border-style: solid;
    border-width: var(--meander-w);
    /* Square meander turns nest inside the card's rounded outline on
       purpose: border-image ignores border-radius, so putting it on the
       card itself would square the back's corners next to round faces. */
    border-image: var(--meander-image) 10 round;
    pointer-events: none;
}

.back-medallion {
    position: absolute;
    inset: 24% 20%;
    background-image: var(--art-laurel);
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    /* Sepia plus a hue shift keeps the wreath's leaf shading, so the tint
       reads as gold foliage rather than flattening it into a disc. */
    filter: sepia(0.85) saturate(2.4) hue-rotate(-12deg) brightness(1.08) contrast(1.05);
    opacity: 0.92;
    pointer-events: none;
}

.pile-empty {
    border-style: dashed;
    border-color: rgba(220, 194, 117, 0.54);
    background: rgba(16, 52, 34, 0.35);
    color: rgba(249, 243, 223, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding-inline: 2px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: clamp(0.5rem, calc(var(--card-w) * 0.16), 0.76rem);
    text-align: center;
}

.pile-empty .tiny {
    font-size: clamp(0.42rem, calc(var(--card-w) * 0.11), 0.55rem);
    opacity: 0.9;
}

.stock-empty {
    background: rgba(22, 64, 42, 0.55);
}

.tableau-scroll {
    display: flex;
    justify-content: center;
    overflow-x: hidden;
    margin-top: 16px;
    padding-bottom: 8px;
}

.tableau-grid {
    display: grid;
    grid-template-columns: repeat(7, var(--card-w));
    gap: var(--pile-gap);
    flex: none;
}

.tableau-column {
    width: var(--card-w);
}

.tableau-pile {
    position: relative;
    width: var(--card-w);
    /* A pathological fanned column may exceed the viewport and scroll the
       page vertically rather than clip. */
    height: calc(
        var(--down-steps, 0) * var(--fan-down) + var(--up-steps, 0) * var(--fan-up) +
            var(--card-h)
    );
}

.tableau-pile.empty {
    border: 2px dashed rgba(220, 194, 117, 0.48);
    border-radius: 12px;
    background: rgba(16, 52, 34, 0.22);
}

.tableau-pile.empty::after {
    content: "KING";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.66rem;
    letter-spacing: 0.12em;
    color: rgba(246, 232, 191, 0.66);
}

.tableau-layer {
    position: absolute;
    left: 0;
    width: var(--card-w);
    top: calc(var(--down-steps, 0) * var(--fan-down) + var(--up-steps, 0) * var(--fan-up));
    /* Scope each layer's own stacking so a face-down card's medallion never
       paints above the face-up cards fanned on top of it. */
    isolation: isolate;
}

/* Restrained drop-target cue: a gold hairline, no glow or pulse, matching
   the felt-and-gold palette rather than the casino look Phase 1 removed. */
.tableau-pile.drop-target,
.pile-empty.drop-target,
.card.drop-target {
    outline: 2px solid rgba(227, 200, 119, 0.75);
    outline-offset: 3px;
}

/* The dragged run's ghost: one fixed layer outside .tableau-scroll so its
   overflow-x: hidden never clips it, following the pointer by transform
   alone so nothing else on the board reflows mid-drag. */
.drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--card-w);
    height: var(--card-h);
    pointer-events: none;
    z-index: 60;
}

.drag-overlay-card {
    position: absolute;
    inset: 0;
    /* Fans the run the same way the board does, via --fan-up. */
    top: calc(var(--fan-index, 0) * var(--fan-up));
    opacity: 0.94;
    box-shadow: 0 16px 24px rgba(0, 0, 0, 0.4);
}

/* Portalled into <body>, never inside .tableau-scroll's clip, and painted
   above every section but below the victory art (z-index: 3). Absolute with
   no positioned ancestor between it and <body> places each card in page
   coordinates, so a scroll mid-flight moves the card and its slot together.
   Each card is its own layer with its own measured destination, so a run's
   cards fly to their own fanned slots rather than one shared point. */
.flight-card {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    pointer-events: none;
    /* box-shadow is inline, not here: it eases from the lifted look to the
       board card's own resting shadow over the same duration as transform,
       so landing changes nothing visible. */
    transition:
        transform 220ms cubic-bezier(0.2, 0, 0, 1),
        box-shadow 220ms cubic-bezier(0.2, 0, 0, 1);
    will-change: transform;
}

.flight-card.settle-back {
    transition-duration: 280ms;
}

.help-strip {
    margin-top: 12px;
    border-radius: 12px;
    border: 1px solid rgba(227, 200, 119, 0.28);
    background: rgba(14, 37, 25, 0.5);
    padding: 8px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    justify-content: center;
    font-size: 0.78rem;
    color: rgba(249, 243, 223, 0.9);
    max-height: 120px;
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.18s ease, opacity 0.18s ease, padding 0.18s ease, margin-top 0.18s ease;
}

.help-strip.collapsed {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    border-width: 0;
}

.version-tag {
    position: absolute;
    right: 18px;
    bottom: 14px;
    z-index: 2;
    pointer-events: none;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.55);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
    font-variant-numeric: tabular-nums;
}

/* No flight ever launches under this preference (main.rs gates it before
   creating one), so only the board's own transitions and animations need
   quieting here: cards land at once, the hover/selection lift snaps
   instead of easing, and the victory motion stops outright. */
@media (prefers-reduced-motion: reduce) {
    .card {
        transition: box-shadow 0.12s ease;
    }

    .help-strip {
        transition: none;
    }

    .victory-coins {
        display: none;
    }

    /* Matches `.victory-ended .victory-temple`'s specificity: a bare
       `.victory-temple` here would lose to that two-class rule regardless
       of media query or source order. */
    .victory-ended .victory-temple {
        animation: none;
    }
}

@media (max-width: 900px) {
    .title-wrap {
        padding-inline: clamp(62px, 16vw, 120px);
    }

    .host-nymph {
        width: clamp(58px, 12vw, 94px);
    }
}

/* "Phone" is width alone; a landscape phone still gets the wide layout. */
@media (max-width: 620px) {
    .host-nymphs,
    .title-art {
        display: none;
    }

    .title-wrap {
        padding-inline: 12px;
    }

    .title-wrap h1 {
        font-size: clamp(1.05rem, 5.6vw, 1.3rem);
        white-space: nowrap;
    }

    /* Pile labels ("Temple 1", "Column 3") don't fit fanned 40px columns. */
    .pile-label {
        display: none;
    }

    /* Three pills must clear the status text at 360px: shrink them and let
       the status text claim its own full-width line below them. */
    .status-pill {
        padding: 4px 8px;
        font-size: 0.66rem;
    }

    .status-text {
        flex: 1 1 100%;
        min-width: 0;
        padding: 4px 10px;
        font-size: 0.75rem;
        line-height: 1.15;
    }

    /* Below this phone breakpoint a fixed-size motif clips into unreadable
       glyph fragments; the corner already carries rank and suit. */
    .card .center .motif {
        display: none;
    }

    .help-strip {
        font-size: 0.72rem;
        gap: 8px;
        order: 5;
    }

    /* The six controls move below the tableau by reordering the existing
       .control-row, never by rendering a second copy. */
    .app-shell {
        display: flex;
        flex-direction: column;
    }

    .status-row {
        order: 1;
    }

    .top-board {
        order: 2;
    }

    .tableau-scroll {
        order: 3;
    }

    .control-row {
        order: 4;
    }
}
