/* Nådesløs – base styles. Mobile-first: base = phone, media queries scale up. */

/* The app always uses its dark theme, whatever the device is set to (the user's choice). */
:root {
    color-scheme: dark;
    --bg: #150f18;
    --surface: #211826;
    --text: #efe8f1;
    --muted: #b3a4b8;
    --border: #3a2d40;
    --primary: #e5484d;
    --primary-text: #ffffff;
    --felt: #3a1430;
    --back: #7a1830;
    --c-R: #e5484d;
    --c-Y: #f5b72b;
    --c-G: #2fb36d;
    --c-B: #3b82f6;
    --c-W: #1d1422;
    --focus: #ffc53d;

    --radius: clamp(8px, 1.2vw, 14px);
    --gap: clamp(0.75rem, 2vw, 1.5rem);
    --gutter: clamp(1rem, 4vw, 2.5rem);
    --max-width: 72rem;
    --tap: 44px; /* minimum touch target */

    --fs-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --fs-h1: clamp(1.75rem, 1.4rem + 1.8vw, 3rem);
    --fs-h2: clamp(1.25rem, 1.1rem + 0.8vw, 1.75rem);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    /* Always reserve the scrollbar's space, so long pages (rules) and short ones (home) have the
       same width and the centred header button does not jump sideways between them */
    scrollbar-gutter: stable;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: var(--fs-base);
    line-height: 1.55;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow-x: hidden;
}

h1, h2, h3 {
    line-height: 1.2;
    margin: 0 0 0.5em;
}

h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); margin-top: 1.5em; }

a { color: var(--primary); }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* ---------- Layout ---------- */

.site-header,
.site-main,
.site-footer {
    width: 100%;
    max-width: var(--max-width);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

/* Three columns: brand left, "Play now" centred, nav right (equal side columns keep the button truly centred) */
.site-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: clamp(0.4rem, 2vw, var(--gap));
    padding-top: calc(env(safe-area-inset-top) + 0.75rem);
    padding-bottom: 0.75rem;
}

.brand {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    min-height: var(--tap);
    font-weight: 700;
    font-size: 1.15em;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.site-nav {
    display: flex;
    gap: 0.25rem;
}

.site-nav a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding-inline: 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}

.site-nav a:hover {
    background: var(--surface);
}

.site-nav {
    justify-self: end;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Small pill sized to the header text beside it; the header height is set by the brand/menu, so it never grows */
.site-header .header-play {
    position: relative;
    justify-self: center;
    min-height: 0;
    min-width: 0;
    padding: 0.3em 0.95em;
    font-size: 0.95em;
    line-height: 1.2;
    white-space: nowrap;
}

/* Invisible tap area keeps the 44px touch target although the pill is smaller */
.site-header .header-play::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: var(--tap);
    transform: translateY(-50%);
}

/* Centre column: "Play now" on the menu pages, "Invite a friend" everywhere else (layout.php) */
.header-center {
    justify-self: center;
    display: flex;
    min-width: 0;
}

