/* ============================================================
   透明麻雀 — 俯瞰3D卓UI
   鋼青の羅紗・漆枠・ガラス牌
   ============================================================ */

:root {
  --wood: #241109;
  --wood-2: #3a1d0e;
  --felt: #34557f;
  --felt-deep: #1f3a5c;
  --panel: #141b2b;
  --panel-edge: #3d4a66;
  --gold: #c9a35a;
  --gold-bright: #eccf92;
  --teal: #43d9c8;
  --ink: #e9e6dd;
  --ink-dim: #93a0b5;
  --accent-red: #c0392b;
  --back-orange: #e79a2e;
  --back-orange-2: #c9761563;
  --glass-edge: rgba(200, 230, 255, 0.65);

  --plane: 138cqmin;          /* 卓の一辺 */
  --guide-inset: 21cqmin;     /* 補助線枠の内側マージン（Figmaの黒線に一致）。副露もこれに沿う */
  --guide-far: 117cqmin;      /* = plane - guide-inset（枠の右辺・下辺の位置） */
  --cp: 30cqmin;              /* 中央パネルの一辺 */
  /* 牌の基準寸法。2026-08-07 に**全体を10%縮小**した（副露が手牌に被るため）。
     元値は river 3.7 / opp 5.8 / p2 5.6 / my 7.5・6cqw / dora 4.76 */
  --tw-river: 3.33cqmin;      /* 捨て牌の幅（4行目が透明牌情報に届かないよう縮小） */
  --trh: calc(var(--tw-river) * 1.39 + 3px);
  --rw: calc(var(--tw-river) + 3px);
  --roff: calc(var(--cp) / 2 + var(--trh) * 1.5 + 1.8cqmin);
  /* 川の内側の端（中央パネルのすぐ外）。ここを固定して外側へ行を伸ばす */
  --rinner: calc(var(--cp) / 2 + 1.8cqmin);
  --tw-opp: 5.22cqmin;        /* 他家の手牌（左右） */
  /* 対面の手牌1枚。立ち牌(#hand3d-p2)と読み取りストリップ(#read-p2)が
     1牌ずつ縦に対応する必要があるので、**必ず同じ値**を使う。
     以前ここが4か所ベタ書きで、片方だけ縮めて対応がずれた */
  --tw-p2: 5.04cqmin;
  /* 自分の手牌：Figma node186-93 実測（河の牌を基準に換算・射影込みで手牌1枚≒7.5cqmin） */
  /* 自分の手牌だけ10%大きくして読みやすくする（ユーザー指示 2026-08-09）。
     手牌は下端揃えなので、大きくすると**上へ伸びる**。そのぶん自分のアイコンを
     上げないと牌に被る（--my-grow がその差分。牌の高さ = 幅×1.39 の10%ぶん）。
     長考タイムバーは #myzone の下端固定フレックス列に入っているので自動で上がる */
  --tw-my: clamp(47.52px, min(7.425cqmin, 5.94cqw), 110.88px);
  --my-grow: calc(var(--tw-my) * .1264);   /* = 新しい牌の高さ × (0.1/1.1) */
  --tw-dora: clamp(30.6px, 4.28cqmin, 54.9px);   /* ドラ表示牌を15%小さく */
  /* 牌の角丸。牌画像の実際の角丸（横10.2% / 縦6.9%）に合わせてある。
     これより丸くすると、画像も背景も無い四隅ができて卓が透けて見える。
     画像側は blender/render_lib.py の bev.width で決まる */
  --tile-r: 10.2% / 6.9%;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

/* タッチ端末：ダブルタップズーム・長押し選択を無効化。
   touch-action は「タップした要素からスクロール枠までの祖先」で解決されるので、
   html にも付けておく（body だけだと途中に別の枠があると効かないことがある）。
   ただし **Safari はこれだけでは拡大を止めない**。実際の防止は
   js/client/lobby.js の blockDoubleTapZoom() が行う。 */
html { touch-action: manipulation; }
body {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }

/* 他家の副露（チーポン情報）パネルは廃止（全サイズで非表示）。
   副露は卓上の各家の位置に表示されるためパネルは不要。 */
#melds-panel { display: none !important; }

/* 右側のチャット/スタンプ欄は **PC専用**（ユーザー判断 2026-08-08）。
   条件はこのファイル共通の「小画面」＝ `max-width:1138px` または `max-height:640px`。
   スマホ・横持ちスマホ・小さいウィンドウでは丸ごと隠す。
   ※後方のベース定義(display:flex)に同一詳細度で負けないよう !important */
@media (max-width: 1138px), (max-height: 640px) {
  #chat-panel, #stamp-toggle { display: none !important; }
}

/* タブレット〜小さめ画面（iPad 1024など）：卓に対して大きいHUDを縮小。
   ドラ(左上)が対面の手牌に重なるのを防ぎ、理/和/鳴/切も小さくする。
   ※スマホ用のさらに強い縮小はファイル末尾の @media で上書きされる。 */
@media (max-width: 1200px) {
  #topleft { transform: scale(.78); transform-origin: top left; }
  /* #auto-panel の縮小は基準ルール(#auto-panel)より後ろで指定しないと
     ソース順で打ち消されるため、下部（.auto-btn 定義の後）にまとめて置く。 */
}

body {
  font-family: "Zen Kaku Gothic New", sans-serif;
  color: var(--ink);
  background: #000; /* レターボックスの黒帯 */
  overflow: hidden;
  user-select: none;
}

/* ============================================================
   レターボックス枠。画面を一定比率(16:9)に固定し、余白は黒帯に。
   内部の cqmin/cqw/cqh はこの #app を基準に解決される（＝どの端末比率でも
   16:9 と同じ配置になり、名札と透明牌情報の被りが起きない）。
   container-type:size により内部の position:fixed もこの枠が基準になる。
   ============================================================ */
#app {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* 比率は縦向きでも常に 16:9 〜 2.2:1 の範囲に収める。
     - 高さ側(9/16)で「16:9より縦長にはしない」→ 縦長の窓・iPadの4:3は上下が黒帯
     - 幅側(2.2)で「2.2:1より横長にはしない」→ スマホ横持ち(19.5:9≒2.17)は画面を使い切る
     以前は縦向きだけ全面(比率固定なし)にしていたが、cq単位のレイアウトは
     16:9前提のため崩れていた。縦長でも16:9レターボックスに統一する */
  width: min(100vw, calc(100vh * 22 / 10));
  height: min(100vh, calc(100vw * 9 / 16));
  /* **スマホは dvh を使う。** `vh` は「URLバーが引っ込んだ状態」の高さなので、
     URLバーが出ているスマホでは #app が実際の表示領域より背が高くなり、
     上下が URLバー／ナビゲーションバーの下に潜り込む。
     実際に **右上の3ボタンと対面の手牌が上で切れ、自分の手牌が下で切れて**いた
     （ユーザー報告 2026-08-09。だから全画面にしないと遊べない状態だった）。
     dvh は「いま見えている高さ」なので、全画面でなくても全部入る。
     dvh を知らない古いブラウザは上の vh 版が残るだけで壊れない */
  width: min(100dvw, calc(100dvh * 22 / 10));
  height: min(100dvh, calc(100dvw * 9 / 16));
  container-type: size;
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 90% at 50% 38%, transparent 55%, rgba(0,0,0,.55) 100%),
    linear-gradient(155deg, var(--wood-2) 0%, var(--wood) 45%, #120803 100%);
}

/* ============================================================
   俯瞰3Dの卓
   ============================================================ */

#stage {
  position: fixed;
  inset: 0;
  /* **カメラ距離は画面に合わせて伸縮させること（px固定にしない）。**
     卓・牌・座標はすべて cqmin なので画面が変われば一様に拡大縮小するが、
     perspective だけ px 固定だと「シーンだけ大きくなってカメラは同じ位置」になり、
     **画面サイズごとに卓を見る角度が変わる**。牌の前面が何px見えるかの実測:
       #app 827×376 → 2.6px ／ 1190×663 → 7.8px ／ 1920×1080 → 19.5px
     これが「iPadだけ手牌が薄っぺらい」の正体。同じCSS・同じ瞬間のPCとiPadの
     画面を並べて確定した（2026-08-09。PCは牌が分厚く、iPadは薄い）。
     一度直して「変わらない」と判断し戻したが、その判断が誤りだった。

     **値は js/ui.js の fitCamera() が実測して入れる。** ここに cqmin で書いては
     いけない: #stage は position:fixed で、`container-type:size` が fixed の
     包含ブロックになるかはブラウザで挙動が割れる。解決できないと宣言ごと捨てられて
     下の 2600px に落ちるので、**PCだけ新しい値・iPadは古い値**という一番たちの悪い
     食い違いになる（実際にこれで何度も判断を誤った 2026-08-09）。
     この 2600px は JS が動かなかったときの保険。 */
  perspective: 2600px;
  perspective-origin: 50% 32%;
  /* **ここに overflow を付けないこと。**
     perspective を持つ要素に overflow!=visible が付くと、Safari は配下の
     preserve-3d をまとめて平面化する（Chrome は平気なので気づけない）。
     はみ出しは #app 側の overflow:hidden が同じ矩形で切るので、ここでは不要。 */
  /* 卓へカメラを一段寄せ、左右の遊び（卓と画面端の帯）を詰める。
     一様ズームなので卓内部の座標・キャリブレーション（cqmin基準）は一切変わらない。
     origin は #plane の中心(top:42%)に合わせ、卓の見かけ位置を保つ */
  transform: scale(var(--stage-zoom, 1.07));
  transform-origin: 50% 42%;
}

#plane {
  position: absolute;
  left: 50%;
  top: 42%;
  width: var(--plane);
  height: var(--plane);
  transform: translate(-50%, -50%) rotateX(48deg);
  transform-style: preserve-3d;
  border-radius: 3cqmin;
  background:
    linear-gradient(115deg, transparent 42%, rgba(255,255,255,.045) 46%, transparent 50%, rgba(255,255,255,.03) 56%, transparent 62%),
    radial-gradient(circle at 50% 42%, #40628e 0%, var(--felt) 45%, var(--felt-deep) 100%);
  box-shadow:
    0 0 0 1.6cqmin #2c1710,
    0 0 0 2cqmin #4a2a15,
    0 0 9cqmin rgba(0,0,0,.8),
    inset 0 0 18cqmin rgba(0,0,0,.4);
}

/* 卓面の飾り線 */
#plane::after {
  content: "";
  position: absolute;
  inset: 17%;
  border: 1px solid rgba(255,255,255,.09);
  transform: rotate(45deg);
  pointer-events: none;
}

/* ---------------- 中央パネル ---------------- */

#center-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--cp);
  height: var(--cp);
  transform: translate(-50%, -50%);
  border-radius: 8%;
  background:
    linear-gradient(160deg, #2b3550 0%, var(--panel) 55%, #0c111d 100%);
  border: 2px solid var(--panel-edge);
  box-shadow:
    inset 0 0 3cqmin rgba(0,0,0,.8),
    0 .5cqmin 2cqmin rgba(0,0,0,.55);
}
#center-panel::before {
  content: "";
  position: absolute;
  inset: 5%;
  border: 1px solid rgba(201,163,90,.3);
  border-radius: 8%;
  pointer-events: none;
}

#box-hole {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 52%;
  height: 52%;
  border-radius: 12%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .4cqmin;
  background: radial-gradient(circle at 40% 30%, #1a2438, #0a0f1a 75%);
  border: 1px solid rgba(67,217,200,.35);
}
#box-hole.pulse { animation: boxPulse .5s ease; }
@keyframes boxPulse {
  0% { box-shadow: 0 0 0 0 rgba(67,217,200,.55); }
  100% { box-shadow: 0 0 0 2.6cqmin rgba(67,217,200,0); }
}

/* 局数・残り牌数は卓の中心にある一番よく見る情報なので大きく取る。
   入れ物の #box-hole は --cp(30cqmin) の52% ＝ 15.6cqmin 角。
   4.2 + 3.2 + 1.8 ＋ gap 0.8 ＝ 10cqmin で収まる。
   スマホは cqmin が 3.75px しかないので px 下限も置く */
#kyoku-info {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  /* --kf は字数に応じた縮小率（renderHub が入れる）。
     「東二局1本場」のように本場が付くと6文字になり、卓中央の穴(#box-hole)の幅
     （基準サイズで約4文字ぶん）に収まらず**全サイズで2行に折り返していた**
     （ユーザー指摘 2026-08-09）。字数で詰めて必ず1行に収める */
  font-size: calc(clamp(15px, 4.2cqmin, 52px) * var(--kf, 1));
  white-space: nowrap;
  line-height: 1.1;
  color: var(--teal);
  text-shadow: 0 0 10px rgba(67,217,200,.55);
}
#box-count {
  font-size: clamp(12px, 3.2cqmin, 40px);
  line-height: 1.1;
  font-weight: 700;
  color: var(--teal);
  text-shadow: 0 0 8px rgba(67,217,200,.45);
}
#pot-info {
  font-size: clamp(9px, 1.8cqmin, 22px);
  color: var(--gold-bright);
  min-height: 1.5cqmin;
}

.cscore {
  position: absolute;
  font-size: 2.5cqmin;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--gold-bright);
  text-shadow: 0 0 6px rgba(0,0,0,.95), 0 0 14px rgba(0,0,0,.7);
}
/* リーチ棒を外側（各プレイヤー側）に置けるよう、点数はやや内側（端から17%）に寄せる。
   4席とも「中心点を置いてから回転」で統一（リーチ棒は端から7%） */
#score-p0 { left: 50%; top: 83%; transform: translate(-50%, -50%); }
#score-p1 { left: 83%; top: 50%; transform: translate(-50%, -50%) rotate(-90deg); }
#score-p2 { left: 50%; top: 17%; transform: translate(-50%, -50%) rotate(180deg); }
#score-p3 { left: 17%; top: 50%; transform: translate(-50%, -50%) rotate(90deg); }

/* リーチ棒（千点棒）。点数表示の外側＝各プレイヤーの手前に置く */
.rstick {
  position: absolute;
  width: 32%;
  height: 1.15cqmin;
  border-radius: .6cqmin;
  background: linear-gradient(180deg, #fefdf8 0%, #ece9dd 55%, #cfccbe 100%);
  box-shadow: 0 .25cqmin .6cqmin rgba(0, 0, 0, .55), inset 0 1px 1px rgba(255,255,255,.9);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}
.rstick::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: .6cqmin;
  height: .6cqmin;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #c22f24;
  box-shadow: 0 0 .3cqmin rgba(194,47,36,.8);
}
#rstick-p0 { left: 50%; top: 93%; transform: translate(-50%, -50%) scale(.7); }
#rstick-p1 { left: 93%; top: 50%; transform: translate(-50%, -50%) rotate(90deg) scale(.7); }
#rstick-p2 { left: 50%; top: 7%;  transform: translate(-50%, -50%) rotate(180deg) scale(.7); }
#rstick-p3 { left: 7%;  top: 50%; transform: translate(-50%, -50%) rotate(-90deg) scale(.7); }
#rstick-p0.on { transform: translate(-50%, -50%) scale(1); }
#rstick-p1.on { transform: translate(-50%, -50%) rotate(90deg) scale(1); }
#rstick-p2.on { transform: translate(-50%, -50%) rotate(180deg) scale(1); }
#rstick-p3.on { transform: translate(-50%, -50%) rotate(-90deg) scale(1); }
.rstick.on { opacity: 1; }

