:root {
    --bg-deep: #0b1d17;
    --bg-table: #14603c;
    --bg-table2: #0d4a2c;
    --gold: #f3c969;
    --gold-deep: #d9a441;
    --text: #eaf3ee;
    --muted: #9fb8aa;
    --danger: #e8544b;
    --success: #3fbf7f;
    --card-w: 60px;
    --card-h: 84px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg-deep);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; }

/* ---------- 通用组件 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 10px 22px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #2a1b05;
    background: linear-gradient(180deg, #f7d680, var(--gold-deep));
    box-shadow: 0 3px 0 #a97b23;
    transition: transform .08s ease, filter .15s ease;
    user-select: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #a97b23; }
.btn:disabled, .btn.disabled {
    background: #55635b; color: #96a79d; box-shadow: 0 3px 0 #3b453f; cursor: not-allowed; filter: none;
}
.btn.ghost {
    background: rgba(255,255,255,.08); color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
}
.btn.danger { background: linear-gradient(180deg,#f0796f,#d8402f); color:#fff; box-shadow: 0 3px 0 #9c2a1e; }
.btn.sm { padding: 5px 12px; font-size: 13px; border-radius: 6px; }

.input, select.input {
    width: 100%;
    padding: 11px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,.16);
    background: rgba(0,0,0,.28);
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color .15s;
}
.input:focus { border-color: var(--gold); }
select.input option { background: #14231c; }

.panel {
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 14px;
    padding: 20px;
}

.tag {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 12px;
    background: rgba(255,255,255,.12);
}
.tag.gold { background: rgba(243,201,105,.2); color: var(--gold); }
.tag.green { background: rgba(63,191,127,.18); color: var(--success); }
.tag.red { background: rgba(232,84,75,.18); color: #ff8b83; }

.mask {
    position: fixed; inset: 0; display: none;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,.62); z-index: 100;
}
.mask.show { display: flex; }
.modal {
    width: 92%; max-width: 380px;
    background: #14251e; border-radius: 16px; padding: 26px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h3 { margin: 0 0 18px; font-size: 19px; text-align: center; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }

.toast-wrap { position: fixed; top: 22px; left: 50%; transform: translateX(-50%); z-index: 200; }
.toast {
    margin-bottom: 8px; padding: 10px 18px; border-radius: 8px;
    background: rgba(20,37,30,.96); border: 1px solid rgba(243,201,105,.35);
    font-size: 14px; animation: fadeIn .2s ease;
}
.toast.err { border-color: rgba(232,84,75,.5); color: #ff9c95; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px);} to {opacity:1;transform:none;} }

/* ---------- 扑克牌 ---------- */
.card {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 7px;
    background: #fff;
    color: #1d1d1d;
    box-shadow: 0 2px 5px rgba(0,0,0,.35);
    user-select: none;
    flex: 0 0 auto;
    font-weight: 700;
}
.card .c-rank { position: absolute; top: 4px; left: 5px; font-size: 17px; line-height: 1; }
.card .c-suit { position: absolute; top: 21px; left: 5px; font-size: 14px; line-height: 1; }
.card .c-big {
    position: absolute; right: 5px; bottom: 3px;
    font-size: 24px; opacity: .9; line-height: 1;
}
.card.red { color: #d8232a; }
.card.joker .c-rank { font-size: 13px; }
.card.laizi { box-shadow: 0 0 0 2px var(--gold), 0 2px 8px rgba(243,201,105,.5); }
.card.laizi::after {
    content: '癞'; position: absolute; top: -8px; right: -6px;
    width: 20px; height: 20px; line-height: 20px; text-align: center;
    font-size: 11px; border-radius: 50%; background: var(--gold); color: #402a00;
}
.card.back {
    background: repeating-linear-gradient(45deg, #1d5fa8, #1d5fa8 6px, #17487f 6px, #17487f 12px);
    box-shadow: 0 2px 5px rgba(0,0,0,.35);
}
.card.mini { --card-w: 38px; --card-h: 54px; }
.card.mini .c-rank { font-size: 12px; top: 3px; left: 4px; }
.card.mini .c-suit { display: none; }
.card.mini .c-big { font-size: 15px; }
.card.mini.laizi::after { width: 15px; height: 15px; line-height: 15px; font-size: 9px; top:-6px; right:-5px; }

.hand { display: flex; flex-wrap: wrap; justify-content: center; }
.hand .card { margin-left: -26px; cursor: pointer; transition: transform .12s ease; }
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-6px); }
.hand .card.selected { transform: translateY(-16px); box-shadow: 0 6px 12px rgba(0,0,0,.45); }
.hand.mini-cards .card { margin-left: -16px; }

