: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; }
.stock { font-size: 12px; color: var(--muted); }

.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 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 { margin: 10px 0 14px; text-align: left; }
.standings .seat { margin-bottom: 6px; }
.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;
}