.cwind {
  position: absolute;
  width: 4.6cqmin;
  height: 4.6cqmin;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 3cqmin;
  color: #f4efe3;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
  background: linear-gradient(160deg, #323d5c, #171e30);
  border: 1px solid var(--panel-edge);
  border-radius: 14%;
}
.cwind.dealer {
  color: #fff;
  background: linear-gradient(160deg, #d84a38, #8f1f12);
  border-color: #e8907f;
  box-shadow: 0 0 1.4cqmin rgba(216,74,56,.6);
}
#cwind-p0 { bottom: 5%; left: 6%; }
#cwind-p1 { bottom: 5%; right: 6%; transform: rotate(-90deg); }
#cwind-p2 { top: 5%; right: 6%; transform: rotate(180deg); }
#cwind-p3 { top: 5%; left: 6%; transform: rotate(90deg); }

/* ---------------- 捨て牌（河） ---------------- */

.river {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(6, var(--rw));
  grid-auto-rows: var(--trh);
  gap: 2px;
  min-height: calc(var(--trh) * 3 + 4px);
}
/* 内側の端を軸(transform-origin 50% 0)にして、行は外側へだけ伸ばす（中央パネルに被らない） */
.river { transform-origin: 50% 0; }
#river-p0 { left: 50%; top: calc(50% + var(--rinner)); transform: translate(-50%, 0); }
#river-p2 { left: 50%; top: calc(50% - var(--rinner)); transform: translate(-50%, 0) rotate(180deg); }
#river-p1 { left: calc(50% + var(--rinner)); top: 50%; transform: translate(-50%, 0) rotate(-90deg); }
#river-p3 { left: calc(50% - var(--rinner)); top: 50%; transform: translate(-50%, 0) rotate(90deg); }

/* 河は卓面に寝かせた3Dボックス牌 */
.river { transform-style: preserve-3d; }
.river .tile3d { --t3w: var(--tw-river); transform: translateZ(.26em); }
.river .tile3d::after { content: ""; }
.river .tile3d.riichi-decl { transform: translateZ(.26em) rotate(90deg) scale(.92); }

/* 他家の副露・抜きドラ：河と同じ「平置きの表向き」で、本人から見て右側の
   コーナー（補助線）に詰めて置く。画面上では 対面=左上 / 下家=右上 / 上家=左下 */
.omelds {
  position: absolute;
  display: flex;
  gap: 8px;
  transform-style: preserve-3d;
  /* 手牌と同格の大きさ（雀魂準拠の視覚階層: 手牌≒副露 > ドラ > 河）。
     牌を大きくしても副露は枠(inset34cqmin)の外側の帯で「卓の内側」へ伸びるため
     手牌・河とは被らない（アンカーは外側の辺に固定）。
     .called-slot も同じ値を参照するので、牌だけでなく .omelds に定義して継承させる
     （tile3d だけに定義するとスロットで var(--t3w) が未定義になり幅確保が失敗する） */
  --t3w: calc(var(--tw-opp) * .92);
}
/* 4組フル副露（カン込み最悪16枚）だけは行が伸びて隣家の副露コーナーに届くため、
   その行だけ自動でひと回り縮める。3組以下は手牌同格サイズのまま */
.omelds:has(.omeld:nth-child(4)) { --t3w: calc(var(--tw-opp) * .75); }
.omelds .omeld { display: flex; gap: 2px; transform-style: preserve-3d; }
.omelds .tile3d { transform: translateZ(.26em) rotate(180deg); }
/* 補助線枠（#plane内 inset:34cqmin）の各辺コーナーに副露を貼り付ける。
   枠のコーナー座標(#plane基準): 左上(34cqmin,34cqmin) 右上(104cqmin,34cqmin) 左下(34cqmin,104cqmin)。
   本人から見て右側のコーナーを起点に、辺に沿って中央方向へ流す。 */
/* 対面（上辺）：左端コーナー(x=17cqmin)から右へ左詰め。牌180°で河p2と同じ向き。
   帯の高さは「読み取りストリップの内側・河(最大3段固定)の外側」の空き帯に置く。
   牌を手牌同格に大きくしたら旧位置(18.6)で読み取りストリップと交差したため内側へ。
   高さ方向の余裕が薄いので対面だけ .85（手牌5.6cqminの88%でほぼ同格に見える） */
#omelds-p2 { left: 17cqmin; top: 20.6cqmin; transform-origin: 0 0; --t3w: calc(var(--tw-opp) * .85); }
#omelds-p2:has(.omeld:nth-child(4)) { --t3w: calc(var(--tw-opp) * .72); }
/* 下家（右辺）：上端(y=28cqmin)から下へ詰める。rotate(90)で牌の高さは origin から
   左（卓の内側）へ伸びる。手牌の立ち牌(列軸x=128)や河に被らない位置 */
/* 下家の副露は **上家と左右対称**（卓の手前側の縁）に置く。
   plane 座標で 180°回転の対称（`left:136 / top:21`＝卓の**奥**の隅）にすると、
   卓は遠近で奥ほど狭いので画面上では窮屈になり、席アイコンや手牌の上端と競合する。
   `top` を奥から手前へ振って上家(#omelds-p3)の画面座標に合わせ込んだ実測:
     top 55 → y −18.1〜18.4 / 60 → −14.6〜23.1 / 65 → −11〜27.9 / 70 → −7.2〜32.9
     **73 → x 54.9〜72.5, y −5〜36**（上家 x −55〜−72.5, y −4.8〜36.2 の鏡像）
   これで卓からはみ出さない。
   left は **135**（＝上家 3 の左右対称 138−3）。126.4 だと副露が手牌の帯に
   食い込む（下記の実測表）。 */
#omelds-p1 { left: 136cqmin; top: 35cqmin; transform: rotate(90deg); transform-origin: 0 0; }
/* 上家（左辺）：下端(y=119cqmin)から上へ詰める。rotate(-90)で牌の高さは origin から
   右（卓の内側）へ伸びる。
   left は長らく 11.6 だったが、それだと**副露が手牌にめり込む**。副露の高さ帯
   （y −7〜36）での手牌＋読み札の占有は −64.2〜−49.4 で、副露は −72.8〜−54.8 だった。
   外へ振った実測（重なり / 卓外。卓外は − が内側）:
     11.6 → 4.5 / −11.1   8 → 2.4 / −7.1   6 → 2.4 / −4.9
     4 → 0〜1.0 / −2.8    **3 → 0 / −1.6〜−2.7（採用）**   2 → 0 / −0.4   0 → 0 / +2.1（はみ出す）
   1920×1080 / 1366×768 / 844×390 × 1・4副露で確認。
   top は **105**（119 ではない）。119 だと下家より下に出て左右が揃わない。
   下家(1副露)の画面上の箱 x 64.5〜79.8 / y −5.9〜21.5 の鏡像に合わせ込んだ実測:
     6/100 → −74.8〜−60.3 / −9.8〜16.7   6/104 → −75.9〜−61.0 / −6.8〜20.4
     **3/105 → −79.8〜−64.5 / −6.1〜21.4（ほぼ一致）**
   ※ p1 と p3 は回転の符号が逆なので、鳴くほど p1 は下＋外、p3 は上＋内へ伸びる。
     1副露の位置は一致するが、4副露では左右で伸びる向きが異なる（衝突は無い）。 */
#omelds-p3 { left: 1.9cqmin; top: 117cqmin; transform: rotate(-90deg); transform-origin: 0 0; }

/* ---------------- 他家の手牌（卓上に立てた3Dボックス牌） ---------------- */

.hand3d {
  position: absolute;
  transform-style: preserve-3d;
}
.hand3d .stand {
  transform-origin: center bottom;
  transform: rotateX(-90deg);
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.34, 1.2, .5, 1);
}
/* 和了：立牌を手前に倒して卓面に face-up で寝かせる（牌を倒して公開） */
.hand3d.revealed .stand { transform: rotateX(0deg); }
/* 公開手牌の行の回転は JS 側（ui.js の LAID_ROW_TF / fitLaidRow）がインラインで当てる。
   枠 #hand3d-pN の回転を打ち消して画面上で横一列にし、はみ出す分は縮小・移動で収める。 */
/* 対面：奥側。面は対面側を向き、こちらからは背が見える */
#hand3d-p2 {
  left: 50%;
  top: 17cqmin;
  transform: translateX(-50%) rotate(180deg);
}
/* 対面は遠くて小さく見えるぶん、読みやすさ優先で少しだけ大きく */
#hand3d-p2 .tile3d { --t3w: var(--tw-p2); }
/* 右家・左家：側辺に沿って立てる */
/* 側家は外側へ寄せる（53→59cqmin）。①対面の副露が伸びるコーナーを空ける
   ②側家の手牌・副露と卓の縁の間の余白を詰める（かねての要望） */
#hand3d-p1 {
  left: calc(50% + 59cqmin);
  top: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
}
#hand3d-p3 {
  left: calc(50% - 59cqmin);
  top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
}
/* 自分（手前）：対面(top:17cqmin)の反対側。回転なし＝面はこちらを向く。
   和了時だけ中身を入れて倒す（通常は空＝非表示）。牌は自分の手牌に近い大きさ */
#hand3d-p0 {
  left: 50%;
  top: 121cqmin;
  transform: translateX(-50%);
}
#hand3d-p0 .tile3d { --t3w: 5.4cqmin; }
/* 自分の手牌を卓に倒して見せている間は、下段バーの手牌・副露を隠す（場所は保つ） */
body.my-hand-on-table #my-row { visibility: hidden; }

.hand { display: flex; gap: 2px; align-items: flex-end; transform-style: preserve-3d; position: relative; }
.hand3d .tile3d {
  --t3w: var(--tw-opp);
  /* 公開時の牌の回転を、手牌が倒れる動き(.stand と同じ .55s)に合わせて動かす。
     transition が無いと回転だけ即座に効いて、倒れ切るまでの間「立ったまま横向き」＝
     鳴き牌のような見た目で止まって見える */
  transition: transform .55s cubic-bezier(.34, 1.2, .5, 1);
}
/* 他家の手牌・読み取りストリップは13枚ぶんの「固定幅」。鳴きで手牌が減っても各家の
   左端が動かず、ツモで増えても幅は変わらない（＝中央基準のまま広がらない）。ツモ牌は
   固定幅からはみ出して手牌の右端に隣接して並ぶ。下家/上家はコンテナ回転で局所座標が
   反転するため row-reverse にして「各家から見て左詰め・右端にツモ牌」を実現する。 */
#hand-p2, #read-p2 { width: calc(var(--tw-p2) * 13 + 24px); }
#hand-p1, #hand-p3, #read-p1, #read-p3 { width: calc(var(--tw-opp) * 13 + 24px); flex-direction: row-reverse; }
.read-strip .tile, .read-strip .read-ph { flex: none; }

/* 三人麻雀：対面の枠は使わない（上家は左＝p3の位置に表示） */
body.sanma #seat-p2,
body.sanma #hand3d-p2,
body.sanma #omelds-p2,
body.sanma #river-p2,
body.sanma #cwind-p2,
body.sanma #score-p2,
body.sanma #rstick-p2 { display: none; }

/* 抜きドラ（北）は副露と少し離して表示 */
#my-melds .meld.nuki { margin-left: 10px; }

/* 赤ドラ（赤5）は柄そのものが赤い専用画像（*_aka.png）を使う。
   CSSフィルタで牌ごと染める方式は、透明牌だと染める実体が無く濁るだけだった。

   加えて、3秒に1回ガラスに光が走る。透明牌は卓に溶けるので、
   赤い縁だけでなく動きでも赤ドラの在り処が分かるようにする */
@keyframes akaShine {
  0%,  46% { transform: translateX(-160%) skewX(-18deg); opacity: 0; }
  52%      { opacity: 1; }
  92%      { transform: translateX(240%) skewX(-18deg); opacity: 1; }
  100%     { transform: translateX(240%) skewX(-18deg); opacity: 0; }
}
.tile3d.red .tf-front, .tile.red { overflow: hidden; }
.tile3d.red .tf-front::after,
.tile.red::after {
  content: "";
  position: absolute;
  top: -25%;
  left: 0;
  width: 38%;
  height: 150%;
  background: linear-gradient(90deg,
    rgba(255,255,255,0) 0%, rgba(255,255,255,.85) 45%,
    rgba(255,235,235,.95) 55%, rgba(255,255,255,0) 100%);
  animation: akaShine 1.5s ease-in-out infinite;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  .tile3d.red .tf-front::after, .tile.red::after { animation: none; opacity: 0; }
}
/* 右家・左家はコンテナの rotate(±90deg) の向きの都合で牌面が卓中央側を向いてしまうため、
   1牌ずつ水平に反転して対面と同じ「面は持ち主側・中央からは背面」にする */
#hand3d-p1 .tile3d, #hand3d-p3 .tile3d { transform: rotateY(180deg); }

/* 卓に倒して公開した牌（和了リビール／流局のテンパイ公開）
   - translateZ(.26em)：倒すと牌の中心が卓面に一致してしまい厚みの下半分がめり込むので、
     厚み(.52em)の半分だけ持ち上げて卓の上に載せる
   - 左右家は上の rotateY(180deg) で裏返してあるが、倒すときは面を上に向けたいので打ち消す
     （これが無いと下家・上家の和了だけ裏が見えて「隠している」ように見える）
   #hand3d-pN .tile3d(ID+クラス) に勝つ必要があるのでセレクタにIDを含める */
#hand3d-p1.revealed .tile3d,
#hand3d-p2.revealed .tile3d,
#hand3d-p3.revealed .tile3d { transform: translateZ(.26em); }

/* 公開時の向きは JS 側（ui.js の LAID_ROW_TF / fitLaidRow）が行ごと回して決める。
   牌を1枚ずつ回すと、文字は正立しても行は縦のままなので
   「縦に並んだ横向きの牌」＝鳴き牌の並びに見えてしまうため、行単位で回している。 */

/* ---------------- 透明牌の読み取りストリップ ---------------- */

/* 立ち牌と同じコンテナ内で同じ回転・同じ並びを共有するので、
   1牌ずつの位置が構造的に一致する */
.read-strip {
  position: absolute;
  left: 0;
  display: flex;
  gap: 2px;
  transform: translateZ(.2cqmin);
}
/* ここは「卓に映った他家の透明牌」＝読み取るための情報表示。牌そのものではないので
   質感を一切持たせない（地の白は .tile.flat 側で付く）。象牙色やガラスの地だと
   卓のライトブルーに対してコントラストが足りない。
   **2Dのまま置くこと。** 一度3D(tileEl3d)にしたが、情報表示のほうが実際の手牌より
   牌らしくなり、主従が逆に見えた（ユーザー判断 2026-08-09）。立体感は
   立っている手牌（.hand3d）側で出す。 */
.read-strip .tile {
  width: var(--tw-opp);
  border-bottom: none;
  box-shadow: 0 .45cqmin .6cqmin rgba(0, 0, 0, .45);
  opacity: 1;
}
#read-p1 .tile, #read-p3 .tile { transform: rotate(180deg); }
#read-p2 .tile { width: var(--tw-p2); }
.read-ph, .read-sp {
  width: var(--tw-opp);
  aspect-ratio: 36 / 50;
  border-radius: var(--tile-r);
  flex: none;
}
.read-ph { background: rgba(0, 0, 0, .16); }
.read-sp { visibility: hidden; }
#read-p2 .read-ph, #read-p2 .read-sp { width: var(--tw-p2); }
/* 左右の読み取り牌は上下反転で表示 */

/* 手牌の手前（中央側）に置く。p2 は rotate(180deg) で軸が反転するので bottom 側。
   立ち牌の接地線（ローカル下端）から左右と同じ 1.6cqmin の間隔で密着させる */
#read-p1, #read-p3 { top: calc(100% + 1.6cqmin); }
/* 対面の読み取りは常に手牌のすぐ下（左右家と同じ密着）。
   行の幅を13枚ぶんに固定し、鳴いて門前が減ったら右（本人から見て左＝実物の並び）へ
   詰めることで、左コーナーの副露と横並びで共存できる（帯の上下移動はしない） */
#read-p2 { bottom: 1.6cqmin; }
/* コンテナが rotate(180deg) なのでローカル左詰め＝画面では右詰めになる */
#hand-p2, #read-p2 { min-width: calc(13 * var(--tw-p2) + 12 * 2px); justify-content: flex-start; }

/* ============================================================
   3Dボックス牌（6面体）
   font-size = 牌の幅。各面は em で寸法指定（奥行き .52em）
   ============================================================ */

.tile3d {
  position: relative;
  width: var(--t3w, var(--tw-opp));
  height: calc(var(--t3w, var(--tw-opp)) * 1.39);
  font-size: var(--t3w, var(--tw-opp));
  transform-style: preserve-3d;
  flex: none;
}

.tile3d .tf {
  position: absolute;
  left: 50%;
  top: 50%;
  backface-visibility: hidden;
  border-radius: var(--tile-r);
}
.tile3d .tf img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.tf-front { width: 1em; height: 1.39em; transform: translate(-50%, -50%) translateZ(.26em); }
.tf-back  { width: 1em; height: 1.39em; transform: translate(-50%, -50%) rotateY(180deg) translateZ(.26em); }
.tf-left  { width: .52em; height: 1.39em; transform: translate(-50%, -50%) rotateY(-90deg) translateZ(.5em); }
.tf-right { width: .52em; height: 1.39em; transform: translate(-50%, -50%) rotateY(90deg) translateZ(.5em); }
.tf-top   { width: 1em; height: .52em; transform: translate(-50%, -50%) rotateX(90deg) translateZ(.695em); }
.tf-bot   { width: 1em; height: .52em; transform: translate(-50%, -50%) rotateX(-90deg) translateZ(.695em); }

/* 側面の4枚は牌の「厚み」を作る帯で、輪郭を決めるのは前面と背面だけ。
   ここまで丸めると前面の角丸とのあいだに隙間ができ、牌の角が欠けて
   卓が透けて見える（--tile-r を大きくするほど目立つ）。
   セレクタは .tile3d .tf と詳細度を揃えること */
.tile3d .tf-left,
.tile3d .tf-right,
.tile3d .tf-top,
.tile3d .tf-bot { border-radius: 0; }

