:root {
    --felt: #17603f;
    --felt-dark: #0e3f2a;
    --panel: rgba(0, 0, 0, 0.22);
    --plate: #1d2330;
    --plate-edge: #5b6580;
    --text: #f4f1e8;
    --muted: #bcd3c5;
    --accent: #f2c14e;
    --drawn: #4fd1ff;
    --card: #fdfcf8;
    --black: #1c1c1c;
}

* { box-sizing: border-box; }

html {
    background: var(--felt-dark);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    /* Stops pull-to-refresh reloading the game by accident. */
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: radial-gradient(circle at 50% 0%, var(--felt), var(--felt-dark)) fixed;
    color: var(--text);
}

h1:focus { outline: none; }
h1, h2, h3 { margin: 0.5rem 0; }
a { color: var(--accent); }

button, .button, input {
    font: inherit;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    padding: 0.5rem 0.9rem;
}

button, .button {
    min-height: 2.75rem;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    /* No double-tap zoom when tapping cards and buttons quickly. */
    touch-action: manipulation;
}

.button { display: inline-flex; align-items: center; justify-content: center; text-align: center; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible, .file-button:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #2b2106; font-weight: 600; }
button.danger { background: #7c241c; border-color: #ffd2cc; }
button.link { background: none; border: 0; color: var(--accent); text-decoration: underline; }
input { min-height: 2.75rem; background: var(--card); color: var(--black); min-width: 0; }
.room-code { text-transform: uppercase; }
.room-code::placeholder { text-transform: none; }
summary { min-height: 2rem; align-content: center; }

/* Shown only where the browser supports them; see pwa.js. */
.install-button, .share-button, .ios-hint { display: none; }
.can-install .install-button { display: inline-block; margin-top: 1rem; }
.can-share .share-button { display: block; }
.ios .ios-hint { display: block; color: var(--muted); }

/* Pictures */
.avatar { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 3rem; height: 3rem; border-radius: 50%; overflow: hidden; background: linear-gradient(160deg, #7fb7d6, #3d6f99); border: 2px solid #e9e4d4; line-height: 1; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-emoji { font-size: 1.7rem; }
.avatar-initial { font-size: 1.4rem; font-weight: 700; color: #fff; }
.avatar.mini { width: 2rem; height: 2rem; margin-right: 0.35rem; vertical-align: middle; border-width: 1px; }
.avatar.mini .avatar-emoji { font-size: 1.15rem; }
.avatar.mini .avatar-initial { font-size: 0.95rem; }
.avatar.large { width: 8rem; height: 8rem; align-self: center; border-width: 3px; }
.avatar.large .avatar-emoji { font-size: 4.5rem; }
.avatar.large .avatar-initial { font-size: 3.5rem; }

/* Start page, lobby, profile and admin */
.home { max-width: 28rem; margin: 0 auto; padding: calc(2rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left)); text-align: center; }
.topbar ~ .home { padding-top: 1rem; }
.tagline, .meta, .rules-note { color: var(--muted); }
.panel { background: var(--panel); border-radius: 12px; padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; text-align: left; }
.home .panel + .panel, .home .panel + button { margin-top: 1rem; }
.panel h2 { margin: 0; font-size: 1.15rem; }
.panel .meta { margin: 0; font-size: 0.9rem; }
.join { display: flex; gap: 0.5rem; }
.join input { flex: 1; }
.error { color: #ffd2cc; margin: 0; }
.success { color: #c9f2d4; }
.seats { margin: 0; padding-left: 1.5rem; }
.seats li > span { display: inline-block; width: calc(100% - 6.5rem); padding: 0.4rem 0; vertical-align: middle; overflow-wrap: anywhere; }
.seats li > button { vertical-align: middle; }
.seats li { margin-bottom: 0.25rem; }
.seats small { margin-left: 0.4rem; color: var(--accent); }

/* The waiting room's choice of game. */
.game-choice { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.game-choice legend { padding: 0; margin-bottom: 0.4rem; font-weight: 600; }
.game-choice label { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.75rem; border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 10px; cursor: pointer; }
.game-choice label.chosen { border-color: var(--accent); background: rgba(242, 193, 78, 0.14); }
.game-choice label.unavailable { opacity: 0.55; }
.game-choice input { flex: none; width: 1.35rem; height: 1.35rem; min-height: 0; margin: 0; accent-color: var(--accent); }
.game-choice small { display: block; color: var(--muted); }
.game-choice:disabled label, .game-choice label.unavailable { cursor: default; }

.game-choice span { min-width: 0; }

.profile-link { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: var(--text); }
.profile-link small { display: block; color: var(--accent); text-decoration: underline; }
.file-button { position: relative; }
.file-button input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr)); gap: 0.35rem; }
.emoji-grid button { padding: 0; font-size: 1.5rem; }
.emoji-grid button.chosen { border: 3px solid var(--accent); }

.tabs { display: flex; gap: 0.5rem; }
.tabs button { flex: 1; }
.tabs button.chosen { background: var(--accent); border-color: var(--accent); color: #2b2106; font-weight: 600; }
.standings { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
.standings th, .standings td { white-space: nowrap; padding: 0.55rem 0.35rem; text-align: center; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.standings .player { white-space: normal; text-align: left; width: 100%; overflow-wrap: anywhere; }
.standings tr.mine td { background: rgba(242, 193, 78, 0.18); font-weight: 600; }
.standings abbr { text-decoration: none; }

.check { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; cursor: pointer; }
.check input { width: 1.5rem; height: 1.5rem; min-height: 0; margin: 0; accent-color: var(--accent); }

.players li { justify-content: flex-start; }
.presence::before { content: ""; display: inline-block; width: 0.6rem; height: 0.6rem; margin-right: 0.3rem; border-radius: 50%; border: 1px solid var(--muted); }
.presence.online::before { background: #4ade80; border-color: #4ade80; }

/* Invites and the answers to them, above whatever page is showing. Empty space lets taps through. */
.invites { position: fixed; top: calc(0.5rem + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 25; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; width: min(26rem, calc(100vw - 1rem)); max-height: calc(100dvh - 1rem); overflow-y: auto; pointer-events: none; }
.invite-card { width: 100%; padding: 0.7rem 0.9rem; background: var(--plate); border: 2px solid var(--accent); border-radius: 14px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55); pointer-events: auto; animation: invite-in 0.35s ease-out; }
.invite-card .meta { font-size: 0.82rem; }
.invite-who { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.55rem; overflow-wrap: anywhere; }
.invite-actions { display: flex; align-items: center; gap: 0.5rem; }
.invite-actions .primary { flex: 1; }
.invite-card.notice { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; border-color: var(--plate-edge); }
.invite-card.notice span { flex: 1; }

@keyframes invite-in { from { opacity: 0; translate: 0 -1.5rem; } }
@media (prefers-reduced-motion: reduce) { .invite-card { animation: none; } }

.rooms { margin-top: 1rem; }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.room-list li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; background: var(--panel); border: 1px solid transparent; border-radius: 8px; padding: 0.6rem 0.75rem; text-align: left; }
.room-list li.mine { border-color: var(--accent); }
.room-details { min-width: 0; overflow-wrap: anywhere; }
.user-details { flex: 1; }
.room-details .meta { font-size: 0.85rem; }
.room-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; flex: none; }
.badge { font-size: 0.8rem; white-space: nowrap; border: 1px solid var(--muted); color: var(--muted); border-radius: 999px; padding: 0.15rem 0.6rem; }

.topbar { display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: calc(0.3rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right)) 0.3rem calc(1rem + env(safe-area-inset-left)); background: var(--panel); }
.brand { font-weight: 700; text-decoration: none; }

.toast { position: fixed; top: calc(4rem + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20; display: flex; gap: 0.75rem; align-items: center; width: max-content; max-width: 92vw; background: #7c241c; border-radius: 8px; padding: 0.6rem 1rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }

/* ---------------- Cards. The pictures are 2:3. ---------------- */
.card {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 4.5rem;
    min-height: 0;
    aspect-ratio: 2 / 3;
    padding: 0;
    background: var(--card);
    border: 1px solid #77776e;
    border-radius: 0.4rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.card img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; -webkit-touch-callout: none; }
/* The card beneath the top of the discard pile, seen while the next one is on its way. */
.card img.under { position: absolute; inset: 0; }
.card img.top { position: relative; }
/* With nothing beneath, the pile mustn't look like a blank card while its first card flies in. */
.pile.discard:not(:has(img.under)) { background: transparent; }
.card.small { width: 2.75rem; border-radius: 0.25rem; }

/* A coloured band along the top, where it stays visible in a fanned hand. One colour per meld. */
.card.melded::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5%; min-height: 4px; background: var(--meld); }
.card.meld-0 { --meld: #1f9d55; }
.card.meld-1 { --meld: #2f6fe0; }
.card.meld-2 { --meld: #c2410c; }

/* "translate" and "scale" are used for effects so they add to the fan's "transform". */
.card.selected { translate: 0 -1rem; outline: 3px solid var(--accent); }
button.card:not(.back):not(:disabled):focus-visible { outline: 3px solid var(--accent); }
.card:disabled { opacity: 1; }

.card.back {
    background:
        radial-gradient(circle at center, #f2c14e 0 11%, transparent 12%),
        repeating-linear-gradient(45deg, transparent 0 5px, rgba(242, 193, 78, 0.28) 5px 6px),
        repeating-linear-gradient(-45deg, transparent 0 5px, rgba(242, 193, 78, 0.28) 5px 6px),
        #6d1f2e;
    border: 3px solid var(--card);
    box-shadow: inset 0 0 0 2px #f2c14e, 0 2px 5px rgba(0, 0, 0, 0.4);
    color: var(--card);
}

.card.empty { background: transparent; border: 2px dashed var(--muted); color: var(--muted); box-shadow: none; }
.pile:not(:disabled):is(button) { outline: 3px solid var(--accent); outline-offset: 3px; }
.stock .count { position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%); min-width: 2.2rem; padding: 0.15rem 0.35rem; border-radius: 999px; background: rgba(0, 0, 0, 0.75); font-weight: 700; font-size: 1.05rem; }

/* A card on its way between a pile and a player; see table.js. */
.card.flying { position: fixed; top: 0; left: 0; z-index: 12; margin: 0; pointer-events: none; box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55), 0 0 0 3px var(--drawn); will-change: transform; }

/* The "Your turn" pop-up. It stays about two seconds and never gets in the way of a tap. */
.turn-banner { position: fixed; top: 42%; left: 50%; z-index: 13; translate: -50% -50%; padding: 0.7rem 2.2rem; border: 3px solid #ffe3a1; border-radius: 999px; background: radial-gradient(circle at 35% 28%, #ffdf8e, #e0a526 55%, #a8740f); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 30px 6px rgba(242, 193, 78, 0.55); color: #2b1d02; font-size: clamp(1.5rem, 7vmin, 2.75rem); font-weight: 800; text-transform: uppercase; white-space: nowrap; pointer-events: none; animation: turn-banner 1.9s ease-out both; }
.turn-banner.after-move { animation-delay: 0.7s; }

@keyframes turn-banner {
    0% { opacity: 0; scale: 0.5; }
    12% { opacity: 1; scale: 1.12; }
    20% { scale: 1; }
    82% { opacity: 1; scale: 1; }
    100% { opacity: 0; scale: 1.06; visibility: hidden; }
}

/* The card just drawn: once it has flown in, it jumps out and glows for about two seconds, then keeps a quieter marker. */
.card.drawn { box-shadow: 0 0 0 3px var(--drawn), 0 0 10px 3px var(--drawn); animation: card-drawn 2.2s ease-out 0.7s; }
.card.drawn::before { content: "NEW"; position: absolute; left: 0; top: 40%; z-index: 1; padding: 0.1rem 0.2rem; border-radius: 0 4px 4px 0; background: var(--drawn); color: #04222e; font-size: 0.6rem; font-weight: 800; line-height: 1.2; }
.slot:has(> .drawn) { animation: slot-raise 2.9s step-end; }

/* While jumping, the card's slot sits above its neighbours so the whole face can be read. */
@keyframes slot-raise { 0% { z-index: 6; } 100% { z-index: auto; } }

@keyframes card-drawn {
    0% { translate: 0 -2.25rem; scale: 1.2; box-shadow: 0 0 0 4px var(--drawn), 0 0 24px 10px var(--drawn); }
    25% { translate: 0 -1.5rem; scale: 1.14; box-shadow: 0 0 0 4px var(--drawn), 0 0 10px 3px var(--drawn); }
    50% { translate: 0 -1.5rem; scale: 1.14; box-shadow: 0 0 0 4px var(--drawn), 0 0 24px 10px var(--drawn); }
    75% { translate: 0 -1.5rem; scale: 1.14; box-shadow: 0 0 0 4px var(--drawn), 0 0 10px 3px var(--drawn); }
}

/* With motion turned off on the device, the pop-up only fades and no cards fly (the piles still glow). */
@media (prefers-reduced-motion: reduce) {
    .card.drawn, .slot:has(> .drawn) { animation: none; }
    .turn-banner { animation-name: turn-banner-still; }
}

@keyframes turn-banner-still {
    0%, 100% { opacity: 0; }
    10%, 85% { opacity: 1; }
    100% { visibility: hidden; }
}

/* ---------------- Game table: always exactly one screen ---------------- */
.game {
    --hand-card-width: min(calc((100vw - 3rem) / 6), 5rem);
    --pile-card-height: clamp(5rem, 17dvh, 10rem);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    height: 100vh;
    height: 100dvh;
    padding: calc(0.4rem + env(safe-area-inset-top)) env(safe-area-inset-right) 0 env(safe-area-inset-left);
    overflow: hidden;
    /* A faint weave, so the table reads as cloth. */
    background:
        radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.35)),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 9px),
        repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 9px);
}

.corner { position: absolute; top: calc(0.4rem + env(safe-area-inset-top)); z-index: 4; }
.corner.left { left: calc(0.5rem + env(safe-area-inset-left)); }
.corner.right { right: calc(0.5rem + env(safe-area-inset-right)); }
.round { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; padding: 0; border-radius: 50%; background: var(--plate); border: 2px solid var(--plate-edge); color: var(--text); font-size: 1.25rem; text-decoration: none; }

/* Plates for the players, hanging from the top edge and rising from the bottom. */
.opponents { flex: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem; padding: 0 3.5rem; }
.player-plate { display: flex; align-items: center; gap: 0.5rem; min-width: 0; max-width: 15rem; padding: 0.25rem 0.9rem 0.25rem 0.4rem; background: var(--plate); border: 2px solid var(--plate-edge); border-radius: 999px; }
.player-plate .who { min-width: 0; }
.player-plate .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.numbers { display: flex; gap: 0.5rem; font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.numbers .score { color: var(--accent); font-weight: 700; }
.player-plate button { min-height: 1.9rem; padding: 0 0.5rem; font-size: 0.75rem; }
.warning { color: #ffd2cc; font-size: 0.75rem; }
.player-plate.acting, .my-plate.acting .me .avatar { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 14px 2px var(--accent); }
.chip { display: inline-block; width: 1.15rem; height: 1.15rem; border-radius: 50%; background: var(--card); color: var(--black); font-size: 0.7rem; line-height: 1.15rem; text-align: center; vertical-align: middle; }

/* Upright: the two piles side by side, with everything else beneath them. */
.board { flex: 1 1 0; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "stock discard" "middle middle"; align-content: safe center; justify-items: center; gap: 0.6rem 1rem; padding: 0.4rem; }
.stock { grid-area: stock; justify-self: end; }
.discard { grid-area: discard; justify-self: start; }
.pile.card { width: calc(var(--pile-card-height) * 2 / 3); }
.middle { grid-area: middle; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.45rem; width: 100%; min-width: 0; min-height: 0; }
.prompt { margin: 0; font-weight: 600; text-align: center; }
.last-move { margin: 0; font-size: 0.82rem; color: var(--muted); text-align: center; }

.table-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.75rem; min-height: 2.75rem; }
/* The main move: one large round button in the middle of the table. */
.big-button { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: 5.75rem; height: 5.75rem; padding: 0; border-radius: 50%; border: 3px solid #ffe3a1; background: radial-gradient(circle at 35% 28%, #ffdf8e, #e0a526 55%, #a8740f); box-shadow: 0 6px 0 #6e4b08, 0 10px 18px rgba(0, 0, 0, 0.45); color: #2b1d02; font-size: 1.35rem; font-weight: 800; text-transform: uppercase; line-height: 1.1; }
.big-button:active { translate: 0 3px; box-shadow: 0 3px 0 #6e4b08, 0 6px 12px rgba(0, 0, 0, 0.45); }
.big-button small { font-size: 0.68rem; font-weight: 700; text-transform: none; }
/* A longer word than the other round buttons carry. */
.big-button.rummy-call { font-size: 1.05rem; }
.pill { border-radius: 999px; background: var(--plate); border: 2px solid var(--plate-edge); font-weight: 600; min-width: 7rem; }

.melds, .groups { display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 0.4rem; }
.group { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.15rem; max-width: 100%; background: var(--panel); border-radius: 8px; padding: 0.3rem; }
.group.target { outline: 2px dashed var(--accent); }
.group-label { font-size: 0.75rem; color: var(--muted); margin-right: 0.3rem; }
.melds:empty { display: none; }

/* The discard pile laid out, oldest first, for taking cards from deep in it. */
.discard-spread { display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 0.3rem; width: 100%; min-height: 0; max-height: 42dvh; overflow-y: auto; padding: 0.35rem; background: var(--panel); border-radius: 10px; }
.spread-card { display: inline-flex; border-radius: 6px; padding: 2px; border: 2px solid transparent; }
.spread-card.taking { border-color: var(--drawn); background: rgba(79, 209, 255, 0.22); }
.spread-card button.card { min-height: 0; }
.spread-card .card.selected { translate: none; }

/* Your hand and plate */
.my-area { flex: none; display: flex; flex-direction: column; align-items: center; }
.hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem; width: 100%; max-width: 34rem; padding: 0.9rem 0.5rem 0.5rem; }
.slot { position: relative; display: inline-flex; }
.hand .card { width: var(--hand-card-width); }

.my-plate { position: relative; z-index: 7; display: grid; grid-template-columns: auto 1fr auto 1fr; align-items: center; gap: 0.6rem; width: min(100%, 36rem); padding: 0.35rem 0.75rem calc(0.35rem + env(safe-area-inset-bottom)); background: var(--plate); border: 2px solid var(--plate-edge); border-bottom: 0; border-radius: 2.5rem 2.5rem 0 0; }
.my-plate .sort { display: flex; flex-direction: column; justify-content: center; min-width: 4.25rem; padding: 0.15rem 0.6rem; border-radius: 999px; font-weight: 700; line-height: 1.15; }
.my-plate small { font-size: 0.68rem; font-weight: 400; color: var(--muted); }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.stat span { font-size: 0.75rem; font-weight: 700; }
.stat strong { min-width: 4.5rem; padding: 0 0.5rem; border-radius: 6px; background: #0b0e14; color: var(--accent); text-align: center; }
.stat strong.good { color: #6ee7a0; }
.me { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; white-space: nowrap; }

/* End of a hand */
.result { flex: 1 1 0; min-height: 0; overflow-y: auto; margin: 0 auto; width: min(100% - 1rem, 62rem); background: var(--panel); border-radius: 12px; padding: 0.5rem 0.75rem 0; text-align: center; }
.result h2 { font-size: 1.15rem; }
.winner { font-size: 1.2rem; margin: 0.25rem 0; }
.points { color: var(--accent); margin-left: 0.4rem; }
.reveal { display: flex; flex-direction: column; align-items: center; margin-bottom: 0.5rem; }
.reveal h3 { margin: 0.2rem 0; font-size: 1rem; }
.result-actions { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.35rem 0.75rem; padding: 0.4rem 0.5rem 0.5rem; background: var(--felt-dark); border-radius: 8px; }
.result-actions p { margin: 0; }

/* History, rules and leaving slide in from the side. */
.menu-panel { display: none; }
.menu-panel.open { display: flex; flex-direction: column; gap: 0.6rem; position: fixed; top: 0; right: 0; bottom: 0; z-index: 15; width: min(24rem, 86vw); overflow-y: auto; padding: calc(0.75rem + env(safe-area-inset-top)) calc(0.75rem + env(safe-area-inset-right)) calc(0.75rem + env(safe-area-inset-bottom)) 0.75rem; background: var(--felt-dark); box-shadow: -6px 0 18px rgba(0, 0, 0, 0.5); }
.menu-panel > * { flex: none; }
.menu-panel .meta { margin: 0; font-size: 0.85rem; }
.menu-head { display: flex; justify-content: space-between; align-items: center; }
.log { background: var(--panel); border-radius: 8px; padding: 0.5rem 1rem; }
.log summary { cursor: pointer; }
.log ul { padding-left: 1.1rem; margin: 0.5rem 0; color: var(--muted); }

/* ---------------- Landscape: a wide table with a fanned hand ---------------- */
@media (orientation: landscape) and (min-width: 30rem) {
    .game {
        /* Card sizes follow the screen's height, so everything scales together. */
        --hand-card-height: clamp(6rem, 36dvh, 15rem);
        --hand-card-width: calc(var(--hand-card-height) * 2 / 3);
        --pile-card-height: clamp(5rem, 33dvh, 13rem);
        /* How far the bottom of the fan tucks behind your plate. */
        --tuck: calc(var(--hand-card-height) * 0.2);
        gap: 0.2rem;
    }

    .opponents { flex-wrap: nowrap; padding: 0 4rem; }
    .player-plate { flex: 0 1 15rem; }

    .board { grid-template-columns: auto 1fr auto; grid-template-areas: "stock middle discard"; align-items: center; align-content: stretch; grid-template-rows: 100%; gap: 0 1rem; padding: 0.35rem calc(2.5vw + 0.35rem); }
    .middle { height: 100%; justify-content: safe center; overflow-y: auto; padding: 0.25rem; gap: 0.35rem; }
    .board.rummy .melds { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
    .melds .card.small { width: clamp(2.1rem, 7.5dvh, 3.5rem); }
    /* Too short to wrap: one row to swipe along. */
    .discard-spread { flex: none; flex-wrap: nowrap; justify-content: safe center; overflow-x: auto; max-height: none; }
    .spread-card { flex: none; }
    .spread-card .card.small { width: 2.1rem; }
    /* The spread shows the discards, so the two piles make way and the buttons sit beside it. */
    .board.picking { grid-template-columns: minmax(0, 1fr); grid-template-areas: "middle"; }
    .board.picking > .pile { display: none; }
    .board.picking .middle { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "prompt prompt" "spread actions"; align-content: safe center; align-items: center; gap: 0.2rem 0.5rem; }
    .board.picking .prompt { grid-area: prompt; }
    .board.picking .discard-spread { grid-area: spread; padding: 0.15rem; }
    .board.picking .table-actions { grid-area: actions; flex-wrap: nowrap; }
    .board.picking .last-move { display: none; }

    .hand { flex-wrap: nowrap; gap: 0; max-width: min(72rem, 100%); padding: 0.9rem 1.5rem 0; margin-bottom: calc(-1 * var(--tuck)); }
    /* Overlap only as much as needed to fit every card across the screen. */
    .slot + .slot { margin-left: min(-0.3rem, calc((100% - var(--cards) * var(--hand-card-width)) / (var(--cards) - 1))); }
    /* The fan: each card turns and drops a little more the further it is from the middle. */
    .slot { transform: translateY(calc(var(--offset) * var(--offset) * 0.2dvh)) rotate(calc(var(--offset) * 2.1deg)); transform-origin: 50% 100%; }
    .card.selected { translate: 0 -1.4rem; }

    .my-plate { width: min(94%, 40rem); }
}

/* Short screens, such as a phone held sideways. */
@media (orientation: landscape) and (max-height: 34rem) and (min-width: 30rem) {
    .game { --hand-card-height: clamp(6rem, 38dvh, 12rem); --pile-card-height: clamp(4.5rem, 34dvh, 10rem); gap: 0; padding-top: calc(0.2rem + env(safe-area-inset-top)); }
    .corner { top: calc(0.2rem + env(safe-area-inset-top)); }
    .round { width: 2.4rem; height: 2.4rem; min-height: 0; font-size: 1.1rem; }
    .player-plate { padding-block: 0.1rem; }
    .player-plate .avatar { width: 2.25rem; height: 2.25rem; }
    .player-plate .avatar-emoji { font-size: 1.3rem; }
    .numbers { font-size: 0.7rem; gap: 0.35rem; }
    .prompt { font-size: 0.85rem; }
    .last-move { font-size: 0.72rem; }
    .big-button { width: 4.5rem; height: 4.5rem; font-size: 1.05rem; box-shadow: 0 4px 0 #6e4b08, 0 6px 12px rgba(0, 0, 0, 0.45); }
    .table-actions { gap: 0.6rem; min-height: 2.4rem; }
    .pill { min-height: 2.4rem; }
    .board.rummy .big-button { width: auto; height: 2.4rem; min-height: 0; padding: 0 1rem; border-radius: 999px; flex-direction: row; gap: 0.35rem; font-size: 0.95rem; }
    .my-plate { padding-top: 0.15rem; padding-bottom: calc(0.15rem + env(safe-area-inset-bottom)); }
    .my-plate .avatar { width: 2.25rem; height: 2.25rem; }
    .my-plate .avatar-emoji { font-size: 1.3rem; }
    .my-plate .sort { min-height: 2.25rem; }
    .reveal { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 0.25rem 0.75rem; }
}

/* With several opponents on a narrow screen, keep each plate small. */
@media (max-width: 52rem) {
    .opponents:has(> :nth-child(3)) .player-plate { gap: 0.25rem; padding: 0.15rem 0.4rem 0.15rem 0.2rem; }
    .opponents:has(> :nth-child(3)) .avatar { width: 1.75rem; height: 1.75rem; }
    .opponents:has(> :nth-child(3)) .avatar-emoji { font-size: 1.05rem; }
    .opponents:has(> :nth-child(3)) .name { font-size: 0.8rem; }
    .opponents:has(> :nth-child(3)) .numbers { flex-direction: column; gap: 0; line-height: 1.15; }
}

/* Upright phones: opponents sit below the corner buttons. */
@media (orientation: portrait) {
    .opponents { padding: 0 3.4rem; min-height: 2.75rem; }
}

@media (orientation: portrait) and (max-width: 40rem) {
    .opponents:has(> :nth-child(2)) { padding: 3.1rem 0.35rem 0; }
    .player-plate { flex: 0 1 auto; }
}

#blazor-error-ui { color: var(--black); }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "An error has occurred."; }
