:root {
    --felt: #146246;
    --felt-dark: #0d3b2e;
    --ink: #1a1a1a;
    --paper: #f6f1e6;
    --gold: #f0c36a;
    --danger: #d64545;
    --ok: #2ecc71;
    --muted: rgba(255, 255, 255, 0.72);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--felt-dark);
    color: #fff;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    padding: var(--safe-t) 0 var(--safe-b);
}

#app {
    height: 100dvh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        radial-gradient(circle at 20% 10%, rgba(255, 255, 255, .06), transparent 40%),
        linear-gradient(180deg, #0f4a38 0%, var(--felt) 40%, #0b3328 100%);
}

.topbar {
    padding: 14px 16px 8px;
    text-align: center;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
    letter-spacing: 4px;
}

.topbar .sub {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--muted);
}

#view {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 14px 16px;
    gap: 12px;
    min-height: 0;
    overflow: auto;
}

#view.is-table {
    overflow: hidden;
}

.card-box,
.panel {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 16px;
    padding: 16px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

input[type="text"] {
    width: 100%;
    border: 0;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 16px;
    background: var(--paper);
    color: var(--ink);
    outline: none;
    user-select: text;
    -webkit-user-select: text;
    pointer-events: auto;
    position: relative;
    z-index: 1;
}

.row {
    display: flex;
    gap: 10px;
}

.row>* {
    flex: 1;
}

button,
.btn {
    appearance: none;
    border: 0;
    border-radius: 14px;
    padding: 13px 16px;
    font-size: 16px;
    font-weight: 700;
    background: var(--gold);
    color: #3b2a08;
    cursor: pointer;
}

button.ghost {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

button.danger {
    background: #c0392b;
    color: #fff;
}

button:disabled {
    opacity: .45;
}

.actions {
    display: flex;
    gap: 8px;
}

.actions button {
    flex: 1;
}

.room-code {
    font-size: 42px;
    letter-spacing: 10px;
    text-align: center;
    font-weight: 800;
    color: var(--gold);
}

.qr-wrap {
    text-align: center;
}

.qr-wrap img {
    width: 168px;
    height: 168px;
    background: #fff;
    border-radius: 12px;
    padding: 8px;
}

.url-line {
    font-size: 12px;
    word-break: break-all;
    color: var(--muted);
    text-align: center;
}

.seat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.seat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .08);
}

.seat.turn {
    border: 2px solid var(--gold);
}

.seat .meta {
    font-size: 12px;
    color: var(--muted);
}

.table-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.opponents {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    flex-wrap: wrap;
    padding: 6px 4px 10px;
}

.opp {
    min-width: 72px;
    text-align: center;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(0, 0, 0, .22);
    font-size: 13px;
    border: 2px solid transparent;
    box-sizing: border-box;
}

.opp.turn {
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(240, 195, 106, .35);
}

.opp .n {
    font-weight: 700;
}

.opp .c {
    color: var(--gold);
    font-size: 18px;
}

.center-play {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 150px;
}

.event {
    font-size: 13px;
    color: var(--gold);
    text-align: center;
    min-height: 18px;
}

.turn-clock {
    font-variant-numeric: tabular-nums;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--gold);
    line-height: 1;
    min-height: 32px;
}

.turn-clock.warn {
    color: #ff6b6b;
    animation: tick-warn .5s ease-in-out infinite alternate;
}

.opp .hint[data-turn-clock] {
    color: var(--gold);
    font-weight: 700;
}

.opp .hint[data-turn-clock].warn {
    color: #ff6b6b;
}

@keyframes tick-warn {
    from {
        opacity: 1;
    }

    to {
        opacity: .55;
    }
}

.stock {
    font-size: 12px;
    color: var(--muted);
}

.abort-game {
    display: block;
    width: auto;
    margin: 10px auto 0;
    padding: 8px 16px;
    font-size: 13px;
    color: #ffb4b4;
    background: transparent;
    border: 1px solid rgba(214, 69, 69, .45);
}

.cards {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: hidden;
}

.cards.is-overflow {
    overflow-x: auto;
}

.pk {
    --card-w: 68px;
    width: var(--card-w);
    height: calc(var(--card-w) * 1.4);
    border-radius: 7px;
    background: #fff;
    color: #111;
    position: relative;
    box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
    padding: 0;
    overflow: hidden;
    flex: 0 0 auto;
}

