/* ============================================
   SPY AGENCY — The Directorate
   Uses arcade-common.css variables.

   Layout: one screen, no page scroll on desktop.
     top bar
     agencies (left, scrolls itself) | mission row / prompt / hand
   Log + Quick Reference live in a slide-out tray (right): spy-tray.css.
   Card tips: spy-tips.css. Lobby: spy-lobby.css. Briefing: spy-guide.css.

   Palette, on purpose kept small:
     text: --color-text, --color-text-dim, gold (you / your turn / selection)
     cards: cream faces with black or red ink
     players: their colour only on dots and stripes
     outcomes: --good / --bad, only on small badges and the result banner
   ============================================ */

.sa[hidden],
.sa [hidden] {
    display: none !important;
}

body.sa-playing {
    overflow: hidden;
}

.sa {
    --good: #5dd477;
    --bad: #ef6b6b;
    --ink: #1d1a17;
    --cream: linear-gradient(160deg, #fbf6e6, #e8dcb8);

    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.6rem 16px 0.8rem;
}

.sa-label {
    display: block;
    font-family: var(--font-ui);
    font-size: 1rem;
    line-height: 1.1;
    color: var(--color-text-dim);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.sa kbd {
    font-family: var(--font-body);
    font-size: 0.7em;
    opacity: 0.6;
    border: 1px solid currentColor;
    border-radius: 3px;
    padding: 0 0.25em;
    margin-left: 0.3em;
}


/* Hidden while a flying card is on its way to this spot */
.sa .is-pending {
    visibility: hidden;
}

/* --- Top bar --- */

.sa-top {
    position: relative;
    z-index: 51;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding-bottom: 0.6rem;
    margin-bottom: 0.8rem;
    border-bottom: var(--border-subtle);
}

.sa-top__title {
    font-family: var(--font-title);
    font-size: 1.45rem;
    line-height: 1;
    color: var(--title-color);
    text-shadow: var(--title-shadow-small);
    white-space: nowrap;
}

.sa-top__round {
    font-size: 0.95rem;
    color: var(--color-text-dim);
}

.sa-top__buttons {
    display: flex;
    gap: var(--spacing-xs);
}

.sa-top__buttons .btn {
    padding: 0.5rem 0.9rem;
}

.sa-tray-btn {
    position: relative;
}

.sa-short { display: none; }

.sa-tray-btn.is-active {
    border-color: var(--color-gold);
}

.sa-unread {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--color-gold);
    color: var(--ink);
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

/* --- Layout --- */

.sa-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    gap: var(--spacing-sm);
}

/* --- Agencies (left) --- */

.sa-players {
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
}

.sa-players .sa-label {
    margin-bottom: 0.5rem;
}

.sa-players__list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sa-player {
    background: var(--color-bg-card);
    border: 1px solid rgba(212, 175, 55, 0.12);
    border-left: 4px solid var(--player, transparent);
    border-radius: var(--radius-md);
    padding: 0.55rem 0.7rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.sa-player.is-current {
    border-color: var(--player);
    box-shadow: 0 0 0 1px var(--player), 0 0 18px rgba(0, 0, 0, 0.45);
}

.sa-player.is-acting {
    animation: sa-acting 700ms ease;
}

@keyframes sa-acting {
    0%, 100% { background: var(--color-bg-card); }
    30% { background: var(--color-purple); }
}

.sa-player__top {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sa-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sa-player__name {
    font-weight: 600;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-player.is-me .sa-player__name {
    color: var(--color-gold);
}

.sa-player__score {
    margin-left: auto;
    font-family: var(--font-ui);
    font-size: 1.35rem;
    line-height: 1;
    color: var(--color-gold);
}

.sa-player__info {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.sa-player__cards {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 18px;
    margin-right: 0.2rem;
}

.sa-back {
    width: 11px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid var(--color-gold-dim);
    background: repeating-linear-gradient(45deg, var(--color-purple) 0 3px, var(--color-bg-mid) 3px 6px);
}

.sa-player__count {
    margin-left: 0.3rem;
    font-size: 0.8rem;
    color: var(--color-text-dim);
}

.sa-chip {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-radius: var(--radius-sm);
    padding: 0.05rem 0.35rem;
    background: var(--color-bg-mid);
    color: var(--color-text-dim);
}

.sa-chip.is-warn {
    color: var(--bad);
}

.sa-dossier {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-top: 0.45rem;
    font-size: 0.75rem;
}

.sa-dossier.is-empty {
    color: var(--color-text-dim);
}

.sa-dossier__suit {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem;
}

.sa-dossier__head {
    min-width: 2em;
    font-weight: 700;
    color: var(--color-text);
}

.sa-crown {
    color: var(--color-gold);
    margin-left: 1px;
}

/* Small card label: "10♠" */
.sa-tag {
    display: inline-block;
    background: #f4ecd2;
    color: var(--ink);
    border-radius: 3px;
    padding: 0 0.3rem;
    font-weight: 700;
    font-size: 0.72rem;
    line-height: 1.45;
}

/* On the cream chip: the suit's card ink (four-colour deck, spy-theme.css) */
.sa-tag { color: var(--suit-card, var(--ink)); }

.sa-tag.is-landed { animation: sa-pop 350ms ease; }

/* --- Center column --- */

.sa-center {
    min-height: 0;
    min-width: 0;          /* let the mission row shrink its cards instead of widening the page */
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

/* Mission board — takes the spare height, so the missions grow on tall screens */
.sa-board {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse at center, #22344a 0%, #172434 80%);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: var(--radius-lg);
    padding: 0.6rem 0.8rem 0.8rem;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45);
}

/* "Mission Row" in the board's top-left corner, out of the flow, so the
   cards get the full height (the piles column under it is centred, so they don't meet) */
.sa-board { position: relative; }

.sa-board__title {
    position: absolute;
    top: 0.6rem;
    left: 0.8rem;
    margin: 0;
    pointer-events: none;
}

/* Deck + discard stacked on the left; an empty column of the same width on
   the right keeps the missions centred in the board. */
.sa-board__main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--piles-w) minmax(0, 1fr) var(--piles-w);
    grid-template-rows: minmax(0, 1fr);
    gap: 0.6rem;
    --piles-w: 64px;
}

.sa-piles {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.sa-row { grid-column: 2; }

.sa-pile-wrap {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

.sa-pile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 64px;
    border-radius: 4px;
    border: 2px solid var(--color-gold-dim);
    background: repeating-linear-gradient(45deg, var(--color-purple) 0 4px, var(--color-bg-card) 4px 8px);
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--color-text);
    text-shadow: 0 1px 2px #000;
}

.sa-pile--discard {
    background: rgba(0, 0, 0, 0.35);
    border-style: dashed;
    border-color: rgba(232, 228, 240, 0.3);
}

/* The row is a size container: mission cards take the height left over
   after the text under them (--mission-text), up to --mcard-max wide. */
.sa-row {
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    container-type: size;
    --mission-text: 100px;
    --mcard-max: 300px;
    --mcard-w: min(var(--mcard-max), calc((100cqh - var(--mission-text)) * 5 / 7));
}

.sa-row__empty {
    padding: 3rem 0;
    color: var(--color-text-dim);
}

/* Hugs its card; shrinks (with the card) if the row runs out of width */
.sa-mission {
    flex: 0 1 auto;
    width: calc(var(--mcard-w) + 1rem);
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.55rem 0.5rem 0.5rem;
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    background: rgba(0, 0, 0, 0.22);
    color: var(--color-text);
    font: inherit;
    cursor: default;
    transition: border-color var(--transition-fast), transform var(--transition-fast), background var(--transition-fast);
}

.sa-mission:disabled { opacity: 1; }

.sa-mission.is-playable {
    cursor: pointer;
    border-color: rgba(212, 175, 55, 0.45);
}

.sa-mission.is-playable:hover {
    border-color: var(--color-gold);
    background: rgba(212, 175, 55, 0.1);
    transform: translateY(-3px);
}

.sa-mission.is-watch {
    border-color: rgba(232, 228, 240, 0.7);
}

.sa-mission.is-cover {
    border-color: var(--bad);
}

.sa-mission.is-shake {
    animation: sa-shake 450ms ease;
}

@keyframes sa-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Card faces (shared shape) */
.sa-mcard,
.sa-hcard,
.sa-pcard {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--cream);
    color: var(--ink);
    border: 2px solid var(--color-gold-dim);
    font: inherit;
}

.sa-mcard,
.sa-hcard,
.sa-pcard {
    color: var(--suit-card, var(--ink));
}

.sa-face__v {
    font-family: var(--font-ui);
    line-height: 1;
    letter-spacing: 0.5px;
}

.sa-face__s {
    line-height: 1;
}

.sa-mcard {
    width: 100%;
    aspect-ratio: 5 / 7;
    border-radius: var(--radius-md);
    border-width: 3px;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.45);
}

.sa-mcard .sa-face__v { font-size: clamp(1.5rem, 5.4vh, 3.4rem); }
.sa-mcard .sa-face__s { font-size: clamp(1.05rem, 3.8vh, 2.4rem); }

.sa-mcard.is-landed { animation: sa-pop 350ms ease; }

/* Framed cards (cards/card-frame.js): the SVG draws the stock, corners and
   art, so the box only keeps its size, lift and shadow. The radius matches
   the frame's corner (11 / 250 wide, 11 / 350 tall). */
.sa-mcard.is-framed,
.sa-hcard.is-framed,
.sa-ghost.is-framed {
    display: block;
    padding: 0;
    border: none;
    background: none;
    border-radius: 4.4% / 3.14%;
}

.sa .is-framed .card-frame {
    width: 100%;
    height: 100%;
    filter: none;
    pointer-events: none;
}

.sa-mission__meta {
    width: 100%;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.3rem;
    padding: 0 0.15rem;
}

.sa-mission__field {
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--color-text-dim);
}