/* "Invite a friend": an even smaller pill; opens the share sheet like the waiting room's button */
.site-header .header-invite {
    font-size: 0.82em;
    padding: 0.28em 0.85em;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Narrow phones: only the icon, so brand, button and menu fit on one line */
@media (max-width: 479px) {
    /* Logged out (Rules + language) is too wide beside the button: one row of its own below */
    .site-nav-guest {
        grid-column: 1 / -1;
        flex-wrap: nowrap;
    }
    .brand-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
}

/* User dropdown: the username opens settings, language and logout */
.user-menu {
    position: relative;
}

.user-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: var(--tap);
    padding-inline: 0.75rem;
    border-radius: var(--radius);
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.user-menu-toggle::-webkit-details-marker {
    display: none;
}

.user-menu-toggle:hover,
.user-menu[open] .user-menu-toggle {
    background: var(--surface);
}

.user-menu-name {
    max-width: clamp(4rem, 20vw, 14rem); /* long names get "…" so the header stays on one line */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-caret {
    flex: none;
    width: 0.45em;
    height: 0.45em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-25%) rotate(45deg);
    transition: transform 0.15s;
}

.user-menu[open] .user-menu-caret {
    transform: translateY(25%) rotate(-135deg);
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    min-width: 13rem;
    max-width: calc(100vw - 2 * var(--gutter));
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.user-menu-panel > form {
    margin: 0.25rem 0 0;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
}

.site-nav .user-menu-panel a,
.user-menu-panel > form button {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    min-height: var(--tap);
    padding-inline: 0.75rem;
    border: 0;
    border-radius: calc(var(--radius) - 2px);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
}

.site-nav .user-menu-panel a:hover,
.user-menu-panel > form button:hover {
    background: var(--bg);
}

/* Language: one big tap target with the name of the other language */
.site-nav .lang-toggle {
    justify-content: center;
    min-width: var(--tap);
    padding-inline: 0.5rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Forms ---------- */

.form-panel {
    max-width: 28rem;
    margin-inline: auto;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
}

.form-panel h1 {
    font-size: var(--fs-h2);
    margin-bottom: 1.25rem;
    text-align: center;
}

/* Tablets and computers: give the form some air above it */
@media (min-width: 768px) {
    .form-panel {
        margin-top: clamp(1rem, 4vh, 3rem);
    }
}

.form {
    display: grid;
    gap: 1rem;
}

.field {
    display: grid;
    gap: 0.35rem;
}

.field label {
    font-weight: 600;
}

.field input {
    width: 100%;
    min-height: var(--tap);
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    /* 16px+ stops iPhone Safari from zooming in on focus */
    font: inherit;
    font-size: max(16px, 1em);
}

.field select {
    width: 100%;
    min-height: var(--tap);
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: max(16px, 1em);
}

.check {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--tap);
    cursor: pointer;
}

.check input {
    width: 1.35rem;
    height: 1.35rem;
    accent-color: var(--primary);
    flex: none;
}

.code-input {
    text-transform: uppercase;
    letter-spacing: 0.2em;
    font-weight: 700;
    text-align: center;
}

.field input:focus,
.field select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.field[aria-invalid="true"] input {
    border-color: #c0392b;
}

.field-error,
.field-hint {
    margin: 0;
    font-size: 0.9em;
}

.field-error {
    color: #c0392b;
}

.field-hint {
    color: var(--muted);
}

.form .btn {
    width: 100%;
    margin-top: 0.5rem;
    min-height: 3rem;
}

.form-footer {
    margin: 1.25rem 0 0;
    text-align: center;
}

.alert {
    margin: 0 0 var(--gap);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid;
}

.alert-success {
    background: rgba(63, 168, 102, 0.12);
    border-color: rgba(63, 168, 102, 0.5);
}

.alert.is-hiding {
    opacity: 0;
    transition: opacity 0.4s ease;
}

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

.alert-error {
    background: rgba(192, 57, 43, 0.1);
    border-color: rgba(192, 57, 43, 0.5);
}

.field-error { color: #ff8a7a; }
.field[aria-invalid="true"] input { border-color: #ff8a7a; }

.site-main {
    flex: 1;
    padding-block: var(--gap);
}

.site-footer {
    padding-top: var(--gap);
    padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
    color: var(--muted);
    text-align: center;
}

/* ---------- Components ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1.25rem, 4vw, 2.5rem);
}

.hero {
    text-align: center;
    background:
        radial-gradient(ellipse at top, rgba(255, 255, 255, 0.12), transparent 60%),
        var(--felt);
    color: #ffffff;
    border: none;
    padding-block: clamp(2.5rem, 10vw, 6rem);
}

.hero .muted {
    color: rgba(255, 255, 255, 0.75);
}

.lead {
    font-size: 1.15em;
    max-width: 38rem;
    margin: 0 auto 1.5rem;
}

.muted {
    color: var(--muted);
}

/* Short message pages (404, expired form): narrow, centred card */
.message-panel {
    max-width: 32rem;
    margin-inline: auto;
    text-align: center;
}

.prose {
    max-width: 48rem;
    margin-inline: auto; /* centred like the other narrow panels (terms, rules) */
}

.prose ul {
    padding-left: 1.25em;
}

.prose li + li {
    margin-top: 0.35em;
}

/* Rules page: each rule with the cards it talks about (cards wrap above the text on narrow screens) */
.rules .rule-list {
    list-style: none;
    padding-left: 0;
}

.rules .rule-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 1rem;
    padding-left: 1rem;
    border-left: 3px solid rgba(255, 255, 255, 0.12);
}

.rules .rule-item + .rule-item {
    margin-top: 0.9em;
}

.rules .rule-cards {
    --rule-card-w: clamp(2.6rem, 9vw, 3.6rem);
    display: flex;
    flex: 0 0 auto;
    gap: 0.35rem;
    /* room for two cards, so the text of 1- and 2-card rules lines up */
    min-width: calc(var(--rule-card-w) * 2 + 0.35rem);
}

.rules .rule-card {
    display: block;
    width: var(--rule-card-w);
}

.rules .rule-text {
    flex: 1 1 16rem;
    min-width: 0;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-block: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    min-width: var(--tap);
    padding: 0.6em 1.4em;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--focus);
    border-color: transparent;
    color: #1c2420;
}

/* ---------- Statistics ---------- */

.results-title {
    font-size: var(--fs-h2);
    margin: 0 0 1rem;
}

.stats-page h2 {
    margin-top: 0;
}

.stats-page h3 {
    margin: 1.25rem 0 0.5rem;
}

.stat-tiles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0;
}

@media (min-width: 768px) {
    .stat-tiles {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.stats-history h2 {
    margin-top: 0;
}

.stats-page h3 + .muted {
    margin-top: -0.25rem;
    font-size: 0.9em;
}

/* Leaderboard: scrolls sideways inside its box on very narrow phones instead of the page */
.table-wrap {
    overflow-x: auto;
}

.leaderboard {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.leaderboard th,
.leaderboard td {
    padding: 0.55rem 0.4rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.leaderboard th {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.9em;
}

.leaderboard .num {
    text-align: right;
    width: 1%;
    white-space: nowrap;
}

.leaderboard .name {
    overflow-wrap: anywhere;
    font-weight: 600;
}

.leaderboard tr.is-me td {
    background: rgba(242, 182, 50, 0.1);
}

.leaderboard tr.is-me .name {
    color: var(--focus);
}

.stat-tile {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.02);
}

.stat-tile dt {
    color: var(--muted);
    font-size: 0.9em;
}

.stat-tile dd {
    margin: 0.2rem 0 0;
    font-size: 1.6em;
    font-weight: 700;
    line-height: 1.2;
}

.stat-tile dd small {
    font-size: 0.55em;
    font-weight: 400;
    color: var(--muted);
}

.history-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    min-height: var(--tap);
    padding: 0.5rem 0.25rem;
}

.result-badge {
    min-width: 6.5rem;
    font-weight: 700;
}

.result-badge.is-win {
    color: var(--primary);
}

.result-badge.is-out {
    color: #e0675a;
}

/* Lobby: your own games sit on top of the open-games list, highlighted so they are easy to get back into */
.game-list .open-game.is-mine {
    padding-inline: 0.75rem;
    margin-bottom: 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(242, 182, 50, 0.05);
}

.game-list .open-game.is-mine.is-playing {
    border-color: var(--focus);
    background: rgba(242, 182, 50, 0.1);
}

/* No divider line under the last own-game box (it has its own border) */
.game-list .open-game.is-mine + li:not(.is-mine) {
    border-top: none;
}

.btn-danger {
    background: #c0392b;
    border-color: transparent;
    color: #fff;
}

/* Settings: delete-account box under the normal settings */
.danger-panel {
    border-color: rgba(192, 57, 43, 0.5);
}

.form-panel h2 {
    font-size: var(--fs-h2);
    margin-bottom: 0.75rem;
    text-align: center;
}

.danger-panel > p {
    color: var(--muted);
    margin-bottom: 1rem;
}

.btn:hover {
    filter: brightness(1.05);
}

.btn:active {
    transform: translateY(1px);
}

/* iPhone "Add to Home Screen" hint */
.install-hint {
    position: fixed;
    left: max(0.75rem, env(safe-area-inset-left));
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 30rem;
    margin-inline: auto;
    padding: 0.75rem 0.75rem 0.75rem 1rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.install-hint p {
    margin: 0;
    flex: 1;
}

.install-hint__share {
    display: inline-flex;
    vertical-align: middle;
    color: #0a84ff;
}

.install-hint__close {
    flex: none;
    padding: 0;
    border-radius: 50%;
}

.install-hint__how {
    color: var(--focus);
    white-space: nowrap;
}

/* Home page "Get the app" guide (tabs per device, numbered illustrated steps) */
.install-guide {
    padding: 0;
    overflow: hidden;
    scroll-margin-top: 5rem;
}

.install-guide__box > summary {
    display: flex;
    align-items: center;
    gap: clamp(0.75rem, 2vw, 1.25rem);
    min-height: var(--tap);
    padding: clamp(1rem, 3vw, 1.5rem) clamp(1rem, 4vw, 2rem);
    cursor: pointer;
    list-style: none;
}

.install-guide__box > summary::-webkit-details-marker {
    display: none;
}

.install-guide__box > summary::after {
    content: "";
    flex: none;
    width: 0.65em;
    height: 0.65em;
    margin-left: auto;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform 0.2s;
}

.install-guide__box[open] > summary::after {
    transform: rotate(-135deg);
}

.install-guide__box > summary:hover .install-guide__title {
    color: var(--focus);
}

.install-guide__icon {
    flex: none;
    font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem);
    line-height: 1;
}

.install-guide__text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.install-guide__title {
    font-size: var(--fs-h2);
    font-weight: 700;
    line-height: 1.2;
}

.install-guide__lead {
    font-size: 0.95em;
}

.install-tabs {
    display: none; /* without JS every device's steps are simply shown one after another */
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0 clamp(1rem, 4vw, 2rem);
}

.install-guide.has-tabs .install-tabs {
    display: flex;
}

.install-guide.has-tabs .install-panel__heading {
    display: none;
}

.install-tab {
    min-height: var(--tap);
    padding: 0.5rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.install-tab:hover {
    border-color: var(--muted);
}

.install-tab[aria-selected="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-text);
    font-weight: 600;
}

.install-tab:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.install-panel {
    padding: clamp(1rem, 3vw, 1.5rem) clamp(1rem, 4vw, 2rem) clamp(1.25rem, 4vw, 2rem);
}

.install-panel__heading {
    font-size: 1.1em;
}

.install-now {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin: 0 0 1rem;
}

.install-now[hidden] {
    display: none;
}

.install-steps {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, clamp(7rem, 26vw, 11rem)), 1fr));
    gap: clamp(1rem, 2.5vw, 1.5rem);
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: install-step;
}

.install-steps--wide {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, clamp(15rem, 40vw, 22rem)), 1fr));
}