/* ---------- 大厅 ---------- */
.hall {
    max-width: 980px; margin: 0 auto; padding: 34px 18px 60px;
}
.hall-title {
    text-align: center; margin-bottom: 26px;
}
.hall-title h1 {
    margin: 0; font-size: 32px; letter-spacing: 4px;
    background: linear-gradient(180deg, #fff3cf, var(--gold));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hall-title p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.mode-card {
    cursor: pointer; padding: 20px; border-radius: 14px; text-align: left;
    background: rgba(255,255,255,.05); border: 2px solid transparent;
    transition: all .15s ease;
}
.mode-card:hover { background: rgba(255,255,255,.09); }
.mode-card.active { border-color: var(--gold); background: rgba(243,201,105,.12); }
.mode-card h4 { margin: 0 0 6px; font-size: 17px; }
.mode-card span { color: var(--muted); font-size: 13px; line-height: 1.6; }
.opt-row { display: flex; gap: 14px; flex-wrap: wrap; }
.opt-row .field { flex: 1; min-width: 140px; }
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.stat-row .stat { flex: 1; min-width: 100px; text-align: center; }
.stat b { display: block; font-size: 22px; color: var(--gold); }
.stat span { font-size: 12px; color: var(--muted); }

.room-list { margin-top: 10px; max-height: 260px; overflow-y: auto; }
.room-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.2); margin-bottom: 8px;
}
.room-item .ri-no { font-weight: 700; letter-spacing: 1px; }
.room-item .ri-info { font-size: 12px; color: var(--muted); margin-top: 3px; }
.empty-tip { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }

/* ---------- 牌桌 ---------- */
.table-wrap {
    position: relative; height: 100vh; min-height: 100vh; overflow: hidden;
    display: flex; flex-direction: column;
    background: radial-gradient(ellipse at 50% 42%, var(--bg-table) 0%, var(--bg-table2) 55%, var(--bg-deep) 100%);
}
@supports (height: 100dvh) {
    .table-wrap { height: 100dvh; min-height: 100dvh; }
}
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    flex: 0 0 auto;
    padding: 10px 16px; background: rgba(0,0,0,.28); backdrop-filter: blur(4px);
    padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .tb-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar .tb-title { font-weight: 700; letter-spacing: 1px; }
.topbar .tb-meta { font-size: 12px; color: var(--muted); }
.icon-btn {
    width: 30px; height: 30px; border-radius: 8px; border: none; cursor: pointer;
    background: rgba(255,255,255,.12); color: var(--text); font-size: 15px;
}

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

