* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --felt: #10402f;
    --felt-dark: #0a2a1f;
    --gold: #f4c76b;
    --gold-dim: #b6904a;
    --ink: #1d2430;
    --red: #d0342c;
    --card: #fbf8f1;
    --text: #eaf2ec;
    --muted: #8fae9f;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--felt-dark);
    color: var(--text);
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    /* The seats and the played cards are pinned to the sides of this box, so on
       a desktop without a cap they end up at opposite ends of the screen with
       the table empty between them. */
    max-width: 720px;
    margin: 0 auto;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background:
        radial-gradient(ellipse at 50% 30%, #17543d 0%, var(--felt) 45%, var(--felt-dark) 100%);
}

/* ---------- toolbar ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    flex: 0 0 auto;
}
.spacer { flex: 1; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid rgba(244, 199, 107, 0.28);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.24);
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.icon-btn:active { background: rgba(0, 0, 0, 0.4); }
.icon-btn-text { font-size: 14px; }
.stakes {
    font-size: 12px;
    color: var(--muted);
    padding-right: 4px;
}
.stakes b { color: var(--gold); font-size: 15px; margin-left: 2px; }

/* ---------- table ---------- */
.table {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

.bottom-cards {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    z-index: 3;
}

.seats { position: absolute; inset: 0; pointer-events: none; }
.seat {
    position: absolute;
    top: 54px;
    width: 76px;
    text-align: center;
}
.seat-left { left: 8px; }
.seat-right { right: 8px; }
.avatar {
    position: relative;
    width: 46px;
    height: 46px;
    margin: 0 auto;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(244, 199, 107, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}
.seat.is-turn .avatar {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(244, 199, 107, 0.22);
}
.crown {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 15px;
    display: none;
}
.seat.is-landlord .crown { display: block; }
.seat-name { font-size: 11px; color: var(--muted); margin-top: 3px; }
.seat-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 20px;
    margin-top: 2px;
    padding: 0 6px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.42);
    font-size: 12px;
    font-weight: 700;
    color: var(--gold);
}
.seat-status {
    height: 18px;
    margin-top: 3px;
    font-size: 12px;
    font-weight: 700;
    color: var(--gold);
}

/* played cards on the table */
.played {
    position: absolute;
    display: flex;
    align-items: center;
    min-height: 58px;
}
/* 52% rather than centred: on a 640px-tall phone the table is short enough
   that a centred row runs into the seat badges above it. */
.played-left { top: 52%; left: 82px; transform: translateY(-50%); }
.played-right { top: 52%; right: 82px; transform: translateY(-50%); flex-direction: row-reverse; }
.played-self { bottom: 4px; left: 50%; transform: translateX(-50%); }

.pass-tag {
    padding: 5px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(244, 199, 107, 0.3);
    color: var(--gold);
    font-size: 13px;
    font-weight: 700;
}

.banner {
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    padding: 8px 20px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.66);
    border: 1px solid var(--gold);
    color: var(--gold);
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 2px;
    opacity: 0;
    pointer-events: none;
    z-index: 6;
    white-space: nowrap;
}
.banner.show { animation: pop 1.1s ease forwards; }
@keyframes pop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
    18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
    72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- cards ---------- */
.card {
    position: relative;
    width: 42px;
    height: 58px;
    border-radius: 5px;
    background: var(--card);
    color: var(--ink);
    border: 1px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    flex: 0 0 auto;
    overflow: hidden;
}
.card.red { color: var(--red); }
.card .corner {
    position: absolute;
    top: 2px;
    left: 3px;
    line-height: 1;
    font-weight: 800;
    font-family: "Helvetica Neue", Arial, sans-serif;
}
.card .corner .r { display: block; font-size: 14px; }
.card .corner .s { display: block; font-size: 11px; margin-top: -1px; }
.card .pip {
    position: absolute;
    right: 3px;
    bottom: 2px;
    font-size: 17px;
    line-height: 1;
    opacity: 0.9;
}
.card.joker .corner .r { font-size: 11px; letter-spacing: -0.5px; }
.card.back {
    background: repeating-linear-gradient(45deg, #1d4f7a 0 5px, #17416a 5px 10px);
    border-color: rgba(0, 0, 0, 0.4);
}
.played .card, .bottom-cards .card {
    box-shadow: -1px 0 0 rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.4);
}
.card.small { width: 30px; height: 42px; }
.card.small .corner .r { font-size: 11px; }
.card.small .corner .s { font-size: 8px; }
.card.small .pip { font-size: 12px; }