.install-step {
    counter-increment: install-step;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.install-step img {
    display: block;
    width: 100%;
    height: auto;
    max-width: 13rem;
    margin-inline: auto;
}

.install-steps--wide .install-step img {
    max-width: 26rem;
}

.install-step p {
    margin: 0;
    font-size: 0.95em;
    line-height: 1.45;
}

.install-step p::before {
    content: counter(install-step);
    display: inline-grid;
    place-items: center;
    width: 1.6em;
    height: 1.6em;
    margin-right: 0.4em;
    border-radius: 50%;
    background: var(--focus);
    color: #1a1406;
    font-weight: 700;
    font-size: 0.9em;
}

.install-step--done p::before {
    content: "✓";
    background: var(--primary);
    color: var(--primary-text);
}

.install-tip {
    margin: clamp(1rem, 3vw, 1.5rem) 0 0;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--focus);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: rgba(242, 182, 50, 0.08);
    color: var(--muted);
    font-size: 0.95em;
}

.install-hide {
    margin: 0;
    padding: 0 clamp(1rem, 4vw, 2rem) clamp(1.25rem, 4vw, 2rem);
    text-align: center;
}

.install-hide .btn {
    min-height: var(--tap);
    font-size: 0.95em;
}

@media (prefers-reduced-motion: reduce) {
    .install-guide__box > summary::after {
        transition: none;
    }
}

/* ---------- Lobby & waiting room ---------- */

.h2 {
    font-size: var(--fs-h2);
}

.center {
    text-align: center;
}

.site-main > .panel + .panel,
.room > .panel + .panel {
    margin-top: var(--gap);
}

/* Lobby panel head: title left, "N online" in the top-right corner */
.lobby-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    flex-wrap: wrap;
}

.online-count {
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    font-size: 0.9rem;
    color: var(--muted);
    white-space: nowrap;
}

.online-dot {
    width: 0.55em;
    height: 0.55em;
    border-radius: 50%;
    background: #3ecf6e;
    box-shadow: 0 0 0 0.18em rgba(62, 207, 110, 0.2);
}

