:root {
  --felt: #0d5c3b;
  --felt-dark: #0a4a30;
  --gold: #e7c96b;
  --ivory: #f7f1dd;
  --tw-hand: 42px;
  --tw-river: 26px;
  --tw-opp: 22px;
  --tw-meld: 26px;
  --tw-dora: 28px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', system-ui, sans-serif;
  background: #072418; color: #f7f1dd;
  overflow: hidden; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  overscroll-behavior: none;
}
#app { height: 100%; height: 100dvh; }
.hidden { display: none !important; }

/* ===== 牌 ===== */
.tile {
  display: inline-block; width: var(--tw); vertical-align: bottom; line-height: 0;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.4));
  transition: transform .12s ease;
}
.tile img { width: 100%; height: auto; display: block; aspect-ratio: 300 / 420; }
.tile.selectable { cursor: pointer; }
.hand-tile.selectable:hover { transform: translateY(-10px); }
.hand-tile.drawn { margin-left: 2px; }
.tile.disabled { opacity: .45; pointer-events: none; }
.tile.riichi-candidate { animation: glow 1s ease-in-out infinite alternate; cursor: pointer; }
@keyframes glow { from { filter: drop-shadow(0 0 1px #ffd94a); } to { filter: drop-shadow(0 0 8px #ffd94a) drop-shadow(0 0 3px #ffb300); } }
.tile.dim { opacity: .6; }
.river-tile.called { opacity: .35; }

/* ===== 設定画面 ===== */
#settings-screen {
  height: 100%; overflow-y: auto;
  background:
    radial-gradient(circle at 50% -10%, #147a4f 0%, var(--felt) 40%, var(--felt-dark) 100%);
  padding: 24px 14px 60px;
}
.settings-panel { max-width: 780px; margin: 0 auto; }
.title { text-align: center; font-size: 34px; margin: 10px 0 4px; letter-spacing: 2px;
  text-shadow: 0 2px 0 #063; }
.subtitle { display: block; font-size: 14px; color: var(--gold); letter-spacing: 1px; margin-top: 4px; }
.opt-section {
  background: rgba(0,0,0,.22); border: 1px solid rgba(231,201,107,.25);
  border-radius: 14px; padding: 14px 16px; margin: 14px 0;
}
.opt-title { margin: 0 0 10px; font-size: 17px; color: var(--gold); border-left: 4px solid var(--gold); padding-left: 8px; }
.cheat-section { border-color: #e07b7b66; background: rgba(80,0,0,.22); }
.cheat-section .opt-title { color: #ff9d9d; border-color: #ff6b6b; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 14px; }

/* ローカル役アコーディオン */
.localyaku-section .opt-title { color: #9fe0b0; border-color: #6bd39a; }
.accordion { margin-top: 8px; }
.accordion-head {
  width: 100%; text-align: left; cursor: pointer;
  background: rgba(0,0,0,.28); color: #d7f5e2;
  border: 1px solid rgba(107,211,154,.35); border-radius: 10px;
  padding: 9px 12px; font-size: 14px; font-weight: 600;
}
.accordion-head:hover { background: rgba(107,211,154,.14); }
.accordion-body { margin-top: 10px; }
.accordion-body.hidden { display: none; }
.accordion-body.disabled { opacity: .4; pointer-events: none; }
.localyaku-tools { display: flex; gap: 8px; margin-bottom: 8px; }
.mini-btn {
  cursor: pointer; font-size: 12px; padding: 4px 12px; border-radius: 999px;
  background: rgba(107,211,154,.16); color: #d7f5e2;
  border: 1px solid rgba(107,211,154,.4);
}
.mini-btn:hover { background: rgba(107,211,154,.3); }
.mini-btn:disabled { opacity: .4; cursor: default; }
.localyaku-grid { grid-template-columns: 1fr; }
.localyaku-grid .opt-check { font-size: 13px; line-height: 1.3; align-items: flex-start; }
.localyaku-grid .opt-check input { margin-top: 2px; flex: 0 0 auto; }
.opt-check { display: flex; align-items: center; gap: 8px; padding: 5px 4px; cursor: pointer; font-size: 14px; }
.opt-check input { width: 18px; height: 18px; accent-color: var(--gold); }
.opt-select {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin: 0;
  padding: 8px 10px; background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.08); border-radius: 10px;
}
.opt-label { font-size: 13px; opacity: .95; line-height: 1.25; }
.opt-select select {
  width: 100%; padding: 7px 8px; border-radius: 8px; border: 1px solid #ffffff44;
  background: #0a3f2a; color: #fff; font-size: 14px;
}
.radio-grp { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-btn {
  padding: 7px 16px; border-radius: 20px; border: 1px solid #ffffff55;
  background: transparent; color: #fff; cursor: pointer; font-size: 14px;
}
.radio-btn.on { background: var(--gold); color: #063; border-color: var(--gold); font-weight: 700; }
.start-btn {
  display: block; width: 100%; margin: 22px auto 8px; padding: 16px;
  font-size: 20px; font-weight: 800; letter-spacing: 4px;
  background: linear-gradient(180deg, #ffde7a, #e7b93b); color: #5a3d00;
  border: none; border-radius: 14px; cursor: pointer;
  box-shadow: 0 4px 0 #a97e1a, 0 8px 18px rgba(0,0,0,.4);
}
.start-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a97e1a; }
.back-btn {
  display: block; width: 100%; margin: 8px auto 4px; padding: 12px;
  font-size: 15px; font-weight: 700; letter-spacing: 2px;
  background: rgba(255,255,255,.08); color: var(--ivory, #f4efe2);
  border: 1px solid rgba(255,255,255,.28); border-radius: 12px; cursor: pointer;
}
.back-btn:active { transform: translateY(2px); }
.note { font-size: 12px; color: #cbe6d5; text-align: center; line-height: 1.6; }

/* ===== 卓 ===== */
#game-screen { height: 100%; height: 100dvh; max-height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  background: radial-gradient(circle at 50% 45%, #16714a 0%, var(--felt) 55%, var(--felt-dark) 100%); }
#table {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 130px;
  grid-template-rows: 120px 1fr 200px;
  gap: 4px; padding: 8px;
  min-height: 0;
}
.seat { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
.seat-top    { grid-column: 2; grid-row: 1; transform: rotate(180deg); }
.seat-bottom { grid-column: 2; grid-row: 3; }
.seat-left   { grid-column: 1; grid-row: 2; }
.seat-right  { grid-column: 3; grid-row: 2; }
/* 左右席は「席まるごと」を1単位で回転する。子要素を個別に回すと回転後も
   レイアウト箱が横並びのままになり、席情報と手牌が重なってしまうため。 */
.seat-left  { transform: rotate(90deg); }
.seat-right { transform: rotate(-90deg); }
.seat-left, .seat-right { overflow: visible; }
.seat-left .hand-melds, .seat-right .hand-melds { align-items: center; }
/* 中央: 情報ボックス + 4家の河 */
#center {
  grid-column: 2; grid-row: 2; align-self: center; justify-self: stretch;
  display: grid;
  grid-template-columns: 1fr auto 1fr;   /* 中央ボックスを必ずビューポート中央に固定 */
  grid-template-rows: auto auto auto;
  align-items: center; justify-items: center;
  gap: 4px 8px;
}
.slot-top    { grid-column: 2; grid-row: 1; }
.slot-left   { grid-column: 1; grid-row: 2; justify-self: end; }   /* 河は中央ボックス側へ寄せ、はみ出しは外側へ対称に */
.slot-center { grid-column: 2; grid-row: 2; }
.slot-right  { grid-column: 3; grid-row: 2; justify-self: start; }
.slot-bottom { grid-column: 2; grid-row: 3; }
.pond-slot { display: flex; align-items: center; justify-content: center; }

/* 河（捨て牌）: 全ポンドを同一レイアウトで組む＝上向きプレイヤー視点で
   「左→右・1段目→2段目」に6枚並び、以降下へ折り返す。
   その塊(コンテナ)を席の角度でまるごと回転させて各家の向きにする。
   各牌は逆回転で正立に戻す。リーチ牌は読み方向に幅を確保して重なり防止。 */
.pond { display: flex; gap: 2px; }
.pond .tile { --tw: var(--tw-river); }
.pond .river-tile {
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: var(--tw-river); height: calc(var(--tw-river) * 1.4);
}
.pond .river-tile img { width: var(--tw-river); height: auto; display: block; }
.pond .river-tile.called { opacity: .38; }
.pond-left, .pond-right { align-items: flex-start; }

/* 自分(手前): 正立。横6枚→下へ折り返し。リーチ牌は横倒し(90°)。 */
.pond-bottom {
  flex-flow: row wrap; align-content: flex-start;
  width: calc(var(--tw-river) * 6 + 10px);
}
.pond-bottom .river-tile.riichi-tile { width: calc(var(--tw-river) * 1.4); }
.pond-bottom .river-tile.riichi-tile img { transform: rotate(90deg); }

/* 対面(上): 塊ごと180°回転（footprintは不変）。牌も対面向き=上下逆。 */
.pond-top {
  flex-flow: row wrap; align-content: flex-start;
  width: calc(var(--tw-river) * 6 + 10px);
  transform: rotate(180deg);
}
.pond-top .river-tile.riichi-tile { width: calc(var(--tw-river) * 1.4); }
.pond-top .river-tile.riichi-tile img { transform: rotate(90deg); }

/* 上家(左)/下家(右): 各牌を90°回して各家へ向ける（牌箱は横長）。
   縦に6枚積み、列は中央方向へ折り返す＝footprintが細い。 */
.pond-left .river-tile, .pond-right .river-tile {
  width: calc(var(--tw-river) * 1.4); height: var(--tw-river);
}
.pond-left  { flex-flow: column wrap-reverse; align-content: flex-start; height: calc(var(--tw-river) * 6 + 10px); }
.pond-right { flex-flow: column-reverse wrap; align-content: flex-start; height: calc(var(--tw-river) * 6 + 10px); }
.pond-left  .river-tile img { transform: rotate(90deg); }
.pond-right .river-tile img { transform: rotate(-90deg); }
/* リーチ牌: 隣と90°違い＝正立。牌箱は縦長に戻す。 */
.pond-left .river-tile.riichi-tile, .pond-right .river-tile.riichi-tile {
  width: var(--tw-river); height: calc(var(--tw-river) * 1.4);
}
.pond-left .river-tile.riichi-tile img, .pond-right .river-tile.riichi-tile img { transform: rotate(0deg); }

/* 鳴ける捨て牌の点滅（ポン・チー・カン・ロン対象を光らせる） */
.pond .river-tile.call-target { animation: call-blink .7s ease-in-out infinite; z-index: 5; position: relative; }
@keyframes call-blink {
  0%,100% { filter: drop-shadow(0 0 2px #ffdf5a) brightness(1); }
  50%     { filter: drop-shadow(0 0 11px #ffdf5a) drop-shadow(0 0 5px #ff9d00) brightness(1.25); }
}
/* 各スロットの最小サイズ確保（河が空でもレイアウトを安定） */
.slot-top, .slot-bottom { min-height: calc(var(--tw-river) * 1.4 * 3); }
.slot-left, .slot-right { min-width: calc(var(--tw-river) * 2); }

/* 席情報 */
.seat-info { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 2px 0;
  background: rgba(0,0,0,.35); padding: 3px 9px; border-radius: 12px; white-space: nowrap; }
.wind-badge { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center;
  background: #2b6; color: #042; border-radius: 50%; font-weight: 800; font-size: 13px; }
.wind-badge.oya { background: var(--gold); color: #630; }
.pname { color: #dfeee6; }
.pts { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.badge-oya { background: #d33; color: #fff; border-radius: 6px; padding: 0 5px; font-size: 11px; }

/* 手牌・鳴き・河 */
.hand-melds { display: flex; align-items: flex-end; gap: 8px; flex-wrap: nowrap; }
.hand-area { display: flex; align-items: flex-end; }
/* 自席テンパイ時の待ち牌表示（自分だけ） */
.wait-holder { display: flex; justify-content: center; }
.wait-row { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; margin: 0 0 3px;
  background: rgba(0,0,0,.42); border: 1px solid var(--gold); border-radius: 999px; }
.wait-label { color: var(--gold); font-size: 12px; font-weight: 700; margin-right: 2px; }
.wait-tile { --tw: 22px; }
.wait-tile img { width: 22px; height: auto; display: block; }
.seat-bottom .hand-area .tile { --tw: var(--tw-hand); }
.seat-bottom .hand-area { margin-bottom: 2px; }
.seat-top .hand-area .tile, .seat-left .hand-area .tile, .seat-right .hand-area .tile { --tw: var(--tw-opp); }
.tsumo-gap { width: 12px; } .tsumo-gap-sm { width: 6px; }
/* ツモ牌が無い13枚形でも右端に牌1枚分の空きを確保（手牌がツモ位置からズレないように） */
.hand-drawslot { width: var(--tw-hand); flex: 0 0 auto; }

.melds-area { display: flex; gap: 4px; align-items: flex-end; }
.meld { display: flex; align-items: flex-end; }
.meld .tile { --tw: var(--tw-meld); }
.meld-tile.rotated { transform: rotate(90deg); margin: 0 5px; }
.kita { font-size: 11px; background: rgba(0,0,0,.4); padding: 2px 6px; border-radius: 8px; align-self: center; }

/* 中央 */
.center-box { background: rgba(0,0,0,.45); border: 1px solid var(--gold); border-radius: 12px;
  padding: 10px 14px; text-align: center; min-width: 170px; }
.round-name { font-size: 17px; font-weight: 800; color: var(--gold); letter-spacing: 1px; }
.center-sub { display: flex; justify-content: center; gap: 14px; font-size: 12px; margin: 4px 0 8px; color: #cfe; }
.center-sub b { color: #fff; font-size: 14px; }
.dora-row { display: flex; align-items: center; justify-content: center; gap: 3px; }
.dora-tiles { display: flex; align-items: center; gap: 3px; }
.dora-label { font-size: 11px; color: var(--gold); margin-right: 4px; }
.dora-tile { --tw: var(--tw-dora); }

.riichi-bar { width: 46px; height: 6px; background: #fff; border-radius: 3px; position: relative; margin: 2px auto; }
.riichi-bar::after { content: ''; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px;
  transform: translate(-50%,-50%); background: #d33; border-radius: 50%; }

/* アクションバー（高さ固定＝盤面サイズを変えない） */
#action-bar { flex: 0 0 132px; height: 132px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 8px; background: rgba(0,0,0,.35);
  border-top: 1px solid rgba(231,201,107,.25); }
.act-hint { font-size: 13px; color: var(--gold); }
.act-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.act-btn { padding: 12px 22px; font-size: 16px; font-weight: 700; border: none; border-radius: 12px;
  cursor: pointer; background: #2a6; color: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.act-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.act-btn.primary { background: linear-gradient(180deg,#ff6b6b,#e23b3b); }
.act-btn.accent { background: linear-gradient(180deg,#ffd166,#e0a800); color: #5a3d00; }
.act-btn.ghost { background: #35564a; }

/* 盤面右上の「自動ツモ」チェック */
#auto-draw-toggle.board-check {
  position: absolute; top: 8px; right: 10px; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 10px; cursor: pointer;
  background: rgba(0,0,0,.4); border: 1px solid rgba(231,201,107,.3);
  color: #f1e6c0; font-size: 13px; font-weight: 700; user-select: none;
}
#auto-draw-toggle.board-check input { width: 16px; height: 16px; accent-color: #3fae1e; cursor: pointer; }
#auto-draw-toggle.board-check:hover { background: rgba(0,0,0,.55); }

/* 盤面の「やめる」ボタン＝左上（退出） */
.board-leave {
  position: absolute; top: 8px; left: 10px; z-index: 21;
  padding: 7px 12px; border-radius: 10px; cursor: pointer;
  background: rgba(120,20,20,.62); border: 1px solid rgba(255,140,140,.45);
  color: #ffe3e3; font-size: 13px; font-weight: 800; line-height: 1; user-select: none;
  transition: background .15s, transform .1s;
}
.board-leave:hover { background: rgba(150,26,26,.8); }
.board-leave:active { transform: translateY(1px) scale(.97); }

/* 盤面の設定(歯車)ボタン＝「やめる」の右隣 */
.board-gear {
  position: absolute; top: 8px; left: 82px; z-index: 20;
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  background: rgba(0,0,0,.42); border: 1px solid rgba(231,201,107,.35);
  color: #f1e6c0; font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: transform .25s ease, background .15s;
}
.board-gear:hover { background: rgba(0,0,0,.62); transform: rotate(45deg); }
.board-gear:active { transform: rotate(90deg) scale(.94); }

/* チート即時変更パネル（盤面オーバーレイ） */
.cheat-overlay {
  position: absolute; inset: 0; z-index: 45; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 10px; overflow: auto;
}
.cheat-overlay.hidden { display: none; }
.cheat-box {
  background: #14261c; color: #eafff2;
  border: 1px solid rgba(231,201,107,.3); border-radius: 14px;
  padding: 8px 14px 14px; width: min(420px, 94%);
  max-height: calc(100% - 12px); overflow: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,.55);
}
.cheat-head { display: flex; justify-content: flex-end; align-items: center; min-height: 22px; }
.cheat-close {
  background: none; border: none; color: #eafff2; font-size: 18px; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px;
}
.cheat-close:hover { background: rgba(255,255,255,.12); }
.cheat-box .opt-section { margin: 0; }
.cheat-note { font-size: 11px; opacity: .7; margin: 10px 2px 0; line-height: 1.4; }
.act-btn.guguu { background: linear-gradient(180deg,#8fe34a,#3fae1e); color: #123d05;
  text-shadow: 0 1px 0 rgba(255,255,255,.35); box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 14px rgba(120,220,80,.55);
  animation: guguu-pulse 1s ease-in-out infinite; }
@keyframes guguu-pulse {
  0%,100% { box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 10px rgba(120,220,80,.45); }
  50%     { box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 20px rgba(150,240,90,.85); }
}

/* フラッシュ */
.call-flash { position: absolute; font-size: 34px; font-weight: 900; color: #fff;
  text-shadow: 0 0 10px #000, 0 0 20px #ff0; pointer-events: none; z-index: 30;
  animation: pop .9s ease-out forwards; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 30% { transform: scale(1.2); opacity: 1; } 100% { transform: scale(1); opacity: 0; } }
.seat-flash-bottom { bottom: 210px; left: 50%; margin-left: -40px; }
.seat-flash-top { top: 120px; left: 50%; margin-left: -40px; }
.seat-flash-left { left: 140px; top: 50%; }
.seat-flash-right { right: 140px; top: 50%; }

/* オーバーレイ */
#overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); z-index: 50; }
#overlay.visible { display: flex; }
.overlay-box { background: linear-gradient(180deg,#0e6b46,#0a4a30); border: 2px solid var(--gold);
  border-radius: 18px; padding: 24px 28px; min-width: 320px; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.6); animation: rise .3s ease; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.overlay-box h2 { margin: 0 0 14px; color: var(--gold); font-size: 26px; }
.result-card { background: rgba(0,0,0,.3); border-radius: 12px; padding: 12px 16px; margin: 10px 0; }
.result-card.me { border: 1px solid var(--gold); }
.rc-head { font-size: 16px; }
.rc-yaku { color: #ffe08a; font-size: 14px; margin: 6px 0; line-height: 1.5; }
.rc-score { font-size: 20px; font-weight: 800; }
.ura-row { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 8px; font-size: 12px; }
.ura-row .dora-tile { --tw: 24px; }
.ryuu-detail { font-size: 15px; margin-bottom: 14px; }
.next-btn { margin-top: 12px; padding: 12px 30px; font-size: 17px; font-weight: 800;
  background: var(--gold); color: #5a3d00; border: none; border-radius: 12px; cursor: pointer; }
.next-wait { margin-top: 14px; font-size: 15px; font-weight: 700; color: var(--gold);
  opacity: .9; animation: nextwait-pulse 1.1s ease-in-out infinite; }
@keyframes nextwait-pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.rank-table { margin: 0 auto 8px; border-collapse: collapse; font-size: 16px; }
.rank-table td, .rank-table th { padding: 6px 16px; border-bottom: 1px solid #ffffff33; }
.rank-table tr.me { color: var(--gold); font-weight: 800; }

/* ===== スマホ対応 ===== */
@media (max-width: 640px) {
  :root { --tw-hand: 28px; --tw-river: 14px; --tw-opp: 13px; --tw-meld: 16px; --tw-dora: 15px; }
  #table { grid-template-columns: 54px minmax(0, 1fr) 54px; grid-template-rows: 70px 1fr 120px; gap: 2px; padding: 3px; }
  #center { gap: 2px 3px; }
  .seat-info { font-size: 10px; gap: 3px; padding: 2px 5px; }
  .wind-badge { width: 16px; height: 16px; font-size: 10px; }
  .center-box { min-width: 0; padding: 6px 8px; }
  .round-name { font-size: 13px; }
  .center-sub { font-size: 11px; gap: 8px; margin: 3px 0 5px; }
  .dora-label { margin-right: 2px; }
  .hand-melds { gap: 4px; }
  #action-bar { flex: 0 0 118px; height: 118px; gap: 6px; padding: 6px; }
  .act-hint { font-size: 12px; text-align: center; }
  .act-btn { padding: 11px 16px; font-size: 15px; border-radius: 10px; }
  .act-btns { gap: 7px; }
  .settings-panel { max-width: 100%; }
  .title { font-size: 26px; }
  #auto-draw-toggle.board-check { font-size: 11px; padding: 4px 7px; top: 4px; right: 5px; }
  .call-flash { font-size: 26px; }
  .overlay-box { min-width: 260px; padding: 18px 16px; }
}

/* さらに小さい端末（iPhone SE 等） */
@media (max-width: 400px) {
  :root { --tw-hand: 24px; --tw-river: 12px; --tw-opp: 11px; --tw-meld: 14px; --tw-dora: 13px; }
  #table { grid-template-columns: 48px minmax(0, 1fr) 48px; grid-template-rows: 62px 1fr 116px; }
  .center-box { min-width: 0; padding: 5px 6px; }
  .round-name { font-size: 12px; }
  .center-sub { font-size: 10px; gap: 6px; }
  .act-btn { padding: 10px 12px; font-size: 14px; }
  .tsumo-gap { width: 8px; }
}

/* 横向きで縦がやや狭い画面（多くのノートPC＝1366x768・1280x720・1440x900 等）。
   既定は固定px行（120+1fr+200）で、河4面の最小高が縦に収まらずグリッドが
   あふれ、下段の手牌がアクションバーに重なる。中央行を minmax(0,1fr)+vh で
   伸縮させ、アクションバーを内容高にして重なり・見切れを防ぐ。 */
@media (orientation: landscape) and (min-height: 561px) and (max-height: 900px) {
  :root { --tw-hand: 34px; --tw-river: 19px; --tw-opp: 16px; --tw-meld: 20px; --tw-dora: 20px; }
  #table {
    grid-template-columns: 120px minmax(0, 1fr) 120px;
    grid-template-rows: minmax(60px, 13vh) minmax(0, 1fr) minmax(88px, 26vh);
    gap: 3px; padding: 6px;
  }
  #center { min-height: 0; }
  #action-bar { flex: 0 0 auto; height: auto; min-height: 84px; max-height: 120px; }
}

/* 横向き（ランドスケープ）: 縦が狭いので行を高さ比率で組み、はみ出しを防ぐ。
   固定px行だと 120+200+アクションバー でビューポート高さを超えて手牌や
   アクションバーが画面外へ切れてしまうため、minmax+vh で伸縮させる。 */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --tw-hand: 28px; --tw-river: 15px; --tw-opp: 13px; --tw-meld: 16px; --tw-dora: 16px; }
  #table {
    grid-template-columns: 104px minmax(0, 1fr) 104px;
    grid-template-rows: minmax(42px, 13vh) minmax(0, 1fr) minmax(64px, 24vh);
    gap: 2px; padding: 3px;
  }
  #center { gap: 1px 4px; }
  .center-box { min-width: 0; padding: 4px 8px; }
  .round-name { font-size: 12px; }
  .center-sub { font-size: 10px; gap: 8px; margin: 2px 0 3px; }
  .seat-info { font-size: 10px; gap: 3px; padding: 2px 5px; }
  .wind-badge { width: 15px; height: 15px; font-size: 10px; }
  /* アクションバーは高さ固定をやめ、内容に合わせて低く保つ */
  #action-bar { flex: 0 0 auto; height: auto; min-height: 60px; max-height: 84px; gap: 6px; padding: 5px 8px; }
  .act-hint { font-size: 11px; text-align: center; }
  .act-btn { padding: 8px 14px; font-size: 14px; border-radius: 9px; }
  .act-btns { gap: 6px; }
  #auto-draw-toggle.board-check { font-size: 10px; padding: 3px 6px; top: 3px; right: 4px; }
  .board-gear { transform: scale(.85); }
}

/* さらに縦が極端に狭い横向き端末 */
@media (orientation: landscape) and (max-height: 400px) {
  :root { --tw-hand: 24px; --tw-river: 13px; --tw-opp: 11px; --tw-meld: 14px; --tw-dora: 14px; }
  #table { grid-template-columns: 90px minmax(0, 1fr) 90px;
    grid-template-rows: minmax(36px, 12vh) minmax(0, 1fr) minmax(54px, 26vh); }
  #action-bar { min-height: 52px; max-height: 72px; }
  .act-btn { padding: 7px 11px; font-size: 13px; }
}

/* ===== タイトル画面 ===== */
#title-screen {
  height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at 50% -10%, #147a4f 0%, var(--felt) 45%, var(--felt-dark) 100%);
}
.title-panel { width: 100%; max-width: 460px; text-align: center; }
.title-logo { font-size: 40px; letter-spacing: 3px; margin: 0 0 4px; color: var(--ivory);
  text-shadow: 0 3px 0 #063, 0 0 18px rgba(231,201,107,.4); }
.title-sub { color: var(--gold); font-size: 14px; margin: 0 0 34px; letter-spacing: 1px; }
.title-btn {
  display: block; width: 100%; margin: 14px 0; padding: 18px 20px; border: none; border-radius: 16px;
  font-size: 22px; font-weight: 800; cursor: pointer; color: #063; line-height: 1.2;
  box-shadow: 0 5px 0 rgba(0,0,0,.35); transition: transform .06s, box-shadow .06s;
}
.title-btn span { display: block; font-size: 12px; font-weight: 600; opacity: .75; margin-top: 4px; }
.title-btn.primary { background: linear-gradient(180deg, #ffde7a, #e7b93b); box-shadow: 0 5px 0 #a97e1a; }
.title-btn.accent { background: linear-gradient(180deg, #8fe6c0, #46c48a); box-shadow: 0 5px 0 #2c9366; }
.title-btn.ghost { background: rgba(255,255,255,.1); color: var(--ivory); font-size: 18px;
  border: 1px solid rgba(231,201,107,.4); box-shadow: 0 5px 0 rgba(0,0,0,.3); }
.title-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }

/* ===== 遊び方ページ ===== */
#howto-screen {
  height: 100dvh; overflow-y: auto; padding: 18px 16px 48px;
  background: radial-gradient(circle at 50% -10%, #147a4f 0%, var(--felt) 45%, var(--felt-dark) 100%);
  -webkit-overflow-scrolling: touch;
}
.howto-panel { max-width: 640px; margin: 0 auto; }
.howto-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.howto-title { color: var(--ivory); font-size: 24px; margin: 0; letter-spacing: 1px; }
.howto-back { padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 700;
  background: rgba(0,0,0,.35); color: var(--gold); border: 1px solid rgba(231,201,107,.4); }
.howto-back:active { transform: translateY(1px); }
.howto-back.bottom { display: block; width: 100%; margin-top: 20px; text-align: center; font-size: 17px; padding: 14px; }
.howto-body { display: flex; flex-direction: column; gap: 14px; }
.howto-sec { background: rgba(0,0,0,.24); border: 1px solid rgba(231,201,107,.24);
  border-radius: 14px; padding: 14px 16px; }
.howto-h2 { margin: 0 0 8px; font-size: 17px; color: var(--gold);
  border-left: 4px solid var(--gold); padding-left: 8px; }
.howto-sec p { margin: 6px 0; color: #eef3ea; font-size: 14px; line-height: 1.7; }
.howto-sec ul, .howto-sec ol { margin: 6px 0; padding-left: 22px; color: #eef3ea; font-size: 14px; line-height: 1.75; }
.howto-sec li { margin: 3px 0; }
.howto-sec b { color: #fff; }

/* ===== ロビー画面 ===== */
#lobby-screen {
  height: 100dvh; overflow-y: auto; padding: 22px 16px 40px;
  background: radial-gradient(circle at 50% -10%, #147a4f 0%, var(--felt) 45%, var(--felt-dark) 100%);
}
.lobby-panel { max-width: 460px; margin: 0 auto; }
.lobby-title { text-align: center; color: var(--ivory); font-size: 26px; margin: 6px 0 18px; letter-spacing: 2px; }
.lobby-box { background: rgba(0,0,0,.24); border: 1px solid rgba(231,201,107,.28);
  border-radius: 14px; padding: 14px 16px; margin: 14px 0; }
.lobby-h2 { margin: 0 0 12px; font-size: 17px; color: var(--gold); border-left: 4px solid var(--gold); padding-left: 8px; }
/* ホスト設定内に再利用したシングルの設定セクションは、箱の入れ子を避けて平坦化 */
.lobby-hostcfg .opt-section { background: transparent; border: none; border-radius: 0; padding: 0; margin: 12px 0 0; }
.lobby-hostcfg .opt-title { font-size: 15px; }
.lobby-hostcfg .opt-check { font-size: 13px; }
.lobby-rosummary-line { font-size: 13px; color: var(--ivory); line-height: 1.7; opacity: .92; }
.lobby-field { margin: 8px 0 4px; }
.lobby-label { display: block; font-size: 13px; color: var(--gold); margin-bottom: 6px; }
.lobby-input {
  width: 100%; box-sizing: border-box; padding: 12px 14px; border-radius: 10px;
  border: 1px solid rgba(231,201,107,.35); background: rgba(0,0,0,.28); color: #fff; font-size: 17px;
}
.lobby-code-input { text-align: center; font-size: 26px; letter-spacing: 10px; font-weight: 800; margin-bottom: 12px; }
.lobby-optrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; }
.lobby-optlabel { font-size: 14px; color: #d7f5e2; }
.lobby-radio { display: flex; gap: 6px; }
.lobby-rbtn { padding: 7px 14px; border-radius: 8px; border: 1px solid rgba(231,201,107,.4);
  background: transparent; color: #fff; cursor: pointer; font-size: 14px; }
.lobby-rbtn.on { background: var(--gold); color: #063; border-color: var(--gold); font-weight: 700; }
.lobby-btn {
  display: block; width: 100%; margin: 12px 0 2px; padding: 15px; border: none; border-radius: 12px;
  font-size: 18px; font-weight: 800; cursor: pointer; color: #063; box-shadow: 0 4px 0 rgba(0,0,0,.3);
  transition: transform .06s, box-shadow .06s;
}
.lobby-btn.primary { background: linear-gradient(180deg, #ffde7a, #e7b93b); box-shadow: 0 4px 0 #a97e1a; }
.lobby-btn.accent { background: linear-gradient(180deg, #8fe6c0, #46c48a); box-shadow: 0 4px 0 #2c9366; }
.lobby-btn.ghost { background: rgba(0,0,0,.25); color: #d7f5e2; box-shadow: none; border: 1px solid rgba(231,201,107,.3); }
.lobby-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.3); }
.lobby-btn:disabled { opacity: .5; pointer-events: none; }

.lobby-codebox { text-align: center; background: rgba(0,0,0,.3); border: 2px dashed var(--gold);
  border-radius: 14px; padding: 14px; margin: 8px 0 16px; }
.lobby-code-label { font-size: 12px; color: var(--gold); margin-bottom: 6px; }
.lobby-code { font-size: 46px; font-weight: 900; letter-spacing: 12px; color: var(--ivory);
  text-shadow: 0 2px 0 #063; }

.lobby-members { margin: 8px 0 14px; }
.lobby-member { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(0,0,0,.2); border: 1px solid rgba(231,201,107,.2); border-radius: 10px;
  padding: 10px 12px; margin: 7px 0; }
.lobby-member.me { border-color: var(--gold); background: rgba(231,201,107,.1); }
.lobby-mname { font-size: 15px; color: #eafff3; }
.lobby-seatno { font-size: 11px; color: var(--gold); margin-right: 4px; }
.lobby-tag { font-size: 10px; padding: 2px 6px; border-radius: 6px; margin-left: 5px; vertical-align: middle; }
.lobby-tag.host { background: #e7b93b; color: #5a3d00; }
.lobby-tag.you { background: #46c48a; color: #063; }
.lobby-hcap { display: flex; align-items: center; gap: 6px; }
.lobby-hcap-label { font-size: 11px; color: var(--gold); }
.lobby-slider { width: 96px; accent-color: var(--gold); }
.lobby-hcap-val { font-size: 14px; font-weight: 800; color: var(--ivory); min-width: 22px; text-align: center; }
.lobby-hcap-val.ro { color: #d7f5e2; }
.lobby-wait { text-align: center; color: var(--gold); font-size: 15px; margin: 18px 0; }
.lobby-note { text-align: center; color: #bfe9d3; font-size: 12px; margin: 6px 0 0; }
.lobby-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.85); color: #fff; padding: 12px 20px; border-radius: 24px; font-size: 14px;
  border: 1px solid var(--gold); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.lobby-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