.seat {
    position: absolute; width: 190px;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.seat-avatar {
    width: 54px; height: 54px; border-radius: 50%;
    background: linear-gradient(180deg,#2f6b4f,#1b4531);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700; color: #fff;
    box-shadow: 0 3px 10px rgba(0,0,0,.4); position: relative;
}
.seat-avatar.turn { box-shadow: 0 0 0 3px var(--gold), 0 3px 10px rgba(0,0,0,.5); }
.seat-avatar .count-badge {
    position: absolute; top: -6px; right: -8px; min-width: 22px; height: 22px; padding: 0 5px;
    border-radius: 11px; background: var(--danger); color: #fff; font-size: 12px; line-height: 22px; text-align: center;
}
.seat-name { font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-name .lord {
    margin-left: 4px; padding: 1px 6px; border-radius: 8px; font-size: 11px;
    background: var(--gold); color: #3a2600;
}
.seat-tip { font-size: 12px; color: var(--gold); min-height: 16px; }

.seat-top { top: 12px; left: 50%; transform: translateX(-50%); }
.seat-left { top: 44%; left: 12px; transform: translateY(-50%); }
.seat-right { top: 44%; right: 12px; transform: translateY(-50%); }

.play-center {
    position: absolute; top: 46%; left: 50%; transform: translate(-50%,-50%);
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    min-width: 260px;
}
.played-cards { display: flex; min-height: 60px; align-items: center; }
.played-cards .card { margin-left: -22px; }
.played-cards .card:first-child { margin-left: 0; }
.center-info { font-size: 13px; color: var(--muted); text-align: center; }
.bottom-cards { display: flex; gap: 2px; }
.bottom-cards .card { margin-left: -20px; }
.bottom-cards .card:first-child { margin-left: 0; }
.laizi-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 12px; border-radius: 20px; font-size: 13px; font-weight: 700;
    background: linear-gradient(180deg,#f7d680,var(--gold-deep)); color: #3a2600;
}

.bottom-bar {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 8px 12px 14px; background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,0,.5));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.my-hand { display: flex; justify-content: center; min-height: 92px; }
.operate { display: flex; justify-content: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.bid-box { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }

.log-panel {
    position: absolute; right: 10px; top: 10px; width: 210px; max-height: 42vh;
    overflow-y: auto; background: rgba(0,0,0,.28); border-radius: 10px; padding: 8px 10px;
    font-size: 12px; line-height: 1.7; color: #cfe0d6;
}
.log-panel .lg-item { border-bottom: 1px dashed rgba(255,255,255,.07); padding: 2px 0; }
.log-panel .lg-name { color: var(--gold); }

.result-mask .modal { max-width: 460px; }
.result-title { font-size: 26px; text-align: center; margin: 0 0 6px; }
.result-title.win { color: var(--gold); }
.result-title.lose { color: #ff9c95; }
.result-list { margin: 14px 0; }
.result-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 12px; border-radius: 9px; background: rgba(0,0,0,.25); margin-bottom: 7px; font-size: 14px;
}
.delta-plus { color: var(--success); font-weight: 700; }
.delta-minus { color: #ff9c95; font-weight: 700; }

.waiting-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.waiting-seats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: 100%; }
.waiting-seat {
    padding: 14px 6px; border-radius: 10px; text-align: center; font-size: 13px;
    background: rgba(0,0,0,.25); border: 1px dashed rgba(255,255,255,.2);
}
.waiting-seat.filled { border-style: solid; border-color: rgba(243,201,105,.6); background: rgba(243,201,105,.1); }

/* ---------- 后台 ---------- */
.admin-wrap { display: flex; min-height: 100vh; background: #0e1714; }
.admin-side {
    width: 208px; flex: 0 0 208px; background: #101d18; border-right: 1px solid rgba(255,255,255,.06);
    padding: 18px 0;
}
.admin-side .brand {
    padding: 0 20px 18px; font-size: 17px; font-weight: 700; color: var(--gold); letter-spacing: 1px;
}
.admin-side .nav-item {
    padding: 11px 22px; cursor: pointer; font-size: 14px; color: #b9cdc2;
    border-left: 3px solid transparent; transition: all .12s;
}
.admin-side .nav-item:hover { background: rgba(255,255,255,.04); color: #fff; }
.admin-side .nav-item.active { background: rgba(243,201,105,.1); color: var(--gold); border-left-color: var(--gold); }
.admin-main { flex: 1; padding: 22px 26px; overflow-x: hidden; }
.admin-head {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;
}
.admin-head h2 { margin: 0; font-size: 21px; }
.admin-head .who { font-size: 13px; color: var(--muted); }

.cards-stat { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; }
.stat-card {
    background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07);
    border-radius: 12px; padding: 16px 18px;
}
.stat-card .sc-label { font-size: 13px; color: var(--muted); }
.stat-card .sc-value { font-size: 26px; font-weight: 700; margin-top: 6px; color: var(--gold); }
.stat-card .sc-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.admin-table th, .admin-table td {
    padding: 10px 12px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.07); white-space: nowrap;
}
.admin-table th { color: var(--muted); font-weight: 600; background: rgba(255,255,255,.03); }
.admin-table tbody tr:hover { background: rgba(255,255,255,.03); }
.admin-table td.wrap-cell { white-space: normal; max-width: 320px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: 13px; color: var(--muted); }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding: 10px 0; }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bar {
    width: 100%; max-width: 42px; border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, var(--gold), var(--gold-deep)); min-height: 3px;
}
.chart .bar-label { font-size: 11px; color: var(--muted); }
.chart .bar-val { font-size: 11px; color: var(--text); }

.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 30%, #16493a, #0b1d17 70%);
}
.login-box { width: 92%; max-width: 360px; }
.login-box .panel { background: rgba(0,0,0,.3); }
.login-box h2 { margin: 0 0 4px; font-size: 24px; text-align: center; color: var(--gold); letter-spacing: 2px; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }

@media (max-width: 820px) {
    .admin-side { width: 62px; flex-basis: 62px; }
    .admin-side .brand { font-size: 13px; padding: 0 8px 16px; text-align: center; }
    .admin-side .nav-item { padding: 12px 8px; text-align: center; font-size: 12px; }
    .topbar { padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
    .topbar .tb-left { gap: 6px; }
    .topbar .tb-title { font-size: 13px; letter-spacing: 0; }
    .topbar .tag { font-size: 11px; padding: 2px 7px; }
    .topbar .btn.sm { font-size: 12px; padding: 5px 9px; }
    .seat { width: 130px; }
    :root { --card-w: 52px; --card-h: 74px; }
    .my-hand { min-height: 74px; }
    .operate, .bid-box { margin-top: 8px; }
    .bottom-bar { padding: 6px 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    .log-panel { display: none; }
}