/* Lobby panel: "Your games" and "Open games" as two parts of one box */
.lobby-sub-title {
    margin: 0 0 0.35em;
    font-size: var(--fs-base, 1rem);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.lobby-sub + .lobby-sub {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.game-list,
.seat-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.game-list li + li,
.seat-list li + li {
    border-top: 1px solid var(--border);
}

.game-list a {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
    min-height: var(--tap);
    padding: 0.6rem 0.25rem;
    color: var(--text);
    text-decoration: none;
}

.code {
    font-weight: 700;
    letter-spacing: 0.12em;
}

.seat-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: var(--tap);
    padding: 0.4rem 0.25rem;
}

.seat-list form {
    margin: 0;
}

.seat-name {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.badge {
    padding: 0.1em 0.55em;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8em;
}

.invite {
    text-align: center;
}

.invite .muted {
    margin: 0;
}

.invite-code {
    margin: 0.25rem 0 1rem;
    font-size: clamp(2rem, 9vw, 3rem);
    font-weight: 800;
    letter-spacing: 0.18em;
    user-select: all;
}

.invite .btn {
    min-width: min(100%, 16rem);
}

.settings-summary {
    margin-block: 1rem;
    text-align: center;
}

.actions-stack {
    flex-direction: column;
    align-items: stretch;
    max-width: 22rem;
    margin-inline: auto;
}

.actions-stack form,
.actions-stack .btn {
    width: 100%;
}

.btn-small {
    min-height: 36px;
    padding: 0.3em 0.9em;
    font-size: 0.9em;
}

/* Keep 44px tap height on touch screens */
@media (pointer: coarse) {
    .btn-small {
        min-height: var(--tap);
    }
}

.btn-link {
    border: 0;
    background: none;
    color: var(--muted);
    text-decoration: underline;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.alert-info {
    background: rgba(242, 182, 50, 0.12);
    border-color: rgba(242, 182, 50, 0.55);
}

/* Full-width, stacked buttons on all phones (iPhone 14 up to 16 Pro Max is 390-440px wide) */
@media (max-width: 599px) {
    .actions .btn {
        width: 100%;
    }
}

/* Tablet and up */
@media (min-width: 768px) {
    .site-nav {
        gap: 0.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* iPhone Safari (iOS 26+) blurs/fades content just under the status bar.
   On touch phones push the header further down so it sits below that zone. */
@media (pointer: coarse) and (max-width: 599px) {
    .site-header {
        padding-top: calc(env(safe-area-inset-top) + 1.75rem);
    }
}

.brand-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    flex: none;
}

/* ---------- Game table ---------- */

.is-game .site-footer {
    display: none; /* every bit of height goes to the table */
}

/* The game page is exactly one screen tall (no scrolling): header, bar, status and hand keep
   their size and the felt takes whatever height is left (iPhone Safari bars included, via dvh) */
body.is-game {
    height: 100vh;
    height: 100dvh;
}

.is-game .site-main {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-block: 0 max(0.5rem, env(safe-area-inset-bottom));
}

.game {
    /* Clicking and tapping around the table must never highlight names, points or cards */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: clamp(0.35rem, 1.2vh, 1rem);
    max-width: 60rem;
    margin-inline: auto;
}

.game-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* Buttons side by side in one row, so the bar stays one button tall on phones */
.game-bar-actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 0.4rem;
}

.game-bar-actions .btn {
    white-space: nowrap;
}

.game-bar-actions form {
    margin: 0;
}

/* Quick reactions: emoji button in the felt's bottom-right corner (outside the oval),
   the picker opens upwards from it */
.react {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 8; /* above the seats */
}

.react-toggle,
.corner-btn {
    min-width: var(--tap);
    min-height: var(--tap);
    padding: 0;
    border-radius: 50%;
    font-size: 1.3rem;
}

/* Round history button: the empty bottom-left corner outside the oval */
.history-toggle {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 8;
}

.react-picker {
    position: absolute;
    bottom: calc(100% + 0.35rem);
    right: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(3, var(--tap));
    gap: 0.25rem;
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.react-picker[hidden] {
    display: none;
}

.react-choice {
    width: var(--tap);
    height: var(--tap);
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.react-choice:hover,
.react-choice:focus-visible {
    background: rgba(255, 255, 255, 0.08);
}

/* A reaction rises from the player who sent it and fades out */
.reaction-bubble {
    position: fixed;
    z-index: 90;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    line-height: 1;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: reaction-rise 2.5s ease-out forwards;
}

@keyframes reaction-rise {
    0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
    15%  { opacity: 1; transform: translate(-50%, -80%) scale(1.1); }
    70%  { opacity: 1; transform: translate(-50%, -160%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -210%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .reaction-bubble {
        animation: reaction-fade 2.5s linear forwards;
    }

    @keyframes reaction-fade {
        0%, 80% { opacity: 1; transform: translate(-50%, -100%); }
        100%    { opacity: 0; transform: translate(-50%, -100%); }
    }
}

.game-info {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    color: var(--muted);
    font-size: clamp(0.8rem, 3.4vw, 1rem);
    font-weight: 600;
    line-height: 1.3;
    text-align: right;
}

/* Opponents: seats around the edge of the oval felt.
   game.js sets --x/--y = the seat's point on the unit circle (you are at the bottom). */
.opponents {
    list-style: none;
    margin: 0;
    padding: 0;
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.opponent {
    position: absolute;
    left: calc(50% + var(--x, 0) * (50% - var(--seat-w) / 2));
    top: calc(50% + var(--y, -1) * (50% - var(--seat-anchor)));
    translate: -50% -50%;
    z-index: 6;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.15rem 0.35rem;
    width: var(--seat-w);
    min-width: 0;
    padding: 0.3rem 0.4rem;
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius);
    background: rgba(8, 4, 10, 0.55);
    color: #ffffff;
    font-size: 0.8rem;
    text-align: center;
    pointer-events: auto;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.opponent .opponent-head,
.opponent .backs {
    flex-basis: 100%;
    justify-content: center;
}

.opponent.is-turn,
.me-head.is-turn {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent);
}

.opponent.is-out {
    opacity: 0.5;
}

.opponent.is-danger .card-count,
.me-head.is-danger .card-count {
    color: #ff8a80;
    font-weight: 700;
}

.opponent-head,
.me-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem 0.4rem;
}

.opponent-name,
.me-name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    max-width: 100%;
}

.opponent .badge,
.me-head .badge {
    font-size: 0.75em;
}

.badge-alert {
    background: var(--primary);
    color: #ffffff;
    border-color: transparent;
    animation: pulse 1.2s ease-in-out infinite;
}

.card-count,
.seat-score {
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.8);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.btn-catch {
    flex-basis: 100%;
    background: #ffb020;
    color: #1b1206;
    border-color: transparent;
    font-weight: 800;
    animation: pulse 0.9s ease-in-out infinite;
}

/* Card backs: one small back per card, overlapping */
.backs {
    display: flex;
    min-height: 1.1rem;
    margin: 0.2rem 0 0.1rem;
}

.back {
    width: 0.75rem;
    height: 1.05rem;
    margin-right: -0.4rem;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background:
        repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0 2px, transparent 2px 5px),
        var(--back);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* The oval felt: opponents round the edge, the piles in the middle */
.felt {
    --seat-w: clamp(4.8rem, 23vw, 8.5rem);
    --seat-anchor: 2.4rem;
    --pile-w: clamp(3.4rem, 13vw, 5.4rem);
    position: relative;
    flex: 1 1 0;
    min-height: 9rem;
    max-height: 34rem;
    border-radius: 42% / 34%;
    border: 3px solid color-mix(in srgb, var(--felt) 60%, #ffffff);
    background:
        radial-gradient(ellipse at center, rgba(255, 255, 255, 0.1), transparent 70%),
        var(--felt);
    color: #ffffff;
    overflow: visible;
}

.piles {
    position: absolute;
    left: 50%;
    top: 50%;
    translate: -50% -50%;
    display: flex;
    align-items: center;
    gap: clamp(0.6rem, 3vw, 1.4rem);
    z-index: 3;
}

.pile {
    position: relative;
    width: var(--pile-w);
    display: grid;
    place-items: center;
}

.draw-pile {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: default;
    -webkit-tap-highlight-color: transparent;
}

.draw-pile .card {
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35), 4px 4px 0 rgba(0, 0, 0, 0.25);
}

.draw-pile.is-active {
    cursor: pointer;
}

.draw-pile.is-active .card {
    box-shadow: 0 0 0 3px var(--focus), 2px 2px 0 rgba(0, 0, 0, 0.35), 4px 4px 0 rgba(0, 0, 0, 0.25);
    animation: nudge 1.6s ease-in-out infinite;
}

.pile-count {
    position: absolute;
    bottom: -1.35rem;
    font-size: 0.72rem;
    white-space: nowrap;
    opacity: 0.8;
}

/* The colour to match glows round the discard pile */
.discard-pile .card {
    transition: box-shadow 0.3s;
}

.discard-pile.glow-R .card { box-shadow: 0 0 0 3px var(--c-R), 0 0 22px var(--c-R); }
.discard-pile.glow-Y .card { box-shadow: 0 0 0 3px var(--c-Y), 0 0 22px var(--c-Y); }
.discard-pile.glow-G .card { box-shadow: 0 0 0 3px var(--c-G), 0 0 22px var(--c-G); }
.discard-pile.glow-B .card { box-shadow: 0 0 0 3px var(--c-B), 0 0 22px var(--c-B); }

/* Direction of play: a dashed ring round the piles that turns the way play goes */
.direction {
    position: absolute;
    inset: -1.6rem -1.4rem;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.22);
    pointer-events: none;
    animation: spin 14s linear infinite;
}

.direction::before {
    content: "";
    position: absolute;
    top: -0.45rem;
    left: 50%;
    border: 0.4rem solid transparent;
    border-left: 0.6rem solid rgba(255, 255, 255, 0.55);
    translate: -30% 0;
}

.direction.is-ccw {
    animation-direction: reverse;
}

.direction.is-ccw::before {
    border-left-color: transparent;
    border-right: 0.6rem solid rgba(255, 255, 255, 0.55);
    border-left-width: 0;
    translate: -70% 0;
}

/* A waiting draw stack */
.stack-badge {
    position: absolute;
    right: -1.2rem;
    top: -1rem;
    z-index: 4;
    min-width: 2.6rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: var(--primary);
    color: #ffffff;
    font-size: clamp(1rem, 4vw, 1.35rem);
    font-weight: 900;
    text-align: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    animation: pulse 1s ease-in-out infinite;
}

.stack-badge[hidden] {
    display: none;
}

/* What just happened: the last few moves, newest at the bottom */
.event-feed {
    position: absolute;
    left: 50%;
    top: calc(50% + var(--pile-w) * 0.85 + 1.6rem);
    translate: -50% 0;
    width: min(70%, 22rem);
    margin: 0;
    padding: 0;
    list-style: none;
    z-index: 2;
    font-size: clamp(0.68rem, 2.6vw, 0.82rem);
    line-height: 1.3;
    text-align: center;
    pointer-events: none;
}

.event-feed li {
    opacity: calc(1 - var(--age, 0) * 0.25);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-feed li.is-mine {
    color: #ffd27a;
}

/* Status line and turn timer, between the table and your hand */
.table-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 2.8em;
}

.status {
    margin: 0;
    text-align: center;
    font-weight: 600;
    line-height: 1.35;
}

.status.is-mine {
    color: var(--focus);
}

.timer {
    width: min(100%, 18rem);
    height: 0.35rem;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}

.timer[hidden] {
    display: none;
}

.timer > span {
    display: block;
    height: 100%;
    background: var(--focus);
    transition: width 0.25s linear;
}

.timer.is-low > span {
    background: #ff7a6b;
}

/* ---------- Cards (drawn with CSS: own design) ----------
   A dark frame, a colour panel, the symbol in a tilted diamond, small marks in two corners. */
.card {
    --c: var(--c-W);
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 5 / 7.4;
    /* The card is its own size container: its children use cqi, but its own box must not
       (cqi here would resolve against the viewport) */
    border-radius: 11% / 7.5%;
    background: #120c16;
    padding: 6%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    line-height: 1;
    user-select: none;
    container-type: inline-size;
}

.card.c-R { --c: var(--c-R); }
.card.c-Y { --c: var(--c-Y); }
.card.c-G { --c: var(--c-G); }
.card.c-B { --c: var(--c-B); }

.card-face {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border-radius: 8cqi;
    background:
        linear-gradient(155deg, rgba(255, 255, 255, 0.28), transparent 45%),
        var(--c);
    overflow: hidden;
}

/* Wild cards: dark panel with the four colours as a ring */
.card.c-W .card-face {
    background:
        radial-gradient(circle at center, #1d1422 0 38%, transparent 39%),
        conic-gradient(from 45deg, var(--c-R) 0 25%, var(--c-Y) 0 50%, var(--c-G) 0 75%, var(--c-B) 0);
}

.card-mark {
    display: grid;
    place-items: center;
    width: 62cqi;
    aspect-ratio: 1;
    rotate: 45deg;
    border-radius: 10cqi;
    background: #120c16;
    box-shadow: inset 0 0 0 3cqi rgba(255, 255, 255, 0.85);
}

.card.c-W .card-mark {
    background: #120c16;
    box-shadow: inset 0 0 0 3cqi #ffffff;
}

.card-mark > .card-sym {
    rotate: -45deg;
    color: var(--c);
    font-size: 38cqi;
    font-weight: 900;
    letter-spacing: -0.05em;
}

.card.c-W .card-mark > .card-sym {
    color: #ffffff;
}

.card-mark > .card-sym.is-draw {
    font-size: 30cqi;
}

.card-sym.is-underlined {
    text-decoration: underline;
    text-decoration-thickness: 3cqi;
    text-underline-offset: 3cqi;
}

.card-sym.card-icon,
.card-sym .card-icon {
    display: grid;
    place-items: center;
}

.card-mark > .card-sym.card-icon svg {
    width: 34cqi;
    height: 34cqi;
}

.card-sym.is-combo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1cqi;
}

.card-mark > .card-sym.is-combo svg {
    width: 20cqi;
    height: 20cqi;
}

.card-mark > .card-sym.is-combo .card-draw {
    font-size: 22cqi;
}

.card-corner {
    position: absolute;
    display: grid;
    place-items: center;
    color: #ffffff;
    font-size: 19cqi;
    font-weight: 900;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.card-corner.is-tl {
    top: 5cqi;
    left: 6cqi;
}

.card-corner.is-br {
    bottom: 5cqi;
    right: 6cqi;
    rotate: 180deg;
}

.card-corner svg {
    width: 20cqi;
    height: 20cqi;
}

.card-corner .card-sym.is-combo {
    flex-direction: row;
    gap: 0;
}

.card-corner .card-sym.is-combo svg {
    width: 14cqi;
    height: 14cqi;
}

.card-corner .card-sym.is-combo .card-draw {
    font-size: 15cqi;
}

/* Card back: the game's own mark on a dark, striped back */
.card.is-back {
    background: #120c16;
}

.card.is-back::before {
    content: "";
    position: absolute;
    inset: 6cqi;
    border-radius: 8cqi;
    background:
        repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.07) 0 4cqi, transparent 4cqi 9cqi),
        var(--back);
}

.back-mark {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46cqi;
    aspect-ratio: 1;
    translate: -50% -50%;
    rotate: 45deg;
    border-radius: 8cqi;
    border: 3cqi solid rgba(255, 255, 255, 0.85);
    background: #120c16;
}

.back-mark::after {
    content: "N";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    rotate: -45deg;
    color: #ffffff;
    font-size: 26cqi;
    font-weight: 900;
}

/* Cards flying from the draw pile to a player */
.fly-ghost {
    position: fixed;
    z-index: 70;
    width: var(--fly-w, 3rem);
    pointer-events: none;
}

/* "+3", "Skip" etc. popping up at a seat */
.seat-bubble {
    position: fixed;
    z-index: 80;
    translate: -50% -50%;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: #ffffff;
    color: #1b1206;
    font-weight: 900;
    font-size: clamp(0.9rem, 3.5vw, 1.2rem);
    pointer-events: none;
    animation: reaction-rise 1.8s ease-out forwards;
}

.seat-bubble.is-draw {
    background: var(--primary);
    color: #ffffff;
}

.seat-bubble.is-call {
    background: #ffb020;
}

/* Your own hand */
.me {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.me-head {
    padding: 0.4rem 0.65rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
}

/* Your hand: overlapping cards. game.js sets --cw (card width) and --step (distance
   between cards) so the hand fits the width; with very many cards it scrolls sideways. */
.hand {
    --cw: 4.5rem;
    --step: 3.3rem;
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 0.9rem 0 0.4rem;
}

/* Many cards on a narrow screen: rows of overlapping cards (the upper row shows its top part) */
.hand.is-rows {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: min(100%, var(--row-w));
    margin-inline: auto;
    padding-right: calc(var(--cw) - var(--step));
    padding-bottom: calc(var(--cw) * 0.55 + 0.4rem);
}

.hand.is-rows .hand-card {
    margin-right: calc(var(--step) - var(--cw));
    margin-bottom: calc(var(--cw) * -0.55);
}

.hand.is-scroll {
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
}

.hand-card {
    flex: none;
    width: var(--cw);
    margin-right: calc(var(--step) - var(--cw));
    padding: 0;
    border: 0;
    background: none;
    border-radius: 11%;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s, opacity 0.15s, filter 0.15s;
}

.hand-card:last-child {
    margin-right: 0;
}

.hand-card:focus-visible {
    z-index: 1;
    transform: translateY(-0.5rem);
}

.hand-card:disabled {
    cursor: default;
}

.hand-card.is-illegal {
    filter: brightness(0.45) saturate(0.6);
}

.hand-card.is-legal {
    transform: translateY(-0.35rem);
}

.hand-card.is-drawn .card {
    box-shadow: 0 0 0 3px var(--focus), 0 6px 14px rgba(0, 0, 0, 0.35);
}

@media (hover: hover) {
    .hand-card:not(:disabled):hover {
        transform: translateY(-0.9rem);
        z-index: 2;
    }
}

.hand-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--tap);
}

.hand-actions .btn {
    flex: 1 1 8rem;
    max-width: 14rem;
}

.btn-danger {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.btn-call {
    background: #ffb020;
    border-color: #ffb020;
    color: #1b1206;
    font-weight: 800;
}

.btn-call.is-called {
    background: transparent;
    color: #ffb020;
}

/* Error / connection message */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom) + 1rem);
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 2rem);
    margin: 0;
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    background: #2b1720;
    color: #ffffff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.toast[hidden] {
    display: none;
}