/* 通常牌：白い前面＋オレンジの背。側面は前半分が白、後ろ半分がオレンジ */
.tf-front { background: linear-gradient(172deg, #fdfbf5 0%, #efe9da 80%, #e3d9c4 100%); }

/* 質感なしのマットな牌（flat_*.png）。象牙のテクスチャとツヤは柄と干渉して
   読みにくいので、面が見えている不透明牌はすべてこれ（透明牌はガラスのまま）。
   ただし真っ白＋直角だと「牌」に見えないので、面取り（丸まった縁の陰影）を
   ::before で敷いて牌らしい厚み・丸みを出す。柄は img が上に乗るので読みやすさは不変。 */
.tile3d.flat .tf-front { background: #fff; }
.tile3d.flat .tf-left  { background: linear-gradient(270deg, #fff 0%, #f3f5f7 48%, #e08f1d 52%, #c47410 100%); }
.tile3d.flat .tf-right { background: linear-gradient(90deg,  #fff 0%, #f3f5f7 48%, #e08f1d 52%, #c47410 100%); }
.tile3d.flat .tf-top   { background: linear-gradient(0deg,   #fff 0%, #f5f7f9 48%, #e79a2e 52%, #cf7c12 100%); }
.tile3d.flat .tf-bot   { background: linear-gradient(180deg, #eef1f4 0%, #e4e8ec 48%, #d0820f 52%, #b56a08 100%); }
.tile3d.flat .tf-front::before,
.tile.flat::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  /* 面取り：上左に光、下右に陰、外周に薄い縁。牌のふちが丸くすぼまって見える */
  box-shadow:
    inset 0 0 0 1px rgba(70, 58, 40, .07),
    inset 3px 3px 5px -1px rgba(255, 255, 255, .9),
    inset -3px -5px 8px -2px rgba(74, 60, 40, .20);
}
.tf-back {
  background: linear-gradient(172deg, var(--back-orange) 0%, #d9820f 62%, #b56a08 100%);
}
.tf-left  { background: linear-gradient(270deg, #f2e9d6 0%, #e6dbc2 48%, #e08f1d 52%, #c47410 100%); }
.tf-right { background: linear-gradient(90deg, #f2e9d6 0%, #e6dbc2 48%, #e08f1d 52%, #c47410 100%); }
.tf-top   { background: linear-gradient(0deg, #f6efdd 0%, #eee3cb 48%, #e79a2e 52%, #cf7c12 100%); }
.tf-bot   { background: linear-gradient(180deg, #e9dfc8 0%, #ddd0b4 48%, #d0820f 52%, #b56a08 100%); }

/* 不透明な他家の牌：どの角度から見てもオレンジ（＝見えない牌） */
.tile3d.hidden-tile .tf-front {
  background: linear-gradient(172deg, var(--back-orange) 0%, #d9820f 62%, #b56a08 100%);
}

/* 透明牌：全面ガラス */
.tile3d.clear .tf {
  backface-visibility: visible;
  border: 1px solid var(--glass-edge);
  background: linear-gradient(160deg, rgba(180,215,245,.4) 0%, rgba(125,170,215,.22) 55%, rgba(175,215,248,.36) 100%);
}
.tile3d.clear .tf img { opacity: .72; }
/* 前面は clear_*.png（白い半透明の板＋柄）そのもの。CSS側でガラス地を
   重ねると柄と干渉して読みにくくなるので何も足さない */
.tile3d.clear .tf-front {
  background: none;
  border-color: transparent;
}
.tile3d.clear .tf-front img { opacity: 1; }
/* 背面はすりガラスのアクリル調。牌の情報は載せない（読み取りはストリップで）。
   前面の画像は本当に透けるので、背面が濃いと卓が見えない＝薄めに張る */
.tile3d.clear .tf-back {
  background: linear-gradient(160deg, rgba(214,235,252,.34) 0%, rgba(165,200,230,.26) 55%, rgba(206,232,252,.32) 100%);
  box-shadow: inset 0 0 .1em rgba(255,255,255,.45);
}
.tile3d.clear .tf-back::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg, transparent 32%, rgba(255,255,255,.35) 46%, transparent 62%);
}

/* 場に見えているドラ牌（表示牌の次の牌）は金色にゆっくり光る。
   ホバーの kind-glow や鳴きの call-target はセレクタが強いのでそちらが優先される */
@keyframes doraTileGlow {
  from { box-shadow: 0 0 .35cqmin rgba(255, 208, 100, .5); }
  to   { box-shadow: 0 0 1.3cqmin rgba(255, 208, 100, .95); }
}
.tile3d.dora-glow .tf {
  animation: doraTileGlow 1.6s ease-in-out infinite alternate;
}
.tile3d.dora-glow .tf-front { outline: 1px solid rgba(255, 216, 130, .85); outline-offset: -1px; }
.tile.dora-glow {
  animation: doraTileGlow 1.6s ease-in-out infinite alternate;
}

/* 手牌ホバー中：同種の捨て牌が浮き上がって青緑に強く光る */
.river .tile3d.kind-glow {
  transform: translateZ(.9em);
  transition: transform .12s ease;
}
.river .tile3d.kind-glow .tf {
  animation: riverGlow .6s ease-in-out infinite alternate;
}
.river .tile3d.kind-glow .tf-front {
  outline: 2px solid rgba(140, 255, 235, .95);
  outline-offset: -1px;
}
@keyframes riverGlow {
  from { filter: brightness(1.4);  box-shadow: 0 0 .8cqmin rgba(90, 245, 220, .8); }
  to   { filter: brightness(1.85); box-shadow: 0 0 2.8cqmin rgba(90, 245, 220, 1); }
}

/* 鳴き確認中：鳴ける牌（相手が今切った牌）を赤く光らせる */
.river .tile3d.call-target .tf {
  animation: callGlow .7s ease-in-out infinite alternate;
}
@keyframes callGlow {
  from {
    filter: sepia(.7) saturate(4) hue-rotate(-38deg) brightness(1.15);
    box-shadow: 0 0 .5cqmin rgba(255, 76, 56, .65);
  }
  to {
    filter: sepia(.7) saturate(4) hue-rotate(-38deg) brightness(1.55);
    box-shadow: 0 0 2cqmin rgba(255, 76, 56, 1);
  }
}

/* 河に落ちる影 */
.river .tile3d::after {
  content: "";
  position: absolute;
  inset: -6% -10%;
  border-radius: 14%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.42) 40%, transparent 75%);
  transform: translateZ(-.27em);
  transition: transform .12s ease;
}
/* ハイライトで浮き上がった牌：影は卓面に残して立体感を出す
   （牌が +.9em 浮くぶん、影を -.9em 押し戻す） */
.river .tile3d.kind-glow::after {
  inset: -16% -22%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .6) 30%, transparent 70%);
  transform: translateZ(-1.17em);
}

/* ============================================================
   牌
   ============================================================ */

.tile {
  position: relative;
  width: var(--tw-opp);
  aspect-ratio: 36 / 50;
  border-radius: var(--tile-r);
  background: linear-gradient(172deg, #fdfbf5 0%, #efe9da 78%, #d9cfba 100%);
  border-bottom: solid .45cqmin #c3b79c;
  box-shadow: 0 .4cqmin .7cqmin rgba(0, 0, 0, .45);
  overflow: hidden;
  flex: none;
}
.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* 質感なしのマットな牌面（2D）。柄だけの flat_*.png を白地に載せる */
.tile.flat { background: #fff; }

/* 透明牌（2D表示）。clear_*.png がガラスの見た目を全部持っているので、
   CSS では影だけ足して枠やツヤは重ねない */
.tile.clear {
  background: transparent;
  border: none;
  box-shadow: 0 .4cqmin .8cqmin rgba(0,0,0,.4);
}
.tile.clear img { opacity: 1; }

/* 不透明牌の裏（オレンジの背） */
.tile.back {
  background:
    linear-gradient(172deg, var(--back-orange) 0%, #d9820f 62%, #b56a08 100%);
  border: 1px solid rgba(255,220,160,.35);
  border-bottom: solid .45cqmin #f7ecd6;
}
.tile.back::after {
  content: "";
  position: absolute;
  inset: 12% 14%;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 12%;
}

.tile.deal-in { animation: dealIn .28s cubic-bezier(.2, .7, .3, 1) backwards; }
@keyframes dealIn {
  from { opacity: 0; transform: translateY(-8px) scale(.7); }
}

/* ============================================================
   画面固定UI
   ============================================================ */

/* ---------------- 左上：ドラ・モード・捨て牌 ---------------- */

#topleft {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
}

/* 対局画面のパネルは紺地＋金の細枠（UI_SPEC §10）。
   開始前フローの中華風（赤地＋金二重線）は卓上で情報がうるさいので使わない */
#dora-panel {
  display: flex;
  flex-direction: column;   /* 上段=ドラ表示 / 下段=点棒カウンター（雀魂式） */
  padding: 9px;
  gap: 6px;
  background: linear-gradient(160deg, #2a3147, var(--panel));
  border: 1px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}

/* 雀魂式の点棒カウンター：供託リーチ棒(千点棒)×N ・ 本場(百点棒)×N */
#stick-counts {
  display: flex;
  align-items: center;
  gap: .6cqmin;
  padding: 0 .4cqmin .2cqmin;
}
.stick-icon {
  width: clamp(7px, .95cqmin, 13px);
  height: clamp(20px, 2.7cqmin, 36px);
  border-radius: 3px;
  background: linear-gradient(180deg, #fdfdfa, #dfe3e8);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
  position: relative;
}
.stick-icon.s1000::after {   /* 千点棒：中央に赤丸1つ */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, #d0342c 0 22%, transparent 26%);
}
.stick-icon.s100::after {    /* 百点棒：黒い点々 */
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 18%, #333 0 12%, transparent 16%),
    radial-gradient(circle at 70% 18%, #333 0 12%, transparent 16%),
    radial-gradient(circle at 30% 42%, #333 0 12%, transparent 16%),
    radial-gradient(circle at 70% 42%, #333 0 12%, transparent 16%),
    radial-gradient(circle at 30% 66%, #333 0 12%, transparent 16%),
    radial-gradient(circle at 70% 66%, #333 0 12%, transparent 16%);
}
.stick-x {
  font-size: clamp(10px, 1.3cqmin, 16px);
  color: #cfd6e4;
}
.stick-num {
  font-family: "Shippori Mincho B1", serif;
  font-style: italic;
  font-weight: 800;
  font-size: clamp(15px, 2cqmin, 26px);
  color: #f2f5fa;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .7);
  margin-right: .8cqmin;
  min-width: 1.2ch;
}
#dora-tiles { display: flex; gap: 4px; }
#dora-tiles .dora-slot {
  width: var(--tw-dora);
  aspect-ratio: 36 / 50;
  border-radius: var(--tile-r);
  background: rgba(0,0,0,.5);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.8);
}
#dora-tiles .tile { width: var(--tw-dora); }
/* パネルの地が暗いので、半透明の透明牌をそのまま置くと柄が沈んで読めない。
   ここだけ白い台紙を敷く（卓の上と違って背後に透かすものが無い） */
#dora-tiles .tile.clear {
  background: linear-gradient(160deg, #f3f6fa, #dde5ee);
  box-shadow: 0 .4cqmin .7cqmin rgba(0, 0, 0, .45);
}

/* 左上パネルにあるのは「表示牌」（この次の牌がドラ）なので、パネル内では光らせない */
#dora-tiles .tile.dora-glow { animation: none; box-shadow: 0 .4cqmin .7cqmin rgba(0, 0, 0, .45); }

#mode-name {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .22em;
  color: var(--gold-bright);
  text-shadow: 0 0 12px rgba(201,163,90,.4), 0 2px 4px rgba(0,0,0,.8);
  padding-left: 2px;
}


/* ---------------- 右上：持ち時間 ---------------- */

#topright {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  gap: 10px;
}
/* 全画面・設定・退出。ドラ枠／理和鳴切と同じ赤地＋金二重線（UI_SPEC §10） */
.icon-btn {
  /* 理/和/鳴/切(.auto-btn)と同寸。縮小も #auto-panel と同じ段階で掛ける
     （以前は 7.6cqmin の可変＋.82 縮小だけで、小画面ほど相対的に大きくなり
       画面の右端で見切れていた） */
  width: 71px;
  height: 71px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8fb4e8;
  /* 下家の副露が卓の奥の縁まで来るとこのアイコンの下に潜る（重なりは許容する方針）。
     半透明だと牌が透けてアイコンが読めなくなるので**不透明**にする */
  background: linear-gradient(160deg, rgb(48, 60, 92), rgb(20, 27, 45));
  border: 1px solid rgba(120, 150, 210, .45);
  border-radius: 12%;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45);
  transition: all .15s ease;
}
.icon-btn svg { width: 55%; height: 55%; }
.icon-btn:hover {
  color: #c4dbff;
  border-color: rgba(160, 190, 245, .8);
  box-shadow: 0 0 12px rgba(120, 160, 230, .5);
}
.icon-btn:active { transform: scale(.96); }

/* ---------------- 設定モーダル ----------------
   ルール説明（マニュアル）画面と同じ中華風の意匠。金枠パネル panel.png を
   border-image で使い、四隅の飾りを潰さずに縦へ伸びるモーダルへ流用する。
   ※卓に常時出ている HUD（ドラ枠・理和鳴切・右上アイコン・タイムバー）は
     情報がうるさくならないよう青系のまま（UI_SPEC §10）。 */

#settings-wrap {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 8, 5, .72);
}
#settings-wrap.hidden { display: none; }
#settings {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(600px, 94cqw);
  max-height: 88cqh;
  overflow: hidden;        /* スクロールは #settings-body が持つ */
  padding: 4px 16px 12px;
  /* 中央(fill)がパネルの赤地、辺が金の二重線、角が飾り。角のスライスは 130px */
  border: 34px solid transparent;
  border-image: url("../assets/setup/panel.png") 130 fill / 34px stretch;
  border-radius: 0;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .72);
  font-family: "Shippori Mincho B1", "Yu Mincho", serif;
  color: #f2e5d1;
}
/* 見出し＋×は枠に固定、本文だけスクロール */
#settings-head { position: relative; flex: 0 0 auto; }
#settings-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 8px;
}
#settings-body::-webkit-scrollbar { width: 8px; }
#settings-body::-webkit-scrollbar-thumb { background: rgba(244, 195, 113, .5); border-radius: 5px; }
#settings-body::-webkit-scrollbar-track { background: rgba(0, 0, 0, .25); }
#settings h2 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: .35em;
  text-indent: .35em;      /* letter-spacing のぶん左に寄るのを戻す */
  text-align: center;
  color: #f4c371;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(244, 195, 113, .42);
  text-shadow: 0 2px 5px rgba(0, 0, 0, .6);
}
#settings-close {
  position: absolute;
  top: -1px;
  right: 0;
  width: 30px;
  height: 30px;
  font-size: 22px;
  line-height: 1;
  color: #e8c78f;
  background: rgba(20, 10, 6, .82);
  border: 1px solid rgba(244, 195, 113, .4);
  border-radius: 50%;
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease, background .12s ease;
}
#settings-close:hover { color: #3a1206; background: #f4c371; border-color: #ffe6b4; }

.set-section {
  margin: 16px 0 2px;
  padding: 7px 14px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .08em;
  color: #f4c371;
  background: rgba(244, 195, 113, .12);
  border-left: 5px solid #f4c371;
  border-radius: 0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
.set-note { font-size: 11px; font-weight: 400; color: rgba(232, 199, 143, .65); }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 6px;
  border-bottom: 1px solid rgba(244, 195, 113, .18);
}
.set-label { font-size: 14px; color: #f2e5d1; text-shadow: 0 1px 2px rgba(0, 0, 0, .5); }

.seg { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.seg button {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 999px;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, .35);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .12s ease;
}
.seg button:hover { color: var(--ink); }
.seg button.on {
  color: #fff;
  background: linear-gradient(180deg, #3d4d7a, #2a3550);
  border-color: rgba(140, 170, 230, .65);
  box-shadow: 0 0 8px rgba(120, 160, 230, .35);
}

/* 設定モーダル内だけ金の選択ピルにする（旧ロビーの .seg.orange には触れない） */
#settings .seg button {
  font-family: "Shippori Mincho B1", "Yu Mincho", serif;
  font-weight: 700;
  border-radius: 5px;
  color: #e8c78f;
  background: rgba(20, 10, 6, .5);
  border: 1px solid rgba(244, 195, 113, .32);
}
#settings .seg button:hover {
  color: #f9dcae;
  background: rgba(60, 26, 12, .6);
  border-color: rgba(244, 195, 113, .75);
}
#settings .seg button.on {
  color: #3a1206;
  background: linear-gradient(180deg, #f4c371, #d9a441);
  border-color: #ffe6b4;
  box-shadow: 0 0 8px rgba(244, 195, 113, .4);
  text-shadow: 0 1px 1px rgba(255, 236, 190, .45);
}

/* 音量スライダー */
.vol-ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 300px;
}
.vol-ctl input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, #2a0d08, #4a1512);
  border: 1px solid rgba(244, 195, 113, .45);
  outline: none;
  cursor: pointer;
}
.vol-ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffe6b4, #d9a441);
  border: 1px solid #ffe6b4;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.vol-ctl input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffe6b4, #d9a441);
  border: 1px solid #ffe6b4;
}
.vol-num {
  min-width: 3ch;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: #f4c371;
}

#settings-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
/* 退出・ルール説明を左に並べ、注記だけ右端へ寄せる */
#settings-footer .set-note { margin-left: auto; }
/* 退出＝金の塗り、ルール説明＝金の線。マニュアルの章タブと同じ配色 */
#btn-manual, #btn-exit-room {
  font-family: "Shippori Mincho B1", "Yu Mincho", serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .15em;
  padding: 7px 20px;
  border-radius: 5px;
  cursor: pointer;
  transition: color .12s ease, background .12s ease, border-color .12s ease, filter .12s ease;
}
#btn-exit-room {
  color: #3a1206;
  background: linear-gradient(180deg, #f4c371, #d9a441);
  border: 1px solid #ffe6b4;
  text-shadow: 0 1px 1px rgba(255, 236, 190, .45);
}
#btn-exit-room:hover { filter: brightness(1.08); }
#btn-manual {
  color: #e8c78f;
  background: rgba(20, 10, 6, .5);
  border: 1px solid rgba(244, 195, 113, .4);
}
#btn-manual:hover {
  color: #f9dcae;
  background: rgba(60, 26, 12, .6);
  border-color: rgba(244, 195, 113, .8);
}

/* ---------------- 左：オートボタン ---------------- */

#auto-panel {
  position: fixed;
  left: 14px;
  top: 62%;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 13px 10px;
  background: linear-gradient(160deg, rgba(30,37,58,.9), rgba(12,16,28,.9));
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.auto-btn {
  /* 理/和/鳴/切。84px から約15%小さく */
  width: 71px;
  height: 71px;
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 34px;
  color: var(--ink-dim);
  background: linear-gradient(160deg, #232b42, #10141f);
  border: 1px solid #37415c;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s ease;
}
.auto-btn:hover { border-color: var(--teal); color: var(--ink); }
.auto-btn.on {
  color: var(--teal);
  border-color: var(--teal);
  text-shadow: 0 0 10px rgba(67,217,200,.7);
  box-shadow: 0 0 12px rgba(67,217,200,.35), inset 0 0 8px rgba(67,217,200,.15);
}
/* タブレット〜小さめ画面で理/和/鳴/切を縮小（基準ルールより後ろに置き確実に上書き）。
   スマホ用のさらに強い .6 縮小はファイル末尾の @media で上書きされる。 */
@media (max-width: 1200px) {
  #auto-panel { transform: translateY(-50%) scale(.72); transform-origin: left center; }
  /* 右上アイコンも理和鳴切と同じ率で縮める（origin: top right なので右上は動かない） */
  #topright { transform: scale(.72); transform-origin: top right; }
}

/* ---------------- プレイヤー枠 ---------------- */

.seat {
  position: fixed;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
/* 配置はFigma node186-93準拠（卓中心=50cqw/42cqh-3cqmin 基準のvmin換算）。
   牌や河に被らない位置: 自分=手牌の左上 / 上家=左上の外側 / 対面=手牌右横 / 下家=右辺 */
/* +80px相当は 7.4cqmin（1920x1080基準）に換算してレスポンシブ化。高さは30px相当(2.6cqmin)上げ */
#seat-p0 { left: calc(50cqw - 38.1cqmin); top: calc(42cqh + 27.3cqmin - var(--my-grow)); transform: translateX(-50%); }
/* 16:9固定フレームなので px クランプは不要。比率基準で透明牌情報の外側に置く */
/* 左右の席アイコンは同じ高さに揃える（左側の元の高さ 42cqh-15.3cqmin に統一） */
/* 左右（上家・下家）は席アイコンが各家の手牌に被るので、さらに 30px相当(2.8cqmin)
   ずつ外へ逃がす。1920x1080基準の px 換算はこのファイルの他の値と同じ */
/* 上家・下家の席アイコンが置けるのは「読み札ストリップ #read-p1/p3 の内端」と
   「河の外端」に挟まれた **1本のレーンだけ**。実測（画面中心=0・cqmin）:
     手牌 #hand3d  ∓56.9〜∓69.9
     読み札 #read  ∓47.8〜∓60.0   ← 透明牌の面を見せる列。ここを塞ぐと情報が読めない
     河   #river   ∓17.7〜∓36.7   （6列グリッドの最大値）
     副露 #omelds  p1 +70.8〜+79.8 / p3 −55.6〜−65.0
   内側（読み札と河のあいだ）にもレーンはあるが 8.2cqmin しかなく、アイコンを
   一回り小さくしないと入らない。**アイコンは元の大きさのまま手牌の外側へ出す**
   （ユーザー指示）。外側の空きはアイコンの高さ帯で実測 ∓75.1〜∓88.9（13.8cqmin、
   ∓88.9 = #app の端）。ただし ∓82 だと画面端に張り付いて理和鳴切/右上アイコンに
   当たるので、**10%内側**の ∓74 ＝「手牌と卓の枠のあいだ」に置く（ユーザー指示）。
   幅は 12.8cqmin まで。
   基準も p3 と同じ cqmin に揃えた。以前の `86cqw + 2.8cqmin` は
   cqw 基準なので、16:9 より横長の画面ほど外へ流れて位置が安定しなかった */
#seat-p1 { left: calc(50cqw + 76cqmin); top: calc(42cqh - 19.5cqmin); transform: translateX(-50%); }
#seat-p2 { left: calc(50cqw + 26.9cqmin); top: calc(42cqh - 26cqmin); transform: translateX(-50%); }
/* 対面だけ名札を**アイコンの右**へ出す。縦積みのままだと、リーチ札が付いたときに
   名札が下へ伸びて対面の河に重なり、捨て牌が読めなくなる。
   position:absolute にすると席の幅がアイコンだけになるので、
   translateX(-50%) の基準＝アイコンの位置は動かない */
/* 並びは **1行目 = 風 + リーチ札 / 2行目 = 名前**（ユーザー指示 2026-08-09）。
   flex + flex-wrap では折り返しても幅が縮まない
   （shrink-to-fit の max-content が「1行に並べた幅」で決まる）ので **grid** を使う。
   grid なら名札の幅は max(風+リーチ, 名前) になり、余白が出ない */
#seat-p2 .plate {
  position: absolute;
  left: calc(100% + 6px);
  /* **幅は必ず max-content で取る。** 対面の名札だけ position:absolute で、
     包含ブロックは #seat-p2（アイコン幅 = 32px 前後）。`left: 100% + 6px` を引くと
     使える幅が 0 になるので、既定の shrink-to-fit だと「幅0に収まるように」畳まれる。
     PCでは中身が縮まないので溢れて見えていたが、小画面では
     `.plate .pname { overflow: hidden; text-overflow: ellipsis }`（下の@media）が
     効いて**名前が幅0まで潰れ、対面の名前だけ消えていた**（ユーザー報告 2026-08-08）。
     max-content なら使える幅に関係なく中身どおりの幅になる（長い名前は .pname の
     max-width: 7em で従来どおり…に省略される） */
  width: max-content;
  /* 縦位置はアイコンの**下端合わせ**。中央合わせだと名札が下へはみ出して、
     上家・下家のアイコンが入る内側レーン（∓41.6・y −25〜−7）に食い込む
     （実測 844x390 で名札 35.1〜53.8 / y −31.4〜−23.2 がレーンを塞いでいた） */
  bottom: 0;
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: start;
  gap: 2px 6px;
}
/* 1行目: 風（左）とリーチ札（その右）。2行目: 名前が全幅 */
#seat-p2 .pwind  { grid-area: 1 / 1; }
#seat-p2 .pbadge { grid-area: 1 / 2; justify-self: start; }
#seat-p2 .pname  { grid-area: 2 / 1 / 3 / 3; justify-self: start; max-width: 6em; overflow: hidden; text-overflow: ellipsis; }
/* 上家も下家と同じく手牌の外側へ（#seat-p1 のコメント参照）。左右対称 */
#seat-p3 { left: calc(50cqw - 76cqmin); top: calc(42cqh - 19.5cqmin); transform: translateX(-50%); }
/* 名札は **風・名前・リーチ札を縦積み**にして幅を max(風, 名前, リーチ) に抑える。
   横並びのままだと「padding + 風 + gap + 名前」の **px 固定分**が効いて、
   小画面ほど cqmin 換算で太る（実測 844x390 で 14.3cqmin）。縦積みなら 7cqmin 台。
   リーチ札も自動的に名前の下に来るので、小画面用の折り返し指定（flex-basis:100%）は不要。

   **名札は外側（画面の端の方）へ伸ばす**（ユーザー指示 2026-08-09）。
   以前はアイコン幅(9.3cqmin)で頭打ちにしていたので、スマホでは名前が2〜3文字しか出ず、
   「ゲスト1」と「ゲスト2」がどちらも「ゲ…」になって区別できなかった。
   内側（卓の中心側）は手牌と透明牌の読み札のレーンなので広げられないが、
   **外側は画面の端まで空いている**ので、そちらへ伸ばせば何も塞がない。
     上家(p3, 画面の左) … 右端をアイコンに合わせ、**左へ**伸ばす（右揃え）
     下家(p1, 画面の右) … 左端をアイコンに合わせ、**右へ**伸ばす（左揃え）
   position:absolute にするのは、席の箱(.seat)の幅をアイコンのままにするため。
   幅が変わると translateX(-50%) でアイコンの位置ごとずれてしまう */
#seat-p1 .plate, #seat-p3 .plate {
  position: absolute;
  top: calc(100% + 5px);   /* アイコンの真下（.seat の gap と同じ） */
  flex-direction: column;
  gap: 1px;
  padding: 3px 5px;
  width: max-content;
  max-width: none;
}
#seat-p3 .plate { right: 0; align-items: flex-end;   text-align: right; }
#seat-p1 .plate { left: 0;  align-items: flex-start; text-align: left; }
/* 名前は6文字まで（全角1文字=1em）。それ以上は…で省略 */
#seat-p1 .pname, #seat-p3 .pname {
  max-width: 6em;
  overflow: hidden;
  text-overflow: ellipsis;
}
#seat-p1 .pbadge, #seat-p3 .pbadge { letter-spacing: 0; padding: 1px 3px; }

.avatar {
  position: relative;
  overflow: hidden;
  width: clamp(52px, 9.3cqmin, 112px);
  aspect-ratio: 1;
  border-radius: 12%;
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: clamp(20px, 3cqmin, 36px);
  color: rgba(255,255,255,.92);
  text-shadow: 0 2px 6px rgba(0,0,0,.6);
  box-shadow: 0 4px 14px rgba(0,0,0,.55);
  transition: box-shadow .25s ease;
}
.av0 { background: linear-gradient(150deg, #3f5e8c, #1d2c47); }
.av1 { background: linear-gradient(150deg, #8c5a3f, #47281d); }
.av2 { background: linear-gradient(150deg, #5e8c3f, #2b471d); }
.av3 { background: linear-gradient(150deg, #7c3f8c, #3c1d47); }

.seat.turn .avatar {
  border-color: var(--gold-bright);
  box-shadow: 0 0 18px rgba(236,207,146,.75), 0 4px 14px rgba(0,0,0,.55);
  animation: turnGlow 1.2s ease-in-out infinite alternate;
}
@keyframes turnGlow {
  from { box-shadow: 0 0 10px rgba(236,207,146,.45); }
  to   { box-shadow: 0 0 22px rgba(236,207,146,.9); }
}

.plate {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--ink);
  background: rgba(10,14,24,.82);
  border: 1px solid rgba(61,74,102,.8);
  border-radius: 5px;
  white-space: nowrap;
}
.pwind {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 17px;
  color: #f4efe3;
}
.pwind.dealer { color: #ff6d5a; }
.pbadge:empty { display: none; }
.pbadge {
  color: #fff;
  background: var(--accent-red);
  font-weight: 700;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 2px;
  letter-spacing: .15em;
}

/* ---------------- 自分のゾーン ---------------- */

#myzone {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 18;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
/* 手牌の下端を自分バンドの下端(42cqh+54.72cqmin)に揃える
   （#appは縦向きでも16:9レターボックスなので常に適用） */
#myzone { padding-bottom: max(12px, calc(58cqh - 54.72cqmin + 2px)); }
#myzone > * { pointer-events: auto; }

#message {
  min-height: 1.4em;
  text-align: center;
  font-size: clamp(12px, 1.8cqmin, 16px);
  color: var(--gold-bright);
  letter-spacing: .08em;
  text-shadow: 0 1px 6px rgba(0,0,0,.9);
  margin-bottom: 2.6cqmin;   /* 手牌と近くて読みづらいので30px相当上げる */
}

#turn-timer {
  /* ラベル（ツモ切りまで/スキップまで）はバーの上段に表示 */
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: center;
  column-gap: clamp(6px, .93cqmin, 12px);
  row-gap: 3px;
  /* 手牌から離して見やすくする（30px相当を比率化。#myzone は下端固定なので上に浮く） */
  margin-bottom: 2.8cqmin;
}
/* 鳴き選択パネルが出ている間、タイムバーは JS（fitTimerToCallPanel）が
   パネル全体の中央・真上へ実測配置する（パネル幅が候補数で変わるため） */
#turn-timer-label { grid-column: 1; justify-self: center; }  /* バーの真上・中央 */
#turn-timer-bar { grid-row: 2; }
#turn-timer-num { grid-row: 2; }
#turn-timer.hidden { display: none; }
#turn-timer-label {
  font-size: clamp(11px, 1.6cqmin, 14px);
  letter-spacing: .1em;
  color: var(--gold-bright);
  text-shadow: 0 1px 6px rgba(0,0,0,.9);
  white-space: nowrap;
}
#turn-timer-bar {
  width: min(31.5cqmin, 60cqw);   /* 340px相当を比率化 */
  height: clamp(5px, .65cqmin, 9px);
  border-radius: 4px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
}
#turn-timer-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--teal), #7ee8dc);
}
#turn-timer-fill.warn { background: linear-gradient(90deg, #c0392b, #e06550); }
#turn-timer-num {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: clamp(12px, 1.6cqmin, 24px);   /* 17px相当を比率化 */
  color: var(--teal);
  min-width: 2ch;
  text-align: center;
}
/* 残り秒数とラベルもバーと一緒に赤へ（ui.js は fill にしか warn を付けないので :has で拾う） */
#turn-timer:has(#turn-timer-fill.warn) #turn-timer-num { color: #e06550; }
#turn-timer:has(#turn-timer-fill.warn) #turn-timer-label { color: #e8a08f; }

#my-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  gap: clamp(8px, 2cqmin, 20px);
  /* 自分バンドの左端(50cqw-59.44cqmin)+1.5cqmin を基準に左詰め。ツモしても左側の牌は動かない */
  padding-left: max(2cqw, calc(50cqw - 57.9cqmin));
  perspective: 1200px;
}

/* ほぼ垂直に立てて、上面がわずかに見える程度（手牌は非公開の見た目） */
#my-hand {
  position: relative;
  display: flex;
  gap: 3px;
  align-items: flex-end;
  transform: rotateX(-10deg);
  transform-origin: 50% 100%;
  transform-style: preserve-3d;
}
#my-hand .tile3d {
  --t3w: var(--tw-my);
  cursor: pointer;
  transition: transform .12s ease;
}
/* ホバーした牌を持ち上げて「今どれを選んでいるか」を分かりやすくする。
   20px を基準にし、大きい画面では見た目の動きが同じになるよう cqmin でも下支えする。
   他家の手番中（.no-click）も持ち上げる。打牌できるかどうかは cursor と
   クリック処理側で分けており、「どの牌を指しているか」は常に見えた方がよい */
#my-hand .tile3d { --lift: max(20px, 2.5cqmin); }
/* **持ち上げはマウスのある端末だけ。**
   タッチ端末では、一度タップした牌に `:hover` が張り付いたまま残る（次にどこかを
   タップするまで解除されない）。牌が20px浮いたままになるので、見えている位置と
   指が覚えている位置がずれ、「感度が悪い・隣の牌が選ばれる」と感じる原因になる
   （Androidスマホでの報告 2026-08-09）。タッチ端末では下の .selected だけが動く */
@media (hover: hover) {
  #my-hand .tile3d:hover { transform: translateY(calc(var(--lift) * -1)); }
}
/* タッチ端末：1タップ目の選択状態。ホバーより少し高く上げて区別する */
#my-hand .tile3d.selected { transform: translateY(calc(var(--lift) * -1.2)); }
#my-hand .tile3d.selected .tf-front { outline: 2px solid var(--teal); outline-offset: 2px; }
#my-hand .tile3d .tf-front { box-shadow: 0 .1em .18em rgba(0,0,0,.35); }
/* ツモ牌はフローから外して手牌の右に置く。
   ツモった瞬間に手牌13枚が中央寄せで動いて誤クリックするのを防ぐ。
   見分けやすいように1.25倍で表示 */
#my-hand .tile3d.drawn-tile {
  --t3w: calc(var(--tw-my) * 1.15); /* Figma実測: 手牌の約1.15倍 */
  position: absolute;
  left: calc(100% + clamp(12px, 2.2cqmin, 26px));
  bottom: 0;
}
#my-hand .tile3d.no-click { cursor: default; } /* ホバー（河ハイライト）は待機中も有効 */
#my-hand .tile3d.dimmed { pointer-events: none; }
#my-hand .tile3d.dimmed .tf { filter: brightness(.45); }
#my-hand .tile3d.riichi-ok .tf-front { outline: 2px solid var(--teal); outline-offset: 2px; }

/* 副露は雀魂と同じく画面右下の隅に固定（手牌は中央のまま） */
#my-melds {
  position: absolute;
  /* 自分バンド(#guide-self: 右端 50cqw+56.96cqmin, 下端 42cqh+54.72cqmin)の右下に収める */
  /* 自分バンドの右端から **さらに120px相当右**（ユーザー指示 2026-08-08）。
     1920x1080 で右端まで 362→242px。これ以上寄せると待ち牌パネルに当たる（-16cqminで43px） */
  right: max(8px, calc(50cqw - 68.06cqmin + 4px));
  /* 自分バンドの右下から **さらに60px相当下**（ユーザー指示 2026-08-08）。
     以前の `max(12px, …)` の下限はこの下げを打ち消してしまう（1920x1080 で
     計算値 −21px が 12px に張り付く）ので外した。牌の下端は画面内に 10〜17px 残る */
  bottom: calc(58cqh - 59.39cqmin + 4px);
  pointer-events: none;
  display: flex;
  /* 実物の作法: 最初の副露が右端(コーナー)に固定、後から鳴いた面子はその左へ追加。
     これで鳴くたびに既存の面子が左へずれて見える問題も無くなる */
  flex-direction: row-reverse;
  gap: 8px;
  align-items: flex-end;
  justify-content: flex-start;
}
#my-melds .meld { display: flex; gap: 1px; }
#my-melds .tile { width: calc(var(--tw-my) * .936); } /* Figma実測 .78 の20%増（待ち牌パネルを20%縮めたぶん） */
/* 横長が弱い画面(4:3のiPad等)では横幅が足りず、右下固定の副露が手牌に食い込む。
   面子を右下で縦積みにし、ひと回り縮めて手牌との横の取り合いをなくす
   （16:9等の横長では従来どおり横並び） */