.pk.sprite {
    background-color: #fff;
    background-image: url(../img/cards.jpg);
    background-repeat: no-repeat;
    background-size: 1300% 500%;
    background-position: calc(var(--sx, 0) * 100% / 12) calc(var(--sy, 0) * 100% / 4);
}

@supports (background-image: image-set(url("../img/cards.webp") type("image/webp"))) {
    .pk.sprite {
        background-image: image-set(url("../img/cards.webp") type("image/webp"),
                url("../img/cards.jpg") type("image/jpeg"));
    }
}

.pk img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    user-select: none;
}

.pk .fallback {
    display: none;
}

.pk.no-img {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    font-size: 12px;
    font-weight: 700;
    background: #fffaf0;
}

.pk.no-img .fallback {
    display: block;
}

.pk.tiny {
    --card-w: 44px;
    border-radius: 5px;
}

.hand-dock {
    flex-shrink: 0;
    padding: 4px 0 calc(8px + var(--safe-b));
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .28) 16%);
}

.hand-scroll {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    overflow-x: hidden;
    overflow-y: hidden;
    padding: 20px 2px 10px;
    gap: 0;
    -webkit-overflow-scrolling: touch;
}

.hand-scroll.is-overflow {
    overflow-x: auto;
}

.hand-scroll .pk {
    --card-w: min(74px, 20vw);
    margin-right: 0;
    transition: transform .12s ease, margin-left .12s ease;
}

.hand-scroll .pk.must {
    box-shadow: 0 0 0 2px #f0c36a, 0 4px 10px rgba(0, 0, 0, .25);
    border: 2px solid #f0c36a;
    box-sizing: border-box;
}

.hand-scroll .pk.on {
    transform: translateY(-18px);
}

#toast {
    position: fixed;
    left: 50%;
    bottom: 96px;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .82);
    color: #fff;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 20;
    max-width: 86%;
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #16382e;
    border-radius: 18px 18px 0 0;
    padding: 16px 16px calc(18px + var(--safe-b));
    z-index: 30;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .4);
}

.sheet h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.sheet .opt {
    width: 100%;
    margin-bottom: 8px;
    text-align: left;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .62);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 24px;
}

.overlay .box {
    background: #184536;
    border-radius: 18px;
    padding: 22px 18px;
    width: min(380px, 100%);
    max-height: 80dvh;
    overflow: auto;
    text-align: center;
}

.overlay h2 {
    margin: 0 0 10px;
}

.overlay .box>.pk {
    margin: 0 auto 12px;
}

.end-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

.last-hand {
    margin: 8px 0 12px;
}

.last-hand .hint {
    margin: 0 0 8px;
    color: var(--gold);
}

.last-hand .cards {
    justify-content: center;
    margin: 0;
}

.last-hand .pk {
    --card-w: min(58px, 16vw);
    margin: 0;
}

.standings {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 14px 0 4px;
    text-align: left;
}

.stand-row {
    background: rgba(0, 0, 0, .22);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 14px;
    padding: 10px 12px 12px;
}

.stand-row.win {
    border-color: rgba(240, 195, 106, .4);
    background: rgba(240, 195, 106, .1);
}

.stand-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.stand-who {
    display: flex;
    align-items: center;
    min-width: 0;
}

.stand-who strong {
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stand-count {
    flex-shrink: 0;
    font-size: 12px;
    line-height: 1.2;
    color: var(--gold);
    white-space: nowrap;
    background: rgba(240, 195, 106, .16);
    padding: 4px 8px;
    border-radius: 999px;
}

.stand-row.win .stand-count {
    color: #3b2a08;
    background: var(--gold);
}

.remain-cards {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    overflow-x: auto;
    gap: 0;
    width: max-content;
    max-width: 100%;
}

.remain-cards .pk {
    --card-w: min(48px, 13vw);
    margin: 0;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, .32);
}

.log-block {
    text-align: left;
    margin-top: 10px;
}

.log-block summary {
    cursor: pointer;
    color: var(--gold);
    font-weight: 700;
    margin-bottom: 8px;
}

.log-round {
    margin: 0 0 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, .2);
}

.log-round p {
    margin: 4px 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--muted);
}

.hint {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(240, 195, 106, .2);
    color: var(--gold);
    font-size: 12px;
    margin-left: 6px;
    vertical-align: middle;
}

.badge.gdy {
    background: rgba(214, 69, 69, .22);
    color: #ffb4b4;
}