/* Keep the HUD outside the renderer's replaceable DOM but on the same felt. */
#tableFrame { position:relative; display:flex; flex-direction:column; min-width:0; min-height:0; flex:0 1 auto; margin-top:5px; }
#tableFrame #table { margin:0; }
#tableHud { position:absolute; inset:1px; pointer-events:none; }
#tableHud #seatPlates { z-index:auto; }
.table-seat-tag {
  display:inline-flex; align-items:center; gap:5px; padding:2px 6px 2px 2px; color:#f1e8d2;
  background:linear-gradient(105deg,#24382ff0,#101e19ee); border:1px solid #aa976b99; border-radius:4px;
  box-shadow:0 1px 3px #07120f80; white-space:nowrap; line-height:1.06;
}
.table-seat-tag.turn { border-color:#dfc28a; }
.table-seat-tag img { width:clamp(21px,2.4vw,32px); aspect-ratio:1; border-radius:2px; object-fit:cover; }
.seat-identity { display:grid; gap:2px; text-align:left; }
.seat-identity small { color:#d4c6a7; font-size:10px; }
.seat-identity b { font-size:clamp(11px,1.18vw,15px); }
.seat-dealer,.seat-riichi { color:#f4d397; font-size:11px; font-weight:800; }
.seat-riichi { color:#ffb4a2; }
#seatPlates .table-seat-tag { position:absolute; }
#seatPlates .pos2 { top:2%; left:50%; transform:translateX(-50%); }
#seatPlates .pos3 { top:24%; left:1.15%; }
#seatPlates .pos1 { top:24%; right:1.15%; }
#handGuide,#tableControls { position:absolute; bottom:2.4%; }
#handGuide { left:1.15%; pointer-events:auto; z-index:4; color:#f0e7d0; }
#handGuide summary {
  width:max-content; max-width:100%; list-style:none; cursor:pointer; touch-action:manipulation; display:flex;
  align-items:center; gap:6px; min-height:42px; padding:2px 8px 2px 3px;
  border:1px solid #9e8d68; border-radius:5px; background:linear-gradient(110deg,#263c31f5,#11221cf5);
}
#handGuide summary:focus-visible { outline:2px solid #f6dda2; }
#handGuide summary::-webkit-details-marker { display:none; }
#handGuide .table-seat-tag { border:0; background:none; box-shadow:none; padding:0 5px 0 0; border-right:1px solid #827b6099; border-radius:0; }
.guide-caption { display:grid; grid-template-columns:auto 8px; align-items:center; font:700 11px/1.15 system-ui,sans-serif; color:#e9d3a3; }
.guide-caption::after { content:""; border:solid currentColor; border-width:1.5px 1.5px 0 0; width:5px; height:5px; display:inline-block; transform:rotate(-45deg); margin:0 0 0 5px; }
#handGuide[open] .guide-caption::after { transform:rotate(135deg); vertical-align:3px; }
#guideState { display:block; color:#fff0c9; font-size:13px; margin-top:2px; }
.guide-caption::after { grid-area:1 / 2 / 3; }
#guideState { grid-area:2 / 1; }
.guide-card {
  position:absolute; bottom:calc(100% + 4px); left:0; width:min(435px,calc(100vw - 27px)); max-height:min(270px,47svh); overflow:auto;
  overscroll-behavior:contain; padding:10px; color:#f1e6cd; border:1px solid #aa966c; border-radius:5px; background:#14251ffb;
  box-shadow:0 5px 18px #02090566;
}
.guide-card .statusline { margin:0; }
.guide-card .statusline:empty { display:none; }
.guide-card .wait-options { max-height:none; overflow:visible; }
#tableControls { right:1.15%; text-align:right; max-width:64%; }
#tableControls .hand-prompt { margin:0; display:inline-block; color:#f1e8ce; border-radius:3px; background:#11241dd9; padding:3px 7px; font-size:12px; line-height:1.3; }
#tableControls .hand-prompt[hidden] { display:none; }
#tableControls .actions,body.has-stage #tableControls .actions {
  margin:0; display:flex; gap:4px; flex-wrap:wrap; justify-content:flex-end; pointer-events:none;
}
#tableControls .actions:empty { display:none; }
#tableControls .actions button { pointer-events:auto; min-height:42px; flex:0 1 auto; padding:3px 12px; font-size:15px; touch-action:manipulation; }
#tableControls .actions .hint { display:none; }
#tableFrame:has(#stage3d) #tableControls:has(button) { bottom:15%; }
/* Spoken captions stay on the felt and follow the dialogue player's single
   active speaker through a draw, an interruption or a 2D board repaint. */
#tableSpeech {
  position:absolute; z-index:2; display:flex; align-items:flex-start; gap:8px;
  width:max-content; max-width:min(27%,335px); padding:7px 10px 8px 7px;
  border:1px solid #c8baa0; border-left:4px solid var(--speaker-edge); border-radius:7px;
  color:#1b2b24; background:#fff9e9; box-shadow:0 3px 12px #06110b55;
  font:700 clamp(16px,1.62vw,23px)/1.45 system-ui,sans-serif; text-align:left;
  overflow-wrap:anywhere; line-break:strict; animation:seat-speech-in .16s ease-out both;
}
#tableSpeech[hidden] { display:none; }
#tableSpeech img { flex:none; width:clamp(37px,3.7vw,54px); aspect-ratio:1; border-radius:4px; object-fit:cover; background:#c9d3bf; }
#tableSpeech strong { display:block; color:#486053; font-size:clamp(12px,1.2vw,16px); line-height:1.15; margin-bottom:3px; }
#tableSpeech p { margin:0; }
#tableFrame[data-speaker="1"] { --speaker-edge:#8992bd; }
#tableFrame[data-speaker="2"] { --speaker-edge:#c58f94; }
#tableFrame[data-speaker="3"] { --speaker-edge:#bd9876; }
#tableSpeech::after {
  content:""; position:absolute; top:-5px; right:18px; width:9px; height:9px;
  transform:rotate(45deg); background:#fff9e9; border:solid #c8baa0; border-width:1px 0 0 1px;
}
#tableFrame[data-speaker="3"] #tableSpeech::after { left:16px; right:auto; }
#tableFrame[data-speaker="2"] #tableSpeech::after { left:-6px; top:13px; transform:rotate(-45deg); }
#tableFrame[data-speaker="1"] #tableSpeech { top:calc(24% + 40px); right:1.15%; }
#tableFrame[data-speaker="3"] #tableSpeech { top:calc(24% + 40px); left:1.15%; }
#tableFrame[data-speaker="2"] #tableSpeech { top:2%; right:1.15%; }
#tableFrame[data-speaker="1"] :is(.pos1,.opp-head[data-seat="1"]),
#tableFrame[data-speaker="2"] :is(.pos2,.opp-head[data-seat="2"]),
#tableFrame[data-speaker="3"] :is(.pos3,.opp-head[data-seat="3"]) { outline:2px solid var(--speaker-edge); outline-offset:1px; }
@keyframes seat-speech-in { from { opacity:.4; translate:0 3px; } }

@media (min-width:850px) and (min-aspect-ratio:6/5) {
  body.has-stage .wrap { width:min(100%,calc((100svh - 75px) * 1.67 + 24px)); }
}
@media (max-width:700px) and (orientation:portrait) {
  .table-seat-tag { gap:3px; padding-right:4px; }
  #handGuide summary { gap:4px; min-height:40px; padding-right:6px; }
  #tableControls .actions button { min-height:40px; padding:3px 8px; font-size:14px; }
  #tableFrame:has(#stage3d) #stage3d { aspect-ratio:.65; }
  #tableFrame #seatPlates .pos2 { top:calc(50% - 48vw); }
  #tableFrame #seatPlates :is(.pos1,.pos3) { top:calc(50% - 33vw); }
  #tableFrame #tableControls,#tableFrame:has(#stage3d) #tableControls:has(button) { bottom:2.4%; max-width:52%; }
  #tableFrame[data-speaker] #tableSpeech { top:2%; max-width:95%; padding:5px 8px 6px 5px; gap:6px; font-size:clamp(16px,4.4vw,19px); }
  #tableFrame[data-speaker="2"] #tableSpeech { left:50%; right:auto; transform:translateX(-50%); }
  #tableFrame[data-speaker] #tableSpeech::after { top:auto; bottom:-5px; transform:rotate(225deg); }
  #tableFrame[data-speaker="2"] #tableSpeech::after { left:50%; }
  #tableSpeech img { width:34px; }
  #tableSpeech strong { font-size:12px; }
  #tableFrame:not(:has(#stage3d)) #table { padding-top:90px; }
  #tableFrame:not(:has(#stage3d)) #tableSpeech { top:2%; max-width:96%; }
  .wrap:has(#tableCalls:not([hidden])) #handGuide { bottom:1.2%; }
}
@media (max-height:530px) and (orientation:landscape) and (min-width:480px) {
  .wrap { grid-template-columns:minmax(0,1fr); }
  #tableFrame { grid-area:3 / 1; margin:0; }
  #tableFrame #table.stage-mode { flex:1; }
  #handGuide summary { min-height:36px; }
  #tableControls .actions button { min-height:36px; }
}
@media (prefers-reduced-motion:reduce) {
  #tableSpeech { animation:none; }
}
@media (max-height:530px) and (orientation:landscape) {
  #tableFrame[data-speaker] #tableSpeech { top:2%; max-width:33%; font-size:15px; gap:5px; padding:4px 6px 5px 4px; }
  #tableSpeech img { width:29px; }
  #tableSpeech strong { font-size:11px; }
  #tableFrame #table:not(.stage-mode) { height:100%; padding:2px 5px; }
  #table:not(.stage-mode) .board {
    min-height:100%; gap:2px; grid-template-columns:minmax(0,1fr) clamp(80px,26svh,126px) minmax(0,1fr);
  }
  #table .b-top .seat-block { flex-direction:row; align-items:center; gap:6px; }
  #table .board .opp-head { width:fit-content; align-self:center; margin:0; }
  #table .board .b-right .opp-head { margin-left:auto; }
  #table .b-top .backs .tileback { width:8px; height:13px; }
  #table .board .pool.tb { margin:0; }
  #table .b-top .pool.tb { grid-template-columns:repeat(6,15px); }
  #table .b-top .pool.tb .tile.pool-t { width:15px; }
  #tableFrame:is([data-speaker="1"],[data-speaker="3"]) #tableSpeech::after {
    top:auto; bottom:-5px; transform:rotate(225deg);
  }
  #table .board .b-right .backs.side { justify-content:flex-end; }
}
@media (max-width:360px) and (orientation:portrait) {
  #tableSpeech strong { display:inline; margin-right:5px; vertical-align:1px; }
  #tableSpeech p { display:inline; }
  #tableHud:has(#tableControls button:nth-of-type(2)) #myPlate img { display:none; }
}

/* Both renderers present one hand inside the rim. WebGL uses the native
   controls as accessibility targets aligned to its meshes. */
#stage3d #tableHand,#stage3d #handRow {
  position:absolute; inset:0; margin:0; padding:0; border:0; background:none; box-shadow:none; pointer-events:none;
}
#stage3d #handRow button.tile {
  position:absolute; display:block; margin:0; padding:0; min-width:0; max-width:none; aspect-ratio:auto;
  pointer-events:none; border:0; background:none!important; box-shadow:none; translate:none; transform:none; transition:none;
}
#stage3d #handRow button.tile > *,#stage3d #handRow button.tile::before,#stage3d #handRow button.tile::after { display:none; }
#stage3d #handRow button.tile:focus-visible { outline:3px solid #ffedac; outline-offset:1px; box-shadow:0 0 0 5px #58451b; }
#stage3d #openSets { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
#tableFrame:has(> #table:not(.stage-mode)) {
  --rack-height:clamp(25px,9vw,65px);
}
#tableFrame #table:not(.stage-mode) {
  display:flex; flex-direction:column; padding-bottom:6px; overflow:hidden;
}
#table:not(.stage-mode) .board { flex:1 1 auto; min-height:0; overflow:auto; }
#table:not(.stage-mode) #tableHand {
  height:var(--rack-height); flex:none; width:min(100%,860px); margin:4px auto 0; display:flex; align-items:end; justify-content:center;
}
#table:not(.stage-mode) #handRow,#table:not(.stage-mode) #openSets {
  display:flex; align-items:end; justify-content:center; flex-basis:0; min-width:0;
  padding:0; margin:0; gap:1px; border:0; background:none; box-shadow:none;
}
#table:not(.stage-mode) #openSets:empty { display:none; }
#table:not(.stage-mode) #handRow .tile.hand {
  min-width:0; max-width:calc(var(--rack-height)*.75); height:auto; aspect-ratio:21 / 28;
}
#table:not(.stage-mode) #handRow .tile.drawn { margin-left:clamp(3px,.65vw,9px); }
#table:not(.stage-mode) #openSets .openset { flex:1; padding:0; margin:0 0 0 4px; gap:1px; border:0; background:none; }
#table:not(.stage-mode) #openSets .tile { flex:1; min-width:0; max-width:calc(var(--rack-height)*.58); }
#tableFrame:has(> #table:not(.stage-mode)) :is(#handGuide,#tableControls) { bottom:calc(var(--rack-height) + 12px); }
@media (max-height:530px) and (orientation:landscape) {
  .wrap { grid-template-rows:auto auto minmax(0,1fr); }
  #tableFrame #table .board { min-height:0; }
  #tableFrame:has(> #table:not(.stage-mode)) { --rack-height:clamp(30px,10svh,42px); }
}
/* Use the height released by the old HTML rack for the playing surface. */
#tableFrame, #tableFrame #table:not(.stage-mode), #tableFrame #table.stage-mode, #tableFrame #table.stage-mode #stage3d {
  flex:1 1 0; min-height:0;
}
#tableFrame #table.stage-mode #stage3d { height:0; aspect-ratio:auto; }