/* 崩れの原因はアスペクト比ではなく「小ささ」：#app は常に16:9固定だが、手牌には
   可読性のための px 下限(--tw-my の 48px 床)があり、小さい画面では縮み止まって
   相対的に膨らみ、右下固定の副露に届いてしまう。床が効き始めるのは app 高さ<640px
   ＝ 縦640px未満 または 横1138px未満（16:9で height=width×9/16 のため） */
@media (max-width: 1138px), (max-height: 640px) {
  /* 間隔だけ詰める。**right は基準の式（自分バンドの右下）のまま**にする。
     以前は `right: 12px` で画面の右端いっぱいへ寄せていたが、それだと副露が
     青い卓から外れて木枠の上に乗ってしまう。
     牌を10%小さくした今は、バンド基準でも手牌には届かない
     （副露が増えるほど門前の手牌は短くなるので、両方が最長になることはない） */
  #my-melds { gap: 6px; }
  /* .62 は手牌に対して小さすぎて何を鳴いたか読めない（ユーザー指摘）。
     4副露＋1枚手牌の最悪形でも下段に収まる .74 まで戻す */
  #my-melds .tile { width: calc(var(--tw-my) * .888); }
  /* 小画面では右下端に副露が居るので、待ち牌表記はその上へ退避 */
  #wait-panel { bottom: calc(var(--tw-my) * .888 * 1.39 + 24px); }

  /* ---- スマホの被り対策（実機スクショで確認した3点）---- */

  /* ① 牌の10%縮小は :root の基準値に入れた（PC・スマホ共通）ので、ここには置かない。
     ただし**川だけは逆に10%大きく**する。スマホでは1枚が12px台まで落ちて
     何を切ったか読めないため。広げたぶんは牌と牌の隙間から取る:
     セル幅の余白 3px→1px、grid の gap 2px→1px。
     これで川全体の幅はむしろ 103px→93px と縮み、牌だけ大きくなる */
  :root {
    --tw-river: 3.66cqmin;                          /* 3.33 × 1.1 */
    --trh: calc(var(--tw-river) * 1.39 + 1px);
    --rw: calc(var(--tw-river) + 1px);
  }
  .river { gap: 1px; }

  /* ② 理/和/鳴/切が牌に被るので、さらに20%small（1200px以下の .72 × .8 = .576）。
     transform-origin: left なので**左端は動かない** */
  #auto-panel { transform: translateY(-50%) scale(.576); transform-origin: left center; }
  #topright { transform: scale(.576); transform-origin: top right; }

  /* ③ 右上の全画面・設定・退出は **PC と同じ横一列**（ユーザー指示で縦積みは取りやめ）。
     縦積みにしていたのは下家の副露と当たるためだったが、副露を卓の手前側へ
     移した（§2 の #omelds-p1）ので横一列でも当たらない。
     スタンプ枠 #chat-panel を下げる指定も不要になったので撤去した */

  /* ④ 上家・下家の名札は基準側で縦積み（風／名前／リーチ札）にしてある。
     小画面は 1cqmin が小さく px 指定が効きすぎるので、padding とリーチ札を詰める。
     リーチ札は縦積みなので放っておいても名前の下に来る */
  /* 名札を外側へ伸ばした結果、小画面では真下の牌に6pxほど被る。
     アイコンとの隙間(5px)と余白を詰めて逃がす（実測 844x390 で解消） */
  #seat-p1 .plate, #seat-p3 .plate { top: 100%; padding: 1px 4px; }
}