.sa-mission__bar {
    width: 100%;
    height: 5px;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 3px;
    overflow: hidden;
}

.sa-mission__fill {
    height: 100%;
    background: var(--color-gold);
    transition: width var(--transition-normal);
}

.sa-mission__nums {
    font-size: 0.85rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.sa-mission__raise {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--color-text-dim);
}

/* Cards played on a mission: overlapping minis, player colour underneath */
.sa-mission__tray {
    width: 100%;
    min-height: 36px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.2rem 0.5rem;
}

.sa-mission__cards {
    display: flex;
    justify-content: center;
    padding-left: 10px;
}

.sa-mission__cards:empty { display: none; }

.sa-pcard {
    width: 26px;
    height: 36px;
    margin-left: -10px;
    border-radius: 4px;
    border-width: 1px;
    border-bottom: 4px solid var(--player);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.sa-pcard .sa-face__v { font-size: 0.85rem; }
.sa-pcard .sa-face__s { font-size: 0.75rem; }

.sa-pcard.is-landed { animation: sa-pop 350ms ease; }

.sa-mission__foot {
    white-space: nowrap;
    font-size: 0.75rem;
    color: var(--color-text);
}

.sa-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 0.05rem 0.35rem;
    border-radius: var(--radius-sm);
    border: 1px solid currentColor;
}

