/* =========================================================
   3D 台灣麻將桌 · style.css
   純 HTML / CSS / 原生 JS，無任何框架或外部資源
   麻將牌 SVG 素材來源：WarL0ckNet/tile-art (GPL-3.0)
   ========================================================= */

:root {
  /* 配色 */
  --bg-0: #070b0d;
  --bg-1: #0b1114;
  --felt-0: #0d5948;
  --felt-1: #106b56;
  --frame-0: #201812;
  --frame-1: #37271d;
  --ivory: #f5f0df;
  --ivory-side: #d9d0b9;
  --back: #225b48;
  --warm: #d4aa61;
  --red: #b9463c;
  --green: #50a77c;
  --text: #ece8dc;
  --muted: rgba(236, 232, 220, 0.55);

  /* 牌體尺寸（桌面預設） */
  --tw: 40px;
  --th: 55px;
  --td: 10px;
  --tr: 6px;

  /* 桌面尺寸 */
  --table: 760px;

  /* 視差 */
  --par-x: 0deg;
  --par-y: 0deg;

  /* 視角 */
  --cam-rx: 52deg;
  --cam-scale: 1;
  --cam-ty: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ============================ 場景 ============================ */
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* 視角 CSS 變數（由 camera class 覆寫） */
}
.scene.cam-top   { --cam-rx: 26deg; --cam-scale: 0.9;  --cam-ty: -14px; }
.scene.cam-game  { --cam-rx: 52deg; --cam-scale: 1;    --cam-ty: 0px; }
.scene.cam-close { --cam-rx: 60deg; --cam-scale: 1.38; --cam-ty: 74px; }