#waitPreview {
  position:absolute; z-index:3; box-sizing:border-box; width:max-content; max-width:min(390px,calc(100% - 14px));
  left:50%; transform:translateX(-50%); top:75%; padding:4px 7px;
  color:#f5edd7; background:linear-gradient(120deg,#253e32fa,#10271ffa 74%); border:1px solid #a99d73;
  border-left:3px solid #75d7a8; border-radius:5px; box-shadow:0 3px 12px #06120b66;
  font:700 12px/1.12 system-ui,sans-serif; pointer-events:auto;
}
#waitPreview[data-kind="discard"] { width:min(335px,calc(100% - 14px)); }
#waitPreview[data-align="left"] { left:6px; transform:none; }
#waitPreview[data-align="right"] { left:auto; right:6px; transform:none; }
#waitPreview[hidden] { display:none; }
.wp-heading { display:flex; align-items:center; gap:8px; margin-bottom:2px; }
.wp-heading strong { color:#b5ecd0; font-size:12px; }
.wp-warning,.wp-row-warning { color:#ffc596; font-size:10px; }
.wp-rows { max-height:min(clamp(116px,24svh,210px),var(--wp-list-limit,100vh)); overflow:auto; overscroll-behavior:contain; scrollbar-width:thin; touch-action:pan-y; }
.wp-line {
  display:flex; align-items:center; gap:7px; min-width:0; min-height:30px; padding:3px 2px; box-sizing:border-box;
}
.wp-line + .wp-line { border-top:1px solid #bbceaa44; }
.wp-line[data-active] { background:#39654e; box-shadow:inset 3px 0 #a4edbb; }
.wp-discard {
  display:inline-flex; align-items:center; flex:none; align-self:stretch; gap:3px; margin:0; padding:0 2px 0 4px;
  min-width:0; min-height:0; border:0; border-radius:2px; color:#ffefcd; background:none; box-shadow:none;
  font:700 11px/1.1 system-ui,sans-serif; touch-action:pan-y; cursor:pointer;
}
.wp-discard b { color:#a6c6ac; }
.wp-discard:focus-visible,.wp-rows:focus-visible { outline:2px solid #fff0b4; outline-offset:-2px; }
.wp-tiles { flex:1 1 auto; display:flex; flex-wrap:wrap; align-items:center; gap:3px 6px; min-width:0; }
.wp-item { display:inline-flex; align-items:center; gap:2px; white-space:nowrap; }
.wp-item small { font-size:11px; }
.wp-tally { display:grid; flex:none; gap:2px; justify-items:end; padding-right:2px; }
.wp-total { white-space:nowrap; font-size:12px; }
#waitPreview .tile.wp-face { width:20px; height:27px; min-width:20px; border-bottom-width:2px; margin:0; }
#table:not(.stage-mode) #handRow .tenpai-choice::before { height:4px; width:82%; left:9%; }
#table #handRow button[data-wait-selected]:not(:focus-visible) { outline:2px solid #59dfad; outline-offset:0; }
@media (max-height:530px) and (orientation:landscape) {
  #waitPreview { max-width:min(270px,45%); }
  .wp-line,.wp-tiles { gap:3px; }
  #waitPreview .tile.wp-face { width:17px; min-width:17px; height:23px; }
  .wp-rows { max-height:109px; }
  .wp-heading strong,.wp-item small { font-size:10px; }
}
@media (max-width:700px) and (orientation:portrait) {
  #tableFrame:has(#waitPreview[data-kind="discard"]:not([hidden])) #tableControls .hand-prompt { display:none; }
}
@media (max-width:360px) {
  #waitPreview { padding:3px 6px; }
  #waitPreview .tile.wp-face { width:19px; min-width:19px; height:25px; }
}
@media (min-width:701px) and (min-height:531px) {
  #waitPreview { padding-block:3px; }
  #waitPreview[data-kind="discard"] { width:clamp(196px,20%,282px); }
  #waitPreview[data-kind="discard"] .wp-tiles { gap:3px; }
  #waitPreview[data-kind="discard"] .wp-item { flex-direction:column; gap:0; }
  #waitPreview[data-kind="discard"] .wp-item small { font-size:10px; }
  .wp-heading { margin-bottom:2px; }
}

@media (max-width:700px) and (orientation:portrait) {
  .wrap { width:100%; max-width:none; height:min(100svh,218vw); margin-block:max(0px,calc((100svh - 218vw)/2)); padding-inline:env(safe-area-inset-left,0px) env(safe-area-inset-right,0px); }
  .topbar.refbar { padding-inline:5px; }
  #tableFrame { margin-top:2px; }
  #tableFrame #table.stage-mode { border-radius:3px; }
  #stage3d > .table-meter { width:28.2%; top:calc(var(--portrait-center-y,50%) - var(--table-depth)*.09); }
  #tableFrame #seatPlates .pos2 { top:calc(var(--portrait-far-y) - clamp(44px,11vw,58px)); }
  #tableFrame[data-speaker] #tableSpeech { top:calc(var(--portrait-far-y) + clamp(12px,3.4vw,20px)); }
  #tableFrame #tableControls,#tableFrame:has(#stage3d) #tableControls:has(button),
  #tableFrame:has(> #table:not(.stage-mode)) #tableControls {
    left:var(--mobile-controls-left); right:1.5%; bottom:var(--portrait-action-bottom,22%); max-width:none; text-align:left;
  }
  #tableControls .actions,body.has-stage #tableControls .actions { justify-content:flex-start; }
  #tableControls .actions button { min-height:44px; min-width:clamp(70px,23vw,116px); border-radius:4px; font-size:clamp(17px,4.9vw,24px); }
  #tableControls .actions button.gold { color:#33230f; background:linear-gradient(#fff0ce,#e7c68a 70%,#d8b571); border-color:#f6dfb3; box-shadow:inset 0 -2px #ac834e,0 3px 8px #07130970; }
  #tableControls:has(button) .hand-prompt { display:none; }
  #tableControls .actions:has(button:nth-of-type(3)) { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); }
  #tableControls .actions:has(button:nth-of-type(3)) button { min-width:0; padding-inline:2px; font-size:clamp(14px,4vw,18px); }


  #tableFrame #table:not(.stage-mode) .board { position:absolute; inset:0; display:block; overflow:hidden; }
  #tableFrame #table:not(.stage-mode) #tableHand { position:absolute; left:.35%; top:var(--portrait-hand-y); transform:translateY(-50%); width:99.3%; margin:0; height:var(--rack-height); }
}

/* Opponent racks read left-to-right from each seated player's perspective. */
#table .b-top .backs { flex-direction:row-reverse; }
#table .b-top .backs :is(.cpu-draw,.win-sep) { margin:0 clamp(4px,1vw,9px) 0 0; }
#table .b-right .backs.side { flex-direction:column-reverse; }
#table .b-left .backs.side { flex-direction:column; }
#table .b-right .backs.side :is(.cpu-draw,.win-sep) { margin:0 0 4px; }
#table .b-left .backs.side :is(.cpu-draw,.win-sep) { margin:4px 0 0; }
@media (max-width:700px) and (orientation:portrait) {
  #tableFrame:has(#table:not(.stage-mode))[data-speaker="2"] #tableSpeech { top:max(4px,calc(var(--portrait-far-y) - 53px)); }
  #tableFrame[data-speaker="2"] #table:not(.stage-mode) .opp-head[data-seat="2"] { opacity:0; }
}
@media (max-height:530px) and (orientation:landscape) {
  #table .board .seat-side { position:relative; }
  #table .board .backs.side { position:absolute; top:100%; flex-wrap:nowrap; }
  #table .board .b-left .backs.side { left:0; }
  #table .board .b-right .backs.side { right:0; }
  #table .board .backs.side .tileback { width:14px; height:5px; }
}

@media (max-width:700px) and (orientation:portrait) {
  #tableFrame #table:not(.stage-mode) {
    --river-face:5.12vw; --river-pitch:5.28vw; --river-depth:7.1vw;
    --rack-height:10.2vw; padding-inline:0;
  }
  #tableFrame #table:not(.stage-mode) .board :is(.b-top,.b-left,.b-right,.b-bottom,.seat-block,.seat-side) {
    display:contents; position:static; transform:none;
  }
  #tableFrame #table:not(.stage-mode) .b-center {
    position:absolute; left:50%; top:var(--portrait-center-y); transform:translate(-50%,-50%); width:28.2%; max-width:none; margin:0;
  }
  #tableFrame #table .b-center .meter-dora { position:absolute; bottom:100%; width:94%; left:3%; margin:0; }
  #tableFrame #table .board .opp-head { position:absolute; margin:0; }
  #tableFrame #table .b-top .opp-head { left:50%; bottom:calc(100% - var(--portrait-far-y) + 3.8vw); transform:translateX(-50%); }
  #tableFrame #table .board .backs { position:absolute; min-height:0; gap:.22vw; flex-wrap:nowrap; }
  #tableFrame #table .b-top .backs { left:50%; top:var(--portrait-far-y); transform:translate(-50%,-50%); }
  #tableFrame #table .b-top .backs .tileback { width:5.1vw; height:6.1vw; }
  #tableFrame #table .seat-side .backs.side { top:var(--portrait-center-y); width:auto; transform:translateY(-50%); }
  #tableFrame #table .b-left .backs.side { left:1%; }
  #tableFrame #table .b-right .backs.side { right:1%; }
  #tableFrame #table .seat-side .backs.side .tileback { width:3.7vw; height:4.95vw; margin:0; }
  #tableFrame #table .board .backs.side .tile.mini { width:4.6vw; }
  #tableFrame #table .board .backs.side .cpu-draw { margin-block:1.3vw; }
  #tableFrame #table .board .pool { position:absolute; margin:0; padding:0; gap:0; }
  #tableFrame #table .board .pool.tb {
    left:50%; grid-template-columns:repeat(6,var(--river-pitch)); grid-auto-rows:var(--river-depth); min-height:0;
  }
  #tableFrame #table .board .pool.top {
    bottom:calc(100% - var(--portrait-north-y) - var(--river-depth)/2);
    transform:translateX(-50%) rotate(180deg);
  }
  #tableFrame #table .board .pool.bottom {
    top:calc(var(--portrait-south-y) - var(--river-depth)/2); transform:translateX(-50%);
  }
  #tableFrame #table .board .pool.sd {
    top:calc(var(--portrait-center-y) - 3*var(--river-pitch)); grid-template-rows:repeat(6,var(--river-pitch)); grid-auto-rows:var(--river-pitch); grid-auto-columns:var(--river-depth);
  }
  #tableFrame #table .board .pool.left { right:65.2%; }
  #tableFrame #table .board .pool.right { left:65.2%; top:calc(var(--portrait-center-y) - (3 + var(--extra-files))*var(--river-pitch)); }
  #tableFrame #table .board .pool.left .cell { grid-row:calc(1 + var(--river-file)); grid-column:calc(1 + var(--river-rank)); }
  #tableFrame #table .board .pool.right .cell { grid-row:calc(6 + var(--extra-files) - var(--river-file)); grid-column:calc(1 + var(--river-rank)); }
  #tableFrame #table .board .pool.sd .cell { width:var(--river-depth); height:var(--river-pitch); }
  #tableFrame #table .board .pool .tile.pool-t { width:var(--river-face); flex:none; max-width:none; }
  #tableFrame #table:not(.stage-mode) #handRow { gap:.18vw; }
  #tableFrame #table:not(.stage-mode) #handRow .tile.hand { max-width:7.36vw; }

  #tableFrame:has(> #table) #handGuide,#tableFrame:has(> #table:not(.stage-mode)) #handGuide {
    left:var(--mobile-guide-left); bottom:calc(var(--portrait-action-bottom,22%) - 6px); top:auto; width:var(--mobile-guide-width); height:max-content; pointer-events:none;
  }
  #handGuide :is(summary,.guide-card) { pointer-events:auto; }
  #tableFrame #handGuide .guide-card {
    top:calc(100% + var(--portrait-drawer-offset)); bottom:auto; width:min(97vw,505px);
    max-height:var(--portrait-drawer-height); padding:4px 7px; touch-action:pan-y;
  }
  #tableHud:has(#waitPreview:not([hidden])) #handGuide[open] .statusline > :is(.wait-count,.wait-options,.wait-fixed) { display:none; }
  #tableFrame[data-tight-table] #table .b-center .meter-dora {
    left:auto; right:calc(100% + 4%); bottom:calc(100% + 8%); width:91%;
  }

  #tableFrame #seatPlates .pos3,#tableFrame #table .b-left .opp-head {
    left:6%; top:clamp(calc(var(--portrait-far-y) + 4vw),calc(var(--portrait-center-y) - 44vw),calc(var(--portrait-center-y) - 28vw));
  }
  #tableFrame #seatPlates .pos1,#tableFrame #table .b-right .opp-head {
    right:6%; top:calc(var(--portrait-center-y) + 17vw);
  }
  #tableFrame #table .board .opp-head { min-height:0; }
  #tableFrame #table .board .opp-head .plate-body { padding:1px 3px; }
  #tableFrame #table .board .opp-head :is(.plate-name,.plate-rank,.wind-badge) { font-size:10px; }
  #tableFrame[data-tight-table] #seatPlates .pos2,
  #tableFrame[data-tight-table] #table .b-top .opp-head {
    top:3px; right:2%; bottom:auto; left:auto; transform:none;
  }
}