.sa-badge.is-good { color: var(--good); }
.sa-badge.is-bad { color: var(--bad); }

/* --- Prompt (status / block window / cover) — along the bottom of the board, fixed height --- */

.sa-prompt {
    flex: none;
    min-width: 0;
    position: relative;
    height: 52px;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0 0.7rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.sa-prompt.is-act {
    border-color: var(--color-gold);
    background: rgba(212, 175, 55, 0.08);
    box-shadow: 0 0 14px var(--color-gold-glow);
}

.sa-prompt.is-bad {
    border-color: var(--bad);
    background: rgba(0, 0, 0, 0.25);
}

.sa-prompt__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sa-prompt__main {
    font-size: 1rem;
    line-height: 1.25;
    color: var(--color-text);
}

.sa-prompt.is-act .sa-prompt__main {
    color: var(--color-gold);
}

.sa-prompt__sub {
    font-size: 0.85rem;
    color: var(--color-text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-prompt__error {
    font-size: 0.8rem;
    color: var(--bad);
}

.sa-prompt__error:empty { display: none; }

.sa-prompt__buttons {
    display: flex;
    gap: var(--spacing-xs);
}

.sa-prompt__buttons .btn {
    padding: 0.4rem 0.8rem;
}

.sa-prompt__timer {
    min-width: 2.5em;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-dim);
}

.sa-prompt__bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: transparent;
}

.sa-prompt__fill {
    height: 100%;
    width: 0;
    background: var(--color-gold);
    transition: width 200ms linear;
}

/* --- Hand --- */

.sa-hand {
    flex: none;
    background: var(--color-bg-card);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: var(--radius-lg);
    padding: 0.6rem var(--spacing-sm) 0.7rem;
    display: flex;
    flex-direction: column;
}

.sa-hand__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.4rem;
}

