:root{
  --bg:#0f3d2e;            /* 牌桌绿 */
  --bg2:#0b3024;
  --felt:#14563f;
  --gold:#e8c877;
  --ink:#1d2a24;
  --paper:#f7f3e8;
  --red:#c0392b;
  --blue:#2c6fb0;
  --line:rgba(255,255,255,.14);
  --shadow:0 6px 18px rgba(0,0,0,.35);
  /* 牌尺寸变量：桌面默认值，窄屏媒体查询覆盖 */
  --tile-w:36px; --tile-h:50px; --tile-gap:2px; --drawn-gap:12px;
  --back-w:20px; --back-h:28px; --back-w-side:16px; --back-h-side:22px;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;font-family:"PingFang SC","Microsoft YaHei",system-ui,sans-serif;color:#fff;background:var(--bg)}
.hidden{display:none!important}
button{font-family:inherit}

/* ---------- 通用按钮 ---------- */
.btn{border:none;border-radius:8px;padding:10px 18px;font-size:15px;cursor:pointer;transition:.15s;font-weight:600}
.btn:active{transform:scale(.96)}
.btn-primary{background:linear-gradient(180deg,#f0d488,#d9ab46);color:#3a2a08;box-shadow:0 3px 0 #9c7420}
.btn-primary:disabled{filter:grayscale(.7);opacity:.5;cursor:not-allowed;box-shadow:none}
.btn-ghost{background:rgba(255,255,255,.1);color:#fff;border:1px solid var(--line)}
.btn-ghost:hover{background:rgba(255,255,255,.18)}
.btn-sm{padding:6px 12px;font-size:13px}
.btn-danger{background:#8e2f26;color:#fff}

/* ---------- 邀请码入口 ---------- */
.gate{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;
  background:radial-gradient(circle at 50% 30%,#1a6b4e,#0a2c21);z-index:100}
.gate-card{width:340px;max-width:90vw;background:rgba(255,255,255,.06);border:1px solid var(--line);
  border-radius:18px;padding:32px 26px;text-align:center;box-shadow:var(--shadow)}
.gate-logo{font-size:54px;line-height:1}
.gate-card h1{margin:10px 0 4px;font-size:23px;color:var(--gold)}
.gate-sub{margin:0 0 22px;font-size:13px;color:#bcd2c6}
.gate-card label{display:block;text-align:left;font-size:13px;color:#bcd2c6;margin-bottom:6px}
.gate-card input,.setting-row input,.setting-row select{width:100%;padding:11px 12px;border-radius:8px;border:1px solid var(--line);
  background:rgba(0,0,0,.25);color:#fff;font-size:16px;outline:none;margin-bottom:16px}
.gate-card input:focus{border-color:var(--gold)}
.gate-card .btn{width:100%}
.gate-msg{min-height:18px;color:#ff9b8f;font-size:13px;margin:10px 0 0}
.gate-hint{font-size:12px;color:#8fae9e;margin-top:16px}
.gate-hint b{color:var(--gold)}

/* ---------- 牌桌 ---------- */
.table{height:100%;display:flex;flex-direction:column;max-width:1100px;margin:0 auto}
.topbar{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;
  background:rgba(0,0,0,.18);border-bottom:1px solid var(--line);flex-wrap:wrap;gap:8px}
.brand{font-size:18px;font-weight:800;color:var(--gold)}
.round-info{font-size:13px;color:#cfe0d6}
.round-info b{color:#fff}
.round-info .sep{margin:0 8px;opacity:.4}
.topbar-actions{display:flex;gap:6px}

.board{position:relative;flex:1;min-height:440px;background:
  radial-gradient(ellipse at 50% 45%,var(--felt),var(--bg2) 78%);overflow:hidden}

/* 座位 */
.seat{position:absolute;display:flex;flex-direction:column;align-items:center;gap:4px}
.seat-top{top:10px;left:50%;transform:translateX(-50%)}
.seat-bottom{bottom:8px;left:50%;transform:translateX(-50%);width:100%}
.seat-left{left:10px;top:50%;transform:translateY(-50%)}
.seat-right{right:10px;top:50%;transform:translateY(-50%)}
.seat-info{display:flex;align-items:center;gap:8px;background:rgba(0,0,0,.3);padding:4px 10px;border-radius:20px;font-size:12px}
.seat-name{font-weight:700}
.score{color:var(--gold);font-variant-numeric:tabular-nums}
.my-info{display:flex;align-items:center;gap:10px;font-size:13px;margin-bottom:2px}
.fan-badge{background:var(--red);color:#fff;padding:2px 8px;border-radius:10px;font-size:11px}

/* 手牌背面（对手） */
.hand-back{display:flex;gap:1px}
.hand-back .tile-back{width:var(--back-w);height:var(--back-h);border-radius:3px;
  background:linear-gradient(135deg,#2e7d5b,#14563f);border:1px solid #0c3b2a;box-shadow:inset 0 0 0 2px rgba(255,255,255,.06)}
.seat-left .hand-back,.seat-right .hand-back{flex-direction:column}
.seat-left .tile-back,.seat-right .tile-back{width:var(--back-w-side);height:var(--back-h-side)}

/* 我的手牌 */
.my-hand{display:flex;gap:var(--tile-gap);flex-wrap:nowrap;padding:0 6px;min-height:56px;align-items:flex-end}
.my-hand .tile{cursor:pointer}

/* ---------- 麻将牌（SVG 传统牌面） ---------- */
.tile{position:relative;width:var(--tile-w,36px);height:var(--tile-h,50px);border-radius:5px;
  background:linear-gradient(180deg,#fffdf5,#e9e3d2);
  box-shadow:0 2px 4px rgba(0,0,0,.35),inset 0 -3px 0 rgba(0,0,0,.08);
  user-select:none;flex:none;border:1px solid #cfc7b2;overflow:visible}
.tile svg.face{display:block;width:100%;height:100%;pointer-events:none}
.tile.red{background:linear-gradient(180deg,#fff8e1,#f6d477);border-color:#d9a83c;
  box-shadow:0 2px 4px rgba(0,0,0,.35),inset 0 -3px 0 rgba(180,120,20,.18)}
.tile .wild{position:absolute;top:-6px;right:-5px;background:var(--red);color:#fff;font-size:9px;
  padding:1px 3px;border-radius:8px;box-shadow:0 1px 3px rgba(0,0,0,.4);z-index:2}
.tile .fresh{position:absolute;top:-6px;left:-5px;background:#e91e63;color:#fff;font-size:9px;
  padding:1px 3px;border-radius:8px;box-shadow:0 1px 3px rgba(0,0,0,.4);z-index:2}
.tile.selected{transform:translateY(-12px);box-shadow:0 6px 12px rgba(0,0,0,.5),0 0 0 2px var(--gold)}
.tile.drawn{margin-left:var(--drawn-gap,12px);
  box-shadow:0 2px 4px rgba(0,0,0,.35),0 0 0 2px #e91e63}
.tile.small{width:26px;height:36px}
.tile.tiny{width:20px;height:28px}
.tile.dim{opacity:.55}
.tile.win{background:linear-gradient(180deg,#fff6cf,#ffd75e);box-shadow:0 0 0 2px var(--red),0 2px 6px rgba(0,0,0,.4)}

/* 副露 */
.melds{display:flex;gap:6px;min-height:0;flex-wrap:wrap;justify-content:center;max-width:60%}
.meld{display:flex;gap:1px;background:rgba(0,0,0,.2);padding:2px;border-radius:5px}

/* ---------- 中央牌河 ---------- */
.center{position:absolute;inset:60px 90px 90px;display:grid;
  grid-template:1fr auto 1fr / 1fr auto 1fr;gap:4px;pointer-events:none}
.discard-area{display:flex;flex-wrap:wrap;align-content:flex-start;gap:1px;max-width:230px;max-height:96px;opacity:.96}
#discard-2{grid-area:1/2;justify-content:center}
#discard-3{grid-area:2/1;align-content:center;flex-direction:column;max-width:96px}
#discard-1{grid-area:2/3;align-content:center;flex-direction:column;max-width:96px}
#discard-0{grid-area:3/2;justify-content:center;align-content:flex-end}
.core{grid-area:2/2;display:flex;flex-direction:column;align-items:center;justify-content:center;
  background:rgba(0,0,0,.22);border-radius:12px;padding:10px 18px;min-width:130px;text-align:center}
.turn-tip{font-size:14px;color:#fff}
.last-win{font-size:12px;color:var(--gold);margin-top:4px;min-height:16px}

/* 中央报牌浮层：打出的牌大字显示，手机无语音也能看到 */
.callout{position:fixed;left:50%;top:42%;transform:translate(-50%,-50%) scale(.6);
  z-index:60;display:flex;flex-direction:column;align-items:center;gap:6px;
  padding:14px 22px 12px;border-radius:16px;pointer-events:none;
  background:linear-gradient(180deg,rgba(20,40,30,.94),rgba(10,25,18,.94));
  border:2px solid var(--gold);box-shadow:0 10px 40px rgba(0,0,0,.6),0 0 0 4px rgba(212,175,55,.15);
  opacity:0;transition:opacity .16s ease,transform .16s cubic-bezier(.2,1.4,.4,1)}
.callout.show{opacity:1;transform:translate(-50%,-50%) scale(1)}
.callout .callout-tile{transform:scale(1.7);transform-origin:center center;margin:8px 0 10px}
.callout .callout-name{font-size:22px;font-weight:800;color:#fff;letter-spacing:2px;white-space:nowrap}
.callout .callout-kind{font-size:26px;font-weight:900;color:var(--gold);letter-spacing:3px}
.callout.win{border-color:#ff5b5b}
.callout.win .callout-name{color:#ffd75e}

/* ---------- 操作栏 ---------- */
.actionbar{min-height:66px;background:rgba(0,0,0,.28);border-top:1px solid var(--line);
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;padding:6px}
.action-msg{font-size:13px;color:#d8e6de}
.action-btns{display:flex;gap:8px;flex-wrap:wrap;justify-content:center}
.action-btns .btn{min-width:62px;padding:8px 14px}
.btn-call{background:linear-gradient(180deg,#7ec8ff,#3f8fd0);color:#06263c;box-shadow:0 3px 0 #245d8c}
.btn-win{background:linear-gradient(180deg,#ff8f7a,#e0432f);color:#fff;box-shadow:0 3px 0 #9c2a1d;font-size:16px}
.btn-pass{background:rgba(255,255,255,.12);color:#fff}

/* ---------- 弹窗 ---------- */
.modal{position:fixed;inset:0;background:rgba(0,0,0,.6);display:flex;align-items:center;justify-content:center;z-index:80;padding:16px}
.modal-card{width:420px;max-width:94vw;max-height:86vh;overflow:auto;background:var(--paper);color:var(--ink);
  border-radius:16px;padding:24px;box-shadow:var(--shadow);text-align:center}
.modal-wide{width:640px}
.modal-card h2{margin:0 0 16px;color:var(--red);font-size:22px}
.modal-actions{display:flex;gap:10px;justify-content:center;margin-top:16px}
#resultBody{text-align:left;font-size:14px}
.result-fan{display:flex;flex-wrap:wrap;gap:6px;margin:10px 0}
.result-fan span{background:#f0e6c8;border:1px solid #d9c891;border-radius:12px;padding:3px 10px;font-size:12px}
.result-score{font-size:26px;font-weight:800;color:var(--red);text-align:center;margin:12px 0}
.result-detail{background:#efe9d8;border-radius:8px;padding:10px 12px;line-height:1.8}
#resultNext{margin-top:18px;width:100%}
.setting-row{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px;text-align:left}
.setting-row label{font-size:14px;flex:1}
.setting-row input,.setting-row select{margin:0;width:150px;padding:8px;background:#fff;color:var(--ink);border:1px solid #ccc}
.setting-row .check{display:flex;align-items:center;gap:8px}
.stat-summary{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:14px}
.stat-box{background:#efe9d8;border-radius:8px;padding:10px 4px}
.stat-box b{display:block;font-size:20px;color:var(--red)}
.stat-box span{font-size:11px;color:#666}
.stat-list{max-height:300px;overflow:auto}
.stat-item{display:flex;justify-content:space-between;padding:7px 4px;border-bottom:1px solid #e2dac2;font-size:13px}
.stat-item .win{color:var(--red);font-weight:700}

/* ---------- 响应式：手机 / 窄屏 ---------- */
@media(max-width:700px){
  :root{
    --tile-w:24px; --tile-h:34px; --tile-gap:1px; --drawn-gap:8px;
    --back-w:14px; --back-h:20px; --back-w-side:12px; --back-h-side:17px;
  }
  .tile.small{width:19px;height:27px}
  .tile.tiny{width:15px;height:21px}
  .my-hand{gap:var(--tile-gap);padding:14px 4px 0;overflow-x:auto;justify-content:center;
    scrollbar-width:none}
  .my-hand::-webkit-scrollbar{height:0}
  .board{min-height:0}
  .center{inset:50px 44px 76px}
  .discard-area{max-width:180px;max-height:80px}
  #discard-3,#discard-1{max-width:70px}
  .core{padding:6px 8px;min-width:82px}
  .turn-tip{font-size:11px}
  .seat-top{top:4px}
  .seat-bottom{bottom:2px}
  .seat-left{left:2px}
  .seat-right{right:2px}
  .seat-info{font-size:11px;padding:3px 7px}
  .melds{max-width:72%}
  .topbar{padding:6px 8px;gap:4px}
  .brand{font-size:15px}
  .round-info{font-size:11px}
  .round-info .sep{margin:0 4px}
  .topbar-actions{width:100%;justify-content:center;gap:5px}
  .topbar-actions .btn{flex:1;padding:8px 4px;font-size:12px}
  .actionbar{min-height:60px;padding:5px 4px;gap:4px}
  .action-msg{font-size:11px}
  .action-btns .btn{min-width:56px;padding:10px 12px;font-size:14px}
}
@media(max-width:360px){
  :root{--tile-w:21px; --tile-h:30px; --drawn-gap:6px}
  .center{inset:46px 38px 70px}
  .discard-area{max-width:150px}
}
/* 横屏矮屏：压缩垂直留白 */
@media(max-height:520px) and (orientation:landscape){
  .center{inset:32px 120px 60px}
  .discard-area{max-height:64px}
  .actionbar{min-height:50px}
}