@media (max-width:700px) and (orientation:portrait), (max-width:940px) and (max-height:530px) and (orientation:landscape) {
  .wrap { --mobile-guide-left:1.4vw; --mobile-guide-width:clamp(84px,25vw,117px); --mobile-controls-left:calc(var(--mobile-guide-left) + var(--mobile-guide-width) + 6px); }
  #handGuide summary {
    display:grid; grid-template-columns:1fr; grid-template-rows:auto auto; align-content:center;
    width:100%; min-height:42px; padding:3px 5px; gap:2px;
    background:linear-gradient(115deg,#2a3c30f7,#13261cf8); border-left:2px solid #c3aa77;
  }
  #handGuide #myPlate { position:static; padding:0; }
  #handGuide .table-seat-tag { display:flex; align-items:center; gap:2px; padding:0; border:0; }
  #handGuide .table-seat-tag img { display:none; }
  #handGuide .seat-identity { display:flex; align-items:center; flex-direction:row-reverse; gap:3px; white-space:nowrap; }
  #handGuide .seat-identity b { font-size:10px; }
  #handGuide .seat-identity small { font-size:9px; }
  #handGuide :is(.seat-dealer,.seat-riichi) { font-size:9px; }
  #handGuide .seat-riichi { position:absolute; right:16px; bottom:6px; }
  #handGuide .guide-caption {
    display:flex; justify-content:space-between; width:100%;
    font-size:0; line-height:1.05;
  }
  #handGuide #guideState { font-size:14px; margin:0; }
  #handGuide .guide-caption::after { width:5px; height:5px; margin:0 2px 0 0; }
}