.sa-pips {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--color-gold);
}

.sa-pip {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--color-gold);
}

.sa-hand__body {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.sa-hand__cards {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.6rem;
    padding-top: 12px;   /* room for the selected card to lift */
}

.sa-hand__empty {
    color: var(--color-text-dim);
}

.sa-hcard {
    width: clamp(60px, 13vh, 104px);
    aspect-ratio: 5 / 7;
    border-radius: var(--radius-md);
    border-width: 3px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}

.sa-hcard .sa-face__v { font-size: clamp(1.6rem, 4.5vh, 2.6rem); }
.sa-hcard .sa-face__s { font-size: clamp(1.05rem, 3vh, 1.7rem); }

.sa-hcard:hover:not(:disabled) {
    transform: translateY(-5px);
}

.sa-hcard.is-selected {
    transform: translateY(-12px);
    border-color: var(--color-gold);
    box-shadow: 0 0 0 3px var(--color-gold), 0 10px 22px rgba(0, 0, 0, 0.5);
}

.sa-hcard:disabled {
    cursor: default;
}

.sa-hand__cards.is-idle .sa-hcard {
    opacity: 0.7;
}

.sa-hcard.is-landed { animation: sa-pop 350ms ease; }

.sa-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.sa-actions .btn {
    padding: 0.55rem 1rem;
    white-space: nowrap;
}

.sa-actions .btn:disabled {
    opacity: 0.35;
    cursor: default;
}

@keyframes sa-pop {
    0% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* --- Modals --- */

.sa-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--scrim);
}

.sa-modal__card {
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: var(--color-bg-card);
    border: var(--border-accent);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.sa-modal__card h2 {
    font-size: 0.9rem;
    margin-bottom: var(--spacing-sm);
}

.sa-modal__text {
    color: var(--color-text);
    margin-bottom: var(--spacing-sm);
}

.sa-modal__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
}

.sa-choice {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
}

.sa-choice .sa-hcard {
    width: 76px;
}