/* ---------------- アクションボタン ---------------- */

#actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: clamp(32px, 4.6cqmin, 46px);
}
#actions button {
  font-family: "Shippori Mincho B1", serif;
  font-size: clamp(14px, 2.1cqmin, 19px);
  font-weight: 600;
  letter-spacing: .2em;
  padding: 5px 22px;
  color: var(--gold-bright);
  background: linear-gradient(180deg, #2a3147, var(--panel));
  border: 1px solid var(--gold);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
}
#actions button:hover {
  background: linear-gradient(180deg, #38415f, #1d2438);
  box-shadow: 0 0 14px rgba(201,163,90,.45);
  transform: translateY(-2px);
}
#actions button.hot {
  color: #fff;
  border-color: #e06550;
  background: linear-gradient(180deg, #a03428, #6b1f16);
}
#actions button.hot:hover { box-shadow: 0 0 16px rgba(224,101,80,.6); }

/* リーチボタン：大きく・光らせて目立たせる */
#actions button.riichi {
  font-size: clamp(18px, 2.8cqmin, 28px);
  padding: 10px 36px;
  letter-spacing: .3em;
  color: #10141f;
  border: none;
  background: linear-gradient(180deg, #5fe8d8, var(--teal));
  animation: riichiPulse 1.1s ease-in-out infinite alternate;
}
#actions button.riichi:hover {
  filter: brightness(1.12);
  transform: translateY(-2px);
}
@keyframes riichiPulse {
  from { box-shadow: 0 0 .6cqmin rgba(67, 217, 200, .5); }
  to   { box-shadow: 0 0 2.4cqmin rgba(67, 217, 200, 1); }
}

/* ---------------- 待ち牌パネル ---------------- */

#wait-panel {
  position: fixed;
  /* 右下だが端に付きすぎないよう30px相当の余白（比率単位でレスポンシブ） */
  right: 4cqmin;
  bottom: 3.7cqmin;
  /* 自分の副露と同じ右下の角を取り合うので20%小さくする（ユーザー指示）。
     origin: bottom right なので右下の角は動かない */
  transform: scale(.8);
  transform-origin: bottom right;
  z-index: 19;
  display: flex;
  align-items: center;
  gap: 1cqmin;
  padding: 1cqmin 1.4cqmin;
  background: linear-gradient(160deg, rgba(30,37,58,.92), rgba(12,16,28,.92));
  border: 1px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.55);
}
#wait-panel.hidden { display: none; }
#wait-label {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: clamp(13px, 1.7cqmin, 20px);
  color: var(--gold-bright);
  letter-spacing: .1em;
  white-space: nowrap;
}
#wait-tiles { display: flex; gap: .8cqmin; }
#wait-tiles .wait-tile { display: flex; flex-direction: column; align-items: center; gap: 2px; }
#wait-tiles .tile { width: clamp(30px, 4.2cqmin, 56px); }
#wait-tiles .wait-left {
  font-size: clamp(10px, 1.3cqmin, 16px);
  color: var(--teal);
  font-weight: 700;
}
#wait-tiles .wait-left.none { color: #ff8a75; }
#wait-tiles .noten { font-size: clamp(12px, 1.5cqmin, 18px); color: var(--ink-dim); }

/* 「何を切れば何待ちか」の一覧（切る牌ごとに1行） */
#wait-tiles.rows {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  max-height: 40cqh;
  overflow-y: auto;
}
.wait-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.wait-row + .wait-row { border-top: 1px solid rgba(255,255,255,.08); }
.wait-row-cut {
  min-width: 5.5em;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
}
.wait-row-cut::after { content: "→"; color: var(--ink-dim); margin-left: 4px; }

/* ---------------- 鳴き確認パネル（左側フローティング） ---------------- */

#call-panel {
  position: fixed;
  /* 上へ逃がしたぶん右席の卓上情報（読み取りストリップ）と被らないよう、
     自分の河との間の空き（右端から25cqw）へ左寄せ */
  right: 25cqw;
  /* ツモ牌は手牌の1.15倍高（×1.39×1.15≒×1.6）＋ホバーの浮き12pxがあるので、
     その上に余裕を持って浮かせる（手牌・ツモ牌と被らない） */
  bottom: calc(var(--tw-my) * 1.6 + 5.2cqmin);
  z-index: 25;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  background: linear-gradient(160deg, rgba(30, 37, 58, .95), rgba(12, 16, 28, .95));
  border: 1px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .65);
  animation: callPanelIn .18s ease-out;
}
#call-panel.hidden { display: none; }
@keyframes callPanelIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: none; }
}
.call-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 160px;
}
.call-sub {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid rgba(201, 163, 90, .3);
}
.call-sub.hidden { display: none; }
.call-sub-label {
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 2px;
}
.call-btn {
  font-family: "Shippori Mincho B1", serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .2em;
  padding: 12px 22px;
  color: var(--gold-bright);
  background: linear-gradient(180deg, #2a3147, var(--panel));
  border: 1px solid var(--gold);
  border-radius: 8px;
  cursor: pointer;
  transition: all .12s ease;
}
.call-btn:hover {
  background: linear-gradient(180deg, #38415f, #1d2438);
  box-shadow: 0 0 14px rgba(201, 163, 90, .45);
  transform: translateY(-1px);
}
.call-btn.hot {
  color: #fff;
  border-color: #e06550;
  background: linear-gradient(180deg, #a03428, #6b1f16);
}
.call-btn.hot:hover { box-shadow: 0 0 16px rgba(224, 101, 80, .6); }
.call-btn.cancel {
  font-size: 15px;
  padding: 8px 18px;
  color: var(--ink-dim);
  border-color: var(--panel-edge);
}
.call-btn.small { font-size: 15px; padding: 8px 14px; }

/* ---------------- チャット・スタンプ ---------------- */

#chat-panel {
  position: fixed;
  right: 14px;      /* 右上のアイコン列(#topright)と右端を揃える */
  /* 右上アイコンのすぐ下から開始。アイコンは 71px 固定＋@media で縮小されるので、
     ここは最大時（等倍）の高さで押さえておけば常にアイコンより下になる */
  top: calc(28px + 71px);
  bottom: calc(var(--tw-my) * 1.39 + 120px);
  /* スタンプ1枚の幅＝右上のアイコン(.icon-btn)の1.75倍
     （+パネルの左右padding16px+スクロールバー等の目減り分10px） */
  width: calc(clamp(54px, 7.6cqmin, 94px) * 1.75 + 26px);
  min-height: 200px;
  z-index: 16;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: linear-gradient(160deg, rgba(30, 37, 58, .78), rgba(12, 16, 28, .78));
  border: 1px solid rgba(61, 74, 102, .8);
  border-radius: 10px;
}
/* 受信スタンプの履歴表示は廃止（アイコン変身で伝わるため）。枠だけ残して非表示 */
#chat-log { display: none; }
/* 右上アイコンを縦一列にしていたときは、その下のスタンプ枠を3つぶん下げていたが、
   横一列に戻したので基準の top（アイコン1つぶん下）のままでよい。
   ※ここに小画面用の #chat-panel を足すときは **#chat-panel の定義より後ろ**に
     置くこと。同じ詳細度どうしはソース順で決まる（このファイルで何度か踏んだ罠） */

.chat-line { display: flex; align-items: center; gap: 5px; line-height: 1.35; word-break: break-all; }
.chat-name { color: var(--gold-bright); flex: 0 0 auto; }
.log-stamp { width: 30px; height: 30px; object-fit: contain; }

/* キャラ切替タブ（パックが1つなら JS 側で非表示） */
#stamp-tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.stamp-tab {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 3px 9px;
  color: var(--ink);
  background: rgba(0, 0, 0, .3);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.stamp-tab:hover { border-color: var(--panel-edge); }
.stamp-tab.active { color: var(--gold-bright); border-color: var(--gold); background: rgba(0, 0, 0, .5); }

/* スタンプ画像グリッド（縦スクロール） */
#stamp-row {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr;   /* 縦1列（スクロールで下に続く） */
  gap: 6px;
  align-content: start;
  padding-right: 2px;
}
.stamp-pick {
  aspect-ratio: 1;
  padding: 2px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: transform .1s ease, border-color .1s ease, background .1s ease;
}
.stamp-pick img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stamp-pick:hover { border-color: var(--gold); background: rgba(0, 0, 0, .5); transform: translateY(-1px); }
.stamp-pick:active { transform: scale(.95); }
.stamp-empty { grid-column: 1 / -1; font-size: 11px; color: #8892a6; line-height: 1.6; padding: 6px; }

/* ---------------- 鳴き・宣言の吹き出しカットイン（Figma 531-168ほか） ---------------- */
.call-bubble {
  position: fixed;
  z-index: 36;
  /* 幅は showCallout がタイプごとにインラインで指定（Figmaデザイン実寸のcqmin換算） */
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .45));
  animation: callout-in .22s cubic-bezier(.34, 1.45, .5, 1) both;
}
.call-bubble img { display: block; width: 100%; height: auto; }
.call-bubble.flip img { transform: scaleX(-1); }  /* シッポを反対側へ */
.call-bubble svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.call-bubble.flip svg { transform: scaleX(-1); }  /* シッポを反対側へ（文字は反転しない） */
.call-bubble span {
  position: relative;
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-weight: 900;
  font-size: 4.6cqmin;
  color: #141414;
  letter-spacing: .02em;
  transform: translateY(-8%);
  white-space: nowrap;
}
.call-bubble.burst span {
  font-size: 4.3cqmin;
  -webkit-text-stroke: .42cqmin #fff;
  paint-order: stroke;
  font-style: italic;
  transform: rotate(-6deg);
}
.call-bubble.out { animation: callout-out .22s ease both; }
@keyframes callout-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.35); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes callout-out {
  to { opacity: 0; transform: translate(-50%, -50%) scale(.85); }
}
/* 発声中・スタンプ変身中の席アイコンは20%拡大して誰のものか分かるようにする */
.seat .avatar { transition: transform .15s ease; }
.seat.callout-speaking .avatar,
.seat.stamp-face .avatar { transform: scale(1.2); }

/* 右端中央：スタンプパネルの開閉ハンドル */
#stamp-toggle {
  position: fixed;
  right: 0;
  /* 左端の理和鳴切の開閉ハンドル(#auto-toggle)と同じ高さに揃える（ユーザー指示） */
  top: 62%;
  transform: translateY(-50%);
  z-index: 18;               /* パネル(16)より前 */
  width: clamp(18px, 2.2cqmin, 30px);
  height: clamp(64px, 9cqmin, 120px);
  padding: 0;
  border: 1px solid rgba(61, 74, 102, .8);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: linear-gradient(160deg, rgba(30, 37, 58, .88), rgba(12, 16, 28, .88));
  color: #cfd6e4;
  font-size: clamp(10px, 1.2cqmin, 14px);
  cursor: pointer;
}
#stamp-toggle:hover { color: var(--gold-bright); border-color: var(--gold); }
body.stamps-closed #chat-panel { display: none; }

/* 左端中央：理/和/鳴/切パネルの開閉ハンドル（スタンプの左右反転） */
#auto-toggle {
  position: fixed;
  left: 0;
  top: 62%;                  /* #auto-panel と同じ縦中心に合わせる */
  transform: translateY(-50%);
  z-index: 21;               /* #auto-panel(20) より前 */
  width: clamp(18px, 2.2cqmin, 30px);
  height: clamp(64px, 9cqmin, 120px);
  padding: 0;
  border: 1px solid rgba(61, 74, 102, .8);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: linear-gradient(200deg, rgba(30, 37, 58, .88), rgba(12, 16, 28, .88));
  color: #cfd6e4;
  font-size: clamp(10px, 1.2cqmin, 14px);
  cursor: pointer;
}
#auto-toggle:hover { color: var(--gold-bright); border-color: var(--gold); }
body.auto-closed #auto-panel { display: none; }

/* ---------------- 通信状況インジケータ（左下） ---------------- */
#net-status {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  gap: clamp(2px, .28cqmin, 4px);
  padding: clamp(5px, .6cqmin, 8px) clamp(6px, .75cqmin, 10px);
  background: rgba(12, 16, 28, .55);
  border: 1px solid transparent;
  border-radius: 6px;
}
#net-status i {
  width: clamp(3px, .38cqmin, 6px);
  border-radius: 2px;
  background: rgba(255, 255, 255, .18);   /* 消灯 */
}
#net-status i:nth-child(1) { height: clamp(5px, .6cqmin, 9px); }
#net-status i:nth-child(2) { height: clamp(8px, 1cqmin, 14px); }
#net-status i:nth-child(3) { height: clamp(11px, 1.4cqmin, 19px); }
#net-status i:nth-child(4) { height: clamp(14px, 1.8cqmin, 24px); }
#net-status.good i.on { background: #3ddc84; }
#net-status.warn i.on { background: #ffcc4d; }
#net-status.off { border-color: rgba(224, 80, 60, .8); }
#net-status.off i { background: rgba(224, 80, 60, .55); }

/* スタンプの吹き出し（各プレイヤーのアイコン付近に画像で表示） */
.stamp-bubble {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .6));
  animation: stampPop 2.6s ease forwards;
}
.stamp-bubble img { width: 140px; height: 140px; object-fit: contain; display: block; }
@keyframes stampPop {
  0%   { transform: scale(.3); opacity: 0; }
  10%  { transform: scale(1.2); opacity: 1; }
  16%  { transform: scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ---------------- 配牌アニメーション ---------------- */

#fly-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}
#fly-layer .tile.fly {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--tw-opp);
}

/* ---------------- ロビー ---------------- */

/* ============================================================
   タイトル画面（Figma node 17-152）
   1920x1080 の固定ステージを cover でスケールし、Figma座標のまま配置
   ============================================================ */
#title-screen {
  position: fixed;
  inset: 0;
  z-index: 70;              /* ロビー(60)より前面 */
  overflow: hidden;
  background: #0a0705;
  animation: title-fade .5s ease both;
}
#title-screen.hidden { display: none; }
@keyframes title-fade { from { opacity: 0; } to { opacity: 1; } }

#title-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1920px;
  height: 1080px;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
}
#title-stage img,
#title-stage button { position: absolute; }

#title-bg      { left: 0;      top: -26px; width: 1965px; height: 1106px; object-fit: cover; }
#title-char    { left: 100px;  top: 15px;  width: 681px;  height: 1072px; object-fit: contain;
                 filter: drop-shadow(0 12px 40px rgba(0,0,0,.45)); }
#title-logo    { left: 645px;  top: 18px;  width: 1088px; height: 725px;  object-fit: contain;
                 pointer-events: none; animation: title-logo-in .8s cubic-bezier(.2,.8,.2,1) both; }
#title-version { position: absolute; left: 1111px; top: 949px; width: 187px;  height: 48px;
                 display: flex; align-items: center; justify-content: center;
                 font-family: "Shippori Mincho B1", "Yu Mincho", serif;
                 font-weight: 700; font-size: 30px; letter-spacing: .04em;
                 color: #e7c579; text-shadow: 0 2px 5px rgba(0,0,0,.7), 0 0 3px rgba(50,25,8,.85);
                 pointer-events: none; }

@keyframes title-logo-in {
  from { opacity: 0; transform: translateY(-18px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#title-start {
  left: 918px; top: 704px; width: 605px; height: 269px;
  padding: 0; border: none; background: none; cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
  animation: title-start-pulse 2.4s ease-in-out infinite;
}
#title-start img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
#title-start:hover  { transform: scale(1.045); filter: drop-shadow(0 0 26px rgba(255,205,110,.7)); animation: none; }
#title-start:active { transform: scale(.98); filter: drop-shadow(0 0 14px rgba(255,205,110,.5)); }
#title-start:focus-visible { outline: none; filter: drop-shadow(0 0 26px rgba(255,205,110,.85)); }

@keyframes title-start-pulse {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(255,190,90,.25)); }
  50%      { filter: drop-shadow(0 0 20px rgba(255,205,110,.6)); }
}

#lobby-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 12, .82);
  backdrop-filter: blur(4px);
  z-index: 60;
}
#lobby-wrap.hidden { display: none; }

#lobby {
  width: min(420px, 92cqw);
  padding: 34px 36px;
  text-align: center;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: linear-gradient(160deg, #242c44 0%, var(--panel) 70%);
  box-shadow: 0 0 60px rgba(0,0,0,.9);
}
#lobby h2 {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 30px;
  letter-spacing: .3em;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lobby-sub { font-size: 12px; color: var(--ink-dim); margin: 6px 0 22px; }

#lobby input {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: rgba(0,0,0,.45);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  padding: 10px 12px;
  outline: none;
  text-align: center;
}
#lobby input:focus { border-color: var(--gold); }
#lobby-name { margin-bottom: 12px; }

