/* css/game.css
   牌桌界面（定稿：设计稿 design/ui-redesign 的 theme=B 深蓝桌面 + 琥珀牌背，walls=0 不画牌墙）
   3D 透视参数与 mockup.html 一致，由 renderer.js 按视口写入 CSS 变量 */

:root {
  --ivory: #f3eee4;
  --ivory-d: #e2dccd;
  --bg1: #0f1c26;
  --bg2: #081118;
  --felt: #183a4c;
  --felt-c: #20506a;
  --rim1: #22343f;
  --rim2: #111c23;
  --back: #d98a3a;
  --back-d: #b06a24;
  --console: #0c1820;
  --console-line: #24414f;
  --accent: #4cc9b9;
  --accent-ink: #04201c;
  --text: #eaf2f6;
  --muted: #93aab6;
  --plate: rgba(8, 18, 26, .78);
  --plus: #7fd69a;
  --minus: #ef8a7a;
  --font-display: "STKaiti", "KaiTi", "Kaiti SC", "AR PL UKai CN", "Noto Serif CJK SC", "Songti SC", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Noto Sans CJK SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "WenQuanYi Zen Hei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(70% 55% at 50% 42%, rgba(42, 92, 116, .30), transparent 70%),
    radial-gradient(120% 90% at 50% 40%, var(--bg1), var(--bg2));
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

#app { position: relative; width: 100vw; height: 100vh; overflow: hidden; }

/* ---------- 3D 舞台 ---------- */
#stage {
  position: absolute; left: 50%; top: var(--stage-top); width: 0; height: 0;
  perspective: var(--persp); perspective-origin: 0 var(--po-y);
}
#table {
  position: absolute; left: calc(var(--T) / -2); top: calc(var(--T) / -2);
  width: var(--T); height: var(--T);
  transform-style: preserve-3d; transform: scale(var(--sc)) rotateX(var(--tilt));
}
#table .felt {
  position: absolute; inset: var(--felt-inset, 0px); border-radius: 28px;
  background: radial-gradient(60% 60% at 50% 50%, var(--felt-c), var(--felt) 70%);
  box-shadow: inset 0 0 0 14px var(--rim1), inset 0 0 0 18px var(--rim2), inset 0 0 80px rgba(0, 0, 0, .35);
}
#scene { position: absolute; inset: 0; transform-style: preserve-3d; }
.box { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-style: preserve-3d; }
.f { position: absolute; backface-visibility: visible; }
.face-top { border-radius: 4px; }
.shade1 { filter: brightness(.86); }
.shade2 { filter: brightness(.72); }
.face-top.haku::after, .ht[data-tile="Haku"]::before {
  content: ""; position: absolute; inset: 13% 15%; border: 2px solid #2b54b0; border-radius: 3px;
  box-shadow: inset 0 0 0 2px #f6f2e8, inset 0 0 0 3.5px #2b54b0;
}
.hl { outline: 3px solid var(--accent); outline-offset: 1px; box-shadow: 0 0 18px var(--accent); }