.sa-choice__seat {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.sa-results {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: var(--spacing-sm);
    color: var(--color-text);
}

.sa-results th,
.sa-results td {
    padding: 0.35rem 0.4rem;
    border-bottom: var(--border-subtle);
    text-align: center;
}

.sa-results th {
    color: var(--color-text-dim);
    font-weight: 600;
}

.sa-results th:first-child,
.sa-results td:first-child {
    text-align: left;
}

.sa-results tr.is-winner td {
    color: var(--color-gold);
    font-weight: 700;
}

/* --- Result banner --- */

.sa-toast {
    position: fixed;
    left: 50%;
    top: 34%;
    z-index: 49;
    transform: translate(-50%, -50%);
    pointer-events: none;
    font-family: var(--font-ui);
    font-size: 1.6rem;
    letter-spacing: 1px;
    line-height: 1.1;
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius-md);
    background: rgba(7, 17, 28, 0.94);
    border: 2px solid var(--color-text);
    color: var(--color-text);
    text-transform: uppercase;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.sa-toast.is-good { border-color: var(--good); }
.sa-toast.is-bad { border-color: var(--bad); }

.sa-toast.is-show {
    animation: sa-toast 1400ms ease forwards;
}

@keyframes sa-toast {
    0% { opacity: 0; transform: translate(-50%, -40%) scale(0.92); }
    12% { opacity: 1; transform: translate(-50%, -50%) scale(1.03); }
    20% { transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -58%); }
}

/* --- Flying cards --- */

.sa-fx {
    position: fixed;
    inset: 0;
    z-index: 48;
    pointer-events: none;
}

.sa-ghost {
    position: fixed;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 2px solid var(--color-gold-dim);
    background: var(--cream);
    color: var(--ink);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
    line-height: 1;
    transform-origin: center;
    will-change: transform;
}

.sa-ghost { color: var(--suit-card, var(--ink)); }

.sa-ghost__v {
    font-family: var(--font-ui);
    font-size: 1.25em;
    line-height: 1;
    margin-bottom: 0.15em;
}

.sa-ghost.is-back {
    background: repeating-linear-gradient(45deg, var(--color-purple) 0 5px, var(--color-bg-card) 5px 10px);
}

.sa-ghost.is-glow-good { box-shadow: 0 0 0 3px var(--good), 0 10px 24px rgba(0, 0, 0, 0.55); }
.sa-ghost.is-glow-bad { box-shadow: 0 0 0 3px var(--bad), 0 10px 24px rgba(0, 0, 0, 0.55); }

/* --- Smaller screens --- */

/* Short desktop windows: let the page scroll rather than crush the table */
@media (max-height: 620px) and (min-width: 901px) {
    body.sa-playing { overflow: auto; }
    .sa { height: auto; min-height: 100vh; }
}

@media (max-width: 900px) {
    body.sa-playing { overflow: auto; }
    .sa {
        height: auto;
        min-height: 100vh;
        padding-bottom: 0;
    }
    .sa-top__round { font-size: 0.8rem; }
    .sa-layout {
        grid-template-columns: 1fr;
        align-content: start;
    }
    /* Agencies as a compact strip above the table */
    .sa-players { order: -1; overflow: visible; }
    .sa-players__list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    .sa-dossier { display: none; }
    .sa-board { flex: none; }
    /* the board grows with its content here, so the row can't be a size container */
    .sa-row { container-type: normal; --mcard-w: 150px; }
    /* Hand stays pinned to the bottom of the screen */
    .sa-hand {
        position: sticky;
        bottom: 0;
        z-index: 5;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.45);
    }
}

