/* ============================================================
 * 石家庄麻将 · 联机版样式
 * 3D 实体牌感：象牙牌面 + 木纹侧壁 + 顶部高光 + 落地投影
 * ============================================================ */
:root {
  --felt-1: #16543c;
  --felt-2: #0b2f22;
  --gold: #d9b26a;
  --gold-soft: #b9954f;
  --ink: #eaf3ec;
  --ink-dim: #9db3a5;
  --red: #c0392b;
  --tile-w: clamp(46px, 5.6vw, 86px);
  --river-w: clamp(22px, 2.4vw, 32px);
  --radius: 12px;
  --shadow-deep: 0 18px 50px rgba(0, 0, 0, .45);
}

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

html, body {
  height: 100%; margin: 0;
  background: #061a13;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(120% 80% at 50% 45%, transparent 45%, rgba(0, 0, 0, .55) 100%);
}

/* ---------- 屏幕切换 ---------- */
.screen {
  position: fixed; inset: 0; z-index: 2;
  display: none; opacity: 0;
}
.screen.active { display: block; animation: fadeIn .32s ease forwards; }
@keyframes fadeIn { to { opacity: 1; } }

/* ============================================================
 * 登录
 * ============================================================ */
#screen-auth {
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(30, 110, 78, .55), transparent 70%),
    linear-gradient(180deg, #0a2a1e 0%, #05150f 100%);
  display: none;
}
#screen-auth.active { display: grid; place-items: center; }