/* ルーム作成のルール行（雀魂風：ラベル＋オレンジのピルボタン） */
#rule-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.rule-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rule-label {
  min-width: 4.5em;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--ink);
  white-space: nowrap;
}
.rule-row .seg { flex: 1; justify-content: flex-start; }
.seg.orange button {
  padding: 5px 12px;
  border-radius: 6px;
  color: var(--ink);
  background: linear-gradient(180deg, #2c3550, #1b2236);
  border: 1px solid rgba(90, 110, 160, .5);
}
.seg.orange button.on {
  color: #241503;
  font-weight: 700;
  background: linear-gradient(180deg, #ffc14d, #e8912b);
  border-color: #ffd98a;
  box-shadow: 0 0 8px rgba(240, 160, 60, .45);
}
.seg button:disabled {
  opacity: .4;
  cursor: default;
}
#detail-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0 2px 10px;
  border-left: 2px solid rgba(240, 160, 60, .35);
}
#detail-rows.hidden { display: none; }
#lobby-code { text-transform: uppercase; letter-spacing: .4em; }

.lobby-btn {
  font-family: "Shippori Mincho B1", serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .2em;
  padding: 10px 20px;
  color: var(--gold-bright);
  background: linear-gradient(180deg, #2a3147, var(--panel));
  border: 1px solid var(--gold);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
}
.lobby-btn:hover { box-shadow: 0 0 14px rgba(201,163,90,.45); }
.lobby-btn.primary {
  width: 100%;
  color: #10141f;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border: none;
}
.lobby-btn.primary:hover { filter: brightness(1.08); }

.lobby-or { font-size: 11px; color: var(--ink-dim); margin: 14px 0; }
.lobby-btn.block { width: 100%; margin-bottom: 10px; }
.lobby-row { display: flex; gap: 8px; }
.lobby-row input { flex: 1; }

#lobby-error { color: #ff8a75; font-size: 12px; min-height: 1.4em; margin-top: 12px; }

#lobby-form.hidden, #lobby-room.hidden, #btn-start.hidden, #lobby-wait.hidden { display: none; }

.room-code-label { font-size: 11px; letter-spacing: .3em; color: var(--ink-dim); }
#room-code {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 44px;
  letter-spacing: .35em;
  color: var(--teal);
  text-shadow: 0 0 18px rgba(67,217,200,.5);
  margin: 4px 0 2px;
}
.room-hint { font-size: 11px; color: var(--ink-dim); margin-bottom: 16px; }

/* 参加用QRコード */
#qr-box {
  display: inline-block;
  padding: 8px;
  margin-bottom: 14px;
  background: #fff;
  border-radius: 10px;
  line-height: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
}
#qr-box.hidden { display: none; }
#qr-box img { image-rendering: pixelated; width: 148px; height: 148px; }
#qr-url {
  font-size: 10px;
  color: var(--ink-dim);
  word-break: break-all;
  margin-bottom: 8px;
  padding: 0 10px;
}
#qr-url.hidden { display: none; }
#qr-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin-bottom: 12px;
}
#qr-switch.hidden { display: none; }
.qr-switch-label {
  width: 100%;
  font-size: 10px;
  color: var(--ink-dim);
  margin-bottom: 2px;
}
.qr-switch-btn {
  font-family: inherit;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--ink);
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--panel-edge);
  cursor: pointer;
}
.qr-switch-btn.on {
  color: #241503;
  background: linear-gradient(180deg, #ffc14d, #e8912b);
  border-color: #ffd98a;
}

#lobby-players {
  list-style: none;
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#lobby-players li {
  padding: 8px 12px;
  font-size: 14px;
  background: rgba(0,0,0,.35);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
}
#lobby-players li.empty { color: var(--ink-dim); border-style: dashed; }
#lobby-wait { font-size: 13px; color: var(--ink-dim); }

/* ---------------- モーダル ---------------- */

#modal-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;   /* #modal は max-height で必ず画面内に収まるので中央寄せで切れない */
  justify-content: center;
  overflow-y: auto;
  padding: 12px;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(3px);
  z-index: 50;
}
#modal-wrap.hidden { display: none; }

#modal {
  min-width: min(520px, 90cqw);
  max-width: 92cqw;
  /* 画面より高い結果表示（役・点数・スコア）が見切れないよう内部スクロール。
     vh/dvh の小さい方を使い、モバイルのURLバー分も含めて必ず画面内に収める。 */
  max-height: min(100cqh - 24px, 100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 auto;   /* 横中央のみ。縦は #modal-wrap の flex-start＋padding で上に固定し切れを防ぐ */
  padding: clamp(20px, 4cqmin, 40px);
  border: 1px solid var(--gold);
  border-radius: 10px;
  background: linear-gradient(160deg, #242c44 0%, var(--panel) 70%);
  box-shadow: 0 0 60px rgba(0,0,0,.9), inset 0 0 40px rgba(201,163,90,.05);
  text-align: center;
  animation: modalIn .35s ease;
}
@keyframes modalIn {
  /* translateY を使うと、稀にアニメ開始フレームで止まった際に下方向へずれて
     結果表示が見切れる。縦移動は使わず opacity＋scale のみにする */
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: none; }
}
#modal h2 {
  font-family: "Shippori Mincho B1", serif;
  font-size: clamp(22px, 4cqmin, 34px);
  font-weight: 800;
  letter-spacing: .3em;
  color: var(--gold-bright);
  margin-bottom: 14px;
}
#modal .sub { color: var(--ink-dim); font-size: 13px; margin-bottom: 8px; }
/* 誰が誰からロンしたかを色分けして強調 */
#modal .sub.big { font-size: 17px; color: var(--ink); }
#modal .result-winner { color: var(--teal); font-weight: 700; }
#modal .result-loser { color: #ff8a75; font-weight: 700; }
#modal .result-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; margin: 12px 0; }
#modal .result-tiles .tile { width: clamp(30px, 4.2cqmin, 50px); }
#modal .result-tiles .tile.win-tile { outline: 2px solid var(--accent-red); outline-offset: 1px; }

/* 和了時、卓上で公開する手牌の中で「和了牌」を目立たせる */
.tile3d.win-tile-inline .tf-front {
  box-shadow: 0 0 .8cqmin .4cqmin rgba(255, 180, 60, .85), inset 0 0 .4cqmin rgba(255, 200, 100, .9);
  animation: winTilePulse 1.2s ease-in-out infinite;
}
@keyframes winTilePulse {
  0%, 100% { filter: brightness(1.05); }
  50%      { filter: brightness(1.35); }
}
#modal .dora-row { display: flex; justify-content: center; align-items: center; gap: 4px; margin: 8px 0; font-size: 12px; color: var(--ink-dim); }
#modal .dora-row .tile { width: clamp(20px, 2.8cqmin, 32px); }
#modal .note { font-size: 11px; color: var(--ink-dim); margin-top: 14px; }
#modal .yaku-list { max-width: 340px; margin: 12px auto 4px; }
#modal .yaku-line {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink);
  padding: 2px 8px;
  border-bottom: 1px dashed rgba(147,160,181,.25);
}
#modal .points-line {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 20px;
  color: var(--gold-bright);
  margin: 10px 0 4px;
}
#modal .score-lines { max-width: 340px; margin: 12px auto 0; }
#modal .score-line {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  font-size: 13px;
  color: var(--ink);
  padding: 3px 8px;
}
#modal .score-line .plus { color: var(--teal); }
#modal .score-line .minus { color: #ff8a75; }
#modal .score-line.standing {
  /* 1位/2位を並べたときにズレないよう、順位・名前・点数の3列を固定幅で揃える */
  grid-template-columns: 4em 1fr auto;
  font-size: 16px;
  padding: 6px 8px;
}
#modal .score-line.standing > span:first-child {
  font-weight: 800;
  color: var(--gold-bright);
  text-align: left;
}
#modal .score-line.standing > span:nth-child(2) { text-align: left; }
#modal .score-line.standing > span:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#modal button {
  margin-top: 18px;
  font-family: "Shippori Mincho B1", serif;
  font-size: 16px;
  letter-spacing: .25em;
  padding: 8px 34px;
  color: #10141f;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all .15s;
}
#modal button:hover { filter: brightness(1.1); box-shadow: 0 0 18px rgba(201,163,90,.5); }

/* ---------------- 待機画面：モード選択つき開始ボタン ---------------- */
#start-area { margin-top: 14px; }
.start-btns { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.start-btns .lobby-btn { flex: 1; max-width: 220px; }
#room-error { color: #ff8a75; font-size: 12px; min-height: 1.4em; margin-top: 10px; }

/* ---------------- 右側: 他家の副露パネル ---------------- */
#melds-panel {
  position: fixed;
  right: 12px;
  top: calc(env(safe-area-inset-top, 0px) + 14px + clamp(54px, 7.6cqmin, 94px) + 40px);
  width: min(320px, 24cqw);
  max-height: 44cqh;
  overflow-y: auto;
  z-index: 16;
  padding: 8px 10px;
  background: linear-gradient(160deg, rgba(30, 37, 58, .78), rgba(12, 16, 28, .78));
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  backdrop-filter: blur(4px);
}
#melds-panel.hidden { display: none; }
#melds-panel .mp-title {
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: .18em;
  margin-bottom: 6px;
}
.mp-player { margin-bottom: 8px; }
.mp-player:last-child { margin-bottom: 0; }
.mp-name { font-size: 13px; color: var(--teal); margin-bottom: 4px; }
.mp-meld { display: flex; align-items: center; gap: 3px; margin: 4px 0; }
.mp-meld .mp-type { font-size: 12px; color: var(--ink-dim); width: 44px; flex: none; }
.mp-meld .tile {
  width: 36px;
  border-bottom-width: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  border-radius: 3px;
}

/* PWA(ホーム画面追加)起動時のノッチ・ステータスバー回避 */
#topleft { top: calc(10px + env(safe-area-inset-top, 0px)); }
#topright { top: calc(14px + env(safe-area-inset-top, 0px)); }


/* ---------------- 鳴き確認のカード（牌の組み合わせ画像つき） ---------------- */
.call-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 6px 9px;
  background: linear-gradient(160deg, rgba(48, 60, 92, .92), rgba(20, 27, 45, .92));
  border: 1px solid rgba(120, 150, 210, .5);
  border-radius: 10px;
  cursor: pointer;
  transition: all .12s ease;
}
.call-opt:hover { border-color: var(--gold-bright); box-shadow: 0 0 14px rgba(201, 163, 90, .45); }
.call-opt .call-tiles { display: flex; gap: 2px; }
.call-opt .call-tiles .tile { width: clamp(17px, 2.3cqmin, 28px); } /* 50%縮小 */
.call-opt .call-opt-label {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .15em;
  color: var(--ink);
}
.call-opt.hot .call-opt-label { color: #ffb08a; text-shadow: 0 0 10px rgba(255, 120, 60, .6); }
.call-opt.hot { border-color: rgba(255, 130, 70, .8); }
.call-opt.cancel { opacity: .75; }
.call-opt.cancel .call-opt-label { color: var(--ink-dim); }

/* プレイヤーアイコンの顔画像（avatar.png。無ければ従来の漢字表示のまま） */
.avatar .avface {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------------- 補助線（?guide=1 で表示。位置合わせ用の卓上枠） ---------------- */

/* 鳴いた牌（相手から取った牌）：横向き・他の牌と同じ大きさで各面子の右端（末尾）。
   鳴いた牌は90°回転すると見た目の幅が牌の高さ(=1.39×)になる。
   CSSのflexは回転前(細いまま)の幅しか確保しないため、回転後の実寸ぶんの
   スロットで包み、面子へのめり込み・浮きを防ぐ（全牌フラットのまま） */
.omeld .called-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--t3w) * 1.39);
  transform-style: preserve-3d;
}
.omeld .called-slot .tile3d.called-tile {
  transform: translateZ(.26em) rotate(180deg) rotate(90deg);
  margin: 0;
}
#my-melds .meld .tile.called-tile {
  transform: rotate(90deg);
  margin: 0 calc(var(--tw-my) * .78 * .25);
  align-self: flex-end;
}

/* ============================================================
   スマホ画面：手牌・左右パネル・下部バーを画面に収まるよう縮小する
   （表示のみ。ルール・進行には影響しない）。
   ・縦持ちスマホ … max-width:600px
   ・横持ちスマホ … max-height:500px かつ max-width:**1000px**（低い高さに理/和/鳴/切が収まらない）
     ※950px だと **iPhone 16 Pro Max の横持ち(956x440)** が 6px 差で外れ、
       この端末だけ --tw-my の px 下限が効いて手牌が45%大きくなっていた
   ※ファイル末尾に置き、基準ルールをソース順で確実に上書きする。
   ============================================================ */
@media (max-width: 600px), (max-height: 500px) and (max-width: 1000px) {
  :root {
    /* 元の式 min(7.5cqmin,6cqw) は縦横どちらにも追従する。問題は下限48pxだけ
       だったので、下限を19pxに下げて手牌13枚＋ツモ牌が画面に収まるようにする。
       （縦持ちは幅6cqw、横持ちは高さ基準7.5cqmin が効く） */
    /* 上の小画面ブロックで一律10%縮めているので、こちらの中央値も .9 倍で揃える
       （下限19pxは「13枚＋ツモ牌が収まる」ための床なのでそのまま） */
    --tw-my: clamp(19px, min(7.425cqmin, 5.94cqw), 110.88px);   /* 中央値も10%増（下限19pxは13枚＋ツモ牌が収まる床なので据え置き） */
    /* 小画面は cqmin が数pxしかないので下限で決まる。24pxだと #topleft の
       縮小(.6)と合わさって実寸10px程度になり読めないため大きく引き上げる。
       #topleft 自体の縮小率は上げない（モード名の行が上家の手牌に被るため） */
    --tw-dora: clamp(36px, 4.76cqmin, 37px);   /* ドラ表示牌を15%小さく */
  }
  /* 左上：ドラ・モード名・捨て牌メーターを縮小し、左隣(上家)の手牌に被らない幅に収める */
  #topleft {
    transform: scale(.6);
    transform-origin: top left;
    gap: 4px;
  }
  /* 空きスロットは幅を食うだけなので小画面では隠す。そのぶん牌を大きくできる
     （ドラは通常1枚、カンで増えたときだけ横に伸びる） */
  #dora-tiles .dora-slot { display: none; }
  /* 鳴いた牌：小画面で潰れて読めなくならないよう下限を設ける（基準は手牌に統一）。
     下限・上限とも他と揃えて10%小さくした（24→21.6 / 60→54）。
     さらに **他家の手牌より大きくしない** よう min() で頭を押さえる。
     下限だけだと cqmin が小さい端末で「副露 > 手牌」になり、上家・下家の
     手牌に副露が乗ってしまう（実測 667x375 で 手牌19.6px に対し副露24px だった） */
  .omelds { --t3w: min(clamp(21.6px, calc(var(--tw-opp) * .92), 54px), var(--tw-opp)); }
  /* 各家アイコンを縮小（下限52px→小さく。名前プレートの文字も詰める） */
  .avatar {
    width: clamp(26px, 7.2cqmin, 112px);
    font-size: clamp(12px, 2.4cqmin, 36px);
    border-width: 1.5px;
  }
  .plate { font-size: 10px; padding: 2px 7px; gap: 4px; }
  .pwind { font-size: 12px; }
  /* 左：理/和/鳴/切のオートボタンを縮小（縦積みが画面高に収まるように）。
     上の小画面ブロックと同じく、さらに20%小さくした .48（.6 × .8） */
  #auto-panel {
    transform: translateY(-50%) scale(.48);
    transform-origin: left center;
    gap: 7px;
    padding: 10px 7px;
  }
  /* 右上アイコンも同率。origin: top right なので右上の角は動かない */
  #topright { transform: scale(.48); transform-origin: top right; gap: 7px; }
  /* 下部：長考タイマー。240px のままだとバーの左端が自分の名札(#seat-p0)に
     食い込むので、名札の右端より内側に収まる幅まで縮める。
     タイマーは #myzone の中央に「バー＋残り秒数」ごと寄せられるので、
     バー左端 ≒ 中央 − (バー幅 + 余白6 + 秒数16) / 2。
     名札の右端は 50cqw − 38.1cqmin + 名札幅/2 で、下の max-width で上限を固定してある。 */
  #turn-timer-bar { width: min(130px, 32cqw); }
  /* 名前が長いと名札が横に伸びてバーに届いてしまうため、スマホでは名前の幅を
     頭打ちにする（はみ出す分は…で省略）。CPU名は短いので実質は自分の名前だけ効く。
     ch だと全角名が7文字未満で切れるので em（全角1文字=1em）で指定する */
  .plate .pname {
    display: inline-block;
    max-width: 7em;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
  }
  /* 手牌の行：間隔を詰める（左寄せ位置は元の式＝卓の基準線に沿わせる） */
  #my-row { gap: clamp(3px, 1.4cqw, 12px); }
  #my-hand { gap: 2px; }
}

/* ============================================================
   和了結果（なにで上がったか）フルスクリーン表示 Figma 654-185
   設計フレーム 1920x1080。順位画面（#ranking）と同じステージ方式で、
   --u = 設計1px として中身を実寸で置く。
   重ね順は Figma と同じ「暗転した卓 → 赤い役背景 → 和了者の立ち絵 → 金の筆線 → 中身」。
   ============================================================ */
#winresult {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(14, 21, 34, .65);        /* Figma node654:187 */
  overflow: hidden; cursor: pointer;
  font-family: "BIZ UDPMincho", "Shippori Mincho B1", "Yu Mincho", serif;
  animation: wrFade .3s ease both;
}
#winresult.hidden { display: none; }
@keyframes wrFade { from { opacity: 0; } to { opacity: 1; } }