/* Overlays: pickers, knock-outs, round and game results */
.overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
    background: rgba(12, 6, 14, 0.62);
    z-index: 20;
}

.overlay[hidden] {
    display: none;
}

.overlay.picker {
    z-index: 85;
}

.picker-panel {
    width: min(100%, 24rem);
    text-align: center;
}

.picker-panel h2 {
    margin-top: 0;
}

.picker-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
    margin: 1rem 0 0.5rem;
}

.picker-grid .pick-player {
    grid-column: 1 / -1;
}

.pick-color {
    min-height: 4rem;
    border: 0;
    color: #ffffff;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.pick-color.c-R { background: var(--c-R); }
.pick-color.c-Y { background: var(--c-Y); color: #2a1c00; text-shadow: none; }
.pick-color.c-G { background: var(--c-G); }
.pick-color.c-B { background: var(--c-B); }

.overlay.mercy {
    z-index: 75;
    pointer-events: none;
    text-align: center;
    color: #ffffff;
    align-content: center;
}

.mercy p {
    margin: 0;
}

.mercy-icon {
    font-size: clamp(5rem, 22vw, 9rem);
    animation: mercy-pop 0.7s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.mercy-title {
    font-size: var(--fs-h1);
    font-weight: 900;
    color: var(--primary);
    letter-spacing: 0.02em;
}

.mercy-text {
    font-size: var(--fs-h2);
}

.result-panel {
    width: min(100%, 26rem);
    max-height: 100%;
    overflow-y: auto;
    text-align: center;
}

.result-panel h2 {
    margin-top: 0;
}

.result-winner {
    font-size: 1.2em;
    font-weight: 700;
}

.result-list {
    list-style: none;
    margin: 1rem 0 1.5rem;
    padding: 0;
    text-align: left;
}

.result-list li {
    display: grid;
    grid-template-columns: 2.2rem 1fr auto;
    gap: 0.5rem;
    align-items: center;
    padding: 0.55rem 0.25rem;
    border-bottom: 1px solid var(--border);
}

.result-list li.is-me {
    font-weight: 700;
}

.result-place,
.result-points {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.result-panel .btn {
    width: 100%;
}

@keyframes mercy-pop {
    from { transform: scale(0.2) rotate(-40deg); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

@keyframes nudge {
    0%, 100% { translate: 0 0; }
    50%      { translate: 0 -0.25rem; }
}

@keyframes spin {
    to { rotate: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
    .direction,
    .badge-alert,
    .btn-catch,
    .stack-badge,
    .draw-pile.is-active .card {
        animation: none;
    }
}

/* Short screens: seats become compact, without card backs */
@media (max-height: 760px) {
    .felt {
        --seat-anchor: 1.5rem;
    }
    .opponent {
        gap: 0 0.3rem;
        padding: 0.15rem 0.35rem;
    }
    .opponent .opponent-head {
        flex-basis: auto;
    }
    .opponent .backs {
        display: none;
    }
    .event-feed li:nth-last-child(n + 3) {
        display: none;
    }
}

/* Phones in landscape: little height, so the hand goes next to the felt */
@media (orientation: landscape) and (max-height: 500px) {
    .is-game .site-header {
        padding-top: calc(env(safe-area-inset-top) + 0.25rem);
        padding-bottom: 0.25rem;
    }
    .game {
        display: grid;
        grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "bar bar"
            "felt status"
            "felt me";
        gap: 0.4rem 0.75rem;
    }
    .game-bar     { grid-area: bar; }
    .felt         { grid-area: felt; min-height: 0; max-height: none; --seat-w: clamp(4.4rem, 11vw, 6.5rem); --pile-w: clamp(2.6rem, 7vw, 3.4rem); }
    .table-status { grid-area: status; }
    .me           { grid-area: me; gap: 0.4rem; }
    .backs        { display: none; }
    .opponent     { padding: 0.2rem 0.35rem; }
    .event-feed   { display: none; }
    .hand         { padding-top: 0.6rem; }
    .game-bar .btn-small { min-height: 2.25rem; }
}

/* Tablet and computer: a wider oval, bigger seats and piles */
@media (min-width: 768px) and (min-height: 501px) {
    .felt {
        max-height: 38rem;
        border-radius: 50% / 45%;
        --seat-w: clamp(6.5rem, 14vw, 10rem);
        --pile-w: clamp(4.4rem, 7vw, 6.2rem);
    }
    .opponent {
        font-size: 0.9rem;
    }
}

/* Wide but short screens (a 1366 x 768 laptop): the hand goes next to the table */
@media (min-width: 1100px) and (max-height: 820px) and (min-aspect-ratio: 3/2) {
    .game {
        display: grid;
        grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "bar bar"
            "felt status"
            "felt me";
        gap: 0.6rem 1.5rem;
        max-width: 84rem;
    }
    .game-bar     { grid-area: bar; }
    .felt {
        grid-area: felt;
        min-height: 0;
        max-height: none;
    }
    .table-status { grid-area: status; }
    .me           { grid-area: me; }
}

/* Create form: house rules as checkboxes */
.field-checks {
    border: 0;
    padding: 0;
    margin: 0 0 1rem;
}

.field-checks legend {
    margin-bottom: 0.4rem;
    font-weight: 600;
}

.check {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    min-height: var(--tap);
    padding: 0.35rem 0;
    cursor: pointer;
}

.check input {
    width: 1.3rem;
    height: 1.3rem;
    margin-top: 0.15rem;
    accent-color: var(--primary);
    flex: none;
}

/* Results page: tiles and a few narrow table columns – keep it readable on wide screens */
.results-page {
    max-width: 46rem;
    margin-inline: auto;
}

/* Settings: avatar picker (a grid of emoji radio buttons) */
.avatar-field {
    margin: 0 0 1rem;
    padding: 0;
    border: 0;
}

.avatar-field legend {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--tap), 1fr));
    gap: 0.35rem;
}

.avatar-choice {
    position: relative;
    display: block;
}

.avatar-choice input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
}

.avatar-choice span {
    display: grid;
    place-items: center;
    min-height: var(--tap);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.5rem;
    line-height: 1;
}

.avatar-choice input:checked + span {
    border-color: var(--focus);
    background: rgba(242, 182, 50, 0.12);
}

.avatar-choice input:focus-visible + span {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

/* Result screen: "Play again" form above the lobby link */
.rematch-form {
    margin: 0 0 0.75rem;
}

.rematch-form .field-hint {
    margin-top: 0.4rem;
    font-size: 0.85em;
}

/* First-time guide on the game table (above the result overlays) */
.overlay.guide {
    z-index: 95;
}

.guide-panel {
    width: min(100%, 26rem);
    text-align: center;
}

.guide-panel h2 {
    margin-top: 0;
}

.guide-step {
    margin: 0 0 0.5rem;
    color: var(--muted);
    font-size: 0.9em;
}

.guide-text {
    min-height: 4.5em;
    margin: 0 0 1.25rem;
    line-height: 1.5;
}

.guide-panel .btn {
    width: 100%;
}

.guide-panel .btn-link {
    margin-top: 0.5rem;
}

/* Round history overlay */
.overlay.history {
    z-index: 95;
}

.history-panel {
    width: min(100%, 26rem);
    max-height: 100%;
    overflow-y: auto;
}

.history-panel h2 {
    margin-top: 0;
    text-align: center;
}

.history-rounds {
    list-style: none;
    margin: 0 0 1.25rem;
    padding: 0;
}

.history-rounds li {
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--border);
}

.history-rounds li.is-me .history-text {
    color: var(--focus);
    font-weight: 600;
}

.history-round {
    flex: none;
    min-width: 4.5rem;
    color: var(--muted);
}

.history-panel .btn {
    width: 100%;
}

/* ---------- Admin (/admin, site owner only) ---------- */

.admin-page h1,
.admin-page h2 {
    margin-top: 0;
}

.admin-page h1 {
    font-size: var(--fs-h2);
}

/* Wide tables scroll sideways inside their box on phones instead of breaking every word */
.admin-table {
    min-width: 40rem;
}

.admin-table td {
    vertical-align: middle;
}

.admin-table .name {
    overflow-wrap: normal;
}

.admin-table .email {
    overflow-wrap: anywhere;
    color: var(--muted);
}

.admin-table form {
    margin: 0;
}

.admin-result {
    margin: 0 0 1rem;
    padding-left: 1.2rem;
}

.admin-log {
    max-height: 24rem;
    overflow: auto;
    margin: 0 0 1rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.25);
    font-size: 0.8em;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ---------- Open games list, direct invites ---------- */

.open-game {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--tap);
    padding: 0.5rem 0.25rem;
}

.open-game-icon {
    flex: none;
    font-size: 1.35em;
    line-height: 1;
}

.open-game-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.open-game-host {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.open-game > .btn,
.open-game > .badge,
.open-game > .open-game-code {
    flex: none;
}

/* Private game: "Enter code" opens a code field below the row's text */
.open-game { flex-wrap: wrap; }

.open-game-code summary {
    list-style: none;
    cursor: pointer;
}

.open-game-code summary::-webkit-details-marker { display: none; }

.open-game-code[open] {
    flex: 1 1 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.open-game-code-form {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.open-game-code-form .code-input {
    flex: 1;
    min-width: 0;
    min-height: var(--tap);
    padding: 0.4em 0.6em;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--bg, #121815);
    color: var(--text);
    font: inherit;
}

.open-game-code-form .btn {
    flex: none;
}

.open-game.is-full {
    opacity: 0.6;
}

.room-visibility {
    margin-top: 0.75rem !important;
}

.invite-user {
    max-width: 28rem;
    margin: 1rem auto 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: left;
}

.invite-user label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.invite-user-row {
    margin: 0;
    display: flex;
    gap: 0.5rem;
}

.invite-user-row input {
    flex: 1;
    min-width: 0;
}

.invite .invite-user-row .btn {
    min-width: var(--tap);
    flex: none;
}

.invite-user-msg {
    margin: 0.5rem 0 0;
}

.invited-list {
    margin: 0.5rem 0 0;
    overflow-wrap: anywhere;
}

/* Badge with the number of invites on the username in the header */
.invite-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4em;
    height: 1.4em;
    padding-inline: 0.35em;
    border-radius: 999px;
    background: var(--focus);
    color: #1a1a1a;
    font-size: 0.8em;
    font-weight: 700;
    line-height: 1;
}

.invite-badge[hidden] {
    display: none;
}

.user-menu-invites {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
    padding: 0.25rem 0.25rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.user-menu-heading {
    margin: 0.25rem 0.5rem 0;
    color: var(--muted);
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.invite-item {
    padding: 0.5rem;
    border: 1px solid rgba(242, 182, 50, 0.45);
    border-radius: calc(var(--radius) - 2px);
    background: rgba(242, 182, 50, 0.08);
    white-space: normal;
}

.invite-item-text {
    display: flex;
    flex-direction: column;
    margin: 0 0 0.4rem;
    overflow-wrap: anywhere;
}

.invite-item-actions {
    display: flex;
    gap: 0.4rem;
}

.invite-item-actions form {
    margin: 0;
}

.user-menu-panel:has(.invite-item) {
    width: min(19rem, calc(100vw - 2 * var(--gutter)));
}

.invite-user-msg.is-error {
    color: #e0675a;
}

/* A new invite arrived: the badge pulses a few times */
.invite-badge.is-new {
    animation: invite-pulse 0.9s ease-in-out 3;
}

@keyframes invite-pulse {
    50% { transform: scale(1.35); }
}

@media (prefers-reduced-motion: reduce) {
    .invite-badge.is-new {
        animation: none;
    }
}
