:root {
    --bg: #fbf7ec;
    --ink: #24170d;
    --muted: #6f6258;
    --table: #1d6b4f;
    --table-dark: #14513b;
    --wood: #9a5b2c;
    --card: #fffaf0;
    --accent: #d36b2d;
    --accent-dark: #a94816;
    --danger: #b91c1c;
    --shadow: 0 24px 80px rgba(46, 25, 10, 0.18);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: radial-gradient(circle at top, #fff9e8, var(--bg));
}

button, input, a { font: inherit; }
button, a.small-button { border: 0; cursor: pointer; text-decoration: none; }
[hidden] { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.home-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.big-button,
.big-draw-button {
    padding: 26px 38px;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    font-size: clamp(1.35rem, 4vw, 2.4rem);
    font-weight: 900;
    box-shadow: var(--shadow);
    transform: translateY(0);
    transition: transform 160ms ease, background 160ms ease;
}

.big-button:hover,
.big-draw-button:hover,
.small-button:hover { transform: translateY(-2px); }
.big-button:active,
.big-draw-button:active,
.small-button:active { transform: translateY(1px); }

.small-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
    box-shadow: 0 10px 24px rgba(46, 25, 10, 0.12);
    transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.small-button.secondary { background: var(--table); }
.small-button.ghost { background: rgba(36, 23, 13, 0.08); color: var(--ink); }
.small-button:disabled,
.big-draw-button:disabled { opacity: .55; cursor: not-allowed; }

.game-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 22px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 18px;
}

.topbar h1 { margin: 0; font-size: clamp(2rem, 5vw, 4rem); line-height: 1; }
.topbar p { margin: 6px 0 0; color: var(--muted); font-weight: 700; }

.table-wrap {
    min-height: min(76vh, 740px);
    display: grid;
    place-items: center;
}

.round-table {
    position: relative;
    width: min(88vw, 760px);
    aspect-ratio: 1;
    border-radius: 50%;
    background:
        radial-gradient(circle at center, var(--table) 0 58%, var(--table-dark) 59% 62%, var(--wood) 63% 70%, #6f3d1f 71% 100%);
    box-shadow: var(--shadow), inset 0 0 30px rgba(0,0,0,.18);
}

.center-card {
    position: absolute;
    inset: 28%;
    min-width: 250px;
    display: grid;
    place-items: center;
    align-content: center;
    text-align: center;
    padding: 22px;
    border-radius: 28px;
    background: rgba(255, 250, 240, .96);
    box-shadow: 0 14px 40px rgba(0,0,0,.18);
}

.center-card h2 { margin: 0 0 8px; font-size: clamp(1.25rem, 3vw, 2rem); }
.center-card p { margin: 0 0 16px; color: var(--muted); font-weight: 700; }

.join-form { width: 100%; display: grid; gap: 10px; }
.join-form label { font-weight: 900; }
.join-row { display: flex; gap: 8px; }
.join-row input {
    min-width: 0;
    width: 100%;
    border: 2px solid rgba(36, 23, 13, .16);
    border-radius: 999px;
    padding: 12px 14px;
    background: white;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.message {
    min-height: 24px;
    margin-top: 12px;
    color: var(--danger);
    font-weight: 800;
}

.player-seat {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 112px;
    min-height: 88px;
    margin-left: -56px;
    margin-top: -44px;
    transform: rotate(var(--angle)) translateY(calc(-1 * min(42vw, 365px))) rotate(calc(-1 * var(--angle)));
    display: grid;
    place-items: center;
    gap: 4px;
    padding: 8px;
    border-radius: 18px;
    background: rgba(255, 250, 240, .94);
    box-shadow: 0 10px 28px rgba(0,0,0,.16);
    text-align: center;
}

.player-seat .avatar { font-size: 2rem; line-height: 1; }
.player-seat .name { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 900; }
.player-seat.active { outline: 4px solid #ffd166; }
.player-seat.loser { outline: 5px solid var(--danger); }
.player-seat.me::after {
    content: "toi";
    position: absolute;
    top: -10px;
    right: -8px;
    padding: 3px 7px;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    font-size: .75rem;
    font-weight: 900;
}

.poop-badge {
    display: none;
    position: absolute;
    right: -16px;
    top: -30px;
    font-size: 3rem;
    filter: drop-shadow(0 8px 12px rgba(0,0,0,.25));
}

.player-seat.loser .poop-badge,
.player-seat.crotte-pop .poop-badge {
    display: block;
    animation: poop-pop 650ms cubic-bezier(.2, 1.55, .45, 1) both;
}

@keyframes poop-pop {
    from { opacity: 0; transform: translateY(18px) scale(.25) rotate(-18deg); }
    to { opacity: 1; transform: translateY(0) scale(1) rotate(8deg); }
}

.deck-zone {
    display: grid;
    justify-items: center;
    gap: 8px;
    margin: 0 auto 14px;
}

.deck-stack {
    width: clamp(58px, 12vw, 82px);
    height: clamp(82px, 17vw, 112px);
    border-radius: 12px;
    display: grid;
    place-items: center;
    background:
        linear-gradient(135deg, rgba(255,255,255,.24), transparent 45%),
        repeating-linear-gradient(45deg, #d36b2d 0 9px, #a94816 9px 18px);
    color: white;
    border: 3px solid rgba(255,250,240,.95);
    box-shadow:
        5px 5px 0 rgba(255,250,240,.72),
        10px 10px 0 rgba(255,250,240,.36),
        0 12px 28px rgba(0,0,0,.22);
    font-size: clamp(.72rem, 2.2vw, .9rem);
    font-weight: 1000;
    letter-spacing: .05em;
    text-align: center;
}

.deck-count {
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(36, 23, 13, .08);
    color: var(--muted);
    font-weight: 900;
    font-size: clamp(.78rem, 2.4vw, .95rem);
}

.flying-card,
.table-card {
    width: 92px;
    height: 128px;
    border-radius: 12px;
    background: white;
    color: #151515;
    display: grid;
    place-items: center;
    box-shadow: 0 14px 34px rgba(0,0,0,.22);
    border: 2px solid rgba(0,0,0,.08);
    font-weight: 1000;
}

.table-card {
    margin: 0 auto 12px;
    font-size: 2.2rem;
}

.card-inner {
    display: grid;
    place-items: center;
    gap: 2px;
}

.card-rank { font-size: 2.1rem; line-height: 1; }
.card-suit { font-size: 2.7rem; line-height: 1; }

/* Important: color both the animated container and the nested card content. */
.flying-card.red,
.flying-card.red .card-inner,
.table-card.red,
.table-card.red .card-inner,
.card-inner.red {
    color: #b91c1c !important;
}

.flying-card {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 20;
    transform: translate(-50%, -50%) scale(.6) rotate(-8deg);
    animation: fly-card 650ms ease forwards;
}

@keyframes fly-card {
    to {
        left: var(--target-x);
        top: var(--target-y);
        transform: translate(-50%, -50%) scale(1) rotate(4deg);
    }
}

.flying-card.crotte-card {
    animation: fly-card-crotte 1500ms ease-in-out forwards;
    z-index: 40;
}

@keyframes fly-card-crotte {
    0% { transform: translate(-50%, -50%) scale(.6) rotate(-8deg); }
    45% { left: 50%; top: 42%; transform: translate(-50%, -50%) scale(1.45) rotate(0deg); }
    65% { left: 50%; top: 42%; transform: translate(-50%, -50%) scale(1.45) rotate(0deg); }
    100% { left: var(--target-x); top: var(--target-y); transform: translate(-50%, -50%) scale(1) rotate(4deg); }
}

.taunt {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 18px;
    background: rgba(185, 28, 28, .10);
    color: var(--danger);
    font-size: clamp(1rem, 3vw, 1.35rem);
    font-weight: 1000;
    max-width: min(64vw, 360px);
    text-align: center;
    opacity: 0;
    transform: translateY(6px) scale(.98);
    transition: opacity 450ms ease, transform 450ms ease;
    pointer-events: none;
}

.taunt.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.taunt.fading {
    opacity: 0;
    transform: translateY(8px) scale(.98);
}

.panel {
    background: rgba(255,250,240,.86);
    border: 1px solid rgba(36, 23, 13, .10);
    border-radius: 24px;
    padding: 18px;
    box-shadow: 0 12px 30px rgba(46, 25, 10, 0.08);
}

.draw-log { margin-top: 22px; }
.draw-log h2 { margin: 0 0 8px; }
.draw-log ol { margin: 0; padding-left: 24px; display: grid; gap: 6px; }

@media (max-width: 720px) {
    body { overflow-x: hidden; }
    .game-shell { padding: 10px; }
    .topbar {
        position: sticky;
        top: 0;
        z-index: 10;
        padding: 8px 0;
        margin-bottom: 10px;
        align-items: flex-start;
        background: linear-gradient(to bottom, var(--bg), rgba(251,247,236,.86));
        backdrop-filter: blur(8px);
    }
    .topbar h1 { font-size: clamp(1.65rem, 10vw, 2.5rem); }
    .topbar p { font-size: .85rem; }
    .topbar .small-button { padding: 9px 12px; font-size: .88rem; white-space: nowrap; }
    .table-wrap { min-height: auto; padding: 8px 0 10px; }
    .round-table { width: min(96vw, 430px); min-width: 310px; }
    .center-card { inset: 27%; min-width: 0; padding: 10px; border-radius: 20px; }
    .center-card h2 { margin-bottom: 4px; font-size: clamp(1rem, 4.8vw, 1.35rem); }
    .center-card p { margin-bottom: 10px; font-size: .86rem; }
    .join-form { gap: 7px; }
    .join-form label { font-size: .86rem; }
    .join-row { flex-direction: column; }
    .join-row input { padding: 10px 12px; }
    .small-button { padding: 10px 12px; font-size: .9rem; }
    .big-draw-button { padding: 14px 18px; font-size: clamp(1rem, 5vw, 1.3rem); }
    .actions { gap: 7px; }
    .player-seat {
        width: clamp(62px, 19vw, 78px);
        min-height: clamp(58px, 17vw, 68px);
        margin-left: calc(clamp(62px, 19vw, 78px) / -2);
        margin-top: calc(clamp(58px, 17vw, 68px) / -2);
        padding: 6px;
        border-radius: 14px;
        transform: rotate(var(--angle)) translateY(calc(-1 * min(42vw, 185px))) rotate(calc(-1 * var(--angle)));
    }
    .player-seat .avatar { font-size: 1.35rem; }
    .player-seat .name { max-width: 58px; font-size: .74rem; }
    .player-seat.me::after { font-size: .62rem; top: -8px; right: -8px; }
    .player-seat.active { outline-width: 3px; }
    .player-seat.loser { outline-width: 4px; }
    .poop-badge { font-size: 2.2rem; right: -13px; top: -25px; }
    .flying-card,
    .table-card { width: clamp(58px, 17vw, 76px); height: clamp(82px, 24vw, 104px); border-radius: 10px; }
    .table-card { margin-bottom: 8px; }
    .card-rank { font-size: clamp(1.1rem, 5vw, 1.55rem); }
    .card-suit { font-size: clamp(1.6rem, 7vw, 2.2rem); }
    .draw-log { margin-top: 10px; }
    .panel { border-radius: 18px; padding: 14px; }
    .draw-log ol { max-height: 35vh; overflow: auto; }
}

@media (max-width: 390px) {
    .round-table { width: 96vw; min-width: 0; }
    .center-card { inset: 29%; padding: 8px; }
    .center-card h2 { font-size: .98rem; }
    .center-card p,
    .deck-count,
    .message { font-size: .74rem; }
    .small-button { padding: 9px 10px; font-size: .78rem; }
    .player-seat {
        width: 58px;
        min-height: 54px;
        margin-left: -29px;
        margin-top: -27px;
        transform: rotate(var(--angle)) translateY(calc(-1 * min(42vw, 164px))) rotate(calc(-1 * var(--angle)));
    }
    .player-seat .avatar { font-size: 1.15rem; }
    .player-seat .name { max-width: 48px; font-size: .66rem; }
}


/* --- Responsive table/layout patch --- */
.round-table {
    isolation: isolate;
}

.center-card {
    inset: auto;
    left: 50%;
    top: 50%;
    width: min(44%, 340px);
    min-width: 250px;
    max-width: calc(100% - 190px);
    min-height: 180px;
    transform: translate(-50%, -50%);
    z-index: 6;
    overflow-wrap: anywhere;
}

.center-subtitle {
    width: 100%;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.center-card .small-button,
.center-card .big-draw-button {
    max-width: 100%;
    white-space: normal;
    text-align: center;
}

.deck-zone {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 4;
    margin: 0;
    pointer-events: none;
}

.round-table.status-waiting .deck-zone {
    display: none;
}

.round-table.status-playing .center-card,
.round-table.status-finished .center-card {
    top: 30%;
    min-height: 130px;
}

.round-table.status-playing .deck-zone,
.round-table.status-finished .deck-zone {
    top: 58%;
}

.player-seat .mini-poop {
    display: none !important;
}

.draw-log ol[reversed] {
    list-style-position: outside;
}

@media (max-width: 720px) {
    .center-card {
        width: min(62vw, 270px);
        min-width: 0;
        max-width: calc(100% - 140px);
        min-height: 136px;
        padding: 10px;
        gap: 4px;
    }

    .round-table.status-waiting .center-card {
        width: min(58vw, 250px);
        max-width: calc(100% - 130px);
        min-height: 148px;
    }

    .round-table.status-playing .center-card,
    .round-table.status-finished .center-card {
        top: 29%;
        width: min(50vw, 220px);
        min-height: 108px;
        padding: 8px;
    }

    .round-table.status-playing .deck-zone,
    .round-table.status-finished .deck-zone {
        top: 59%;
    }

    .center-card .actions {
        gap: 6px;
    }

    .center-card .small-button {
        padding: 8px 10px;
        font-size: clamp(.72rem, 3.4vw, .9rem);
        line-height: 1.15;
    }

    .center-card h2 {
        line-height: 1.12;
    }

    .center-card p,
    .center-subtitle,
    .message {
        font-size: clamp(.72rem, 3.4vw, .86rem);
        line-height: 1.22;
    }

    .deck-stack {
        width: clamp(52px, 15vw, 72px);
        height: clamp(72px, 21vw, 98px);
    }
}

@media (max-width: 390px) {
    .center-card,
    .round-table.status-waiting .center-card {
        width: 58vw;
        max-width: calc(100% - 112px);
        min-height: 128px;
        padding: 7px;
    }

    .round-table.status-playing .center-card,
    .round-table.status-finished .center-card {
        width: 48vw;
        min-height: 96px;
    }

    .center-card .small-button {
        padding: 7px 8px;
        font-size: .72rem;
    }

    .join-row input {
        padding: 8px 10px;
        font-size: .78rem;
    }
}

/* --- In-game table cleanup: no center card while cards are being drawn --- */
.round-table.status-playing .center-card,
.round-table.status-finished .center-card,
.center-card[hidden] {
    display: none !important;
}

.round-table.status-playing .deck-zone,
.round-table.status-finished .deck-zone {
    top: 50%;
    z-index: 8;
    pointer-events: auto;
}

.deck-actions {
    margin-top: 10px;
    pointer-events: auto;
}

.deck-actions[hidden] {
    display: none !important;
}

.deck-actions .big-draw-button {
    box-shadow: 0 12px 30px rgba(46, 25, 10, .28);
}

@media (max-width: 720px) {
    .round-table.status-playing .deck-zone,
    .round-table.status-finished .deck-zone {
        top: 50%;
    }

    .deck-actions {
        margin-top: 8px;
    }

    .deck-actions .big-draw-button {
        width: min(58vw, 230px);
        padding: 12px 14px;
        line-height: 1.1;
    }
}

@media (max-width: 390px) {
    .deck-actions .big-draw-button {
        width: min(62vw, 210px);
        font-size: .96rem;
    }
}

/* --- Latest drawn card stays visible on the drawer --- */
.player-seat {
    z-index: 9;
}

.seat-card {
    display: none;
    position: absolute;
    left: 50%;
    top: 100%;
    width: 48px;
    height: 66px;
    transform: translate(-50%, -12px) rotate(3deg);
    border-radius: 8px;
    background: #fff;
    color: #151515;
    border: 1px solid rgba(0,0,0,.12);
    box-shadow: 0 8px 18px rgba(0,0,0,.24);
    place-items: center;
    font-weight: 1000;
    z-index: 12;
    pointer-events: none;
}

.player-seat.has-last-card .seat-card {
    display: grid;
}

.seat-card.red,
.seat-card.red .card-inner,
.seat-card .card-inner.red {
    color: #b91c1c !important;
}

.seat-card .card-rank {
    font-size: 1rem;
}

.seat-card .card-suit {
    font-size: 1.35rem;
}

/* Start the animation from the real deck position. */
.flying-card {
    left: var(--start-x, 50%);
    top: var(--start-y, 50%);
}

.deck-zone .taunt {
    max-width: min(72vw, 320px);
    margin-top: 8px;
    padding: 8px 12px;
    text-align: center;
    background: rgba(255, 250, 240, .92);
    box-shadow: 0 8px 22px rgba(0,0,0,.16);
}

@media (max-width: 720px) {
    .seat-card {
        width: 38px;
        height: 52px;
        border-radius: 7px;
        transform: translate(-50%, -8px) rotate(3deg);
    }
    .seat-card .card-rank { font-size: .82rem; }
    .seat-card .card-suit { font-size: 1.05rem; }
    .deck-zone .taunt {
        max-width: min(66vw, 260px);
        font-size: clamp(.72rem, 3.2vw, .9rem);
        line-height: 1.15;
    }
}

/* --- Public statistics page --- */
.stats-home-link {
    display: inline-flex;
    margin-top: 18px;
    color: var(--muted);
    font-weight: 900;
    text-decoration: none;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.stats-shell {
    max-width: 1120px;
}

.stats-topbar p {
    max-width: 620px;
}

.stats-grid {
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
}

.summary-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
    min-height: 118px;
    padding: 18px;
    border-radius: 24px;
    background: rgba(255,250,240,.9);
    border: 1px solid rgba(36, 23, 13, .10);
    box-shadow: 0 12px 30px rgba(46, 25, 10, 0.08);
    display: grid;
    align-content: space-between;
    gap: 14px;
}

.stat-card span,
.stats-note {
    color: var(--muted);
    font-weight: 800;
}

.stat-card strong {
    font-size: clamp(1.35rem, 3vw, 2.2rem);
    line-height: 1;
}

.stats-section {
    margin-bottom: 18px;
}

.stats-section h2,
.empty-stats h2 {
    margin: 0 0 8px;
    font-size: clamp(1.4rem, 3vw, 2rem);
}

.stats-note {
    margin: 0 0 14px;
}

.stats-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.stats-table th,
.stats-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid rgba(36, 23, 13, .10);
    vertical-align: top;
}

.stats-table th {
    color: var(--muted);
    font-size: .86rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stats-table td:first-child {
    font-weight: 900;
}

.stats-list {
    margin: 0;
    padding-left: 24px;
    display: grid;
    gap: 10px;
}

.stats-list li {
    padding: 10px 0;
    border-bottom: 1px solid rgba(36, 23, 13, .08);
}

.stats-list li:last-child {
    border-bottom: 0;
}

.stats-list strong,
.stats-list span {
    display: block;
}

.stats-list span {
    color: var(--muted);
    font-weight: 800;
    margin-top: 2px;
}

@media (max-width: 980px) {
    .summary-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .topbar-actions {
        gap: 6px;
    }

    .summary-grid,
    .two-col {
        grid-template-columns: 1fr;
    }

    .stat-card {
        min-height: 92px;
    }
}