.wr-stage {
  --u: calc(min(100cqw, 177.7778cqh) / 1920);   /* 設計1px */
  /* 情報パーツ（ドラ/裏ドラ・手牌一覧・役・点数）だけの縮小率。
     背景と立ち絵は原寸のまま。小画面ではこのファイル末尾の @media で下げる */
  --wrs: 1;
  position: absolute; left: 50%; top: 50%;
  width: min(100cqw, 177.7778cqh);
  height: min(56.25cqw, 100cqh);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.wr-stage > * { position: absolute; }

/* 赤い役背景（Figma node654:183: 46,-16 1829x1097。縁がぼけていて卓が透ける） */
.wr-bg { left: calc(46 * var(--u)); top: calc(-16 * var(--u)); width: calc(1829 * var(--u)); height: calc(1097 * var(--u)); }
/* 和了者の立ち絵（node345:80: 104,88 630x992） */
.wr-char {
  left: calc(104 * var(--u)); top: calc(88 * var(--u));
  width: calc(630 * var(--u)); height: calc(992 * var(--u));
  object-fit: contain; object-position: bottom center;
  filter: drop-shadow(0 calc(8 * var(--u)) calc(24 * var(--u)) rgba(0, 0, 0, .5));
  user-select: none;
}
/* 金の筆線（node654:184: 159,669 1716x411）。立ち絵の上を横切る */
.wr-lines { left: calc(159 * var(--u)); top: calc(669 * var(--u)); width: calc(1716 * var(--u)); height: calc(411 * var(--u)); }

/* 16:9より横長の画面（横持ちスマホは 2:1 前後）では、設計フレームを contain した
   ぶん左右に余白ができ、そこに卓とHUDが覗いて画面が割れて見える。
   **背景（赤い役背景と金の筆線）だけ画面いっぱいに広げる**。
   中身（手牌・役・点数）は設計どおり16:9のステージ内に置いたままなので配置は崩れない */
@media (min-aspect-ratio: 1.8) {
  .wr-bg {
    left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 100cqw; height: 100cqh;
    object-fit: cover;
  }
  .wr-lines { left: 50%; transform: translateX(-50%); width: 100cqw; }
  /* 立ち絵も**画面の左端**へ寄せる。ステージ(16:9)基準のままだと横長画面では
     内側に取り残されて、役の一覧に重なって見える。
     ステージ左端から (ステージ幅 - 画面幅)/2 だけ戻すと画面の左端に着く */
  .wr-char { left: calc((177.7778cqh - 100cqw) / 2 + 20px); }
}

/* ---- ドラ / 裏ドラ（金の筆札＋4枠）---- */
/* 箱の基準は枠の上端(67)と筆札の左端。裏ドラは札が広いぶん枠が右にずれる */
/* --wrs で縮めるときは筆札の左端を軸にする（ドラ／裏ドラの間が空くだけで位置は動かない）*/
.wr-dora { top: calc(67 * var(--u)); height: calc(101 * var(--u));
  transform: scale(var(--wrs)); transform-origin: 0 50%; }
#wr-dora { left: calc(734 * var(--u));  --sx: 170; }
#wr-ura  { left: calc(1270 * var(--u)); --sx: 194; }
.wr-dora.hidden { display: none; }
.wr-dlabel {
  position: absolute; left: 0; top: calc(18 * var(--u));
  width: calc(205 * var(--u)); height: calc(80 * var(--u));
  display: flex; align-items: center; justify-content: center;
  background: url("../assets/setup/win-dora-brush.png") center/100% 100% no-repeat;
  font-size: calc(48 * var(--u)); font-weight: 700; color: #f5f5f5;
  white-space: nowrap;
  -webkit-text-stroke: calc(6 * var(--u)) #100c0c; paint-order: stroke fill;
}
.wr-slots {
  position: absolute; left: calc(var(--sx) * var(--u)); top: 0;
  display: flex; gap: calc(4 * var(--u));
}
/* 空枠と牌は同じ寸法。並びのピッチを崩さないので牌は枠いっぱいに入れる */
.wr-slots .dora-slot, .wr-slots .tile {
  width: calc(77 * var(--u)); height: calc(101 * var(--u)); flex: none;
}
.wr-slots .dora-slot {
  background: rgba(217, 217, 217, .4);
  border: calc(1.5 * var(--u)) solid #fff;
}

/* ---- 和了手牌（node345:81: 576,201 1252x140）---- */
.wr-hand {
  left: calc(576 * var(--u)); top: calc(201 * var(--u));
  width: calc(1252 * var(--u)); height: calc(140 * var(--u));
  box-sizing: border-box; padding: 0 calc(14 * var(--u));
  display: flex; gap: calc(14 * var(--u)); align-items: center; justify-content: center;
  background: rgba(27, 34, 53, .92);
  border: calc(3 * var(--u)) solid #8a9fb4;
  border-radius: calc(10 * var(--u));
  transform: scale(var(--wrs));   /* 中心を保ったまま縮む */
}
/* 牌数が多い手（カン・抜きドラ）は枠内で縮む。aspect-ratio が高さを追従させる */
.wr-hand .tile { width: calc(72 * var(--u)); flex: 0 1 auto; min-width: 0; }
.wr-hand .tile.win-tile { outline: calc(3 * var(--u)) solid var(--accent-red); outline-offset: calc(1 * var(--u)); }
.wr-hand .win-sep { width: calc(12 * var(--u)); flex: none; }

/* ---- 役の筆バナー ---- */
/* 1行 = 筆の外接箱 443.149x78.027。行の間隔 110.38（node345:84 → node345:88）。
   役が多い局は --ys で全体を縮めて点数の上に収める */
.wr-yaku {
  left: calc(632 * var(--u)); top: calc(420.89 * var(--u));
  width: calc(443.149 * var(--u));
  /* --ys は役が多い局の詰め（JS が設定）。--wrs は小画面用の縮小。掛け合わせる */
  transform: scale(calc(var(--ys, 1) * var(--wrs))); transform-origin: 0 0;
}
.wr-yline {
  position: absolute; left: 0; top: calc(var(--i) * var(--yp, 110.38) * var(--u));
  width: calc(443.149 * var(--u)); height: calc(78.027 * var(--u));
  animation: wrYakuIn .34s cubic-bezier(.34, 1.35, .5, 1) calc(var(--i) * .1s + .15s) both;
}
@keyframes wrYakuIn {
  from { opacity: 0; transform: scale(1.14); }
  to   { opacity: 1; transform: none; }
}
/* 筆は -2.13°、墨の飛沫は -9.09° 傾いている（Figma の rotate をそのまま） */
.wr-ybrush {
  position: absolute; left: 50%; top: 50%;
  width: calc(441.16 * var(--u)); height: calc(61.656 * var(--u));
  transform: translate(-50%, -50%) rotate(-2.13deg);
  background: url("../assets/setup/win-yaku-brush.png") center/100% 100% no-repeat;
}
.wr-ysplash {
  position: absolute; left: calc(367.3 * var(--u)); top: calc(12.2 * var(--u));
  width: calc(180.335 * var(--u)); height: calc(132.824 * var(--u));
  transform: translate(-50%, -50%) rotate(-9.09deg);
  background: url("../assets/result/win-han.png") center/contain no-repeat;
}
/* 役名は筆の右寄り（設計 x853）で右揃え。長い役名は showWinResult が --yn を下げる */
.wr-yname {
  position: absolute; right: calc(222 * var(--u)); top: calc(7.4 * var(--u));
  font-size: calc(var(--yn, 48) * var(--u)); font-weight: 700; line-height: 1;
  color: #f5f5f5; white-space: nowrap;
  text-shadow: 0 calc(2 * var(--u)) calc(6 * var(--u)) rgba(0, 0, 0, .85);
}
/* 翻数は飛沫の中央。飛沫は傾いているが数字は水平のまま */
.wr-yhan {
  position: absolute; left: calc(367.3 * var(--u)); top: calc(12.2 * var(--u));
  transform: translate(-50%, -50%);
  font-size: calc(var(--hf, 40) * var(--u)); font-weight: 700; line-height: 1;
  color: #f3d99d; white-space: nowrap;
  -webkit-text-stroke: calc(4 * var(--u)) #0d0a0a; paint-order: stroke fill;
}

/* ---- 符・翻・点数（node345:104: 652,788 64px）---- */
/* 点数だけは transform を使えない（wrScoreIn の終端が transform:none なので消える）。
   font-size と縁取りを --wrs 倍して縮める */
.wr-score {
  left: calc(652 * var(--u)); top: calc(788 * var(--u));
  font-size: calc(64 * var(--u) * var(--wrs)); font-weight: 700; line-height: 1;
  color: #f5f5f5; white-space: nowrap; letter-spacing: .02em;
  -webkit-text-stroke: calc(8 * var(--u) * var(--wrs)) #100c0c; paint-order: stroke fill;
  text-shadow: 0 calc(3 * var(--u)) calc(10 * var(--u)) rgba(0, 0, 0, .9);
  animation: wrScoreIn .4s cubic-bezier(.34, 1.35, .5, 1) .45s both;
}
@keyframes wrScoreIn {
  from { opacity: 0; transform: translateY(calc(14 * var(--u))); }
  to   { opacity: 1; transform: none; }
}
/* ダブロンのときだけ出す「誰の・何人目か」。点数の真上、同じ左端に揃える。
   1人和了では hidden なので Figma 654-185 の画は変わらない */
.wr-who {
  left: calc(652 * var(--u)); top: calc(724 * var(--u));
  font-size: calc(38 * var(--u) * var(--wrs)); font-weight: 700; line-height: 1;
  color: #f4c371; white-space: nowrap; letter-spacing: .06em;
  -webkit-text-stroke: calc(6 * var(--u) * var(--wrs)) #100c0c; paint-order: stroke fill;
  text-shadow: 0 calc(2 * var(--u)) calc(8 * var(--u)) rgba(0, 0, 0, .9);
  animation: wrScoreIn .4s cubic-bezier(.34, 1.35, .5, 1) .25s both;
}
.wr-who.hidden { display: none; }

.wr-tap {
  position: absolute; left: 50%; bottom: 1.5%; transform: translateX(-50%);
  color: rgba(255,255,255,.65); font-size: clamp(12px, 1.7cqmin, 18px);
  letter-spacing: .1em; animation: wrTapBlink 1.4s ease-in-out infinite;
}
@keyframes wrTapBlink { 0%,100% { opacity: .3; } 50% { opacity: .85; } }

/* 小画面では情報パーツ（ドラ／裏ドラ・手牌一覧・役・点数）だけ縮める。
   ステージ自体は 1920x1080 の contain スケールなので比率は変わらないが、
   小さい画面では立ち絵に対して情報が大きすぎて窮屈に見えるため。
   ※ .wr-stage の基準ルールより **後ろ** に置くこと（同じ詳細度なのでソース順で決まる） */
@media (max-width: 1138px), (max-height: 640px) {
  .wr-stage { --wrs: .82; }
}
@media (max-width: 600px), (max-height: 500px) and (max-width: 1000px) {
  .wr-stage { --wrs: .72; }
}

/* ============================================================
   局終了の点数移動 Figma 604-180
   ①支払う席→受け取る席へ矢印＋移動点 → ②各家に成績プレート
   座標は卓中心(50cqw, 42cqh)からの cqmin オフセットで、卓のレイアウトと同じ基準。
   ============================================================ */
#scoremove {
  position: fixed; inset: 0; z-index: 54;   /* 和了結果(55)の下・卓の上 */
  background: rgba(14, 21, 34, .65);        /* Figma node604:186 */
  cursor: pointer;
  font-family: "BIZ UDPMincho", "Shippori Mincho B1", "Yu Mincho", serif;
  animation: smFade .25s ease both;
}
#scoremove.hidden { display: none; }
@keyframes smFade { from { opacity: 0; } to { opacity: 1; } }

/* ---- ①点棒が動く向きの白い矢印（尾から先へ太くなる弓なり）---- */
#sm-arrows {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible; pointer-events: none;
}
/* Figma node617:169/193/203/209/210 は**縁も光もない白一色**。
   以前は黄色い縁と二段のにじみで光らせていたが、デザインと違うので落とした。
   暗い落ち影だけは残す（卓の白い牌の上を通っても輪郭が消えないように。
   背景を65%沈めてあるので、この程度でデザインの見え方と変わらない） */
.sm-arrow {
  fill: #fff;
  stroke: none;
  stroke-linejoin: round;
}
.sm-arrow-g {
  filter: drop-shadow(0 .2cqmin .6cqmin rgba(0, 0, 0, .45));
  animation: smArrowIn .3s cubic-bezier(.34, 1.4, .5, 1) var(--d) both;
}
@keyframes smArrowIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- ②各家の成績プレート（Figma node355:123 ほか）---- */
#sm-plates { position: absolute; inset: 0; pointer-events: none; }
.sm-plate {
  /* --u = デザイン1px。プレートは 454x236 で設計されている */
  --u: calc(42cqmin / 454);
  position: absolute;
  width: calc(454 * var(--u)); height: calc(236 * var(--u));
  transform: translate(-50%, -50%);
  background: url("../assets/result/plate.png") center/100% 100% no-repeat;
  filter: drop-shadow(0 calc(8 * var(--u)) calc(20 * var(--u)) rgba(0, 0, 0, .55));
  animation: smPlateIn .32s cubic-bezier(.34, 1.4, .5, 1) both;
}
@keyframes smPlateIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.72); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.sm-plate > * { position: absolute; }
/* 赤帯の名前（Figma node604:188: left54 / 32px / #f3d99d） */
.sm-name {
  left: calc(54 * var(--u)); top: calc(16 * var(--u));
  right: calc(160 * var(--u));
  font-size: calc(32 * var(--u)); line-height: 1; color: #f3d99d;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 右上に飛び出す金枠の顔（Figma node355:182: 145x145 / border4 #f4a323 / r3） */
.sm-face {
  left: calc(309 * var(--u)); top: calc(-62 * var(--u));
  width: calc(145 * var(--u)); height: calc(145 * var(--u));
  border: calc(4 * var(--u)) solid #f4a323;
  border-radius: calc(3 * var(--u));
  overflow: hidden; background: #1b1b1b;
}
.sm-face img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top; }
/* 増減点（Figma node355:146: 36px / 減 #d21f1d・増 #2cd21d） */
.sm-delta {
  left: calc(196 * var(--u)); right: calc(154 * var(--u));
  top: calc(76 * var(--u));
  font-size: calc(36 * var(--u)); line-height: 1;
  text-align: center; white-space: nowrap; color: #f3d99d;
}
.sm-delta.plus  { color: #2cd21d; }
.sm-delta.minus { color: #d21f1d; }
/* 増減なし（全員テンパイ・全員ノーテン・途中流局）。増減にも減にも寄せない中間色 */
.sm-delta.zero  { color: rgba(243, 217, 157, .65); }
/* 順位の筆バッジ（Figma node643:235/236/237/239。1位=金 2位=銀 3位=銅 4位=青の別素材）。
   素材ごとに高さが違う（1位・4位は数字が上に飛び出すぶん背が高い）ので、
   箱は一番大きいものに合わせ、**下端を揃えて** contain で収める。
   下端 = プレート下から41u（Figma実測: 1位42 / 2位41 / 3位41） */
.sm-rank {
  left: calc(20 * var(--u)); bottom: calc(41 * var(--u));
  width: calc(171 * var(--u)); height: calc(96 * var(--u));
  background: left bottom/contain no-repeat;
}
/* 局後の持ち点（Figma node355:169: 56px / #f3d99d） */
.sm-score {
  left: calc(196 * var(--u)); right: calc(16 * var(--u));
  top: calc(130 * var(--u));
  font-size: calc(56 * var(--u)); line-height: 1;
  text-align: center; white-space: nowrap; color: #f3d99d;
}
/* 移動点が着いて数え終わった瞬間の光り */
.sm-score.done { animation: smScoreHit .38s ease; }
@keyframes smScoreHit {
  40% { text-shadow: 0 0 calc(16 * var(--u)) rgba(255, 233, 168, .95); }
}
.sm-tap {
  position: absolute; left: 50%; bottom: 1.5%; transform: translateX(-50%);
  color: rgba(255, 255, 255, .65); font-size: clamp(12px, 1.7cqmin, 18px);
  letter-spacing: .1em; animation: wrTapBlink 1.4s ease-in-out infinite;
}

/* ============================================================
   サーバーから切断（参考画像）
   黒い靄の枠 ＋ 赤帯の見出し ＋ 本文 ＋ 右下のOK
   旧ロビーを出す代わりにこの画面で止める
   ============================================================ */
/* 全画面ボタンのアイコン差し替え。全画面中は「戻す」の絵にして、
   もう一度押せば元に戻ることを見て分かるようにする（body.fs-on は lobby.js が付ける） */
.ic-fs-out { display: none; }
body.fs-on .ic-fs-in { display: none; }
body.fs-on .ic-fs-out { display: block; }

/* ===== 縦持ちの案内（#rotate-hint）=====
   画面の向きはWebから強制できない。`screen.orientation.lock()` は全画面中の
   Android等しか効かず、iOS Safari には API 自体が無い。PWAとして入れたときだけ
   manifest の "orientation": "landscape" が効く。ブラウザで開いた縦持ちは
   これで案内する（タッチ端末の縦向きのときだけ出す。PCの細い窓では出さない）。
   #joining より前面に置いて、QRで開いた直後の縦持ちでも先にこれが出るようにする */
#rotate-hint { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate-hint {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    background: #120803;
    font-family: "BIZ UDPMincho", "Shippori Mincho B1", serif;
    color: #f2e5d1; text-align: center;
  }
}
.rh-box { padding: 0 28px; max-width: 22em; }
.rh-icon { width: 34vw; max-width: 180px; margin: 0 auto 6vh; }
/* 端末を回す動きをそのまま見せる。絵（横向きスマホ＋回転矢印のPNG）は
   **横向き＝ゴールの姿**なので、縦(90deg)から始めて横(0deg)へ回す。
   向きは絵の矢印に合わせて反時計回り（上の矢印が左・下が右を向いている）。
   最後に横のまま一度消してから縦へ戻す（回転で戻すと「縦にしろ」に見えるため、
   戻りは見せない）。 */
.rh-icon img { display: block; width: 100%; animation: rhTurn 3s ease-in-out infinite; transform-origin: 50% 50%; }
@keyframes rhTurn {
  0%, 18%  { transform: rotate(90deg); opacity: 1; }
  46%, 76% { transform: rotate(0deg); opacity: 1; }
  88%      { transform: rotate(0deg); opacity: 0; }
  89%      { transform: rotate(90deg); opacity: 0; }
  100%     { transform: rotate(90deg); opacity: 1; }
}
/* 動きを減らす設定の端末では回さずに、ゴールの姿（横）で止める */
@media (prefers-reduced-motion: reduce) {
  .rh-icon img { animation: none; }
}
.rh-title {
  font-size: clamp(18px, 5.4vw, 30px); font-weight: 800; letter-spacing: .06em; line-height: 1.5;
  color: #f4c371; text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
}
.rh-note {
  margin: 3vh 0 0;
  font-size: clamp(13px, 3.6vw, 20px); line-height: 1.8;
  color: rgba(242, 229, 209, .8);
}

/* ===== QR参加中カバー（#joining）=====
   ?room=CODE で開くとタイトルを即座に飛ばすので、部屋に入れるまでの数百ms、
   何も被っていない対局卓（＝旧UIに見える）が丸見えになっていた。その穴を塞ぐ。
   待機画面(setup-cpu)と同じ酒家の背景にして、画面が切り替わっても違和感が出ないようにする */
