:root {
  --felt: #0f5a43;
  --felt-dark: #0a4232;
  --ink: #f3efe2;
  --muted: #a9c9bb;
  --tile: #fbf8ee;
  --tile-edge: #d8cfb4;
  --tile-side: #3d8f6f;
  --gold: #e8b931;
  --red: #c62f2f;
  --green: #1e7a3c;
  --blue: #1f4f9a;
  --accent: #f0a63a;
  --tw: min(46px, calc((100vw - 48px) / 19));
  --th: calc(var(--tw) * 1.38);
  --sw: calc(var(--tw) * 0.62);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at center, #13704f 0%, var(--felt) 45%, var(--felt-dark) 100%);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  overflow: hidden;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
#table, #result, #fx { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button, input, select { font: inherit; }
button {
  background: #2a7a5c; color: var(--ink); border: 1px solid #4fa283; border-radius: 8px;
  padding: 6px 14px; cursor: pointer;
}
@media (hover: hover) { button:hover { background: #33906c; } }
button.primary { background: var(--accent); border-color: #ffc56e; color: #3a2400; font-weight: 600; }
@media (hover: hover) { button.primary:hover { background: #ffb44d; } }
button:disabled { opacity: .5; cursor: default; }
input, select { background: #fff; color: #222; border: 1px solid #ccc; border-radius: 6px; padding: 6px 8px; }
.hidden { display: none !important; }
.screen { height: 100vh; height: 100dvh; }

/* ---------- 大厅 ---------- */
#lobby, #waiting { display: flex; align-items: center; justify-content: center; overflow: auto; padding: 16px; }
.lobby-card { background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 24px 28px; width: min(720px, 100%); max-height: 100%; overflow: auto; }
.lobby-card h1 { margin: 0; font-size: 32px; letter-spacing: 4px; }
.lobby-card .sub { color: var(--muted); margin: 4px 0 18px; }
.lobby-card label { display: block; margin: 8px 0; }
.lobby-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
@media (max-width: 600px) { .lobby-cols { grid-template-columns: 1fr; } }
.box { background: rgba(0,0,0,.2); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.box h2 { margin: 0; font-size: 18px; }
.preset-pick { display: flex; gap: 16px; }
.preset-pick label { margin: 0; }
details summary { cursor: pointer; color: var(--muted); }
#rule-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 8px; font-size: 14px; }
#rule-opts label { margin: 0; display: flex; align-items: center; gap: 6px; }
#rule-opts input[type=number] { width: 56px; padding: 2px 4px; }
.rules-help { margin-top: 16px; font-size: 14px; line-height: 1.7; }
.rules-help ul { padding-left: 20px; }
.share input { width: 60%; }
.seats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
@media (max-width: 600px) { .seats { grid-template-columns: 1fr 1fr; } }
.seat-card { background: rgba(0,0,0,.25); border-radius: 10px; padding: 12px; text-align: center; min-height: 86px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.seat-card.empty { color: var(--muted); border: 1px dashed rgba(255,255,255,.25); background: transparent; }
.seat-card .kick { font-size: 12px; padding: 2px 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.tip { color: var(--muted); font-size: 14px; }

/* ---------- 玉石牌 ---------- */
.tile {
  --d: calc(var(--tw) * .17);
  position: relative; flex: none; width: var(--tw); height: calc(var(--tw) * 1.36 + var(--d));
  border-radius: calc(var(--tw) * .17);
  background: linear-gradient(180deg, rgba(255,255,255,.25), rgba(0,0,0,.15)), var(--jade-tex) center / 220% auto, #1d8a5f;
  box-shadow: 0 calc(var(--tw) * .07) calc(var(--tw) * .16) rgba(0,0,0,.5), inset 0 -1px 2px rgba(0,0,0,.4), inset 0 0 0 1px rgba(255,255,255,.12);
  user-select: none;
}
.tile::before { /* 白玉牌面 */
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: calc(100% - var(--d));
  border-radius: calc(var(--tw) * .17) calc(var(--tw) * .17) calc(var(--tw) * .12) calc(var(--tw) * .12);
  background: radial-gradient(ellipse 80% 55% at 32% 14%, rgba(255,255,255,.95), rgba(255,255,255,0) 60%),
              linear-gradient(180deg, #fffdf6 0%, #f4efe0 75%, #e6dcc2 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.9), inset 0 calc(var(--tw) * -.05) calc(var(--tw) * .09) rgba(120,100,60,.28), 0 1px 1px rgba(0,0,0,.25);
}
.tile::after { /* 釉面高光 */
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: calc(100% - var(--d)); border-radius: inherit; z-index: 2; pointer-events: none;
  background: linear-gradient(150deg, rgba(255,255,255,.65) 0%, rgba(255,255,255,0) 30%, rgba(255,255,255,0) 78%, rgba(255,255,255,.22) 100%);
  mix-blend-mode: screen;
}
.tile > .art { position: absolute; left: 7%; right: 7%; top: 5%; height: calc(100% - var(--d) - 9%); background: center / contain no-repeat; z-index: 1; }
.tile.back { background: linear-gradient(180deg, #fffdf4, #e8dfc6); }
.tile.back::before {
  background: radial-gradient(ellipse 70% 45% at 30% 15%, rgba(255,255,255,.55), rgba(255,255,255,0) 60%), var(--jade-tex) center / 220% auto, #1d8a5f;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25), inset 0 calc(var(--tw) * -.06) calc(var(--tw) * .1) rgba(0,40,20,.45);
}
.tile.gold::before {
  background: radial-gradient(ellipse 80% 55% at 32% 14%, rgba(255,255,255,.95), rgba(255,255,255,0) 60%), linear-gradient(180deg, #fff7d6 0%, #f6dc8a 80%, #e2b84c 100%);
}
.tile.gold { box-shadow: 0 0 calc(var(--tw) * .25) rgba(255,200,60,.85), 0 calc(var(--tw) * .07) calc(var(--tw) * .16) rgba(0,0,0,.5); }
.tile.gold > .art::after {
  content: '金'; position: absolute; right: -6%; top: -4%; width: calc(var(--tw) * .3); height: calc(var(--tw) * .3);
  background: #b8281e; color: #ffe9a8; border-radius: 3px; font-size: calc(var(--tw) * .22); line-height: calc(var(--tw) * .3); text-align: center; font-weight: 700;
  box-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.tile.sm { --tw: var(--sw); }
.tile.xs { --tw: calc(var(--sw) * .78); }
.tile.last { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile.drop { animation: tileDrop .38s cubic-bezier(.2,1.4,.5,1); }
@keyframes tileDrop { 0% { transform: translateY(-40px) scale(1.5) rotate(-8deg); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* ---------- 角色头像 ---------- */
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; background-position: center; background-size: cover; background-repeat: no-repeat; border: 2px solid rgba(255,255,255,.75); box-shadow: 0 2px 8px rgba(0,0,0,.45); }
.avatar.big { width: 72px; height: 72px; }
.avatar.speaking { animation: talk .25s ease-in-out 6 alternate; border-color: var(--accent); }
@keyframes talk { from { transform: scale(1); } to { transform: scale(1.12) rotate(-3deg); } }
.char-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 6px 0 4px; }
@media (max-width: 600px) { .char-pick { grid-template-columns: repeat(3, 1fr); } }
.char-card { background: rgba(0,0,0,.25); border: 2px solid transparent; border-radius: 12px; padding: 8px 4px; text-align: center; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; }
.char-card b { font-size: 14px; }
.char-card small { color: var(--muted); }
.char-card.on { border-color: var(--accent); background: rgba(240,166,58,.15); }

/* ---------- 声音开关 ---------- */
.toggle { opacity: .5; }
.toggle.on { opacity: 1; }

/* ---------- 特效 ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
#fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 41; }
.fx-stamp { position: absolute; transform: translate(-50%, -50%); }
.fx-stamp .seal {
  position: relative; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 22px;
  display: flex; align-items: center; justify-content: center; font-size: 76px; font-weight: 900; color: #fff;
  font-family: 'Kaiti SC','STKaiti','KaiTi','Songti SC',serif;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,.5), rgba(255,255,255,0) 50%), var(--c);
  border: 4px solid #ffe08a; box-shadow: 0 0 0 4px var(--c), 0 0 40px var(--c), 0 10px 30px rgba(0,0,0,.6);
  text-shadow: 0 3px 0 rgba(0,0,0,.35); animation: sealIn 1.6s cubic-bezier(.2,1.6,.4,1) forwards;
}
.fx-stamp .seal.two { font-size: 46px; width: 150px; margin-left: -75px; }
.fx-stamp.small .seal { transform: scale(.55); animation-name: sealInSmall; animation-duration: 1.1s; }
@keyframes sealIn { 0% { transform: scale(3) rotate(-18deg); opacity: 0; } 18% { transform: scale(.88) rotate(4deg); opacity: 1; } 28% { transform: scale(1.06) rotate(-2deg); } 36%, 78% { transform: scale(1) rotate(0); opacity: 1; } 100% { transform: scale(.7) translateY(-30px); opacity: 0; } }
@keyframes sealInSmall { 0% { transform: scale(1.4); opacity: 0; } 25%, 75% { transform: scale(.55); opacity: 1; } 100% { transform: scale(.45) translateY(-30px); opacity: 0; } }
.fx-stamp .ring { position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; border: 6px solid var(--c); animation: ring 0.9s ease-out .18s forwards; opacity: 0; }
.fx-stamp .ring.r2 { animation-delay: .32s; border-color: #ffe08a; }
@keyframes ring { 0% { transform: scale(.5); opacity: .9; } 100% { transform: scale(7); opacity: 0; border-width: 1px; } }
.fx-stamp .meld-fly { position: absolute; top: 70px; left: 0; transform: translateX(-50%); display: flex; gap: 2px; animation: meldFly 1.6s ease forwards; --tw: 34px; --sw: 34px; }
@keyframes meldFly { 0% { opacity: 0; transform: translate(-50%, 30px) scale(.6); } 25%, 80% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; } }

.fx-sweep { position: absolute; left: 0; width: 100vw; height: 0; }
.fx-sweep .sweep { position: absolute; left: -40vw; top: -60px; width: 40vw; height: 120px; background: linear-gradient(90deg, transparent, rgba(255,215,90,.75), rgba(255,255,255,.9), rgba(255,215,90,.75), transparent); filter: blur(6px); animation: sweep 1.3s ease-in-out forwards; transform: skewX(-20deg); }
@keyframes sweep { to { left: 110vw; } }
.fx-you { position: absolute; transform: translate(-50%, -50%); text-align: center; }
.fx-you .you-text {
  font-size: 84px; font-weight: 900; font-family: 'Kaiti SC','STKaiti','KaiTi','Songti SC',serif; white-space: nowrap;
  background: linear-gradient(180deg, #fffbe0 0%, #ffd84d 45%, #c98a00 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255,200,60,.9)) drop-shadow(0 4px 0 #7a4a00); animation: youIn 2s ease forwards;
}
.fx-you.lv3 .you-text { font-size: 110px; }
@keyframes youIn { 0% { transform: translateX(-120px) scale(.6); opacity: 0; } 25% { transform: translateX(10px) scale(1.1); opacity: 1; } 35%, 80% { transform: none; opacity: 1; } 100% { transform: translateX(80px); opacity: 0; } }
.fx-you .fish { position: relative; height: 20px; }
.fx-you .fish span { position: absolute; left: 50%; width: 22px; height: 10px; border-radius: 50%; background: #ffd84d; box-shadow: 0 0 10px #ffd84d; animation: swim 1.8s ease-in-out forwards; }
.fx-you .fish span:nth-child(2) { animation-delay: .1s; top: -16px; } .fx-you .fish span:nth-child(3) { animation-delay: .2s; top: 16px; }
.fx-you .fish span:nth-child(4) { animation-delay: .3s; top: -30px; } .fx-you .fish span:nth-child(5) { animation-delay: .4s; top: 30px; }
.fx-you .fish span:nth-child(6) { animation-delay: .5s; top: -44px; } .fx-you .fish span:nth-child(7) { animation-delay: .6s; top: 44px; }
@keyframes swim { 0% { transform: translateX(-200px); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateX(240px) translateY(-20px); opacity: 0; } }

.fx-win { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; pointer-events: auto;
  background: radial-gradient(circle at 50% 42%, rgba(120,20,10,.55), rgba(0,0,0,.82) 70%); animation: winBg 4.2s ease forwards; }
@keyframes winBg { 0% { opacity: 0; } 8%, 86% { opacity: 1; } 100% { opacity: 0; } }
.fx-win .rays { position: absolute; left: 50%; top: 42%; width: 160vmax; height: 160vmax; margin: -80vmax 0 0 -80vmax;
  background: repeating-conic-gradient(from 0deg, rgba(255,210,80,.28) 0deg 7deg, rgba(255,210,80,0) 7deg 18deg); animation: spin 9s linear infinite;
  mask-image: radial-gradient(circle, #000 0%, transparent 60%); -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 60%); }
.fx-win .glow { position: absolute; left: 50%; top: 42%; width: 420px; height: 420px; margin: -210px 0 0 -210px; border-radius: 50%; background: radial-gradient(circle, rgba(255,220,120,.6), transparent 65%); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { from { transform: scale(.85); } to { transform: scale(1.15); } }
.fx-win .win-avatar { position: relative; width: 120px; height: 120px; border-radius: 50%; background-position: center; background-size: cover; border: 5px solid #ffd84d; box-shadow: 0 0 40px rgba(255,210,80,.9); animation: avIn .7s cubic-bezier(.2,1.5,.4,1) both; }
@keyframes avIn { from { transform: translateY(-80px) scale(.3); opacity: 0; } }
.fx-win .win-text { position: relative; display: flex; gap: 6px; font-size: 150px; line-height: 1.05; font-weight: 900; font-family: 'Kaiti SC','STKaiti','KaiTi','Songti SC',serif; }
.fx-win .win-text.long { font-size: 112px; }
.fx-win .win-text span { display: inline-block; background: linear-gradient(180deg, #fffbe0 0%, #ffd84d 40%, #e08a00 75%, #a85a00 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255,190,40,.95)) drop-shadow(0 6px 0 #6b2a00); animation: charIn .65s cubic-bezier(.2,1.7,.4,1) both; }
@keyframes charIn { 0% { transform: scale(4) rotate(-20deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.fx-win .win-line { position: relative; font-size: 22px; background: rgba(0,0,0,.5); border: 1px solid rgba(255,216,77,.6); padding: 8px 20px; border-radius: 30px; animation: avIn .6s .5s both; }
.fx-win .three-gold { position: relative; display: flex; gap: 8px; --tw: 54px; --sw: 54px; }
.fx-win .three-gold .tile { animation: flip .8s cubic-bezier(.2,1.4,.4,1) both; }
.fx-win .three-gold .tile:nth-child(2) { animation-delay: .2s; } .fx-win .three-gold .tile:nth-child(3) { animation-delay: .4s; }
@keyframes flip { from { transform: rotateY(180deg) scale(.4); opacity: 0; } }
@media (max-width: 700px) { .bn-text { font-size: 48px; } .bn-text.two { font-size: 38px; } .bn-tiles { --tw: 24px; --sw: 24px; } .bn-who b { display: none; } .fx-win .win-text { font-size: 90px; } .fx-win .win-text.long { font-size: 64px; } .fx-stamp .seal { transform: scale(.7); } }

.fx-bubble { position: absolute; transform: translate(-50%, -100%); }
.fx-bubble.below { transform: translate(-50%, 0); }
.fx-bubble .bubble-in { background: #fffaf0; color: #3a2a1a; padding: 6px 12px; border-radius: 14px; font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.4); animation: bub 2.6s ease forwards; }
@keyframes bub { 0% { transform: scale(.3); opacity: 0; } 10% { transform: scale(1.08); opacity: 1; } 16%, 85% { transform: scale(1); opacity: 1; } 100% { opacity: 0; } }

/* ---------- 中间横幅：吃 / 碰 / 杠 / 胡 ---------- */
.fx-banner, .win-band {
  position: absolute; left: 0; right: 0; top: 46%; transform: translateY(-50%);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 22px; padding: 10px 0;
}
.fx-banner { animation: bnOut .4s ease-in 2.4s forwards; }
.bn-band {
  position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(90deg, transparent 0%, color-mix(in srgb, var(--c) 82%, #000) 14%, var(--c) 50%, color-mix(in srgb, var(--c) 82%, #000) 86%, transparent 100%);
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
  animation: bandIn .4s cubic-bezier(.2,1.3,.4,1) both;
}
.bn-band::before, .bn-band::after { content: ''; position: absolute; left: 6%; right: 6%; height: 2px; background: linear-gradient(90deg, transparent, #ffe08a 20%, #fff6cf 50%, #ffe08a 80%, transparent); }
.bn-band::before { top: 4px; } .bn-band::after { bottom: 4px; }
@keyframes bandIn { from { transform: scaleY(0); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bnOut { to { opacity: 0; transform: translateY(-50%) scaleY(.2); } }
.bn-shine { position: absolute; inset: 0; overflow: hidden; z-index: -1; pointer-events: none; }
.bn-shine::after { content: ''; position: absolute; top: 0; bottom: 0; left: -30%; width: 22%; transform: skewX(-20deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent); animation: shine 1.4s ease-out .3s both; }
@keyframes shine { from { left: -30%; } to { left: 115%; } }
.bn-who { justify-self: end; display: flex; align-items: center; gap: 10px; font-size: 18px; text-shadow: 0 2px 4px rgba(0,0,0,.6); animation: fromLeft .6s cubic-bezier(.2,1.2,.4,1) .15s both; }
.bn-tiles { justify-self: start; display: flex; gap: 2px; --tw: 36px; --sw: 36px; animation: fromRight .6s cubic-bezier(.2,1.2,.4,1) .15s both; }
@keyframes fromLeft { from { transform: translateX(-60vw); opacity: 0; } }
@keyframes fromRight { from { transform: translateX(60vw); opacity: 0; } }
.bn-text { display: flex; gap: 4px; font-size: 72px; line-height: 1.1; font-weight: 900; font-family: 'Kaiti SC','STKaiti','KaiTi','Songti SC',serif; }
.bn-text.two { font-size: 58px; }
.bn-text span, .fx-win .win-text span {
  display: inline-block; background: linear-gradient(180deg, #fffbe0 0%, #ffd84d 45%, #e08a00 80%, #a85a00 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(60,20,0,.8)) drop-shadow(0 0 12px rgba(255,200,60,.7)); animation: charIn .5s cubic-bezier(.2,1.7,.4,1) both;
}
/* 胡：同样的横幅，更高更亮，背景压暗 + 光芒 + 金币雨 */
.fx-win { --c: #b8281e; }
.fx-win .win-band { top: 44%; padding: 14px 0; gap: 28px; }
.fx-win .win-band .bn-band { animation-duration: .5s; }
.fx-win .win-band .bn-who { font-size: 22px; flex-direction: column; gap: 4px; }
.fx-win .win-avatar { width: 84px; height: 84px; }
.fx-win .win-text { font-size: 120px; gap: 6px; }
.fx-win .win-text.long { font-size: 92px; }
.fx-win .win-line { position: absolute; left: 50%; top: calc(44% + 110px); transform: translateX(-50%); white-space: nowrap; }
.fx-win .three-gold { --tw: 44px; --sw: 44px; }

/* ---------- 牌桌布局 ---------- */
#table { display: flex; flex-direction: column; }
#topbar { position: relative; z-index: 25; display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: rgba(0,0,0,.25); font-size: 14px; flex-wrap: wrap; }
#topbar .spacer { flex: 1; }
#topbar button, #topbar select { padding: 3px 10px; font-size: 13px; }
#topbar button { display: inline-flex; align-items: center; gap: 4px; }
.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toggle { position: relative; }
.toggle:not(.on)::after { content: ''; position: absolute; left: 7px; top: 50%; width: 20px; height: 2px; background: currentColor; transform: rotate(-45deg); pointer-events: none; }
.chat-wrap { position: relative; display: inline-flex; align-items: center; }
.chat-wrap .ic { position: absolute; left: 8px; color: #2a5a48; pointer-events: none; }
#topbar .chat-wrap select { padding-left: 28px; }
#board {
  flex: 1; min-height: 0; display: grid; gap: 6px; padding: 6px 10px;
  grid-template-columns: minmax(110px, 17%) 1fr minmax(110px, 17%);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "top top top" "left center right" "bottom bottom bottom";
}
#p-top { grid-area: top; }
#p-left { grid-area: left; }
#p-right { grid-area: right; }
#p-bottom { grid-area: bottom; }
#center {
  grid-area: center; min-height: 0; display: grid; gap: 6px;
  grid-template-columns: 1fr minmax(140px, 1.1fr) 1fr;
  grid-template-rows: 1fr auto 1fr;
  grid-template-areas: ". rtop ." "rleft info rright" ". rbottom .";
}
.river { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px; min-height: 0; overflow: hidden; }
.r-top { grid-area: rtop; align-content: flex-end; flex-wrap: wrap-reverse; justify-content: center; grid-row: 1; }
.r-bottom { grid-area: rbottom; justify-content: center; }
.r-left { grid-area: rleft; justify-content: flex-end; grid-row: 1 / 4; align-content: center; }
.r-right { grid-area: rright; justify-content: flex-start; grid-row: 1 / 4; align-content: center; }
.r-top, .r-bottom { grid-column: 2; }
#info {
  grid-area: info; background: rgba(0,0,0,.3); border-radius: 12px; padding: 8px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; position: relative;
}
.gold-show { display: flex; align-items: center; gap: 6px; }
#info .winds { display: grid; grid-template-columns: repeat(3, 1.6em); grid-template-rows: repeat(3, 1.4em); font-weight: 700; }
#info .winds span { opacity: .45; }
#info .winds span.on { opacity: 1; color: var(--accent); }

.seat-area { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.seat-area.side { justify-content: center; }
#p-top { align-items: center; }
.pinfo { display: flex; align-items: center; gap: 6px; font-size: 13px; flex-wrap: wrap; }
.pinfo .who { display: flex; flex-direction: column; gap: 2px; }
.pinfo .badges { display: flex; gap: 4px; flex-wrap: wrap; }
.seat-area.turn .avatar { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240,166,58,.5), 0 0 18px rgba(240,166,58,.8); }
.pinfo .nm { font-weight: 600; }
.pinfo .sc { color: var(--accent); font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: rgba(0,0,0,.35); }
.badge.dealer { background: var(--red); }
.badge.you { background: var(--gold); color: #3a2400; }
.badge.off { background: #666; }
.seat-area.turn .pinfo .nm { color: var(--accent); }
.seat-area.turn .pinfo .nm::before { content: ''; display: inline-block; margin-right: 4px; border-style: solid; border-width: .35em 0 .35em .55em; border-color: transparent transparent transparent currentColor; vertical-align: .05em; }
.tiles { display: flex; flex-wrap: wrap; gap: 2px; align-items: flex-end; }
.melds { display: flex; flex-wrap: wrap; gap: 8px; }
.meld { display: flex; gap: 1px; }
.flowers { display: flex; gap: 1px; flex-wrap: wrap; }

/* 自己的手牌 */
#p-bottom { align-items: center; }
#p-bottom .handrow { display: flex; align-items: flex-end; gap: 10px; flex-wrap: nowrap; }
#p-bottom .hand { display: flex; gap: 2px; }
#p-bottom .hand .tile { cursor: pointer; transition: transform .1s; }
@media (hover: hover) { #p-bottom .hand .tile:hover { transform: translateY(-4px); } }
#p-bottom .hand .tile.sel { transform: translateY(-14px); }
#p-bottom .hand .tile.dim { filter: brightness(.75); cursor: not-allowed; }
#p-bottom .hand .tile.ting::before { content: ''; position: absolute; top: -8px; left: 50%; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--accent); }
#p-bottom .hand .tile.youjin::before { background: var(--gold); width: 8px; height: 8px; margin-left: -4px; }
#p-bottom .drawn { margin-left: calc(var(--tw) * .4); }
#p-bottom .meta { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; justify-content: center; }

#actions {
  position: fixed; left: 50%; bottom: calc(var(--tw) * 1.38 + 90px); transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; z-index: 5; flex-wrap: wrap; justify-content: center;
}
#actions button { font-size: 18px; padding: 8px 20px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
#actions .win { background: var(--red); border-color: #ff7b7b; font-weight: 700; }
#actions .claim-tile { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.5); padding: 6px 10px; border-radius: 10px; }
#actions .chi-opt { display: inline-flex; gap: 1px; align-items: center; padding: 4px 8px; }
#actions .timer { font-variant-numeric: tabular-nums; color: var(--accent); }
#hint { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; justify-content: center; min-height: 22px; padding: 0 8px 4px; flex-wrap: wrap; }

/* 结算 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; }
.modal .panel { background: #123f30; border: 1px solid #3d8f6f; border-radius: 16px; padding: 18px 22px; width: min(900px, 100%); max-height: 100%; overflow: auto; }
.modal h2 { margin: 0 0 6px; }
.res-row { display: grid; grid-template-columns: 110px 1fr 80px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid rgba(255,255,255,.1); }
.res-row.win { background: rgba(240,166,58,.12); }
.res-row .tiles { gap: 1px; }
.delta.pos { color: #7ee08a; } .delta.neg { color: #ff8a8a; }
.tai { color: var(--muted); font-size: 14px; margin: 6px 0; }

#toast { position: fixed; top: 48px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 30; pointer-events: none; }
#toast div { background: rgba(0,0,0,.75); padding: 8px 16px; border-radius: 8px; animation: fade 3s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

@media (max-width: 760px) {
  #board { grid-template-columns: 76px 1fr 76px; padding: 4px; }
  #center { grid-template-columns: 1fr 120px 1fr; }
  .pinfo { font-size: 11px; }
  #actions button { font-size: 15px; padding: 6px 14px; }
}

/* ---------- 默认（宽屏）隐藏手机专用元素 ---------- */
.badge.fl-cnt, .badge.hd-cnt { display: none; }
#rotate { display: none; }

/* ---------- 触屏通用 ---------- */
@media (pointer: coarse) {
  input, select { font-size: 16px; } /* 防止 iOS 聚焦时放大 */
  button { min-height: 38px; }
  .lobby-card button, .box button { min-height: 44px; }
  .preset-pick label, #rule-opts label { min-height: 32px; }
}

/* ---------- 手机竖屏：大厅 / 房间 ---------- */
@media (max-width: 600px) {
  #lobby, #waiting { align-items: flex-start; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
  .lobby-card { padding: 18px 16px; border-radius: 14px; }
  .lobby-card h1 { font-size: 26px; }
  .char-card { padding: 8px 2px; }
  .char-card small { font-size: 10px; line-height: 1.3; }
  #rule-opts { grid-template-columns: 1fr; }
  .share { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
  .share input { flex: 1; min-width: 0; width: auto; }
  .row button { flex: 1; }
  .modal .panel { padding: 14px; }
  .res-row { grid-template-columns: 1fr 64px; }
  .res-row > .tiles { grid-column: 1 / -1; grid-row: 2; }
}

/* 竖屏手机在牌桌：提示横屏 */
@media (orientation: portrait) and (max-width: 600px) {
  body.in-table #rotate {
    display: flex; position: fixed; inset: 0; z-index: 60; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
    background: radial-gradient(ellipse at center, #13704f 0%, var(--felt-dark) 100%);
  }
  #rotate p { margin: 0; font-size: 20px; }
  #rotate .tip { font-size: 14px; margin-bottom: 18px; }
  #rotate .phone-icon { width: 60px; height: 100px; border: 4px solid var(--ink); border-radius: 12px; margin-bottom: 22px; position: relative; animation: rot 2s ease-in-out infinite; }
  #rotate .phone-icon::after { content: ''; position: absolute; left: 50%; bottom: 6px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--ink); }
  @keyframes rot { 0%, 20% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
}

/* ---------- 手机横屏牌桌 ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
    --tw: min(46px, calc((100vw - var(--sl) - var(--sr) - 84px) / 18.2), calc(100dvh * .12));
    --sw: calc(var(--tw) * .62);
    --rw: min(calc(100dvh * .047), calc(var(--tw) * .55));
  }
  #table { padding-left: var(--sl); padding-right: var(--sr); }

  /* 顶栏：单行图标 */
  #topbar { flex-wrap: nowrap; gap: 6px; padding: 2px 8px; font-size: 12px; min-height: 30px; }
  #topbar .lbl, #t-room { display: none; }
  #topbar button, #topbar select { min-height: 26px; padding: 1px 8px; font-size: 13px; border-radius: 6px; }
  #topbar select { max-width: 92px; padding: 1px 4px; }

  #board { grid-template-columns: 84px 1fr 84px; grid-template-rows: auto 1fr auto; gap: 2px 4px; padding: 2px 4px; }

  /* 对手：头像信息 + 张数，不显示背面手牌 */
  .badge.fl-cnt, .badge.hd-cnt { display: inline-block; }
  .seat-area .flowers { display: none; }
  .seat-area .tiles.hidden-hand { display: none; }
  .seat-area .tiles.open .tile { --tw: calc(var(--sw) * .62); }
  .avatar { width: 32px; height: 32px; border-width: 1.5px; }
  .pinfo { font-size: 11px; gap: 4px; }
  .badge { font-size: 10px; padding: 0 5px; }
  .melds { gap: 3px; }

  #p-top { flex-direction: row; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
  #p-top .tiles.open { order: 3; }
  .seat-area.side { justify-content: flex-start; padding-top: 4px; overflow: hidden; }
  .seat-area.side .pinfo { flex-direction: column; align-items: center; text-align: center; }
  .seat-area.side .pinfo .who { align-items: center; }
  .seat-area.side .pinfo .badges { justify-content: center; }
  .seat-area.side .nm { display: inline-block; max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
  .seat-area.side .melds { justify-content: center; }
  .seat-area.side .tiles.open { justify-content: center; }

  /* 中央牌河 */
  #center { gap: 3px; grid-template-columns: 1fr minmax(96px, 1.25fr) 1fr; }
  .river { gap: 1px; }
  .river .tile.sm { --tw: var(--rw); }
  .river .tile.last { outline-width: 2px; outline-offset: 1px; }
  #info { padding: 3px 6px; gap: 1px; font-size: 11px; border-radius: 8px; justify-content: center; }
  #info .gold-show .tile.sm { --tw: calc(var(--rw) * 1.15); }
  #info .winds { grid-template-columns: repeat(3, 1.5em); grid-template-rows: repeat(3, 1.25em); }
  #info .wall-left { display: none; }

  /* 自己：头像 | 副露 | 手牌 一行 */
  #p-bottom { flex-direction: row; align-items: flex-end; justify-content: center; gap: 6px; padding-bottom: max(2px, env(safe-area-inset-bottom)); }
  #p-bottom .meta { flex-wrap: nowrap; gap: 6px; align-items: flex-end; }
  #p-bottom .pinfo { flex-direction: column; gap: 1px; }
  #p-bottom .pinfo .who { align-items: center; }
  #p-bottom .pinfo .nm { display: none; }
  #p-bottom .pinfo .badges { justify-content: center; max-width: 60px; }
  #p-bottom .melds { flex-wrap: nowrap; gap: 3px; }
  #p-bottom .melds .tile { --tw: calc(var(--tw-base, var(--sw)) * .9); }
  #p-bottom .handrow { gap: 4px; }
  #p-bottom .hand .tile.sel { transform: translateY(-12px); }
  #p-bottom .hand .tile.ting::before { top: -6px; }

  /* 操作按钮：右下角，拇指可达 */
  #actions { left: auto; right: calc(10px + var(--sr)); transform: none; bottom: calc(var(--tw) * 1.53 + 22px); justify-content: flex-end; max-width: 70vw; gap: 8px; }
  #actions button { font-size: 19px; min-height: 46px; min-width: 64px; padding: 6px 16px; border-radius: 14px; }
  #actions .claim-tile { padding: 4px 8px; font-size: 13px; }
  #actions .claim-tile .tile.sm { --tw: calc(var(--sw) * 1.1); }

  /* 提示：手牌上方左侧，浮动不占高度 */
  #hint { position: fixed; left: calc(8px + var(--sl)); bottom: calc(var(--tw) * 1.53 + 22px); min-height: 0; padding: 3px 8px; border-radius: 8px; font-size: 12px; z-index: 4; pointer-events: none; max-width: 50vw; justify-content: flex-start; }
  #hint:not(:empty) { background: rgba(0,0,0,.4); }

  #toast { top: 36px; }
  .fx-bubble .bubble-in { font-size: 12px; padding: 4px 10px; }

  /* 结算 */
  .modal { padding: 6px calc(6px + var(--sr)) 6px calc(6px + var(--sl)); }
  .modal .panel { padding: 10px 14px; border-radius: 12px; }
  .modal h2 { font-size: 18px; margin-bottom: 2px; }
  .tai { font-size: 12px; margin: 2px 0; }
  .res-row { grid-template-columns: 96px 1fr 62px; gap: 6px; padding: 4px 0; font-size: 13px; }
  .res-row .avatar { width: 26px; height: 26px; }
  .res-row .tiles .tile.sm { --tw: min(var(--sw), calc((100vw - 260px) / 19)); }
  .modal .row { margin-top: 8px !important; }

  /* 特效缩小以适应矮屏 */
  .fx-stamp .seal { width: 90px; height: 90px; margin: -45px 0 0 -45px; font-size: 56px; border-radius: 16px; }
  .fx-stamp .seal.two { font-size: 34px; width: 112px; margin-left: -56px; }
  .fx-stamp .meld-fly { top: 52px; --tw: 26px; --sw: 26px; }
  .fx-you .you-text { font-size: 56px; }
  .fx-you.lv3 .you-text { font-size: 72px; }
  .fx-banner { gap: 14px; padding: 6px 0; }
  .bn-text { font-size: 50px; } .bn-text.two { font-size: 40px; }
  .bn-who { font-size: 14px; gap: 6px; }
  .bn-tiles { --tw: 28px; --sw: 28px; }
  .fx-win .win-band { gap: 16px; padding: 8px 0; }
  .fx-win .win-band .bn-who { font-size: 15px; }
  .fx-win .win-line { top: calc(44% + 72px); }
  .fx-win .win-avatar { width: 72px; height: 72px; border-width: 3px; }
  .fx-win .win-text { font-size: 84px; }
  .fx-win .win-text.long { font-size: 60px; }
  .fx-win .win-line { font-size: 15px; padding: 4px 14px; }
  .fx-win .three-gold { --tw: 30px; --sw: 30px; }
  .fx-win .glow { width: 280px; height: 280px; margin: -140px 0 0 -140px; }
}
