* { box-sizing: border-box; }

:root {
  --felt-1: #17705a;
  --felt-2: #0e4739;
  --felt-3: #0a332a;
  --gold: #d9bd7d;
  --gold-dim: #a8905a;
  --ivory: #fffdf4;
  --ink: #2b2a26;
  --red: #b03a2e;
  --blue: #20509e;
  --green: #177a4a;
  /* 移动端视口高度：优先用 dvh（Safari 地址栏收放时更准） */
  --appvh: 100vh;
}

@supports (height: 100dvh) {
  :root { --appvh: 100dvh; }
}

html, body {
  margin: 0;
  padding: 0;
  background: #081f1a;
  color: #eef4f1;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* 移动端：禁止双击缩放（连点两下按钮不再放大页面），捏合缩放保留 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}
body { touch-action: manipulation; }
/* iOS 13 以下对 html 上的 touch-action 支持不完整，按钮/牌面再单独关一次 */
.btn, .act, .tile, .hand, .actions, .tools, .overlay, .modal, .myinfo, .caijin-box {
  touch-action: manipulation;
}
/* 点牌、点按钮时长按不弹「拷贝/打开链接」菜单，也不选中文字 */
.tile, .btn, .act, .avatar, .hud { -webkit-touch-callout: none; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 14px 18px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 4px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.brand > div { min-width: 0; }
.logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(160deg, #f4ead2, #d9c9a1);
  color: #6b4a1f; font-size: 24px; font-weight: 600;
  display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.brand h1 {
  font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand .sub {
  margin: 2px 0 0; font-size: 12px; color: #8fb3a8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.caijin-box {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(217,189,125,.28);
  border-radius: 12px; padding: 6px 12px 6px 14px;
}
.caijin-label { font-size: 12px; color: #cfe3db; letter-spacing: 1px; }
.caijin-slot { display: flex; }
.caijin-slot .tile { box-shadow: 0 0 0 2px #f0c65c, 0 4px 10px rgba(0,0,0,.45); }

.tools { display: flex; gap: 8px; }
.btn {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.18);
  color: #e9f2ee;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: .15s;
  font-family: inherit;
}
.btn:hover { background: rgba(255,255,255,.14); border-color: rgba(217,189,125,.5); }
.btn.primary { background: linear-gradient(180deg,#e6cf95,#c9a95f); color:#3a2a0c; border-color:#e8d9b0; font-weight:600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 12px 44px; font-size: 15px; border-radius: 10px; }

/* ---------- 牌桌 ---------- */
.table {
  position: relative;
  display: grid;
  grid-template-columns: 116px minmax(0,1fr) 116px;
  grid-template-rows: 92px minmax(0,1fr);
  grid-template-areas:
    "top top top"
    "left center right";
  gap: 6px;
  padding: 12px;
  height: min(600px, calc(100vh - 320px));
  min-height: 400px;
  border-radius: 26px;
  background:
    radial-gradient(120% 110% at 50% 42%, #1a7a62 0%, #10513f 55%, #0a332a 100%);
  box-shadow: inset 0 0 70px rgba(0,0,0,.45), inset 0 0 0 2px rgba(217,189,125,.16), 0 14px 34px rgba(0,0,0,.45);
}

.seat { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 4px; }
.seat-top { grid-area: top; flex-direction: row; justify-content: center; align-items: center; gap: 14px; }
.seat-left { grid-area: left; }
.seat-right { grid-area: right; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(3,26,21,.55);
  border: 2px solid rgba(217,189,125,.55);
  display: grid; place-items: center;
  font-size: 15px; color: var(--gold);
  position: relative;
  transition: .2s;
}
.seat.active .avatar { border-color: #ffe9a8; box-shadow: 0 0 0 4px rgba(255,222,150,.22), 0 0 16px rgba(255,215,120,.4); }
.avatar .wind {
  position: absolute; right: -4px; bottom: -4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #e8d3a0; color: #4a3510;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  border: 1px solid #fff8e2;
}
.avatar .dealer {
  position: absolute; left: -6px; top: -6px;
  background: #c0392b; color: #fff; font-size: 10px;
  padding: 1px 5px; border-radius: 6px; letter-spacing: 1px;
}
.pname { font-size: 13px; color: #e8f2ee; }
.pmeta { font-size: 11px; color: #9dc0b5; display: flex; gap: 6px; align-items: center; }
.pmeta .cnt { background: rgba(0,0,0,.25); padding: 1px 6px; border-radius: 6px; }
.pscore { font-size: 11px; color: #f0d99a; }

/* 对家手牌背面 */
.backrow { display: flex; gap: 2px; flex-wrap: nowrap; }
.backrow .tile.back { width: 15px; height: 22px; border-radius: 3px; }

.melds-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
.meld-group { display: flex; gap: 1px; padding: 2px; background: rgba(0,0,0,.16); border-radius: 5px; }
.meld-group .tile { font-size: 10px; }

/* ---------- 中央 ---------- */
.center {
  grid-area: center;
  display: grid;
  grid-template-columns: 88px minmax(0,1fr) 88px;
  grid-template-rows: minmax(0,1fr) auto minmax(0,1fr);
  grid-template-areas:
    "pl pt pr"
    "pl hud pr"
    "pl pb pr";
  gap: 4px;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(217,189,125,.10);
  border-radius: 18px;
  padding: 8px;
  box-shadow: inset 0 0 34px rgba(0,0,0,.25);
}
.pool { display: flex; flex-wrap: wrap; gap: 3px; overflow: hidden; }
.pool-top { grid-area: pt; justify-content: center; align-content: flex-end; padding-bottom: 8px; }
.pool-bottom { grid-area: pb; justify-content: center; align-content: flex-start; padding-top: 8px; }
.pool-left { grid-area: pl; align-content: center; justify-content: flex-end; padding-right: 8px; }
.pool-right { grid-area: pr; align-content: center; justify-content: flex-start; padding-left: 8px; }
.pool .tile { opacity: .96; }
.pool .tile.last { box-shadow: 0 0 0 2px #ffd76e, 0 3px 8px rgba(0,0,0,.4); transform: translateY(-2px); }

.hud {
  grid-area: hud;
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 6px;
}
.hud::before {
  content: "臺";
  position: absolute;
  font-size: 170px;
  line-height: 1;
  color: rgba(217,189,125,.06);
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}
.hud > * { position: relative; }
.wall-count { display: flex; align-items: baseline; gap: 5px; color: #cfe3db; }
.wall-count b { font-size: 26px; color: #ffe6a8; font-weight: 600; }
.wall-count span { font-size: 11px; color: #9dc0b5; }
.turn-tip { font-size: 11px; color: #cfe3db; background: rgba(0,0,0,.25); padding: 3px 10px; border-radius: 20px; white-space: nowrap; }

/* ---------- 牌 ---------- */
.tile {
  position: relative;
  font-size: 16px;
  width: 48px; height: 66px;
  border-radius: 7px;
  background: linear-gradient(175deg, #fffef8 0%, #f6f1e2 62%, #e9e1cc 100%);
  border: 1px solid #d6ccb1;
  box-shadow: 0 2px 0 #c9bda0, 0 4px 8px rgba(0,0,0,.28);
  display: grid; place-items: center;
  user-select: none;
  flex: none;
  transition: transform .1s, box-shadow .1s;
}
.tile .face { position: absolute; inset: 0; display: block; }
.tile .face svg { display: block; width: 100%; height: 100%; }

.tile.sm { width: 30px; height: 42px; font-size: 10px; border-radius: 5px; box-shadow: 0 1px 0 #c9bda0, 0 2px 4px rgba(0,0,0,.28); }
.tile.xs { width: 26px; height: 36px; font-size: 9px; border-radius: 4px; box-shadow: 0 1px 0 #c9bda0, 0 2px 4px rgba(0,0,0,.25); }
.tile.caijin-size { width: 34px; height: 48px; font-size: 11px; border-radius: 5px; }

.tile.back {
  background: linear-gradient(160deg, #2c8a6c, #175b46);
  border: 1px solid #0f4534;
  box-shadow: 0 2px 0 #0d3b2c, 0 3px 6px rgba(0,0,0,.3);
}
.tile.back::after {
  content: "";
  position: absolute; inset: 5px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.13);
}

.tile.wild { box-shadow: 0 0 0 2px #f0c65c, 0 3px 10px rgba(240,198,92,.45), 0 2px 0 #c9bda0; }
.tile.wild::before {
  content: "财";
  position: absolute; top: -6px; right: -6px;
  background: #d8a52a; color: #3d2a05;
  font-size: 9px; font-weight: 700;
  width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid #fff3cf;
  z-index: 2;
}
.tile.wild.sub::before { content: "替"; background: #8a6bc4; color: #fff; border-color: #ded0f5; }
.tile.wild.sub { box-shadow: 0 0 0 2px #a98bd6, 0 3px 10px rgba(169,139,214,.4), 0 2px 0 #c9bda0; }

.tile.clickable { cursor: pointer; }
.tile.clickable:hover { transform: translateY(-8px); box-shadow: 0 6px 14px rgba(0,0,0,.4), 0 2px 0 #c9bda0; }
.tile.picked { transform: translateY(-10px); box-shadow: 0 0 0 2px #ffd76e, 0 6px 14px rgba(0,0,0,.4); }
.tile.hint { box-shadow: 0 0 0 3px #7fd6b0, 0 4px 12px rgba(0,0,0,.4); }
.tile.dead { opacity: .45; cursor: not-allowed; }

/* ---------- 底部 ---------- */
.bottom {
  margin-top: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 16px;
  padding: 10px 14px 12px;
}
.myinfo { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.myinfo .avatar { width: 34px; height: 34px; font-size: 13px; }
.handwrap { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.melds { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 0; }
.hand { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; padding: 10px 4px 4px; min-height: 74px; }
.hand .tile.gap { margin-left: 14px; }

.actions { display: flex; gap: 10px; justify-content: center; min-height: 44px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.act {
  font-family: inherit;
  font-size: 15px;
  padding: 9px 22px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.1);
  color: #fff;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: .15s;
}
.act:hover { background: rgba(255,255,255,.2); transform: translateY(-1px); }
.act.hu { background: linear-gradient(180deg,#e8514a,#c02f28); border-color:#ff8b84; font-weight: 600; letter-spacing: 2px; }
.act.hu:hover { filter: brightness(1.1); }
.act.pass { color: #b9cfc7; }
.act .tile { margin: -6px 0; }

.statusbar { text-align: center; font-size: 12px; color: #9dc0b5; min-height: 18px; margin-top: 4px; }
.statusbar b { color: #ffd98a; font-weight: 600; }
.statusbar .wait { color: #7fe0b0; }
.statusbar .ting-turn { color: #7fe0b0; }
.statusbar .ting-turn .sep { color: #4d7066; margin: 0 6px; }
.statusbar .ting-turn .alt { color: #9dc0b5; }

/* 出牌提示卡：浮在牌桌下沿，不挤压手牌 */
.hintbox {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  z-index: 8;
  text-align: left;
  background: rgba(6,44,36,.95);
  border: 1px solid rgba(240,198,92,.35);
  border-left: 3px solid #f0c65c;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  line-height: 1.6;
  color: #cfe3db;
  box-shadow: 0 10px 26px rgba(0,0,0,.45);
}
.hintbox.show { display: block; }
.hintbox .htitle { color: #ffd98a; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.hintbox .htitle b { color: #fff; }
.hintbox .hrow { display: flex; gap: 7px; align-items: flex-start; }
.hintbox .hrow + .hrow { margin-top: 2px; }
.hintbox .htag {
  flex: 0 0 auto;
  font-size: 10px;
  line-height: 15px;
  padding: 0 4px;
  margin-top: 2px;
  border-radius: 3px;
  background: rgba(240,198,92,.16);
  color: #f0c65c;
  letter-spacing: .5px;
}
.hintbox .htag.good { background: rgba(127,224,176,.16); color: #7fe0b0; }
.hintbox .hnote { margin-top: 5px; font-size: 11px; color: #7f9e94; }

/* ---------- 弹层 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(3,16,13,.78);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay.show { display: flex; }
.modal {
  background: linear-gradient(180deg, #123f34, #0b2b24);
  border: 1px solid rgba(217,189,125,.35);
  border-radius: 18px;
  padding: 26px 30px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  text-align: center;
}
.modal.wide { max-width: 860px; text-align: left; max-height: 88vh; overflow-y: auto; }
.modal h2 { margin: 0 0 12px; font-size: 19px; font-weight: 600; color: #ffe6a8; letter-spacing: 1px; }
.modal .lead { font-size: 13px; color: #b9d5cb; margin: 0 0 16px; line-height: 1.7; }
.rules-brief { text-align: left; margin: 0 0 22px; padding-left: 18px; font-size: 13px; line-height: 1.9; color: #d5e6df; }
.rules-brief b { color: #ffd98a; }
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 22px; margin-bottom: 20px; }
.rules-grid h3 { font-size: 13px; color: #ffd98a; margin: 0 0 8px; font-weight: 600; }
.mini { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini th, .mini td { border-bottom: 1px solid rgba(255,255,255,.1); padding: 5px 4px; text-align: left; }
.mini th { color: #9dc0b5; font-weight: 400; font-size: 11px; }
.dots { margin: 0; padding-left: 16px; font-size: 12.5px; line-height: 1.9; color: #d5e6df; }
.note { font-size: 11.5px; color: #8fb3a8; line-height: 1.7; margin: 10px 0 0; }

.guide { border-top: 1px solid rgba(255,255,255,.12); padding-top: 16px; margin-bottom: 22px; }
.guide h3 { font-size: 13px; color: #ffd98a; margin: 0 0 10px; font-weight: 600; }
.guide-row { display: flex; align-items: flex-end; gap: 5px; margin-bottom: 10px; flex-wrap: wrap; }
.glabel { width: 30px; font-size: 11px; color: #9dc0b5; flex: none; padding-bottom: 15px; }
.guide-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.guide-cell span { font-size: 10px; color: #a8c8bd; }
.tile.guide { width: 38px; height: 53px; border-radius: 5px; box-shadow: 0 2px 0 #c9bda0, 0 3px 6px rgba(0,0,0,.3); }

.result-title { font-size: 22px; color: #ffd98a; margin: 0 0 4px; }.result-sub { font-size: 13px; color: #b9d5cb; margin: 0 0 18px; }
.calc { background: rgba(0,0,0,.25); border-radius: 12px; padding: 14px 16px; margin-bottom: 18px; text-align: left; }
.calc-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; color: #d5e6df; }
.calc-row.total { border-top: 1px solid rgba(255,255,255,.15); margin-top: 8px; padding-top: 8px; font-size: 15px; color: #ffe6a8; }
.calc-fan { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.calc-fan span { background: rgba(217,189,125,.16); color: #ffd98a; font-size: 11.5px; padding: 3px 9px; border-radius: 20px; }
.fan-why { margin-top: 12px; padding-top: 10px; border-top: 1px dashed rgba(255,255,255,.14); }
.fan-why-title { font-size: 11px; color: #b9cbba; margin-bottom: 6px; letter-spacing: .04em; }
.fan-row { display: flex; flex-direction: column; gap: 2px; padding: 5px 0; font-size: 11.5px; line-height: 1.8; }
.fan-row b { color: #ffd98a; font-weight: 600; }
.fan-row span { color: #c9d8c6; }
.winhand { margin-bottom: 16px; }
.winhand-label { font-size: 11px; color: #8fb3a8; margin-bottom: 6px; letter-spacing: 1px; }

/* 胡牌拆解：一组一组摊开，看得懂怎么胡的 */
.decomp { text-align: left; margin-bottom: 18px; }
.decomp-head {
  font-size: 13px; color: #ffd98a; font-weight: 600; letter-spacing: 1px;
  margin-bottom: 8px; display: flex; align-items: baseline; gap: 8px;
}
.decomp-head span { font-size: 11px; color: #8fb3a8; font-weight: 400; letter-spacing: 0; }
.decomp-groups { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.dgroup {
  display: flex; flex-direction: column; gap: 5px;
  background: rgba(0,0,0,.24);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 9px; padding: 7px 10px 8px;
}
.dgroup.meld { border-color: rgba(217,189,125,.4); background: rgba(217,189,125,.07); }
.dgroup.pair { border-color: rgba(127,224,176,.4); background: rgba(127,224,176,.07); }
.dtag { font-size: 10px; color: #9dc0b5; text-align: center; letter-spacing: .5px; white-space: nowrap; }
.dgroup.meld .dtag { color: #f0c65c; }
.dgroup.pair .dtag { color: #7fe0b0; }
.dtiles { display: flex; gap: 5px; }
.dtiles .tile.sm { width: 29px; height: 40px; border-radius: 4px; }
.wildslot { outline: 2px dashed #f0c65c; outline-offset: -2px; }
.wildslot .wtag {
  position: absolute; top: -5px; right: -5px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #d8a52a; color: #3d2a05;
  font-size: 8px; font-weight: 700;
  display: grid; place-items: center;
  border: 1px solid #fff3cf;
  z-index: 2;
}
.dlegend { margin-top: 9px; font-size: 11px; color: #7f9e94; line-height: 1.7; }
.winhand-tiles { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 0; }
.winhand-tiles .wm { display: flex; gap: 3px; margin-right: 12px; padding-right: 12px; border-right: 1px solid rgba(255,255,255,.16); }
.winhand-tiles .wh { display: flex; gap: 3px; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
/* 结算弹层：正文自己滚，按钮钉在底部，内容再长也点得到 */
#resultBox {
  max-width: 700px;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  max-height: calc(100dvh - 40px);
  overflow: hidden;
}
.result-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 28px 6px;
  text-align: center;
}
.result-foot {
  flex: 0 0 auto;
  padding: 10px 24px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255,255,255,.1);
  background: linear-gradient(180deg, rgba(11,43,36,.92), #0b2b24);
}
.result-foot .btn { width: 100%; }

.hu-total { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 0 0 10px; }
.hu-total span { font-size: 12px; color: #9dc0b5; }
.hu-total b { font-size: 26px; color: #ffd98a; line-height: 1; }
.hu-total i { font-style: normal; font-size: 11px; color: #8fb3a8; }

.fold {
  margin-bottom: 10px; text-align: left;
  border: 1px solid rgba(255,255,255,.1); border-radius: 10px;
  background: rgba(0,0,0,.16);
}
.fold > summary {
  list-style: none; cursor: pointer;
  padding: 9px 12px; font-size: 12px; color: #b7d6ca;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after {
  content: '展开'; flex: none;
  font-size: 10px; color: #7f9e94;
  border: 1px solid rgba(255,255,255,.18); border-radius: 20px; padding: 1px 8px;
}
.fold[open] > summary::after { content: '收起'; }
.fold > .calc { margin: 0 8px 8px; }
.fold .winhand-tiles { padding: 2px 12px 12px; }

.total-scores { font-size: 12px; color: #9dc0b5; margin-bottom: 4px; }

.score-delta { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }
.score-delta div { background: rgba(255,255,255,.06); border-radius: 10px; padding: 8px 14px; font-size: 12px; }
.score-delta b { display: block; font-size: 15px; margin-top: 3px; }
.up { color: #ff9a92; }
.down { color: #7fd6b0; }

@media (max-width: 860px) {
  .table { grid-template-columns: 84px minmax(0,1fr) 84px; height: auto; min-height: 420px; }
  .tile { width: 38px; height: 53px; font-size: 13px; }
  .tile.sm { width: 25px; height: 35px; font-size: 8px; }
  .center { grid-template-columns: 70px 1fr 70px; }
  .brand h1 { font-size: 15px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
}

/* ---------- 手机（竖屏） ---------- */
@media (max-width: 560px) {
  .app { padding: 8px 8px 12px; }

  /* 顶栏拆两行：品牌 + 财神 / 三个按钮平分一行 */
  .topbar {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-areas:
      "brand caijin"
      "tools tools";
    align-items: center;
    gap: 8px;
    padding: 2px 2px 8px;
  }
  .brand { grid-area: brand; gap: 8px; }
  .logo { width: 34px; height: 34px; font-size: 19px; border-radius: 9px; flex: none; }
  .brand h1 { font-size: 14px; letter-spacing: 0; }
  .brand .sub { font-size: 11px; margin-top: 1px; }
  .caijin-box { grid-area: caijin; gap: 6px; padding: 3px 7px 3px 9px; border-radius: 10px; }
  .caijin-label { font-size: 10px; letter-spacing: 0; }
  .caijin-slot .tile.caijin-size { width: 26px; height: 36px; border-radius: 4px; }
  .tools { grid-area: tools; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .tools .btn { padding: 7px 0; font-size: 13px; border-radius: 7px; }

  /* 牌桌：固定高度，避免弃牌一多桌面就长高把底下的手牌顶下去；
     小屏（如 iPhone SE）自动压缩，保证手牌和吃碰杠按钮都在首屏里 */
  .table {
    grid-template-columns: 42px minmax(0,1fr) 42px;
    grid-template-rows: 48px minmax(0,1fr);
    height: clamp(200px, calc(var(--appvh) - 368px), 348px);
    min-height: 0;
    padding: 8px; gap: 4px; border-radius: 18px;
  }
  .center {
    grid-template-columns: 44px minmax(0,1fr) 44px;
    gap: 3px; padding: 6px; border-radius: 14px;
  }
  .hud { gap: 3px; padding: 4px; }
  .hud::before { font-size: 84px; }
  .wall-count b { font-size: 20px; }
  .wall-count span { font-size: 10px; }
  .turn-tip { font-size: 10px; padding: 2px 8px; }

  .seat { gap: 3px; padding: 2px; }
  .seat-top { gap: 8px; }
  .avatar { width: 32px; height: 32px; font-size: 12px; border-width: 1.5px; }
  .avatar .wind { width: 15px; height: 15px; font-size: 9px; right: -3px; bottom: -3px; }
  .avatar .dealer { font-size: 8px; padding: 0 4px; left: -4px; top: -4px; }
  .pname { font-size: 11px; }
  .pmeta, .pscore { font-size: 10px; }
  .pmeta .cnt { padding: 0 4px; }
  .seat .backrow { display: none; }
  .melds-row { gap: 4px; }
  .meld-group { padding: 1px; }
  .meld-group .tile { width: 16px; height: 23px; font-size: 7px; }

  /* 弃牌：小一号，但保证整局都能摊开不裁切 */
  .pool { gap: 2px; }
  .pool .tile.sm { width: 19px; height: 27px; font-size: 7px; border-radius: 3px; }
  .pool-top { padding-bottom: 5px; }
  .pool-bottom { padding-top: 5px; }
  .pool-left { padding-right: 3px; }
  .pool-right { padding-left: 3px; }

  /* 底部：手牌尺寸固定不变，一行放不下就折成两行（不再随副露变多而越打越大） */
  .bottom { margin-top: 8px; padding: 8px 8px 10px; border-radius: 14px; }
  .myinfo { margin-bottom: 4px; gap: 8px; }
  .myinfo .avatar { width: 28px; height: 28px; font-size: 11px; }
  .myinfo .pname { font-size: 12px; }
  .handwrap { gap: 6px; }
  .hand {
    --htw: 34px;
    display: grid;
    grid-template-columns: repeat(auto-fit, var(--htw));
    justify-content: center;
    justify-items: center;
    align-items: center;
    row-gap: 9px;
    column-gap: 3px;
    width: 100%;
    padding: 8px 0 2px;
    min-height: 0;
  }
  .hand .tile {
    flex: none;
    width: var(--htw);
    height: calc(var(--htw) * 1.375);
    min-width: 0;
    border-radius: 4px;
  }
  .hand .tile.gap { margin-left: 0; border-left: 2px solid #f0c65c; }
  .melds { gap: 5px; }
  #myMelds .tile.sm { width: 24px; height: 33px; border-radius: 4px; }
  .actions { gap: 8px; min-height: 40px; margin-top: 4px; }
  .act { font-size: 14px; padding: 8px 16px; border-radius: 9px; gap: 4px; }
  .statusbar { font-size: 11.5px; line-height: 1.5; margin-top: 3px; }

  /* 弹层 */
  .overlay { padding: 10px; }
  .modal { padding: 18px 16px; border-radius: 14px; }
  .modal h2 { font-size: 17px; margin-bottom: 10px; }
  .modal.wide { max-height: 94vh; }
  .modal .lead { font-size: 12.5px; }
  .rules-brief { font-size: 12.5px; line-height: 1.75; margin-bottom: 16px; }
  .rules-grid { gap: 14px; margin-bottom: 14px; }
  .dots { font-size: 12px; }
  .note { font-size: 11px; }
  .guide-row { gap: 3px; margin-bottom: 6px; }
  .glabel { width: 24px; font-size: 10px; }
  .tile.guide { width: 25px; height: 35px; border-radius: 4px; }
  .guide-cell { gap: 2px; }
  .guide-cell span { font-size: 8px; }
  .btn.big { padding: 11px 40px; }
  .result-title { font-size: 19px; }
  #resultBox { max-width: 100%; max-height: calc(100dvh - 20px); border-radius: 14px; }
  .result-scroll { padding: 16px 14px 4px; }
  .result-foot { padding: 8px 14px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .result-foot .btn { padding: 12px 0; font-size: 15px; }
  .hu-total { margin-bottom: 8px; }
  .hu-total b { font-size: 23px; }
  .fold > summary { padding: 8px 10px; font-size: 11.5px; }
  .total-scores { font-size: 11px; }
  .calc { padding: 12px 12px; }
  .calc-row { font-size: 12px; }
  .winhand-tiles .wm { margin-right: 8px; padding-right: 8px; }
  .decomp-groups { gap: 6px; }
  .dgroup { padding: 6px 9px 7px; border-radius: 8px; }
  .dtiles .tile.sm { width: 22px; height: 30px; }
  .dtag { font-size: 9px; }
  .dlegend { font-size: 10.5px; line-height: 1.65; }
  .score-delta { gap: 6px; margin-bottom: 14px; }
  .score-delta div { padding: 6px 10px; font-size: 11px; }
}

/* 小屏（320~340）：再收紧一点，弃牌仍要摆得下 */
@media (max-width: 340px) {
  .table { height: clamp(190px, calc(var(--appvh) - 347px), 372px); }
  .pool { gap: 1px; }
  .pool .tile.sm { width: 16px; height: 22px; }
  .hand { --htw: 28px; row-gap: 7px; column-gap: 2px; }
  .hand .tile { border-radius: 3px; }
  .brand h1 { font-size: 13px; }
  .tools .btn { font-size: 12px; }
}