/* ---------- my hand ---------- */
.me { flex: 0 0 auto; padding: 0 8px; }
.me-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 20px;
    font-size: 12px;
    color: var(--muted);
}
.me-role { color: var(--gold); font-weight: 700; }
.me-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 18px;
    padding: 0 6px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.4);
    color: var(--gold);
    font-weight: 700;
}
.hand {
    position: relative;
    height: 92px;
    margin-top: 2px;
    touch-action: none;
}
.hand .card {
    position: absolute;
    bottom: 0;
    transition: transform 0.14s ease;
    cursor: pointer;
    /* Overlapped cards need a visible left edge or a full hand reads as one
       white bar rather than seventeen separate cards. */
    box-shadow: -1px 0 0 rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
}
.hand .card.picked { transform: translateY(-20px); }
.hand .card.picked::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 4px;
    box-shadow: inset 0 0 0 2px var(--gold);
}
.hand .card.hintable { box-shadow: 0 0 0 2px rgba(244, 199, 107, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4); }

/* ---------- actions ---------- */
.actions {
    flex: 0 0 auto;
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
}
.action-row { display: flex; gap: 8px; justify-content: center; }
/* An author `display` beats the browser's own rule for the hidden attribute,
   so both button rows showed at once until this was spelled out. */
[hidden] { display: none !important; }
.btn {
    min-height: 46px;
    padding: 0 18px;
    border: 1px solid rgba(244, 199, 107, 0.35);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    flex: 1 1 0;
    max-width: 140px;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(180deg, #f0c66c, #d09b34);
    border-color: #f5d489;
    color: #3a2606;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-wide { max-width: none; width: 100%; margin-top: 8px; }
.action-hint {
    height: 16px;
    margin-top: 5px;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
}

/* ---------- overlays ---------- */
.overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(4, 18, 13, 0.9);
    z-index: 30;
}
.overlay.is-open { display: flex; }
.overlay-card {
    width: 100%;
    max-width: 330px;
    padding: 24px 20px;
    border-radius: 18px;
    background: linear-gradient(180deg, #16452f, #0e3527);
    border: 1px solid rgba(244, 199, 107, 0.3);
    text-align: center;
}
.title {
    font-size: 34px;
    letter-spacing: 6px;
    color: var(--gold);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.subtitle { margin: 8px 0 20px; font-size: 13px; color: var(--muted); }
.over-title { font-size: 28px; color: var(--gold); letter-spacing: 4px; }
.over-title.lose { color: #e3857c; }
.over-sub { margin: 6px 0 14px; font-size: 13px; color: var(--muted); }
.over-rows { margin-bottom: 6px; }
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 4px;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.record { display: flex; gap: 8px; margin-top: 16px; }
.record-cell {
    flex: 1;
    padding: 8px 4px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.26);
    font-size: 11px;
    color: var(--muted);
}
.record-cell b { display: block; margin-top: 2px; font-size: 17px; color: var(--gold); }
.rules { margin-top: 16px; text-align: left; }
.rules h3 { font-size: 12px; color: var(--gold-dim); margin-bottom: 5px; }
.rules p { font-size: 11px; line-height: 1.7; color: var(--muted); }

/* Wider phones and tablets get roomier cards. */
@media (min-width: 420px) {
    .card { width: 48px; height: 66px; }
    .hand { height: 104px; }
    .played { min-height: 66px; }
}
@media (min-height: 720px) {
    .seat { top: 70px; }
}