.auth-card {
  width: min(400px, 90vw);
  padding: 34px 30px 26px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(22, 66, 48, .92), rgba(9, 30, 22, .96));
  border: 1px solid rgba(217, 178, 106, .26);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .08);
  backdrop-filter: blur(14px);
}
.brand { text-align: center; margin-bottom: 22px; }
.brand-seal {
  width: 52px; height: 52px; margin: 0 auto 12px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(160deg, #b8352a, #8d1f18);
  color: #fff4e0; font-family: STKaiti, KaiTi, serif; font-size: 30px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(180, 50, 40, .45), inset 0 1px 0 rgba(255, 255, 255, .3);
}
.brand h1 {
  margin: 0 0 6px; font-size: 24px; letter-spacing: 3px;
  font-family: STKaiti, KaiTi, serif;
  color: #f2e2bd;
}
.brand-sub { margin: 0; font-size: 11.5px; color: var(--ink-dim); letter-spacing: .6px; }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; background: rgba(0, 0, 0, .28); padding: 5px; border-radius: 10px; }
.tab {
  flex: 1; padding: 9px 0; border: 0; border-radius: 7px; cursor: pointer;
  background: transparent; color: var(--ink-dim); font-size: 13px; letter-spacing: 2px;
  transition: .2s;
}
.tab.active { background: linear-gradient(180deg, rgba(217, 178, 106, .22), rgba(217, 178, 106, .1)); color: #f4dfb4; }

.pane { display: none; flex-direction: column; gap: 12px; }
.pane.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 11.5px; color: var(--ink-dim); padding-left: 2px; }
.field input, .join-row input {
  height: 42px; padding: 0 14px;
  border-radius: 9px;
  border: 1px solid rgba(217, 178, 106, .2);
  background: rgba(0, 0, 0, .34);
  color: var(--ink); font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .join-row input:focus {
  border-color: rgba(217, 178, 106, .7);
  box-shadow: 0 0 0 3px rgba(217, 178, 106, .12);
}

.btn-primary {
  height: 44px; padding: 0 22px; border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(180deg, #d8b271, #b08a45);
  color: #241a06; font-size: 14.5px; font-weight: 700; letter-spacing: 2px;
  box-shadow: 0 8px 22px rgba(180, 140, 70, .3), inset 0 1px 0 rgba(255, 255, 255, .5);
  transition: transform .14s, filter .2s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px) scale(.99); }
.btn-primary.big { width: 100%; }
.btn-primary:disabled { filter: grayscale(.6) brightness(.7); cursor: not-allowed; }

.auth-tip { margin: 14px 0 0; text-align: center; font-size: 11.5px; color: #8ba294; min-height: 16px; }
.auth-tip.err { color: #ff9a8c; }
.auth-tip.invite { color: #f0d9a6; }

/* ============================================================
 * 顶栏 / 大厅
 * ============================================================ */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; z-index: 5;
}
#screen-lobby, #screen-room {
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(24, 96, 68, .5), transparent 70%),
    linear-gradient(180deg, #0a2a1e, #061a13);
  overflow-y: auto;
}
.logo-sm { font-family: STKaiti, KaiTi, serif; font-size: 16px; color: #eed9ab; letter-spacing: 2px; }
.tb-right { display: flex; align-items: center; gap: 10px; }
.me-name { font-size: 13px; color: #dfe9e1; }

.lobby {
  display: grid; grid-template-columns: 1fr 320px; gap: 16px;
  max-width: 1000px; margin: 0 auto; padding: 70px 18px 34px;
  min-height: 100vh; align-content: center;
}
.lobby-main { display: flex; flex-direction: column; gap: 14px; }
.panel {
  padding: 22px; border-radius: 16px;
  background: linear-gradient(180deg, rgba(19, 58, 42, .78), rgba(8, 26, 19, .9));
  border: 1px solid rgba(217, 178, 106, .16);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .34);
}
.panel h2 { margin: 0 0 8px; font-size: 16px; font-family: STKaiti, KaiTi, serif; color: #eddbb2; letter-spacing: 1px; }
.panel-sub { margin: 0 0 16px; font-size: 12.5px; color: var(--ink-dim); line-height: 1.7; }

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; letter-spacing: 8px; text-align: center; font-size: 20px; font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat-grid > div {
  padding: 10px 4px; border-radius: 10px; text-align: center;
  background: rgba(0, 0, 0, .26);
}
.stat-grid b { display: block; font-size: 18px; color: #f0d9a6; }
.stat-grid span { font-size: 10.5px; color: var(--ink-dim); }

.record-list { display: flex; flex-direction: column; gap: 5px; max-height: 170px; overflow-y: auto; }
.record-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; color: #b9cbbd; padding: 6px 9px; border-radius: 7px;
  background: rgba(0, 0, 0, .2);
}
.record-row .up { color: #ff8a75; font-weight: 700; }
.record-row .down { color: #6fd39a; font-weight: 700; }

.rule-list { margin: 0; padding-left: 16px; font-size: 12px; color: #a9bdb0; line-height: 2; }

/* ============================================================
 * 房间
 * ============================================================ */
.room-code {
  font-size: 22px; font-weight: 800; letter-spacing: 5px; color: #f5dca4;
  font-family: ui-monospace, monospace; margin-left: 10px;
  text-shadow: 0 0 18px rgba(245, 220, 164, .35);
}
.room {
  max-width: 900px; margin: 0 auto;
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 70px 18px 50px;
}
.room-seats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 22px; }
.room-seat {
  display: flex; align-items: center; gap: 14px;
  padding: 20px 22px; border-radius: 16px;
  background: linear-gradient(180deg, rgba(21, 62, 46, .82), rgba(8, 26, 19, .92));
  border: 1px solid rgba(217, 178, 106, .16);
  transition: border-color .2s, box-shadow .2s;
}
.room-seat.empty { opacity: .5; border-style: dashed; }
.room-seat.me { border-color: rgba(217, 178, 106, .6); box-shadow: 0 0 0 2px rgba(217, 178, 106, .14); }
.seat-avatar {
  width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center;
  font-size: 19px; font-weight: 700; color: #1d1503;
  background: linear-gradient(160deg, #dcc08a, #b3904d);
  flex: 0 0 auto;
}
.room-seat.empty .seat-avatar { background: rgba(255, 255, 255, .08); color: #7f9588; }
.seat-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.seat-meta b { font-size: 14px; color: #eef4ee; font-weight: 600; }
.seat-meta span { font-size: 11px; color: var(--ink-dim); }
.seat-tag { margin-left: auto; font-size: 10.5px; padding: 3px 8px; border-radius: 20px; background: rgba(217, 178, 106, .16); color: #f0d9a6; }
.seat-tag.ready { background: rgba(90, 200, 140, .16); color: #8fe0b4; }

.room-foot { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.room-tip { text-align: center; font-size: 12px; color: var(--ink-dim); margin: 14px 0; }
.voice-bar { display: flex; align-items: center; justify-content: center; gap: 12px; }
.voice-hint { font-size: 11.5px; color: #7f9588; }

.hud-btn {
  height: 34px; padding: 0 13px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(217, 178, 106, .22);
  background: rgba(0, 0, 0, .3); color: #d8e4da; font-size: 12px;
  transition: .18s;
}
.hud-btn:hover { border-color: rgba(217, 178, 106, .6); color: #f4e2bb; }
.hud-btn.ghost { border-color: rgba(255, 255, 255, .12); color: #9db3a5; }
.hud-btn.off { opacity: .45; }
.hud-btn.on {
  border-color: rgba(120, 220, 160, .75); color: #b6f0ce;
  background: rgba(40, 130, 90, .35);
  box-shadow: 0 0 14px rgba(90, 200, 140, .28);
}

.mic-btn {
  height: 38px; padding: 0 18px; border-radius: 20px; cursor: pointer;
  border: 1px solid rgba(217, 178, 106, .3);
  background: rgba(0, 0, 0, .34); color: #dfe9e1; font-size: 12.5px;
}
.mic-btn.on {
  background: linear-gradient(180deg, rgba(90, 200, 140, .3), rgba(40, 130, 90, .3));
  border-color: rgba(120, 220, 160, .7); color: #b6f0ce;
  box-shadow: 0 0 20px rgba(90, 200, 140, .3);
}

/* ---------- 牌桌上的语音开关（常驻） ---------- */
.voice-dock {
  position: absolute; left: 13px; top: 54px; z-index: 22;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.vd-btn {
  position: relative; cursor: pointer;
  width: 62px; height: 62px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: 1px solid rgba(217, 178, 106, .42);
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 62%),
    rgba(4, 20, 14, .84);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .18);
  color: #dfe9e1; font-size: 10px;
  transition: transform .18s, box-shadow .2s, border-color .2s, background .2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.vd-ic { font-size: 20px; line-height: 1.05; filter: grayscale(.55); opacity: .82; }
.vd-txt { font-size: 9.5px; letter-spacing: .6px; }
.vd-btn:hover { border-color: rgba(255, 214, 130, .8); transform: translateY(-1px); }
.vd-btn.on {
  border-color: rgba(120, 220, 160, .85); color: #c4f5d8;
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 62%),
    rgba(18, 84, 58, .93);
  box-shadow:
    0 0 0 3px rgba(90, 200, 140, .15),
    0 8px 22px rgba(0, 0, 0, .45),
    0 0 26px rgba(90, 200, 140, .38);
}
.vd-btn.on .vd-ic { filter: none; opacity: 1; }
/* 自己说话时的呼吸圈 */
.vd-btn.talking::after {
  content: ""; position: absolute; inset: -7px; border-radius: 50%;
  border: 2px solid rgba(126, 242, 178, .8);
  animation: vd-pulse .95s ease-out infinite;
  pointer-events: none;
}
@keyframes vd-pulse {
  0% { transform: scale(.94); opacity: .85; }
  100% { transform: scale(1.2); opacity: 0; }
}
.vd-lv {
  position: absolute; left: 50%; bottom: -6px; width: 6px; height: 14px;
  border-radius: 3px; transform: translateX(-50%) scaleY(.25);
  transform-origin: bottom center;
  background: linear-gradient(180deg, #9df3c2, #35a173);
  box-shadow: 0 0 9px rgba(120, 240, 175, .75);
  opacity: 0; transition: transform .1s linear, opacity .2s;
}
.vd-btn.on .vd-lv { opacity: 1; }
.vd-state {
  font-size: 10px; color: #9db3a5; white-space: nowrap;
  padding: 2px 9px; border-radius: 20px;
  background: rgba(4, 20, 14, .66);
  border: 1px solid rgba(255, 255, 255, .07);
  font-variant-numeric: tabular-nums;
}
.voice-dock.on .vd-state { color: #a8ecc5; border-color: rgba(120, 220, 160, .35); }

/* ---------- 开局语音提示 ---------- */
.voice-nudge {
  position: absolute; left: 50%; bottom: calc(var(--tile-w) * 1.38 + 156px); z-index: 30;
  transform: translateX(-50%) translateY(12px);
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px 11px 14px; border-radius: 14px;
  width: min(460px, 92vw);
  background: rgba(6, 26, 18, .94);
  border: 1px solid rgba(217, 178, 106, .38);
  box-shadow: 0 18px 46px rgba(0, 0, 0, .55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .26s, transform .26s, visibility .26s;
}
.voice-nudge.show {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.vn-ic { font-size: 23px; line-height: 1; flex: 0 0 auto; }
.vn-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.vn-txt b { font-size: 13px; color: #f4e6c4; font-weight: 600; }
.vn-txt span { font-size: 11.5px; color: #9db3a5; line-height: 1.35; }
.vn-yes {
  flex: 0 0 auto; cursor: pointer; height: 32px; padding: 0 16px; border-radius: 18px;
  border: 1px solid rgba(120, 220, 160, .55);
  background: linear-gradient(180deg, rgba(90, 200, 140, .34), rgba(40, 130, 90, .34));
  color: #d3f7e3; font-size: 12.5px; font-weight: 600;
}
.vn-yes:hover { border-color: rgba(150, 245, 195, .9); }
.vn-no {
  flex: 0 0 auto; cursor: pointer; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .12); background: transparent;
  color: #8fa899; font-size: 15px; line-height: 1;
}
.vn-no:hover { color: #e6d9bd; border-color: rgba(255, 255, 255, .3); }

/* ============================================================
 * 牌桌
 * ============================================================ */
#screen-table { background: #071c14; }
.hud {
  position: absolute; top: 0; left: 0; right: 0; height: 46px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(4, 18, 12, .8), transparent);
}
.hud-left .logo { font-family: STKaiti, KaiTi, serif; font-size: 15px; color: #e9d5a6; letter-spacing: 2px; }
.hud-mid { display: flex; gap: 18px; font-size: 12px; color: #b7cab9; }
.hud-mid b { color: #f2dcaa; font-size: 13px; }
.hud-right { display: flex; gap: 6px; }

.table {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(60% 46% at 50% 44%, rgba(255, 255, 255, .07), transparent 70%),
    url("../assets/table-bg.jpg");
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

/* ---------- 座位 ---------- */
.seat { position: absolute; z-index: 6; display: flex; gap: 5px; }

.plate {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 20px;
  background: rgba(4, 20, 14, .68);
  border: 1px solid rgba(217, 178, 106, .18);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}
.plate .wind {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10.5px; color: #221803;
  background: linear-gradient(160deg, #e0c48d, #b28f4c);
  font-weight: 700;
}
.plate .pname { font-size: 12.5px; color: #e6efe7; max-width: 84px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 默认头像 + 账号 ---------- */
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .32);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .28);
}
.avatar svg { width: 78%; height: 78%; margin-top: 10%; display: block; fill: rgba(255, 255, 255, .95); }
.plate .who, .self-plate .who {
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1.18; min-width: 0;
}
.plate .paccount, .self-plate .paccount {
  font-style: normal; font-size: 9.5px; color: #a2b8a9; letter-spacing: .2px;
  max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.plate .paccount:empty, .self-plate .paccount:empty { display: none; }
.plate .pscore { font-size: 12.5px; font-weight: 700; color: #cdd9cd; }
.plate .pscore.up { color: #ff8a75; }
.plate .pscore.down { color: #6fd39a; }
.plate .pcnt {
  font-size: 10.5px; color: #a9c2b1; padding: 1px 6px; border-radius: 8px;
  background: rgba(255, 255, 255, .09); font-variant-numeric: tabular-nums;
}
.dealer-badge {
  font-size: 9.5px; padding: 1px 6px; border-radius: 8px;
  background: linear-gradient(160deg, #b8352a, #8d1f18); color: #ffeede;
  display: none;
}
.seat.is-dealer .dealer-badge { display: inline-block; }
.seat.active .plate {
  border-color: rgba(255, 214, 130, .85);
  box-shadow: 0 0 22px rgba(255, 200, 100, .38);
}
.seat.active .plate::after {
  content: ""; position: absolute; inset: -2px; border-radius: 22px;
  border: 1px solid rgba(255, 214, 130, .5);
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0% { opacity: .8; transform: scale(1); } 100% { opacity: 0; transform: scale(1.08); } }

.speak {
  width: 8px; height: 8px; border-radius: 50%; background: #4ad07f;
  box-shadow: 0 0 10px #4ad07f; display: none;
}
.plate .speak.on { display: block; animation: blink .9s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.pos-top { top: 50px; left: 50%; transform: translateX(-50%); flex-direction: column; align-items: center; gap: 7px; }
.pos-left { left: 12px; top: 50%; transform: translateY(-50%); flex-direction: column; align-items: flex-start; gap: 8px; }
.pos-right { right: 12px; top: 50%; transform: translateY(-50%); flex-direction: column; align-items: flex-end; gap: 8px; }

.side-tiles { display: flex; gap: 8px; align-items: center; }
.pos-left .side-tiles, .pos-right .side-tiles { flex-direction: column; align-items: flex-start; }
.pos-right .side-tiles { align-items: flex-end; }

/* 对家手牌：一排小牌背（俯视），张张分明 */
.pos-top .backs { flex-direction: row; gap: 4px; }
.pos-top .backs .tile { --tw: calc(var(--tile-w) * 0.5); }

/* 左右两家手牌：横躺的牌背，竖向叠放，能一张张数清 */
.pos-left .backs, .pos-right .backs { flex-direction: column; gap: 4px; }
.pos-left .backs .tile, .pos-right .backs .tile {
  width: calc(var(--tile-w) * 0.66);
  height: calc(var(--tile-w) * 0.29);
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .4),
    inset 0 -1px 0 rgba(0, 0, 0, .34),
    0 1px 0 #0d4a35,
    0 2px 4px rgba(0, 0, 0, .5);
}

/* ---------- 中央：四家牌河 + 余牌 ---------- */
.table-center {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  --hub-h: 100px;          /* 牌河离中心的距离（必须 ≥ 左右两列牌河的高度一半） */
}
.river-slot { position: absolute; display: flex; gap: 3px; }
/* 对家牌河：贴着中心往上长 */
.r-top {
  left: 50%; top: calc(50% - var(--hub-h)); transform: translate(-50%, -100%);
  width: calc(6 * (var(--river-w) + 3px));
  flex-wrap: wrap-reverse; justify-content: center;
}
/* 自家牌河：中心往下长 */
.r-bottom {
  left: 50%; top: calc(50% + var(--hub-h)); transform: translateX(-50%);
  width: calc(6 * (var(--river-w) + 3px));
  flex-wrap: wrap; justify-content: center;
}
/* 左右两家：竖排，上下居中，贴着中心往外长 */
.r-left, .r-right {
  top: 50%;
  height: calc(4 * (var(--river-w) * 1.4 + 3px));
  flex-direction: column; justify-content: center;
}
.r-left { left: calc(50% - var(--hub-h)); transform: translate(-100%, -50%); flex-wrap: wrap-reverse; }
.r-right { left: calc(50% + var(--hub-h)); transform: translateY(-50%); flex-wrap: wrap; }

.center-hub {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 132px; height: 132px; z-index: 4;
  display: grid; place-items: center;
}
.hub-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid rgba(217, 178, 106, .2);
  background: radial-gradient(circle, rgba(8, 36, 25, .82) 40%, rgba(8, 36, 25, .2) 72%, transparent 76%);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .45);
}
.hub-info { position: relative; text-align: center; }
.hub-info b { display: block; font-size: 23px; color: #f0d9a6; line-height: 1; font-family: ui-monospace, monospace; }
.hub-info span { font-size: 9.5px; color: #8ba294; letter-spacing: 1px; }

/* ---------- 手牌 ---------- */
.self-plate {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 12px; border-radius: 20px;
  background: rgba(4, 20, 14, .72);
  border: 1px solid rgba(217, 178, 106, .3);
  backdrop-filter: blur(6px);
  font-size: 12px; margin-bottom: 1px;
}
.self-plate .wind {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10.5px; color: #221803; font-weight: 700;
  background: linear-gradient(160deg, #e0c48d, #b28f4c);
}
.self-plate .pname { color: #eef4ee; }
.self-plate .pscore { font-weight: 700; color: #cdd9cd; }
.self-plate .pscore.up { color: #ff8a75; }
.self-plate .pscore.down { color: #6fd39a; }
.self-plate .dealer-badge { display: none; }
.self-plate.is-dealer .dealer-badge { display: inline-block; }
.self-plate.active { border-color: rgba(255, 214, 130, .8); box-shadow: 0 0 18px rgba(255, 200, 100, .3); }

.self-melds {
  display: none; gap: 6px; justify-content: center;
  margin-bottom: 2px;
}
.self-melds .meld { padding: 2px 4px; }
.self-melds .meld .tile { --tw: calc(var(--tile-w) * 0.7); }
.hand-row {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 12; display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(1180px, 97%);
}
.hand {
  display: flex; gap: 5px; justify-content: center; align-items: flex-end;
  min-height: calc(var(--tile-w) * 1.46);
  flex-wrap: nowrap;
}
.hint {
  font-size: 12px; color: #b6c9ba; min-height: 16px; letter-spacing: .5px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
}

/* ============================================================
 * 麻将牌：象牙牌面 + 实体厚度（不做 3D 旋转，保证图案绝对清晰）
 * ============================================================ */
.tile {
  --tw: var(--tile-w);
  width: var(--tw);
  height: calc(var(--tw) * 1.4);
  position: relative;
  flex: 0 0 auto;
  border-radius: calc(var(--tw) * 0.09);
  background:
    radial-gradient(125% 55% at 28% 2%, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 62%),
    linear-gradient(178deg, #fffefa 0%, #fdf9ef 44%, #f6efdd 76%, #ebdfc4 100%);
  box-shadow:
    inset 0 1px 0 #ffffff,
    inset 0 -2px 0 rgba(140, 114, 68, .22),
    inset 1px 0 0 rgba(255, 255, 255, .9),
    inset -1px 0 0 rgba(140, 114, 68, .12),
    0 1px 0 #eee3c9,
    0 2px 0 #dccfad,
    0 3px 0 #c6b58d,
    0 calc(var(--tw) * 0.055) calc(var(--tw) * 0.11) rgba(0, 0, 0, .48);
  transition: transform .14s ease, box-shadow .14s ease, filter .14s;
}

.tile-face {
  position: absolute; inset: 0;
  border-radius: inherit;
  overflow: hidden;
  display: block;
}
.tile-svg { width: 100%; height: 100%; display: block; }
/* 高清位图牌面：240×336 预渲染，按 CSS 尺寸缩放，视网膜屏也锐利 */
.tile-img {
  width: 100%; height: 100%; display: block;
  object-fit: contain;
  -webkit-user-select: none; user-select: none;
  pointer-events: none;
}

/* 牌背 */
.tile.back {
  background:
    linear-gradient(150deg, rgba(255, 255, 255, .22) 0%, rgba(255, 255, 255, 0) 46%),
    linear-gradient(165deg, #1d7a55 0%, #146442 48%, #0b4230 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .38),
    inset 0 -2px 0 rgba(0, 0, 0, .35),
    0 1px 0 #0d4a35,
    0 2px 0 #0a3a28,
    0 3px 0 #072b1d,
    calc(var(--tw) * 0.02) calc(var(--tw) * 0.06) calc(var(--tw) * 0.12) rgba(0, 0, 0, .5);
}

/* 手牌交互 */
.hand.my-turn .tile { cursor: pointer; }
.hand.my-turn .tile:hover {
  transform: translateY(calc(var(--tw) * -0.16)) scale(1.03);
  box-shadow:
    inset 0 1px 0 #ffffff,
    inset 0 -2px 0 rgba(140, 114, 68, .24),
    0 1px 0 #eee3c9,
    0 3px 0 #dccfad,
    0 5px 0 #c6b58d,
    0 12px 18px rgba(0, 0, 0, .5);
}
.hand .tile.just-drawn { transform: translateY(calc(var(--tw) * -0.1)); }
.hand .tile.picked {
  transform: translateY(calc(var(--tw) * -0.18)) scale(1.02);
  filter: brightness(1.06);
}

/* 小牌：牌河 / 副露 / 结算 */
.tile.river-tile, .meld .tile, .tile.small {
  --tw: var(--river-w);
}
.tile.river-tile.last {
  outline: 2px solid rgba(255, 196, 88, .95);
  outline-offset: 1px;
  box-shadow:
    inset 0 1px 0 #ffffff,
    0 2px 0 #dccfad,
    0 3px 0 #c6b58d,
    0 6px 10px rgba(0, 0, 0, .45),
    0 0 18px rgba(255, 190, 80, .55);
}

/* 副露组 */
.melds { display: flex; gap: 6px; flex-wrap: wrap; }
.meld {
  display: flex; gap: 1px; padding: 2px 3px; border-radius: 5px;
  background: rgba(0, 0, 0, .22);
}
.meld .tile { --tw: calc(var(--river-w) * 0.92); }

/* 对家 / 左右家的背面 */
.backs { display: flex; gap: 4px; align-items: center; }
.backs .tile { --tw: calc(var(--tile-w) * 0.5); }
.backs .tile .tile-svg { opacity: .9; }
/* 左右两家的牌背用横版描边 */
.side-tiles { flex: 0 0 auto; }

/* ---------- 出牌文字播报 / 等待提示 ---------- */
.callout {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(.94);
  z-index: 40; display: flex; align-items: center; gap: 7px;
  padding: 7px 16px; border-radius: 999px;
  background: rgba(4, 20, 14, .9);
  border: 1px solid rgba(217, 178, 106, .45);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55), 0 0 22px rgba(217, 178, 106, .12);
  font-size: 13.5px; color: #dfe9e1; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .16s, transform .16s;
  backdrop-filter: blur(6px);
}
.callout.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.callout b { color: #ffd479; font-weight: 700; }
.callout i { font-style: normal; color: #9db3a5; }

.wait-pill {
  position: relative; display: none; align-items: center; gap: 7px;
  padding: 4px 14px 5px; border-radius: 999px;
  background: rgba(4, 20, 14, .82);
  border: 1px solid rgba(217, 178, 106, .22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
  font-size: 11.5px; color: #b7cab9; white-space: nowrap;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  flex: 0 0 auto;
}
.wait-pill.show { display: flex; }
.wait-pill b { color: #f2dcaa; font-weight: 600; }
.wait-pill.mine { border-color: rgba(255, 214, 130, .7); color: #f7e6bf; }
.wait-pill.mine i { animation: blink 1.2s infinite; }
.wait-pill i {
  width: 6px; height: 6px; border-radius: 50%; background: #6fd39a;
  box-shadow: 0 0 8px #6fd39a; font-style: normal; flex: 0 0 auto;
}
.wait-pill u {
  position: absolute; left: 0; bottom: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, #ffd479, #c9962e);
  transition: width .12s linear;
}
.wait-pill.over { border-color: rgba(255, 120, 96, .8); }
.wait-pill.over b { color: #ff9a86; }
.wait-pill.over u { background: linear-gradient(90deg, #ff9a86, #c0291b); }

/* ---------- 等待倒计时 ---------- */
.cdown {
  position: absolute; left: 50%; bottom: calc(var(--tile-w) * 1.38 + 164px);
  transform: translateX(-50%);
  z-index: 29; display: none; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: rgba(5, 24, 17, .9);
  border: 1px solid rgba(217, 178, 106, .42);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .55);
  font-size: 12px; color: #cfe0d3; letter-spacing: .5px;
  white-space: nowrap;
}
.cdown.show { display: flex; }
.cdown b {
  font-size: 15px; color: #ffd479; font-variant-numeric: tabular-nums;
  font-family: ui-monospace, monospace; min-width: 44px; text-align: right;
}
.cdown i {
  display: block; width: 56px; height: 4px; border-radius: 3px;
  background: linear-gradient(90deg, #ffd479, #c9962e);
  transition: width .1s linear;
}
.cdown.warn { border-color: rgba(255, 120, 96, .85); }
.cdown.warn b { color: #ff9a86; }
.cdown.warn i { background: linear-gradient(90deg, #ff9a86, #c0291b); }

/* ---------- 操作条 ---------- */
.actionbar {
  position: absolute; left: 50%; bottom: calc(var(--tile-w) * 1.4 + 58px);
  transform: translateX(-50%);
  z-index: 30; display: none; gap: 10px;
  padding: 8px 10px; border-radius: 14px;
  background: rgba(4, 20, 14, .82);
  border: 1px solid rgba(217, 178, 106, .32);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .55);
  backdrop-filter: blur(10px);
}
.actionbar.show { display: flex; animation: popIn .2s ease; }
@keyframes popIn { from { transform: translateX(-50%) translateY(8px) scale(.96); opacity: 0; } }

.act {
  min-width: 66px; height: 44px; padding: 0 14px;
  border: 0; border-radius: 9px; cursor: pointer;
  font-size: 17px; font-weight: 800; letter-spacing: 1px;
  font-family: STKaiti, KaiTi, serif;
  color: #2a1c05;
  background: linear-gradient(180deg, #e8cb8f, #c09a51);
  box-shadow: 0 5px 0 #8d6f34, 0 10px 22px rgba(0, 0, 0, .4);
  transition: transform .1s, filter .15s;
}
.act:hover { filter: brightness(1.08); }
.act:active { transform: translateY(3px); box-shadow: 0 2px 0 #8d6f34; }
.act-hu {
  background: linear-gradient(180deg, #f0705c, #c0291b);
  color: #fff6ee; box-shadow: 0 5px 0 #7d1a10, 0 10px 26px rgba(200, 60, 40, .45);
  animation: huGlow 1.1s infinite;
}
@keyframes huGlow { 50% { filter: brightness(1.18); } }
.act-pass { background: linear-gradient(180deg, #566, #3d4a44); color: #d6e2d8; box-shadow: 0 5px 0 #253028; }
.act-gang { background: linear-gradient(180deg, #8fb8f0, #5a86c8); color: #0b1a2e; box-shadow: 0 5px 0 #3a5c8f; }

/* ============================================================
 * 覆盖层 / 结算
 * ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: none; place-items: center;
  background: rgba(2, 12, 8, .74);
  backdrop-filter: blur(6px);
  padding: 16px;
}
.overlay.show { display: grid; animation: fadeIn .22s ease forwards; }

.card {
  width: min(440px, 94vw); max-height: 90vh; overflow-y: auto;
  padding: 26px 24px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(24, 66, 48, .97), rgba(7, 26, 18, .99));
  border: 1px solid rgba(217, 178, 106, .3);
  box-shadow: 0 34px 80px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .08);
  text-align: center;
  position: relative;
}
.card h2 { margin: 0 0 6px; font-size: 22px; font-family: STKaiti, KaiTi, serif; color: #f4e0b4; letter-spacing: 2px; }
.card .sub { font-size: 12px; color: var(--ink-dim); }

.win-ribbon {
  display: inline-block; margin-bottom: 10px;
  padding: 3px 16px; border-radius: 20px;
  background: linear-gradient(180deg, #d8b271, #a8813d);
  color: #241a06; font-size: 12px; font-weight: 800; letter-spacing: 3px;
}
.card.win.big .win-ribbon {
  background: linear-gradient(180deg, #f0b34a, #b8401c);
  color: #fff6e6;
  animation: huGlow 1.2s infinite;
}
.win-ribbon.draw-ribbon {
  background: linear-gradient(180deg, #7d8f86, #4c5d55);
  color: #eef4ee;
}
.fan-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
.fan-chip {
  padding: 4px 11px; border-radius: 20px; font-size: 12px;
  background: rgba(217, 178, 106, .16);
  border: 1px solid rgba(217, 178, 106, .34);
  color: #f2debb;
}
.fan-chip b { color: #ffd479; }
.mult-line { font-size: 11.5px; color: #9fb9a6; letter-spacing: .4px; margin-bottom: 12px; line-height: 1.7; }
.mult-line b { color: #ffd479; font-size: 13px; }

.win-hand { display: flex; gap: 2px; justify-content: center; flex-wrap: wrap; margin: 10px 0 14px; row-gap: 4px; }
.win-hand .tile { --tw: 26px; }
.win-hand .meld { padding: 0; background: transparent; gap: 1px; margin-right: 5px; }
.win-hand .meld .tile { --tw: 24px; }
.win-hand .tile.win-tile {
  outline: 2px solid rgba(255, 196, 88, .85);
  outline-offset: 0;
  border-radius: 3px;
}

.pay-list { display: flex; flex-direction: column; gap: 5px; margin: 12px 0; }
.pay-row {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px;
  padding: 7px 12px; border-radius: 9px; background: rgba(0, 0, 0, .26);
}
.pay-row .arrow { color: #6f8577; }
.pay-row .amt { margin-left: auto; color: #ff8a75; font-weight: 700; }
.gain { margin-top: 8px; font-size: 30px; font-weight: 800; color: #ffd06a; text-shadow: 0 2px 18px rgba(255, 190, 80, .4); }
.tap-tip { margin-top: 14px; font-size: 11px; color: #7f9588; }

/* 结算战绩表 */
.score-table { width: 100%; border-collapse: collapse; margin: 14px 0 8px; font-size: 12.5px; }
.score-table th { color: #8ba294; font-weight: 500; font-size: 11px; padding: 5px; border-bottom: 1px solid rgba(217, 178, 106, .18); }
.score-table td { padding: 8px 5px; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.score-table td.up { color: #ff8a75; font-weight: 700; }
.score-table td.down { color: #6fd39a; font-weight: 700; }
.score-table tr.me td { background: rgba(217, 178, 106, .1); }
.final-list { display: flex; flex-direction: column; gap: 6px; margin: 16px 0; }
.final-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 11px; background: rgba(0, 0, 0, .26);
}
.final-row .rk {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; background: rgba(255, 255, 255, .1); color: #cfe0d3;
}
.final-row:nth-child(1) .rk { background: linear-gradient(160deg, #f0c95c, #b8922e); color: #241a06; }
.final-row .nm { text-align: left; flex: 1; font-size: 13.5px; display: flex; flex-direction: column; line-height: 1.2; }
.final-row .nm .fa-acc { font-style: normal; font-size: 9.5px; color: #8fa899; }
.avatar.sm { width: 26px; height: 26px; }
.final-row .sc { font-size: 15px; font-weight: 800; }
.final-row .sc.up { color: #ff8a75; }
.final-row .sc.down { color: #6fd39a; }

/* ============================================================
 * 其他
 * ============================================================ */
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%) translateY(10px);
  z-index: 80; padding: 9px 20px; border-radius: 22px;
  background: rgba(4, 20, 14, .9); border: 1px solid rgba(217, 178, 106, .3);
  font-size: 12.5px; color: #f0e2c4; opacity: 0; pointer-events: none;
  transition: .24s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.log-panel {
  position: fixed; left: 12px; bottom: 12px; z-index: 25;
  width: 220px; max-height: 84px; overflow: hidden;
  pointer-events: none;
  mask-image: linear-gradient(180deg, transparent, #000 46%);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 46%);
}
.log-list { display: flex; flex-direction: column; gap: 2px; font-size: 10.5px; color: #8fa899; }
.log-item.hu { color: #ffb08a; }
.log-item.peng { color: #9fd8b8; }
.log-item.kong { color: #a9c8f0; }
.log-item.sys { color: #cbb98f; }

.modal {
  position: fixed; inset: 0; z-index: 90; display: none; place-items: center;
  background: rgba(2, 12, 8, .8); backdrop-filter: blur(5px); padding: 16px;
}
.modal.show { display: grid; }
.modal-card {
  width: min(520px, 94vw); max-height: 84vh; display: flex; flex-direction: column;
  border-radius: 18px; padding: 24px;
  background: linear-gradient(180deg, #143c2b, #08201a);
  border: 1px solid rgba(217, 178, 106, .26);
}
.modal-card h2 { margin: 0 0 14px; font-size: 18px; color: #f0d9a6; font-family: STKaiti, KaiTi, serif; }
.modal-body { overflow-y: auto; font-size: 12.5px; line-height: 1.9; color: #b9cbbd; }
.modal-body h3 { font-size: 13px; color: #e0cfa5; margin: 14px 0 4px; }
.modal-body p { margin: 0; }
.modal-body ul { margin: 4px 0; padding-left: 18px; }
.modal-card .btn-primary { margin-top: 16px; }

/* 飘字 */
.flash-text {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%);
  z-index: 70; pointer-events: none; text-align: center;
  animation: flashUp .9s ease forwards;
}
.flash-text b {
  font-size: 46px; font-family: STKaiti, KaiTi, serif; color: #ffd06a;
  text-shadow: 0 0 30px rgba(255, 180, 60, .8), 0 4px 12px rgba(0, 0, 0, .8);
}
.flash-text span { display: block; font-size: 13px; color: #f0e2c4; margin-top: 2px; }
@keyframes flashUp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  70% { opacity: 1; transform: translate(-50%, -56%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(.96); }
}

/* ============================================================
 * 响应式
 * ============================================================ */
@media (max-width: 1100px) {
  :root { --tile-w: clamp(36px, 4.4vw, 46px); --river-w: clamp(18px, 2.4vw, 25px); }
  .pos-left, .pos-right { width: 120px; }
  .pos-top { width: 78%; }
}

@media (max-width: 780px) {
  :root {
    /* 14 张牌不再铺满零留白：两端各留 22px 呼吸感 */
    --tile-w: min(calc((100vw - 44px) / 14), 34px);
    --river-w: clamp(16px, 4.2vw, 24px);
  }
  .hud { height: 38px; padding: 0 8px; }
  .hud-left { display: none; }
  .hud-mid { gap: 9px; font-size: 10.5px; }
  .hud-mid b { font-size: 11px; }
  .hud-mid .hud-item:nth-child(3) { display: none; }
  .hud-right { gap: 3px; }
  .hud-btn {
    height: 28px; padding: 0 7px; font-size: 10.5px;
    white-space: nowrap; border-radius: 6px;
  }
  /* 手机上顶栏放不下，语音开关用牌桌左上角那个大按钮 */
  #btn-voice-table { display: none; }
  .voice-dock { left: 7px; top: 46px; gap: 3px; }
  .vd-btn { width: 50px; height: 50px; }
  .vd-ic { font-size: 17px; }
  .vd-txt { font-size: 8.5px; }
  .vd-state { font-size: 8.5px; padding: 1px 6px; }
  .voice-nudge { gap: 8px; padding: 10px; border-radius: 12px; width: min(344px, 92vw); bottom: calc(var(--tile-w) * 1.4 + 118px); }
  .vn-ic { font-size: 19px; }
  .vn-txt b { font-size: 12px; }
  .vn-txt span { font-size: 10.5px; }
  .vn-yes { height: 29px; padding: 0 12px; font-size: 11.5px; }
  .pos-top { width: 94%; top: 42px; gap: 5px; }
  .pos-left, .pos-right { width: auto; }
  .pos-left { left: 5px; }
  .pos-right { right: 5px; }
  .plate { padding: 3px 7px; gap: 5px; }
  .plate .wind { width: 17px; height: 17px; font-size: 9px; }
  .plate .pname { font-size: 10.5px; max-width: 56px; }
  .avatar { width: 20px; height: 20px; }
  .plate .paccount, .self-plate .paccount { font-size: 8px; max-width: 60px; }
  .plate .pscore { font-size: 10.5px; }
  .dealer-badge { font-size: 8.5px; padding: 0 4px; }

  .table-center { --hub-h: 58px; }
  .center-hub { width: 84px; height: 84px; }
  .hub-info b { font-size: 19px; }
  .hub-info span { font-size: 8.5px; }
  /* 竖屏横向空间充裕：牌河一行放 7 张，免得竖着堆太高 */
  .r-top, .r-bottom { width: calc(7 * (var(--river-w) + 3px)); }
  .r-left, .r-right { height: calc(5 * (var(--river-w) * 1.4 + 3px)); }

  /* 左右座位从屏幕边缘收进来，牌背放大到能数清 */
  .pos-left { left: 10px; }
  .pos-right { right: 10px; }
  .pos-left .backs .tile, .pos-right .backs .tile {
    width: calc(var(--tile-w) * 0.82);
    height: calc(var(--tile-w) * 0.36);
    border-radius: 5px;
  }
  .pos-left .backs, .pos-right .backs { gap: 5px; }

  /* 喊话气泡上移到余牌圈上方，不再盖住中央信息 */
  .table { --hub-h: 58px; }
  .callout { top: calc(50% - var(--hub-h) - 26px); }

  /* 适配 iPhone 底部小白条 / 手势区 */
  .hand-row {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: 100%; gap: 5px;
  }
  .hand { gap: 2px; }
  .self-plate { padding: 3px 9px; font-size: 10.5px; margin-bottom: 0; }
  .self-plate .wind { width: 17px; height: 17px; font-size: 9px; }
  .hint { font-size: 10.5px; }

  .log-panel { display: none; }
  .lobby { grid-template-columns: 1fr; padding: 66px 14px 24px; }
  .room-seats { grid-template-columns: 1fr; }
  .actionbar {
    bottom: calc(var(--tile-w) * 1.4 + 44px);
    padding: 6px 8px; gap: 6px; border-radius: 11px;
  }
  .wait-pill { padding: 3px 10px 4px; font-size: 10px; gap: 5px; }
  .callout { font-size: 11px; padding: 5px 11px; }
  .plate .pcnt { font-size: 9px; padding: 0 4px; }
  .act { min-width: 48px; height: 36px; font-size: 13.5px; padding: 0 9px; }
  .auth-card { padding: 26px 20px 20px; }
  .brand h1 { font-size: 21px; }
  .card { padding: 20px 16px; }
  .card h2 { font-size: 18px; }
  .win-hand .tile { --tw: 20px; }
  .win-hand .meld .tile { --tw: 19px; }
  .gain { font-size: 24px; }
}

@media (max-height: 560px) {
  .hand-row { bottom: 6px; }
  .hint { display: none; }
}