@media (max-width: 600px) {
    .sa-top__title { font-size: 0.6rem; }
    .sa-top__round { font-size: 0.7rem; white-space: nowrap; }
    .sa-players__list { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.35rem; }
    .sa-player { padding: 0.3rem 0.5rem; }
    .sa-player__info { margin-top: 0.15rem; }
    .sa-back { display: none; }
    .sa-player__count { margin-left: 0; }
    .sa-player__count::after { content: ' cards'; }
    .sa-long { display: none; }
    .sa-short { display: inline; }
    .sa-top { gap: 0.5rem; }
    .sa-top__buttons { gap: 0.35rem; }
    .sa-top__buttons .btn { padding: 0.45rem 0.6rem; }
    .sa-row { gap: 0.35rem; }
    .sa-mission { padding: 0.35rem 0.2rem; }
    .sa-row { --mcard-w: 84px; }
    .sa-mcard .sa-face__v { font-size: 1.2rem; }
    .sa-mcard .sa-face__s { font-size: 0.9rem; }
    .sa-mission__field { font-size: 0.55rem; letter-spacing: 0.5px; }
    .sa-mission__nums { font-size: 0.75rem; }
    .sa-mission__meta { flex-direction: column; align-items: center; gap: 0; }
    .sa-pcard { width: 20px; height: 28px; margin-left: -9px; }
    /* Phones: no room for side columns — piles sit in a row above the missions */
    .sa-board__main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; gap: 0.4rem; }
    .sa-piles { flex-direction: row; justify-content: flex-end; gap: 0.9rem; }
    .sa-pile-wrap { flex-direction: row; gap: 0.4rem; }
    .sa-pile { width: 32px; height: 44px; }
    .sa-row { grid-column: 1; }
    /* The hand is pinned to the bottom here and would cover the prompt — keep it on top */
    .sa-prompt { order: -1; margin: 0 0 0.4rem; }
    .sa-prompt { height: auto; min-height: 56px; flex-wrap: wrap; padding: 0.4rem 0.6rem; gap: 0.5rem; }
    .sa-prompt__text { flex-basis: 100%; }
    .sa-prompt__timer { margin-left: auto; }
    .sa-board__title { display: none; }
    .sa-prompt__sub { white-space: normal; }
    .sa-hand__body { flex-direction: column; gap: 0.5rem; }
    .sa-hcard { width: clamp(44px, calc((100vw - 124px) / 5), 62px); }   /* five fit on one row */
    .sa-hcard .sa-face__v { font-size: 1.5rem; }
    .sa-hcard .sa-face__s { font-size: 1rem; }
    .sa-actions { flex-direction: row; }
}

/* ============================================
   TYPOGRAPHY ROLES (fonts come from spy-theme.css)
   Also sets the lobby button fonts; the rest of the lobby skin is spy-lobby.css.
   ============================================ */

.sa .btn,
.proto-lobby .btn,
.proto-options .btn {
    font-family: var(--font-ui);
    font-weight: 400;
    font-size: 1.2rem;
    letter-spacing: 1px;
    line-height: 1.1;
}

.sa .btn kbd { font-size: 0.6em; letter-spacing: 0; }

.sa h2,
.proto-options__card h2 {
    font-family: var(--font-ui);
    font-size: 1.8rem;
    letter-spacing: 1.5px;
    line-height: 1.1;
}

/* In game: the background art fills the window behind the (max 1400px) table */
body.sa-playing::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        var(--game-shade),
        var(--game-bg-image) center / cover no-repeat,
        var(--color-bg-deep);
}

.sa-player,
.sa-hand {
    background: var(--panel-glass);
}

.sa-board {
    background: radial-gradient(ellipse at center, rgba(34, 52, 74, 0.55) 0%, rgba(23, 36, 52, 0.78) 80%);
}

/* Short UI text — tags, counts, field names — in the UI font */
.sa-chip,
.sa-badge,
.sa-mission__field,
.sa-mission__nums,
.sa-player__count,
.sa-pile,
.sa-top__round,
.sa-prompt__timer {
    font-family: var(--font-ui);
    font-weight: 400;
    letter-spacing: 1px;
}

.sa-chip { font-size: 0.85rem; }
.sa-badge { font-size: 0.85rem; padding: 0 0.35rem; }
.sa-mission__field { font-size: 0.95rem; }
.sa-mission__nums { font-size: 1.15rem; }
.sa-player__count { font-size: 1rem; }
.sa-pile { font-size: 1.05rem; }
.sa-top__round { font-size: 1.25rem; }
.sa-prompt__timer { font-size: 1.2rem; }