@media (max-width:700px) and (orientation:portrait) {
  #tableFrame[data-corner-action] { --mobile-guide-width:clamp(46px,15vw,68px); --mobile-controls-left:calc(var(--mobile-guide-left) + var(--mobile-guide-width) + 3px); }
  #tableFrame[data-corner-action] #handGuide .seat-identity { display:grid; gap:0; }
  #tableFrame[data-corner-action] #handGuide .seat-identity b { font-size:9px; }
  #tableFrame[data-corner-action] #handGuide .table-seat-tag { gap:1px; }
  #tableFrame[data-corner-action] #handGuide summary { padding-inline:2px; }
  #tableFrame[data-corner-action] #tableControls .actions button {
    width:calc(33vw - var(--mobile-controls-left)); min-width:0; padding-inline:0; font-size:clamp(14px,4.4vw,19px);
    line-height:1.1; white-space:normal;
  }
}
@media (max-width:940px) and (max-height:530px) and (orientation:landscape) {
  .wrap { --mobile-guide-left:var(--landscape-guide-left,2%); --mobile-guide-width:94px; --mobile-call-bottom:var(--landscape-guide-bottom,14%); --guide-gutter:clamp(130px,24vw,190px); }
  #tableFrame:has(> #table) #handGuide,#tableFrame:has(> #table:not(.stage-mode)) #handGuide {
    left:var(--mobile-guide-left); bottom:var(--landscape-guide-bottom,14%); width:var(--mobile-guide-width); height:max-content; pointer-events:none;
  }
  #handGuide :is(summary,.guide-card) { pointer-events:auto; }
  #tableFrame #tableControls,#tableFrame:has(#stage3d) #tableControls:has(button),#tableFrame:has(> #table:not(.stage-mode)) #tableControls {
    left:var(--landscape-action-left,4px); right:auto; bottom:var(--landscape-action-bottom,14%); max-width:90px;
  }
  .wrap:has(#handGuide[open]) #tableFrame { margin-left:var(--guide-gutter); }
  #tableFrame #handGuide .guide-card {
    position:fixed; left:4px; top:var(--landscape-board-top,40px); bottom:auto; width:calc(var(--guide-gutter) - 6px); max-height:calc(100svh - var(--landscape-board-top,40px) - 5px); padding:6px;
  }
}
@media (max-width:940px) and (max-height:530px) and (orientation:landscape) {
  .wrap:has(#tableCalls:not([hidden])) #table:not(.stage-mode),
  #tableFrame:has(#tableControls button:nth-of-type(2)) #table:not(.stage-mode) { padding-left:calc(var(--landscape-call-width) + 7px); }
  #tableFrame:has(> #table) #tableControls:has(button:nth-of-type(2)) {
    left:3px; right:auto; bottom:3px; width:var(--landscape-call-width); max-width:none;
  }
  #tableControls .actions:has(button:nth-of-type(2)) { display:grid; grid-template-columns:repeat(auto-fit,minmax(44px,1fr)); }
  #tableControls .actions:has(button:nth-of-type(2)) button { min-width:0; padding-inline:1px; }
}