#joining {
  position: fixed; inset: 0; z-index: 95;
  display: flex; align-items: center; justify-content: center;
  background: #1a0d0a url("../assets/setup/scene-bg.png?v=3") center/cover no-repeat;
  font-family: "BIZ UDPMincho", "Shippori Mincho B1", serif;
  color: #f2e5d1;
}
#joining.hidden { display: none; }
/* 背景の情景を沈めて文字を読みやすくする */
#joining::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 70% 60% at 50% 50%, rgba(10, 5, 4, .55), rgba(6, 3, 2, .88) 85%);
}
.jn-box { position: relative; z-index: 1; text-align: center; padding: 0 24px; }
.jn-title {
  font-size: clamp(22px, 4.4vmin, 44px); font-weight: 800; letter-spacing: .1em;
  color: #f4c371; text-shadow: 0 2px 10px rgba(0, 0, 0, .85);
}
.jn-code {
  margin-top: 14px;
  font-size: clamp(14px, 2.4vmin, 24px); letter-spacing: .08em;
  color: rgba(242, 229, 209, .85);
}
/* 待っていることが分かる程度の控えめな三点。読み込みの重さを増やしたくないのでCSSだけ */
.jn-dots { margin-top: 22px; display: flex; gap: 10px; justify-content: center; }
.jn-dots i {
  width: 10px; height: 10px; border-radius: 50%;
  background: #f4c371; opacity: .25;
  animation: jnDot 1.2s ease-in-out infinite;
}
.jn-dots i:nth-child(2) { animation-delay: .2s; }
.jn-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes jnDot { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
/* 参加できなかったとき（部屋が無い・満員・対局中）はここに理由を出す。
   旧ロビーの #lobby-error は非表示なので、出しても誰にも見えない */
.jn-err {
  margin: 22px auto 0; max-width: 30em;
  font-size: clamp(13px, 2.2vmin, 22px); line-height: 1.7;
  color: #ffb3a0; text-shadow: 0 2px 8px rgba(0, 0, 0, .8);
}
.jn-back {
  margin-top: 20px; padding: 12px 28px;
  background: rgba(20, 12, 8, .82); border: 2px solid rgba(240, 195, 113, .8); border-radius: 8px;
  color: #f4c371; font-family: inherit; font-weight: 800; letter-spacing: .06em;
  font-size: clamp(14px, 2.2vmin, 22px); cursor: pointer;
}
.jn-back:hover { background: rgba(70, 30, 15, .9); }
.jn-back.hidden { display: none; }

#disconnect {
  position: fixed; inset: 0; z-index: 90;
  /* 真っ黒にせず、背後の卓がうっすら残る程度に沈める */
  background: rgba(4, 3, 3, .8);
  overflow: hidden;
  font-family: "Zen Kaku Gothic New", "Noto Sans JP", sans-serif;
  color: #fff;
}
#disconnect.hidden { display: none; }
/* 上下にうっすら残る情景の色。単色だと板に見えるので赤茶をにじませる */
#disconnect::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 75% 26% at 50% 0%,   rgba(104, 32, 22, .42), transparent 74%),
    radial-gradient(ellipse 85% 24% at 50% 100%, rgba(140, 60, 16, .38), transparent 76%),
    radial-gradient(ellipse 72% 62% at 50% 50%,  rgba(20, 11, 10, .55), rgba(0, 0, 0, .92) 82%);
}
/* 黒い靄の枠。四隅から内へもやもやと寄せ、ぼかしで境界を曖昧にする */
#disconnect::after {
  content: ""; position: absolute; inset: -10%; pointer-events: none;
  background:
    radial-gradient(ellipse 34% 40% at 0% 0%,     rgba(0, 0, 0, .95), transparent 68%),
    radial-gradient(ellipse 34% 40% at 100% 0%,   rgba(0, 0, 0, .95), transparent 68%),
    radial-gradient(ellipse 34% 40% at 0% 100%,   rgba(0, 0, 0, .95), transparent 68%),
    radial-gradient(ellipse 34% 40% at 100% 100%, rgba(0, 0, 0, .95), transparent 68%),
    radial-gradient(ellipse 56% 52% at 50% 50%, transparent 34%, rgba(0, 0, 0, .92) 78%, #000 100%);
  filter: blur(18px);
}

/* 赤帯（グランジ感を重ねた横断バー） */
.dc-band {
  position: absolute; left: 0; right: 0; top: 9%;
  height: 13%;
  z-index: 1;
  display: flex; align-items: center; justify-content: center;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .6), transparent 20%, transparent 78%, rgba(0, 0, 0, .6)),
    radial-gradient(ellipse 55% 130% at 50% 50%, #b71a1a, #6d0f11 68%, #360608 100%);
  box-shadow: inset 0 1px 0 rgba(255, 92, 74, .5), inset 0 -1px 0 rgba(255, 92, 74, .35);
}
/* 帯のすぐ下を走る明るい赤の細線 */
.dc-band::after {
  content: "";
  position: absolute; left: 3%; right: 3%; bottom: calc(-0.4cqmin);
  height: .28cqmin;
  background: linear-gradient(90deg, transparent, #ff5340 10%, #ff7a63 50%, #ff5340 90%, transparent);
  box-shadow: 0 0 1.2cqmin rgba(255, 80, 58, .85);
}
.dc-title {
  position: relative;
  font-size: clamp(20px, 4.6cqmin, 56px);
  font-weight: 500; letter-spacing: .1em;
  text-shadow: 0 .2cqmin 1cqmin rgba(0, 0, 0, .75);
}

/* 本文（エラーコード込み） */
.dc-body {
  position: absolute; left: 25%; right: 25%; top: 28%;
  margin: 0; z-index: 1;
  font-size: clamp(11px, 2.4cqmin, 27px); line-height: 1.7;
  color: #e6e2df;
  text-shadow: 0 .2cqmin .8cqmin rgba(0, 0, 0, .85);
}

/* 右下のOK。細い枠＋右端の赤いマーカー */
.dc-ok {
  position: absolute; right: 25%; top: 63%;
  width: clamp(120px, 24cqmin, 280px);
  height: clamp(22px, 4.2cqmin, 46px);
  padding: 0 1.4cqmin 0 0;
  z-index: 1;
  display: flex; align-items: center; justify-content: flex-end;
  background: linear-gradient(90deg, rgba(24, 20, 20, .1), rgba(54, 48, 47, .55));
  border: 1px solid rgba(214, 210, 206, .75);
  color: #fff;
  font-family: inherit;
  font-size: clamp(11px, 2.1cqmin, 24px); font-weight: 700; letter-spacing: .12em;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.dc-ok::after {
  content: "";
  position: absolute; right: -1px; top: 6%; bottom: 6%;
  width: .5cqmin; min-width: 3px;
  background: #d8322a;
  box-shadow: 0 0 1cqmin rgba(216, 50, 42, .9);
}
.dc-ok:hover { background: linear-gradient(90deg, rgba(70, 24, 20, .3), rgba(104, 34, 28, .6)); border-color: #fff; }
.dc-ok:active { transform: translateY(1px); }

/* ============================================================
   流局 Figma 617-220
   金の筆文字「流局」＋墨のにじみ。テンパイの席に「聴牌」を出す。
   座標は Figma フレーム(1920x1080)の実測を cqw/cqh 換算したもの
   （下地が実ゲームのスクリーンショットなので卓の配置と一致する）
   ============================================================ */
#ryuukyoku {
  position: fixed; inset: 0; z-index: 46;   /* 役名バナー(45)より前・結果モーダル(50)より後ろ */
  background: rgba(14, 21, 34, .55);        /* Figma node617:222。倒した手牌が読める程度に薄める */
  pointer-events: none;
  animation: rkFade .3s ease both;
}
#ryuukyoku.hidden { display: none; }
@keyframes rkFade { from { opacity: 0; } to { opacity: 1; } }

/* 墨のにじみ（筆文字の下に敷く） */
.rk-ink {
  position: absolute;
  left: 52.9cqw; top: 60.6cqh;
  width: 57.3cqmin; height: 8.1cqmin;
  transform: translate(-50%, -50%);
  opacity: .85;
  animation: rkInk .45s cubic-bezier(.2, .9, .3, 1) both;
}
@keyframes rkInk {
  from { opacity: 0; transform: translate(-50%, -50%) scaleX(.4); }
  to   { opacity: .85; transform: translate(-50%, -50%) scaleX(1); }
}
/* 筆文字「流局」 */
.rk-brush {
  position: absolute;
  left: 50cqw; top: 50cqh;
  width: 46.2cqmin; height: 24.7cqmin;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 .6cqmin 1.4cqmin rgba(0, 0, 0, .65));
  animation: rkBrush .5s cubic-bezier(.2, 1.3, .35, 1) .1s both;
}
@keyframes rkBrush {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* 各席の「聴牌」（Figma node624:186 ほか。48px / #e9ac37） */
.rk-tenpai {
  position: absolute;
  font-family: "BIZ UDPMincho", "Shippori Mincho B1", "Yu Mincho", serif;
  font-weight: 800;
  font-size: 4.44cqmin;
  letter-spacing: .04em;
  color: #e9ac37;
  white-space: nowrap;
  text-shadow: 0 .2cqmin .7cqmin rgba(0, 0, 0, .9), 0 0 1.4cqmin rgba(233, 172, 55, .5);
  animation: rkTenpai .32s cubic-bezier(.34, 1.4, .5, 1) var(--d, .35s) both;
}
.rk-tenpai.hidden { display: none; }
@keyframes rkTenpai {
  from { opacity: 0; transform: translateY(.8cqmin) scale(.85); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* 表示席ごとの位置（0=自分/下 1=下家/右 2=対面/上 3=上家/左） */
.rk-tenpai[data-seat="0"] { left: 34.5cqw; top: 74.4cqh; }
.rk-tenpai[data-seat="1"] { left: 70.4cqw; top: 27.7cqh; }
.rk-tenpai[data-seat="2"] { left: 48.0cqw; top:  8.7cqh; }
.rk-tenpai[data-seat="3"] { left: 26.1cqw; top: 20.7cqh; }

/* ============================================================
   終局の順位画面 Figma 638-184（自分が1位）/ 653-303（自分が2位）
   設計フレーム 1920x1080 をそのまま持ち込む。--u = 設計1px。
   卓（#app）に contain で収まる 16:9 のステージを敷き、中は実寸で置く。
   （#ryuukyoku のように x を cqw にすると、卓が横長のときに菱形とプレートが
     離れてしまう。1行がひとかたまりの絵なのでステージ方式にしてある）

   ・1位だけプレート・顔・点数が大きい。2〜4位は同じ大きさ（--l/--t/… で切替）
   ・自分の行はプレートも菱形も赤、他家は紺。赤と紺は同じ絵の色違いで
     PNGのcanvasも同寸なので、色に関係なく同じ箱に置ける
   ・順位バッジ（筆＋数字＋位）は 1〜4位で別素材。菱形の中央に置く
   ============================================================ */
#ranking {
  position: fixed; inset: 0; z-index: 56;   /* 和了結果(55)より前 */
  background: rgba(14, 21, 34, .65);        /* Figma node638:186 */
  overflow: hidden; cursor: pointer;
  font-family: "BIZ UDPMincho", "Shippori Mincho B1", "Yu Mincho", serif;
  animation: rankFade .3s ease both;
}
#ranking.hidden { display: none; }
@keyframes rankFade { from { opacity: 0; } to { opacity: 1; } }

/* 設計フレームを contain で収める。1920x1080 より横長なら左右が余る */
.rank-stage {
  --u: calc(min(100cqw, 177.7778cqh) / 1920);   /* 設計1px */
  position: absolute; left: 50%; top: 50%;
  width: min(100cqw, 177.7778cqh);
  height: min(56.25cqw, 100cqh);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* 自分のキャラ立ち絵（Figma node653:275: 108,51 654x1029） */
.rank-char {
  position: absolute;
  left: calc(108 * var(--u)); top: calc(51 * var(--u));
  width: calc(654 * var(--u)); height: calc(1029 * var(--u));
  object-fit: contain; object-position: bottom center;
  filter: drop-shadow(0 calc(8 * var(--u)) calc(24 * var(--u)) rgba(0, 0, 0, .5));
  user-select: none;
  animation: rankCharIn .5s cubic-bezier(.2, .9, .3, 1) both;
}
@keyframes rankCharIn {
  from { opacity: 0; transform: translateX(calc(-40 * var(--u))); }
  to   { opacity: 1; transform: none; }
}

/* ---- 1行ぶん。箱＝プレートの矩形で、中身はそこからの相対位置 ---- */
.rank-row {
  position: absolute;
  left: calc(var(--l) * var(--u)); top: calc(var(--t) * var(--u));
  width: calc(var(--w) * var(--u)); height: calc(var(--h) * var(--u));
  animation: rankRowIn .42s cubic-bezier(.34, 1.3, .5, 1) var(--d, 0s) both;
}
@keyframes rankRowIn {
  from { opacity: 0; transform: translateX(calc(80 * var(--u))); }
  to   { opacity: 1; transform: none; }
}
/* 位置と寸法は Figma 実測。1位だけ別枠で、2〜4位は同じ寸法を下へずらすだけ */
.rank-row[data-rank="1"] {
  --l: 820; --t: 147; --w: 942; --h: 207;
  --fx: 34; --fr: 207;                /* 菱形の中心x（箱からの相対）と一辺 */
  --ax: 151; --aw: 139; --ah: 138;    /* 顔 */
  --nx: 312; --ny: 40;  --nf: 32;     /* 名前 */
  --sx: 402; --sy: 90;  --sf: 72;     /* 持ち点 */
}
.rank-row[data-rank="2"] { --l: 910;  --t: 389; }
.rank-row[data-rank="3"] { --l: 971;  --t: 586; }
.rank-row[data-rank="4"] { --l: 1028; --t: 786; }
.rank-row[data-rank="2"], .rank-row[data-rank="3"], .rank-row[data-rank="4"] {
  --w: 723; --h: 159;
  --fx: 4;   --fr: 200;
  --ax: 120; --aw: 104; --ah: 103;
  --nx: 252; --ny: 20;  --nf: 32;
  --sx: 346; --sy: 65;  --sf: 64;
}

/* プレート（Figma「ランキング表示」。自分の行は赤い色違い） */
.rank-plate {
  position: absolute; inset: 0;
  background: url("../assets/rank/plate.png") center/100% 100% no-repeat;
  filter: drop-shadow(0 calc(6 * var(--u)) calc(18 * var(--u)) rgba(0, 0, 0, .5));
}
.rank-row.self .rank-plate {
  background-image: url("../assets/rank/plate-self.png");
  filter: drop-shadow(0 calc(6 * var(--u)) calc(18 * var(--u)) rgba(0, 0, 0, .5))
          drop-shadow(0 0 calc(14 * var(--u)) rgba(255, 120, 70, .35));
}

/* 順位の菱形（Figma「ランキング小枠青」/ 自分は「image 17」の赤）。
   プレートの左端にまたがるので、中心xは箱の左端のすぐ内側 */
.rank-frame {
  position: absolute;
  left: calc(var(--fx) * var(--u)); top: 50%;
  width: calc(var(--fr) * var(--u)); height: calc(var(--fr) * var(--u));
  transform: translate(-50%, -50%);
  background: url("../assets/rank/frame.png") center/contain no-repeat;
  filter: drop-shadow(0 calc(4 * var(--u)) calc(12 * var(--u)) rgba(0, 0, 0, .55));
}
.rank-row.self .rank-frame { background-image: url("../assets/rank/frame-self.png"); }

/* 「1位」〜「4位」の筆バッジ（筆・数字・位を1枚に焼いた素材）。菱形の中央 */
.rank-badge {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--bw) * var(--u)); height: calc(var(--bh) * var(--u));
  transform: translate(-50%, -50%);
  background: center/contain no-repeat;
}
.rank-row[data-rank="1"] .rank-badge { --bw: 127.95; --bh: 71.84; background-image: url("../assets/rank/badge1.png"); }
.rank-row[data-rank="2"] .rank-badge { --bw: 122.32; --bh: 62.24; background-image: url("../assets/rank/badge2.png"); }
.rank-row[data-rank="3"] .rank-badge { --bw: 123.03; --bh: 62.96; background-image: url("../assets/rank/badge3.png"); }
.rank-row[data-rank="4"] .rank-badge { --bw: 122.33; --bh: 68.67; background-image: url("../assets/rank/badge4.png"); }

/* 顔（Figma node653:276 ほか: border4 #f4a323 / r3）。素材の白フチがそのまま額になる */
.rank-face {
  position: absolute;
  left: calc(var(--ax) * var(--u)); top: 50%;
  width: calc(var(--aw) * var(--u)); height: calc(var(--ah) * var(--u));
  transform: translateY(-50%);
  box-sizing: border-box;
  border: calc(4 * var(--u)) solid #f4a323;
  border-radius: calc(3 * var(--u));
  overflow: hidden; background: #fff;
}
.rank-face img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top; }

/* 名前（32px #f3d99d）と持ち点（1位72px / 他64px）。
   Figma のテキスト枠の上端をそのまま top にしている */
.rank-name, .rank-score {
  position: absolute;
  /* Figma は BIZ UDPMincho Bold。BIZ UDPMincho が入っていない環境では
     Google Fonts の Shippori Mincho B1（600/800のみ読み込み）に落ちるので、
     700 を指定して太い方＝800 を拾わせる */
  font-weight: 700;
  line-height: 1; color: #f3d99d; white-space: nowrap;
  text-shadow: 0 calc(2 * var(--u)) calc(6 * var(--u)) rgba(0, 0, 0, .55);
}
.rank-name {
  left: calc(var(--nx) * var(--u)); top: calc(var(--ny) * var(--u));
  font-size: calc(var(--nf) * var(--u));
  max-width: calc((var(--w) - var(--nx) - 56) * var(--u));
  overflow: hidden; text-overflow: ellipsis;
}
.rank-score {
  left: calc(var(--sx) * var(--u)); top: calc(var(--sy) * var(--u));
  font-size: calc(var(--sf) * var(--u));
}

.rank-tap {
  position: absolute; left: 50%; bottom: 1.5%; transform: translateX(-50%);
  color: rgba(255, 255, 255, .65); font-size: clamp(12px, 1.7cqmin, 18px);
  letter-spacing: .1em; animation: wrTapBlink 1.4s ease-in-out infinite;
}