/* 桌心控制台（平铺在桌面上） */
.console {
  position: absolute; display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: var(--console); border: 1px solid var(--console-line); border-radius: 14px; color: var(--text);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, .25);
}
.console .left { font-size: 15px; color: var(--muted); margin-top: 4px; }
.console .num { font-size: 34px; font-weight: 700; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.console .seat { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.console .seat .w {
  position: absolute; left: 0; transform: translateX(-50%); top: 58px;
  font-size: 24px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.console .seat.on .w { color: var(--accent); }
.console .seat .bar {
  position: absolute; left: 0; transform: translateX(-50%); top: 94px;
  width: 110px; height: 5px; border-radius: 3px; background: transparent;
}
.console .seat.on .bar { background: var(--accent); box-shadow: 0 0 12px var(--accent); }

/* ---------- 2D 覆盖层 ---------- */
.topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; padding: 22px 32px 0;
  font-size: 14px; color: var(--muted); pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar .title {
  display: flex; align-items: center; gap: 12px; padding: 9px 18px 9px 12px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(20, 38, 50, .92), rgba(9, 20, 28, .92));
  border: 1px solid rgba(217, 138, 58, .35); box-shadow: 0 6px 18px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.topbar .title .seal {
  width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 19px; font-weight: 700; color: #2a1605;
  background: linear-gradient(180deg, #f2b467, var(--back)); box-shadow: inset 0 -2px 0 var(--back-d);
}
.topbar .t { color: var(--text); font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: 2px; }
.topbar .hint { font-size: 12px; color: var(--muted); padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .12); }
.topbar .btns { display: flex; gap: 10px; }
.gbtn, .topbar .btns button {
  height: 40px; padding: 0 18px; border-radius: 12px; cursor: pointer;
  font-family: var(--font-display); font-size: 17px; font-weight: 700; letter-spacing: 3px; color: #dfeaf0;
  background: linear-gradient(180deg, #2b4656, #172a36); border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 3px 0 #0a151c, 0 8px 16px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .12);
  transition: transform .08s ease, box-shadow .08s ease, filter .12s ease;
}
.topbar .btns button:hover { filter: brightness(1.15); }
.topbar .btns button:active { transform: translateY(2px); box-shadow: 0 1px 0 #0a151c, 0 4px 8px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .12); }

/* 玩家名牌：头像（带门风角标）+ 名字 + 金币。思考时描边高亮并冒思考气泡 */
.plate {
  position: absolute; z-index: 3; display: flex; align-items: center; gap: 10px;
  padding: 7px 16px 7px 7px; border-radius: 16px; white-space: nowrap;
  background: linear-gradient(180deg, rgba(22, 40, 52, .94), rgba(9, 19, 27, .94));
  border: 1px solid rgba(255, 255, 255, .10);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .07);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.plate .av {
  position: relative; flex: none; width: 52px; height: 52px; border-radius: 14px; padding: 2px;
  background: linear-gradient(180deg, #47616f, #1c2f3a);
}
.plate .av svg, .plate .av img { display: block; width: 100%; height: 100%; border-radius: 12px; object-fit: cover; }
.plate .av .wind {
  position: absolute; right: -6px; bottom: -6px; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 13px; font-weight: 700; color: var(--text);
  background: #0c1820; border: 1px solid rgba(255, 255, 255, .25);
}
.plate .av .wind.dealer { background: linear-gradient(180deg, #f2b467, var(--back)); color: #2a1605; border-color: #ffd9a3; }
.plate .nm { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.plate .sc { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 15px; font-weight: 700; color: #f2c77e; font-variant-numeric: tabular-nums; }
.plate .sc::before {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe2a8, #e0962f 70%); box-shadow: inset 0 0 0 1.5px rgba(122, 68, 10, .55);
}
.plate.turn { border-color: rgba(76, 201, 185, .7); box-shadow: 0 0 0 1px rgba(76, 201, 185, .45), 0 8px 22px rgba(0, 0, 0, .4); }
.plate.thinking { border-color: #f2b467; animation: plateGlow 1.6s ease-in-out infinite; }
@keyframes plateGlow {
  0%, 100% { box-shadow: 0 0 0 1px #f2b467, 0 0 10px rgba(242, 180, 103, .30), 0 8px 22px rgba(0, 0, 0, .4); }
  50% { box-shadow: 0 0 0 2px #f2b467, 0 0 26px rgba(242, 180, 103, .65), 0 8px 22px rgba(0, 0, 0, .4); }
}

/* 思考气泡：两个小泡从名牌右上角冒出来，连到一朵装着三个点的云 */
.plate .bubble { position: absolute; right: -8px; bottom: 100%; width: 74px; height: 50px; pointer-events: none; }
.plate .bubble > i, .plate .bubble .cloud {
  position: absolute; background: #fdfaf2; box-shadow: 0 2px 0 #c9c0ad, 0 5px 10px rgba(0, 0, 0, .35);
  transform: scale(0); animation: bubIn .9s cubic-bezier(.3, 1.5, .5, 1) forwards, bubFloat 2.2s ease-in-out .9s infinite;
}
.plate .bubble .b1 { left: 4px; bottom: 0; width: 7px; height: 7px; border-radius: 50%; }
.plate .bubble .b2 { left: 13px; bottom: 9px; width: 11px; height: 11px; border-radius: 50%; animation-delay: .12s, 1.02s; }
.plate .bubble .cloud {
  right: 0; top: 0; width: 50px; height: 28px; border-radius: 16px; animation-delay: .26s, 1.16s;
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.plate .bubble .cloud::before, .plate .bubble .cloud::after {
  content: ""; position: absolute; background: #fdfaf2; border-radius: 50%; z-index: -1;
}
.plate .bubble .cloud::before { left: 7px; top: -6px; width: 18px; height: 18px; }
.plate .bubble .cloud::after { right: 8px; top: -4px; width: 14px; height: 14px; }
.plate .bubble .cloud i { width: 6px; height: 6px; border-radius: 50%; background: #24404f; animation: dot 1s infinite ease-in-out; }
.plate .bubble .cloud i:nth-child(2) { animation-delay: .15s; }
.plate .bubble .cloud i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
@keyframes bubIn { to { transform: scale(1); } }
@keyframes bubFloat { 0%, 100% { translate: 0 0; } 50% { translate: 0 -3px; } }
@media (prefers-reduced-motion: reduce) { .plate.thinking, .plate .bubble > i, .plate .bubble .cloud, .plate .bubble .cloud i { animation-duration: .01s; animation-iteration-count: 1; } }

/* 四家位置：往屏幕中间收，--side = 牌桌中段半宽（renderer.js 按视口写入） */
.plate.p-N { left: 50%; top: 14px; transform: translateX(-50%); z-index: 6; } /* 和顶栏同一行，居中 */
.plate.p-N .bubble { bottom: auto; top: 2px; right: auto; left: calc(100% + 2px); } /* 顶上没地方，气泡放到右侧 */
.plate.p-N .bubble .b1 { bottom: 14px; left: 0; }
.plate.p-N .bubble .b2 { bottom: 20px; left: 9px; }
.plate.p-N .bubble .cloud { top: 6px; }
.plate.p-W, .plate.p-E { top: 30%; }
.plate.p-W { right: calc(50% + var(--side, 480px)); }
.plate.p-E { left: calc(50% + var(--side, 480px)); }
.plate.p-S { left: 50%; bottom: var(--dock-bottom, 20px); transform: translateX(-50%); }

.hand {
  position: absolute; z-index: 4; left: 50%; bottom: var(--hand-bottom); transform: translateX(-50%);
  display: flex; align-items: flex-end; gap: var(--hgap);
}
.ht {
  position: relative; flex: none; width: var(--hw); height: calc(var(--hw) * 1.36); border-radius: 6px;
  background: var(--img) center/84% auto no-repeat, linear-gradient(#fbf8f1, var(--ivory));
  box-shadow: 0 calc(var(--hw) * .12) 0 -1px var(--back), 0 calc(var(--hw) * .12 + 6px) 14px rgba(0, 0, 0, .45), inset 0 -2px 0 var(--ivory-d);
  transition: transform .15s ease;
}
.ht.gapL { margin-left: calc(var(--hw) * .45); }
.ht.can { transform: translateY(-10px); }
.ht.can::after {
  content: ""; position: absolute; left: 18%; right: 18%; bottom: -18px; height: 3px; border-radius: 2px; background: var(--accent);
}
.ht.meld { --hw: calc(var(--hwm, 54px) * .78); }

.actions { position: absolute; z-index: 6; right: calc(50% - var(--side, 480px) - 40px); bottom: calc(var(--hand-bottom) + var(--hw) * 1.36 + 34px); display: flex; gap: 12px; align-items: center; }
.act {
  min-width: 68px; height: 52px; padding: 0 18px; border-radius: 26px; border: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); font-size: 26px; font-weight: 800; letter-spacing: 2px; color: #2a1605;
  background: linear-gradient(180deg, #ffd08a, var(--back)); box-shadow: 0 4px 0 var(--back-d), 0 10px 20px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .5); cursor: default;
}
.act.sec { background: rgba(255, 255, 255, .10); color: var(--text); border: 1px solid rgba(255, 255, 255, .18); font-weight: 600; }
.act small { font-size: 12px; font-weight: 600; letter-spacing: 0; opacity: .8; }
.timer { font-size: 13px; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- 弹窗（结算 / 规则 / 设置 / 大厅） ---------- */
.overlay { position: absolute; inset: 0; z-index: 20; display: none; }
.overlay.show { display: block; }
#lobby-modal { z-index: 4; } /* 大厅时顶栏（规则/设置）仍可点击 */
.dim { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
.panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 680px; max-width: calc(100vw - 32px); max-height: calc(100vh - 24px); overflow: auto;
  border-radius: 18px; background: var(--console); border: 1px solid var(--console-line);
  padding: 26px 30px 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
.panel h2 { margin: 0; font-family: var(--font-display); font-size: 30px; letter-spacing: 3px; }
.panel h2 span { color: var(--accent); }
.panel .sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.panel .row { display: flex; flex-wrap: wrap; gap: 4px; margin: 18px 0 6px; align-items: flex-end; }
.panel .row .ht { --hw: 36px; }
.panel .row .ht.hl { margin-left: 14px; }
.panel .row .ht.mgap { margin-left: 10px; }
.panel .fan { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.panel .fan span {
  padding: 5px 10px; border-radius: 8px; background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08); font-size: 14px;
}
.panel .fan b { color: var(--accent); margin-left: 6px; }
.panel table { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 15px; }
.panel td { padding: 9px 6px; border-top: 1px solid var(--console-line); }
.panel td.n { text-align: right; font-variant-numeric: tabular-nums; }
.panel .plus { color: var(--plus); }
.panel .minus { color: var(--minus); }
.panel .bb { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.panel .bb button {
  height: 44px; padding: 0 24px; border-radius: 12px; cursor: pointer;
  font-family: var(--font-display); font-size: 18px; font-weight: 700; letter-spacing: 3px; color: var(--text);
  background: linear-gradient(180deg, #2b4656, #172a36); border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 3px 0 #0a151c, 0 8px 16px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.panel .bb button:active:not(:disabled) { transform: translateY(2px); }
.panel .bb button.p { color: #2a1605; border-color: #ffd9a3; background: linear-gradient(180deg, #ffd08a, var(--back)); box-shadow: 0 3px 0 var(--back-d), 0 8px 16px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .5); }
.panel .bb button:disabled { opacity: .45; cursor: not-allowed; }
.panel .close {
  position: absolute; right: 16px; top: 12px; border: 0; background: none; color: var(--muted);
  font-size: 26px; cursor: pointer; line-height: 1;
}
.panel.text { width: 560px; font-size: 14px; line-height: 1.7; color: var(--text); }
.panel.text h3 { font-size: 15px; color: var(--accent); margin: 16px 0 4px; }
.panel.text ul { margin: 0; padding-left: 20px; }
.panel.text .muted { color: var(--muted); font-size: 12px; }
.panel label { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; }
.panel select {
  background: rgba(255, 255, 255, .08); color: var(--text); border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 8px; padding: 6px 10px;
}
.panel select option { background: var(--console); }
.panel.lobby { width: 420px; text-align: center; }
.panel.lobby .sub { margin-top: 10px; line-height: 1.6; }
.panel.lobby .bb { justify-content: center; }

/* ---------- 手机横屏（参照 b_mobile.png；3D 参数由 renderer.js 切换） ---------- */
body.mobile .topbar { padding: 8px 14px 0; }
body.mobile .topbar .title { padding: 4px 12px 4px 6px; border-radius: 10px; }
body.mobile .topbar .title .seal { width: 22px; height: 22px; font-size: 14px; border-radius: 6px; }
body.mobile .topbar .t { font-size: 14px; letter-spacing: 1px; }
body.mobile .topbar .btns button { height: 30px; padding: 0 12px; font-size: 13px; letter-spacing: 1px; border-radius: 9px; }
body.mobile .plate { padding: 5px 10px 5px 5px; border-radius: 12px; width: auto; flex-direction: row; }
body.mobile .plate .bubble { scale: .8; transform-origin: right bottom; }
body.mobile .plate .av { width: 36px; height: 36px; border-radius: 10px; }
body.mobile .plate .nm { font-size: 13px; }
body.mobile .plate .sc { font-size: 12px; margin-top: 1px; }
body.mobile .plate.p-N { left: 50%; top: 6px; transform: translateX(-50%); }
body.mobile .plate.p-W { left: 10px; right: auto; top: 40%; }
body.mobile .plate.p-E { right: 10px; left: auto; top: 40%; }
body.mobile .plate.p-S { left: 10px; bottom: 70px; transform: none; }
body.mobile .actions { right: 14px; bottom: 86px; transform: scale(.8); transform-origin: right bottom; }
body.mobile .topbar .hint { display: none; }
body.mobile .panel { padding: 14px 18px 14px; }
body.mobile .panel h2 { font-size: 20px; }
body.mobile .panel .bb button { height: 34px; }
body.mobile .panel .row { margin: 10px 0 4px; }
body.mobile .panel .row .ht { --hw: 26px; }
body.mobile .panel table { margin-top: 8px; font-size: 13px; }
body.mobile .panel td { padding: 4px 6px; }
body.mobile .panel .fan { margin: 8px 0 2px; }
body.mobile .panel .fan span { font-size: 12px; padding: 3px 8px; }
body.mobile .panel .bb { margin-top: 10px; }
body.mobile .panel .bb button { padding: 7px 14px; font-size: 13px; }