@media (max-width: 600px) {
    .sa-top__title { font-size: 1.05rem; text-shadow: var(--title-shadow-tiny); }
    .sa-top__round { font-size: 0.95rem; white-space: normal; flex: 1 1 0; min-width: 0; text-align: center; line-height: 1.05; }
    .sa-mission__field { font-size: 0.75rem; }
    .sa-mission__nums { font-size: 0.95rem; }
}

/* Mission field + progress: always one line; the field name gives way first */
.sa-mission__meta { line-height: 1.1; white-space: nowrap; }
.sa-mission__field { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sa-mission__nums { flex: none; }

/* An Ace you can block with right now: full brightness, a gold ring, a gentle bob */
.sa-hand__cards.is-idle .sa-hcard.is-usable { opacity: 1; }

.sa-hcard.is-usable {
    z-index: 1;
    box-shadow: 0 0 0 2px var(--color-gold), 0 0 18px var(--color-gold-glow), 0 10px 22px rgba(0, 0, 0, 0.5);
    animation: sa-bob 1.6s ease-in-out infinite;
}

@keyframes sa-bob {
    0%, 100% { transform: translateY(-3px) scale(1.07); }
    50% { transform: translateY(-9px) scale(1.07); }
}

@media (prefers-reduced-motion: reduce) {
    .sa-hcard.is-usable { animation: none; transform: translateY(-6px) scale(1.07); }
}

/* --- Mission row with up to 6 missions (players + 1) --- */

/* Big screens: the table may grow wider, so a long row gets bigger cards */
.sa { max-width: 1680px; }

/* Less chrome around each mission, so more of the width goes to the cards */
.sa-board__main { --piles-w: 56px; gap: 0.5rem; }
.sa-row { gap: 0.55rem; }
.sa-mission {
    width: calc(var(--mcard-w) + 0.8rem);
    padding: 0.5rem 0.4rem 0.45rem;
    container-type: inline-size;
}

/* A narrow mission: suit name above the score instead of squeezed beside it */
@container (max-width: 125px) {
    .sa-mission__meta { flex-direction: column; align-items: center; gap: 0; }
    .sa-mission__field { max-width: 100%; }
}

/* Conveyor: the oldest mission leaves at the end of this turn — red edge + "Last chance" tag */
.sa-mission { position: relative; }
.sa-mission.is-expiring {
    border-color: rgba(239, 107, 107, 0.75);
    background: rgba(90, 20, 24, 0.28);
}
.sa-mission__expiring {
    position: absolute;
    top: -0.6rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.05rem 0.45rem;
    border-radius: var(--radius-sm);
    background: var(--bad);
    color: #1d0d0e;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    letter-spacing: 1px;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
    .sa-mission.is-expiring .sa-mission__expiring { animation: sa-expire-pulse 1.8s ease-in-out infinite; }
}
@keyframes sa-expire-pulse { 50% { opacity: 0.65; } }

/* Tablets and phones: 5–6 missions wrap into rows of 3 instead of shrinking to slivers */
@media (max-width: 900px) {
    .sa-row[data-count="5"],
    .sa-row[data-count="6"] { flex-wrap: wrap; row-gap: 0.6rem; }
    .sa-row[data-count="5"] .sa-mission,
    .sa-row[data-count="6"] .sa-mission { flex: 0 1 calc((100% - 2 * 0.55rem) / 3); }
}
@media (max-width: 600px) {
    .sa-row { gap: 0.35rem; }   /* the phone gap (the rule above is later in the file) */
    .sa-row[data-count="5"] .sa-mission,
    .sa-row[data-count="6"] .sa-mission { flex-basis: calc((100% - 2 * 0.35rem) / 3); max-width: 110px; }
}

/* Very narrow phones: slimmer icon buttons so the top bar (with "?") fits */
@media (max-width: 400px) {
    .sa-top__buttons .btn--icon { width: 36px; height: 36px; }
    .sa-top__buttons { gap: 0.25rem; }
}