/* ============================ 背景 ============================ */
.bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.bg__space {
  position: absolute; inset: -10%;
  background:
    radial-gradient(120% 90% at 50% 8%, #14202150 0%, transparent 55%),
    radial-gradient(90% 70% at 50% 120%, #0a201a 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 60%, #05080a);
}
.bg__lattice {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(212, 170, 97, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 170, 97, 0.05) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(70% 55% at 50% 30%, #000 0%, transparent 75%);
          mask-image: radial-gradient(70% 55% at 50% 30%, #000 0%, transparent 75%);
  opacity: 0.5;
  filter: blur(0.3px);
}
.bg__spot {
  position: absolute; border-radius: 50%;
  filter: blur(70px); mix-blend-mode: screen; opacity: 0.55;
}
.bg__spot--main {
  width: 900px; height: 720px; left: 50%; top: -18%;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(120, 200, 175, 0.5), transparent 62%);
}
.bg__spot--warm {
  width: 640px; height: 520px; right: -8%; bottom: -6%;
  background: radial-gradient(circle, rgba(212, 170, 97, 0.42), transparent 60%);
}
.bg__floor-glow {
  position: absolute; left: 50%; bottom: 4%;
  width: 78vmin; height: 26vmin; transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(80, 167, 124, 0.35), transparent 72%);
  filter: blur(30px);
}
.bg__fog {
  position: absolute; inset: 0;
  background: radial-gradient(140% 60% at 50% 100%, rgba(16, 107, 86, 0.16), transparent 60%);
  opacity: 0.8;
}
.bg__particles { position: absolute; inset: 0; }
.bg__particles i {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: rgba(232, 224, 196, 0.55);
  box-shadow: 0 0 6px rgba(212, 170, 97, 0.5);
  animation: drift linear infinite;
}
@keyframes drift {
  0%   { transform: translateY(0) translateX(0); opacity: 0; }
  10%  { opacity: 0.8; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-120px) translateX(24px); opacity: 0; }
}

/* ============================ 頂部 HUD ============================ */
.hud-top {
  position: absolute; z-index: 30; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 22px; pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.brand { line-height: 1.1; }
.brand__title {
  display: block; font-size: 22px; font-weight: 800; letter-spacing: 0.22em;
  color: var(--text);
  text-shadow: 0 2px 18px rgba(212, 170, 97, 0.35);
}
.brand__sub {
  display: block; margin-top: 4px; font-size: 11px; letter-spacing: 0.32em;
  color: var(--warm); opacity: 0.85;
}
.hud-top__actions { display: flex; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 999px; cursor: pointer;
  color: var(--text); font-size: 12px; letter-spacing: 0.08em;
  background: rgba(20, 30, 30, 0.5);
  border: 1px solid rgba(212, 170, 97, 0.25);
  backdrop-filter: blur(6px);
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
}
.chip:hover { border-color: rgba(212, 170, 97, 0.55); background: rgba(28, 42, 40, 0.6); }
.chip:active { transform: translateY(1px); }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.chip__icon { font-size: 13px; color: var(--warm); }

/* 說明浮層 */
.info-panel {
  position: absolute; z-index: 40; top: 66px; right: 22px; width: min(320px, 82vw);
  background: rgba(12, 20, 20, 0.92);
  border: 1px solid rgba(212, 170, 97, 0.3);
  border-radius: 14px; padding: 16px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
}
.info-panel[hidden] { display: none; }
.info-panel h2 { margin: 0 0 10px; font-size: 15px; letter-spacing: 0.1em; color: var(--warm); }
.info-panel ul { margin: 0 0 12px; padding-left: 18px; }
.info-panel li { font-size: 12.5px; line-height: 1.7; color: var(--text); }

/* ============================ 玩家資訊面板 ============================ */
.seats { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.seat {
  position: absolute; pointer-events: auto;
  display: flex; align-items: center; gap: 11px;
  padding: 9px 13px; border-radius: 14px; min-width: 148px;
  background: linear-gradient(160deg, rgba(18, 28, 28, 0.72), rgba(10, 16, 16, 0.62));
  border: 1px solid rgba(212, 170, 97, 0.22);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  transition: border-color 0.35s, box-shadow 0.35s;
}
.seat--local { left: 24px; bottom: 128px; }
.seat--right { right: 24px; top: 50%; transform: translateY(-50%); }
.seat--top   { left: 50%; top: 74px; transform: translateX(-50%); }
.seat--left  { left: 24px; top: 50%; transform: translateY(-50%); }
.seat.is-turn {
  border-color: rgba(212, 170, 97, 0.75);
  box-shadow: 0 0 0 1px rgba(212, 170, 97, 0.4), 0 0 28px rgba(212, 170, 97, 0.35), 0 12px 30px rgba(0, 0, 0, 0.45);
}
.seat__avatar {
  position: relative; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 16px; color: #10201b;
  background: radial-gradient(circle at 35% 30%, #f5e6c2, var(--warm));
  box-shadow: inset 0 -3px 6px rgba(120, 80, 20, 0.5);
  flex: 0 0 auto;
}
.seat__conn {
  position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--green); border: 2px solid #0c1414;
}
.seat__conn.is-off { background: #6b7472; }
.seat__meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.seat__name { font-size: 13.5px; font-weight: 700; letter-spacing: 0.04em; display: flex; align-items: center; gap: 6px; }
.seat__wind {
  font-size: 11px; color: #10201b; background: var(--green);
  border-radius: 5px; padding: 0 5px; font-weight: 700;
}
.seat__dealer {
  font-size: 11px; color: #2a1c08; background: var(--warm);
  border-radius: 5px; padding: 0 5px; font-weight: 800;
}
.seat__score { font-size: 12px; color: var(--warm); letter-spacing: 0.06em; }
.seat__turn { font-size: 10.5px; color: var(--muted); }
.seat.is-turn .seat__turn { color: var(--warm); }

/* ============================ 3D 舞台 ============================ */
.stage {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  perspective: 1600px;
  perspective-origin: 50% 40%;
}
.parallax {
  transform-style: preserve-3d;
  transform: rotateX(var(--par-x)) rotateY(var(--par-y));
  will-change: transform;
}
.table-tilt {
  transform-style: preserve-3d;
  transform: translateY(var(--cam-ty)) rotateX(var(--cam-rx)) scale(calc(var(--cam-scale) * var(--user-zoom, 1)));
  transition: transform 0.85s cubic-bezier(0.22, 0.61, 0.36, 1);
}
/* 使用者主動縮放時改用較快過場，讓滾輪 / pinch 更即時 */
.table-tilt.is-zooming { transition: transform 0.18s ease-out; }
.table3d {
  position: relative;
  width: var(--table); height: var(--table);
  transform-style: preserve-3d;
}

/* 桌座 / 桌柱 / 接地陰影 */
.table__contact {
  position: absolute; left: 50%; top: 50%;
  width: 62%; height: 62%;
  transform: translate(-50%, -50%) translateZ(-150px);
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), transparent 72%);
  filter: blur(18px);
}
.table__base {
  position: absolute; left: 50%; top: 50%;
  width: 40%; height: 40%; border-radius: 22px;
  transform: translate(-50%, -50%) translateZ(-132px);
  background: linear-gradient(160deg, #2a2018, #150f0a);
  box-shadow: 0 30px 40px rgba(0, 0, 0, 0.5);
}
.table__pillar {
  position: absolute; left: 50%; top: 50%;
  width: 24%; height: 24%; border-radius: 14px;
  transform: translate(-50%, -50%) translateZ(-70px);
  background: linear-gradient(160deg, #3a2a1e, #201510);
  box-shadow: inset 0 6px 12px rgba(255, 220, 170, 0.08), 0 20px 30px rgba(0, 0, 0, 0.5);
}

/* 桌框（四邊，具厚度與倒角） */
.frame {
  position: absolute; z-index: 1;
  background: linear-gradient(150deg, var(--frame-1), var(--frame-0));
  box-shadow:
    inset 0 2px 3px rgba(255, 214, 160, 0.18),
    inset 0 -6px 12px rgba(0, 0, 0, 0.55),
    0 10px 24px rgba(0, 0, 0, 0.4);
}
.frame--top, .frame--bottom { left: -30px; right: -30px; height: 58px; }
.frame--top { top: -30px; border-radius: 22px 22px 8px 8px; }
.frame--bottom { bottom: -30px; border-radius: 8px 8px 22px 22px; }
.frame--left, .frame--right { top: -30px; bottom: -30px; width: 58px; }
.frame--left { left: -30px; border-radius: 22px 8px 8px 22px; }
.frame--right { right: -30px; border-radius: 8px 22px 22px 8px; }
.frame::after {
  content: ""; position: absolute; inset: 6px; border-radius: inherit;
  border: 1px solid rgba(212, 170, 97, 0.16);
}

/* 裝飾層不攔截點擊，確保手牌可被點選 */
.felt, .frame, .device, .table__base, .table__pillar, .table__contact,
.walls, .rivers, .melds, .flowers, .bg { pointer-events: none; }

/* 綠絨桌面 */
.felt {
  position: absolute; inset: 0; z-index: 1; border-radius: 16px;
  background:
    radial-gradient(120% 120% at 50% 42%, var(--felt-1), var(--felt-0) 58%, #094436 100%);
  box-shadow:
    inset 0 0 90px rgba(0, 0, 0, 0.55),
    inset 0 3px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
}
.felt__weave {
  position: absolute; inset: 0; opacity: 0.5;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.05) 0 2px, transparent 2px 4px);
}
.felt__dip {
  position: absolute; left: 50%; top: 50%;
  width: 66%; height: 66%; transform: translate(-50%, -50%);
  border-radius: 20px;
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.45),
    inset 0 8px 24px rgba(0, 0, 0, 0.35);
  background: radial-gradient(closest-side, rgba(9, 62, 50, 0.55), transparent 78%);
}
.felt__vignette {
  position: absolute; inset: 0;
  background: radial-gradient(90% 90% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.4));
}

/* ============================ 中央裝置 ============================ */
.device {
  position: absolute; left: 50%; top: 50%; z-index: 2;
  width: 210px; height: 210px;
  transform: translate(-50%, -50%) translateZ(4px);
}
.device__ring {
  position: absolute; inset: -8px; border-radius: 30px;
  background: conic-gradient(from 0deg, #1a3a30, #0d251e, #1a3a30, #0d251e, #1a3a30);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  opacity: 0.9;
}
.device__plate {
  position: absolute; inset: 0; border-radius: 26px;
  background:
    radial-gradient(120% 120% at 50% 30%, #16302a, #0a1a16 70%);
  border: 1px solid rgba(212, 170, 97, 0.28);
  box-shadow:
    inset 0 2px 6px rgba(255, 220, 170, 0.1),
    inset 0 -10px 24px rgba(0, 0, 0, 0.6);
  display: grid; place-items: center;
  overflow: hidden;
}
.device__glyph {
  position: absolute; width: 120px; height: 120px; border-radius: 50%;
  background:
    conic-gradient(from 45deg, transparent 0 8%, rgba(212, 170, 97, 0.16) 8% 12%, transparent 12% 25%,
    rgba(80, 167, 124, 0.14) 25% 29%, transparent 29% 50%,
    rgba(212, 170, 97, 0.16) 50% 54%, transparent 54% 75%,
    rgba(80, 167, 124, 0.14) 75% 79%, transparent 79% 100%);
  border: 1px dashed rgba(212, 170, 97, 0.22);
}
.device__mark {
  position: absolute; font-size: 15px; font-weight: 800; color: var(--warm);
  text-shadow: 0 0 10px rgba(212, 170, 97, 0.4);
}
.device__mark--n { top: 8px; left: 50%; transform: translateX(-50%); }
.device__mark--s { bottom: 8px; left: 50%; transform: translateX(-50%); }
.device__mark--w { left: 9px; top: 50%; transform: translateY(-50%); }
.device__mark--e { right: 9px; top: 50%; transform: translateY(-50%); }
.device__button {
  width: 52px; height: 52px; border-radius: 50%; border: none; cursor: default;
  background: radial-gradient(circle at 38% 32%, #2c5a4c, #103127 70%);
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.6), inset 0 3px 5px rgba(255, 220, 170, 0.15), 0 4px 10px rgba(0, 0, 0, 0.5);
  position: relative;
}
.device__button::after {
  content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(212, 170, 97, 0.7), rgba(120, 80, 20, 0.4));
  box-shadow: 0 0 12px rgba(212, 170, 97, 0.4);
}
.device__dice {
  position: absolute; right: 30px; bottom: 30px; display: flex; gap: 6px;
}
.device__dice .pip {
  width: 20px; height: 20px; border-radius: 5px;
  background: linear-gradient(150deg, #f4efe0, #cfc6ac);
  box-shadow: inset 0 -2px 3px rgba(120, 100, 60, 0.5), 0 2px 4px rgba(0, 0, 0, 0.5);
  position: relative;
}
.device__dice .pip::before,
.device__dice .pip::after {
  content: ""; position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: var(--red);
}
.device__dice .pip--a::before { left: 4px; top: 4px; }
.device__dice .pip--a::after { right: 4px; bottom: 4px; }
.device__dice .pip--b::before { left: 50%; top: 50%; transform: translate(-50%, -50%); background: #10201b; }
.device__dice .pip--b::after { display: none; }
.device__leds {
  position: absolute; left: 26px; top: 30px; display: flex; flex-direction: column; gap: 8px;
}
.device__leds i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 6px rgba(80, 167, 124, 0.8);
  animation: led 3.2s ease-in-out infinite;
}
.device__leds i:nth-child(2) { animation-delay: 0.4s; background: var(--warm); box-shadow: 0 0 6px rgba(212, 170, 97, 0.8); }
.device__leds i:nth-child(3) { animation-delay: 0.8s; }
.device__leds i:nth-child(4) { animation-delay: 1.2s; background: var(--warm); box-shadow: 0 0 6px rgba(212, 170, 97, 0.8); }
@keyframes led { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.device__brand {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  font-size: 9px; letter-spacing: 0.3em; color: rgba(212, 170, 97, 0.5);
}

/* ============================ 麻將牌 3D 牌體 ============================ */
.tile {
  position: relative;
  width: var(--tw); height: var(--th);
  padding: 0; margin: 0; border: none; background: none;
  transform-style: preserve-3d;
  cursor: default;
  flex: 0 0 auto;
}
.tile__face {
  position: absolute; inset: 0;
  border-radius: var(--tr);
  transform: translateZ(var(--td));
  background: linear-gradient(158deg, #fbf7ea 0%, #f2ebd6 55%, #e7dcc0 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -3px 5px rgba(150, 135, 95, 0.28),
    /* 牌側厚度（層疊陰影模擬立體邊緣） */
    0 1px 0 #ede3c8,
    0 2px 0 #e6dbbd,
    0 3px 0 #ded2af,
    0 4px 0 #d6c8a1,
    0 5px 0 #cdbe94,
    0 6px 0 #c4b487,
    /* 接觸桌面陰影 */
    0 10px 12px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.tile__face img {
  width: 100%; height: 100%; object-fit: contain;
  padding: 8% 11%; display: block;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.4));
}
/* 上緣高光 */
.tile__face::before {
  content: ""; position: absolute; left: 8%; right: 8%; top: 5%; height: 22%;
  border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 255, 255, 0.5), transparent 75%);
  pointer-events: none;
}

/* 牌背 */
.tile__face--back {
  background:
    linear-gradient(158deg, #2f7a62 0%, var(--back) 55%, #17452f 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -3px 6px rgba(0, 0, 0, 0.35),
    0 1px 0 #21543f, 0 2px 0 #1e4e3a, 0 3px 0 #1a4835, 0 4px 0 #164230,
    0 5px 0 #123c2b, 0 6px 0 #0f3626,
    0 10px 12px rgba(0, 0, 0, 0.45);
}
/* 牌背改為翡翠玉色，back.svg 僅作低調暖色光澤 */
.tile__face--back img { padding: 16%; opacity: 0.14; mix-blend-mode: soft-light; }
.tile__face--back::after {
  content: ""; position: absolute; inset: 20%;
  border-radius: 4px;
  border: 1px solid rgba(212, 170, 97, 0.32);
  background: radial-gradient(circle at 50% 40%, rgba(212, 170, 97, 0.2), transparent 72%);
  pointer-events: none;
}

/* 花牌（CSS 牌面，與 SVG 牌體一致） */
.tile__face--flower {
  display: grid; place-items: center;
}
.flower__char {
  font-size: calc(var(--tw) * 0.62); font-weight: 800; line-height: 1;
  color: var(--red); z-index: 2;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.tile__face--flower[data-accent="green"] .flower__char { color: #2f7d4f; }
.tile__face--flower[data-accent="gold"] .flower__char { color: #b5852a; }
.tile__face--flower[data-accent="blue"] .flower__char { color: #2f6a8f; }
.flower__deco {
  position: absolute; inset: 12% 14%; border-radius: 40% 40% 42% 42%;
  border: 1px solid currentColor; opacity: 0.16; z-index: 1;
}
.flower__deco::before {
  content: ""; position: absolute; left: 50%; bottom: 6%; width: 2px; height: 42%;
  transform: translateX(-50%); background: currentColor; opacity: 0.5;
}
.tile__face--flower { color: var(--green); }
.tile__corner {
  position: absolute; top: 4%; left: 6%; font-size: calc(var(--tw) * 0.24);
  color: var(--warm); font-weight: 700; z-index: 3; opacity: 0.85;
}

/* 圖片載入失敗 fallback */
.tile__face.is-broken img { display: none; }
.tile__face.is-broken::after {
  content: attr(data-name);
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--tw) * 0.42); font-weight: 800; color: #333; text-align: center;
  padding: 4px; line-height: 1.05;
}

/* ============================ 手牌 ============================ */
.hands { position: absolute; inset: 0; transform-style: preserve-3d; }
.hand {
  position: absolute; left: 50%; top: 50%;
  display: flex; align-items: flex-end; gap: 2px;
  transform-style: preserve-3d;
}
.hand--local { transform: translate(-50%, -50%) translateY(298px); z-index: 6; }
.hand--top   { transform: translate(-50%, -50%) translateY(-298px) rotate(180deg); }
.hand--left  { transform: translate(-50%, -50%) translateX(-298px) rotate(90deg); }
.hand--right { transform: translate(-50%, -50%) translateX(298px) rotate(-90deg); }

/* 本地玩家手牌互動 */
.hand--local .tile { cursor: pointer; }
.hand--local .tile:hover .tile__face,
.hand--local .tile:focus-visible .tile__face {
  transform: translateZ(calc(var(--td) + 16px)) translateY(-10px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -3px 5px rgba(150, 135, 95, 0.28),
    0 1px 0 #ede3c8, 0 2px 0 #e6dbbd, 0 3px 0 #ded2af, 0 4px 0 #d6c8a1,
    0 5px 0 #cdbe94, 0 6px 0 #c4b487,
    0 18px 22px rgba(0, 0, 0, 0.5);
}
.hand--local .tile:focus-visible { outline: none; }
.hand--local .tile:focus-visible .tile__face { outline: 2px solid var(--warm); outline-offset: 2px; }
.hand--local .tile.is-selected .tile__face {
  transform: translateZ(calc(var(--td) + 30px)) translateY(-22px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 0 0 2px var(--warm),
    0 22px 26px rgba(0, 0, 0, 0.55);
}
/* 摸入的第 17 張牌與其他手牌間距 */
.hand--local .tile.is-drawn { margin-left: 22px; }
.hand--local .tile.is-drawn .tile__face::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--tr);
  box-shadow: inset 0 0 0 2px rgba(212, 170, 97, 0.5);
  pointer-events: none;
}

/* 摸牌滑入動畫 */
@keyframes tile-slide-in {
  from { opacity: 0; transform: translateX(40px) translateY(-6px); }
  to   { opacity: 1; transform: translateX(0) translateY(0); }
}
.tile--enter { animation: tile-slide-in 0.4s ease both; }

/* 打牌動畫 */
@keyframes tile-discard-pop {
  from { opacity: 0; transform: translateZ(30px) scale(1.08); }
  to   { opacity: 1; transform: translateZ(var(--td)) scale(1); }
}
.river .tile--enter .tile__face { animation: tile-discard-pop 0.35s ease both; }

/* ============================ 牌河 ============================ */
.rivers { position: absolute; inset: 0; transform-style: preserve-3d; }
.river {
  position: absolute; left: 50%; top: 50%;
  display: grid; grid-template-columns: repeat(6, var(--tw)); gap: 3px;
  --tw: 32px; --th: 44px; --td: 8px;
  transform-style: preserve-3d;
}
.river--local { transform: translate(-50%, -50%) translateY(150px); }
.river--top   { transform: translate(-50%, -50%) translateY(-150px) rotate(180deg); }
.river--left  { transform: translate(-50%, -50%) translateX(-150px) rotate(90deg); }
.river--right { transform: translate(-50%, -50%) translateX(150px) rotate(-90deg); }

/* ============================ 吃碰槓公開牌組 ============================ */
.melds { position: absolute; inset: 0; transform-style: preserve-3d; }
.meld {
  position: absolute; left: 50%; top: 50%;
  display: flex; gap: 8px;
  --tw: 32px; --th: 44px; --td: 8px;
  transform-style: preserve-3d;
}
.meld__group { display: flex; gap: 1px; transform-style: preserve-3d; }
.meld__group .tile { transform: none; }
.meld--local { transform: translate(-50%, -50%) translate(232px, 214px); }
.meld--top   { transform: translate(-50%, -50%) translate(-232px, -214px) rotate(180deg); }
.meld--left  { transform: translate(-50%, -50%) translate(-214px, 232px) rotate(90deg); }
.meld--right { transform: translate(-50%, -50%) translate(214px, -232px) rotate(-90deg); }

/* ============================ 花牌區 ============================ */
.flowers { position: absolute; inset: 0; transform-style: preserve-3d; }
.flower-area {
  position: absolute; left: 50%; top: 50%;
  display: flex; gap: 2px;
  --tw: 30px; --th: 41px; --td: 7px;
  transform-style: preserve-3d;
}
.flower-area--local { transform: translate(-50%, -50%) translate(-236px, 214px); }
.flower-area--top   { transform: translate(-50%, -50%) translate(236px, -214px) rotate(180deg); }
.flower-area--left  { transform: translate(-50%, -50%) translate(-214px, -236px) rotate(90deg); }
.flower-area--right { transform: translate(-50%, -50%) translate(214px, 236px) rotate(-90deg); }

/* ============================ 牌牆 ============================ */
.walls { position: absolute; inset: 0; transform-style: preserve-3d; }
.wall {
  position: absolute; left: 50%; top: 50%;
  display: flex; gap: 1px;
  transform-style: preserve-3d;
}
.wall--bottom { transform: translate(-50%, -50%) translateY(232px); }
.wall--top    { transform: translate(-50%, -50%) translateY(-232px) rotate(180deg); }
.wall--left   { transform: translate(-50%, -50%) translateX(-232px) rotate(90deg); }
.wall--right  { transform: translate(-50%, -50%) translateX(232px) rotate(-90deg); }
.wstack {
  position: relative; width: var(--tw); height: var(--th);
  --tw: 30px; --th: 41px; --td: 9px;
  transform-style: preserve-3d;
}
.wstack .tile { position: absolute; inset: 0; }
.wstack .tile--wbottom .tile__face { transform: translateZ(var(--td)); }
.wstack .tile--wtop .tile__face { transform: translateZ(calc(var(--td) * 2 + 4px)); }

/* ============================ 底部控制列 ============================ */
.hud-bottom {
  position: absolute; z-index: 30; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 18px 22px calc(18px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.controls { display: flex; gap: 8px; }
.btn {
  padding: 11px 18px; border-radius: 12px; cursor: pointer;
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--text);
  background: rgba(20, 30, 30, 0.55);
  border: 1px solid rgba(212, 170, 97, 0.28);
  backdrop-filter: blur(8px);
  transition: transform 0.1s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.btn:hover { border-color: rgba(212, 170, 97, 0.6); background: rgba(28, 42, 40, 0.65); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.cam-btn.is-active, .btn--primary {
  border-color: rgba(80, 167, 124, 0.7);
  background: linear-gradient(160deg, rgba(50, 120, 92, 0.7), rgba(20, 70, 52, 0.7));
  box-shadow: 0 0 18px rgba(80, 167, 124, 0.3);
}
.btn--gold {
  border-color: rgba(212, 170, 97, 0.7);
  background: linear-gradient(160deg, rgba(150, 110, 50, 0.6), rgba(90, 60, 20, 0.6));
  box-shadow: 0 0 18px rgba(212, 170, 97, 0.28);
}
/* 縮放控制 */
.btn--icon {
  width: 40px; padding: 11px 0; text-align: center; font-size: 16px; line-height: 1;
}
.ctl-sep {
  width: 1px; align-self: stretch; margin: 2px 4px;
  background: rgba(212, 170, 97, 0.25);
}

/* 狀態提示 toast */
.toast {
  position: absolute; z-index: 45; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(10px);
  padding: 9px 18px; border-radius: 999px; font-size: 13px; letter-spacing: 0.06em;
  background: rgba(12, 20, 20, 0.9); border: 1px solid rgba(212, 170, 97, 0.35);
  color: var(--text); opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================ 進場動畫 ============================ */
.intro-veil {
  position: fixed; inset: 0; z-index: 60; background: var(--bg-0);
  animation: veil-out 1s ease 0.2s forwards;
}
@keyframes veil-out { to { opacity: 0; visibility: hidden; } }

.scene.is-intro .table-tilt { animation: table-rise 1.5s cubic-bezier(0.22, 0.61, 0.36, 1) both; }
@keyframes table-rise {
  0%   { transform: translateY(120px) rotateX(78deg) scale(0.82); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: translateY(var(--cam-ty)) rotateX(var(--cam-rx)) scale(var(--cam-scale)); opacity: 1; }
}
.scene.is-intro .walls { animation: fade-up 0.7s ease 0.6s both; }
.scene.is-intro .rivers,
.scene.is-intro .melds,
.scene.is-intro .flowers { animation: fade-up 0.7s ease 0.85s both; }
/* 裝置需保留置中位移，避免進場時跑到右下角 */
.scene.is-intro .device { animation: device-in 0.7s ease 0.85s both; }
.scene.is-intro .hands { animation: hand-in 0.8s ease 1s both; }
.scene.is-intro .seats { animation: fade-up 0.6s ease 1.35s both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes device-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 14px)) translateZ(4px); }
  to   { opacity: 1; transform: translate(-50%, -50%) translateZ(4px); }
}
@keyframes hand-in { from { opacity: 0; } to { opacity: 1; } }

/* 洗牌鎖定 */
.scene.is-shuffling .stage { pointer-events: none; }
.scene.is-shuffling .hands .tile__face { animation: shuffle-flip 0.5s ease; }
@keyframes shuffle-flip {
  0% { transform: translateZ(var(--td)) rotateY(0); }
  50% { transform: translateZ(calc(var(--td) + 12px)) rotateY(180deg); }
  100% { transform: translateZ(var(--td)) rotateY(0); }
}

/* ============================ 響應式 ============================ */
@media (max-width: 1200px) {
  :root { --table: 640px; --tw: 36px; --th: 49px; }
  .stage { perspective: 1400px; }
}
@media (max-width: 900px) {
  :root { --table: 540px; --tw: 32px; --th: 44px; --td: 8px; }
  .scene.cam-game { --cam-rx: 46deg; }
  .brand__title { font-size: 18px; }
  .seat { min-width: 120px; padding: 7px 10px; }
  .seat__avatar { width: 34px; height: 34px; font-size: 14px; }
}
@media (max-width: 640px) {
  /* 保留桌面比例，改以整體縮放讓完整麻將桌塞進畫面（避免水平捲軸） */
  :root { --table: 520px; --tw: 30px; --th: 41px; --td: 8px; --tr: 5px; }
  .stage { perspective: 1100px; perspective-origin: 50% 44%; }
  .scene.cam-game  { --cam-rx: 44deg; --cam-scale: 0.60; --cam-ty: 0px; }
  .scene.cam-top   { --cam-rx: 22deg; --cam-scale: 0.55; --cam-ty: -6px; }
  .scene.cam-close { --cam-rx: 48deg; --cam-scale: 0.9;  --cam-ty: 26px; }

  .brand__sub { display: none; }
  .brand__title { font-size: 16px; letter-spacing: 0.16em; }
  .hud-top { padding: 12px 12px; }
  .hud-bottom { flex-direction: column; gap: 8px; align-items: stretch; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .controls { justify-content: center; flex-wrap: wrap; }

  /* 對手資訊簡化：三家收到頂端一列，本地玩家置於左下 */
  .seat { min-width: 0; padding: 5px 9px; gap: 7px; border-radius: 11px; }
  .seat__avatar { width: 27px; height: 27px; font-size: 12px; }
  .seat__score, .seat__turn { display: none; }
  .seat--top   { top: 56px; left: 50%; transform: translateX(-50%); }
  .seat--left  { top: 56px; left: 8px; transform: none; }
  .seat--right { top: 56px; right: 8px; left: auto; transform: none; }
  .seat--local { top: auto; bottom: 132px; left: 8px; transform: none; }

  /* 頂端按鈕收成圖示，避免與右家面板重疊 */
  .chip__label { display: none; }
  .chip { padding: 7px 9px; }

  /* 手機降低裝飾負擔 */
  .bg__particles { display: none; }
  .bg__lattice { opacity: 0.25; }
  .bg__spot { filter: blur(50px); }
  .btn { padding: 12px 14px; font-size: 13px; }
}

@media (max-width: 400px) {
  .scene.cam-game  { --cam-scale: 0.52; }
  .scene.cam-top   { --cam-scale: 0.48; }
  .scene.cam-close { --cam-scale: 0.78; }
  .seat__name { font-size: 12px; }
}

/* 觸控裝置：不依賴 hover */
@media (hover: none) {
  .hand--local .tile:hover .tile__face { transform: translateZ(var(--td)); }
}

/* ============================ 減少動畫偏好 ============================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.12s !important;
  }
  .intro-veil { display: none; }
  .scene.is-intro .table-tilt,
  .scene.is-intro .walls,
  .scene.is-intro .rivers,
  .scene.is-intro .device,
  .scene.is-intro .melds,
  .scene.is-intro .flowers,
  .scene.is-intro .hands,
  .scene.is-intro .seats { animation: none; }
  .bg__particles { display: none; }
  .device__leds i { animation: none; opacity: 0.7; }
  .table-tilt { transition: transform 0.15s ease; }
}
