/* 响应式层：手机横竖屏 / 平板 / 触屏交互。
   在 style.css、m5.css、lobby.css 之后加载；桌面（横屏且高 > 500px）只有 env(safe-area-*) 一条，
   而桌面上 env() 恒为 0，所以 1024×640 ~ 2560×1440 的版面逐像素不变。
   不旋转整页（transform: rotate 会让拖拽 / 箭头 / FLIP 用到的 clientX/Y 全部错位）。 */

:root { --vh: 1vh; }
@supports (height: 1dvh) { :root { --vh: 1dvh; } }

/* ---------- 触屏基础：不缩放、不选字、不拖动页面 ---------- */
html, body { touch-action: manipulation; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (pointer: coarse) {
  body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
  img { -webkit-user-drag: none; }
  /* 没有悬停：取消“悬停上浮”（触屏上 :hover 会粘住），选中态照旧 */
  .hcard:not(.dis):not(.sel):hover, .pm-card.selectable:not(.picked):hover { --ty: 0px; --sc: 1; }
}

/* 刘海 / Home 条：桌面上 env() = 0，max() 退回原值 */
@media (orientation: landscape) and (min-height: 701px) {
  #app { padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
}
@media (orientation: landscape) and (min-height: 501px) and (max-height: 700px) {
  #app { padding-top: max(4px, env(safe-area-inset-top)); padding-left: max(4px, env(safe-area-inset-left)); padding-right: max(4px, env(safe-area-inset-right)); }
}

/* 触屏：铺路箭头 / 锁的命中区上下各外扩，格宽 ≥ 40px 时命中区 ≥ 40×40 */
@media (pointer: coarse) {
  #places .place::after { content: ""; position: absolute; left: 0; right: 0; top: -10px; bottom: -6px; }
}

/* 弹窗 / 大厅压在棋子之上：#pawns 的 z-index 是 1000（m5.css，为了高过悬挂牌），
   原来 #modal 只有 50 / 60，棋子会浮在玩家详情、终局表、局中大厅上面（各尺寸都会，桌面也是） */
#modal, #modal.lobby { z-index: 2000; }
#app #logPanel.open { z-index: 1600 !important; }
/* 新手教程（tutorial.css）在大厅之上；游戏内提示气泡在棋子之上、弹窗之下 */
#tutorial { z-index: 2100; }
.tu-tip { z-index: 1500; }
/* 提示气泡挂在 body 上，而 #modal 在 #app（position: fixed，自成层叠上下文）里，z-index 比不过气泡：
   弹窗 / 大厅 / 教程打开时先藏起来，关掉后原样回来（main 上气泡会盖住玩家详情的「关闭」等按钮） */
body:has(#modal:not([hidden])) .tu-tip, body:has(#tutorial:not([hidden])) .tu-tip { display: none; }

/* 手牌为空的提示：窄面板里换行而不是横向溢出 */
#hand .hint.empty-hand { white-space: normal; min-width: 0; max-width: 100%; }

/* Editing controls and rules take their intrinsic height, not a share of a flex row. */
#app #actionPanel #actions.mode-edit { flex: 0 0 auto; overflow: visible; }
#app #actions.mode-edit .action-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; width: 100%; flex: 0 0 auto; align-items: center; }
#app #actions .action-controls:empty { display: none; }
#app #actions .action-controls .placehint { min-width: 0; margin: 0; white-space: normal; overflow-wrap: anywhere; }
#app #actions .action-controls .placebar { min-width: 0; }
#app #actions .action-controls .devbar,
#app #actions .action-controls .placehint:has(+ .devbar) { grid-column: 1 / -1; }
#app #actions .action-controls .placewhy { grid-column: 1 / -1; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
#app #actionPanel:has(#actions.mode-edit) { height: auto !important; max-height: none !important; min-height: min-content; }
@media (orientation: portrait), (pointer: coarse) and (min-height: 501px) {
  #app #actionPanel #actions.mode-edit > .panel-title { min-height: 40px !important; }
}

/* 触屏：手牌叠放、标题紧贴牌顶，选中只靠金边与光晕，不上浮放大（免得压住标题 / 邻牌） */
@media (pointer: coarse), (orientation: landscape) and (max-height: 500px), (orientation: portrait) {
  #app #hand .hcard { --cs-ty: 0px; --cs-sc: 1; }
}

/* 触屏：顶栏“新局”与弹窗按钮 ≥ 40px 高 */
@media (pointer: coarse) {
  #btnNew, .dialog .btn { min-height: 40px; }
  #modal.lobby .lb-btn { min-height: 40px; }
}

/* =====================================================================
   桌面（鼠标、横屏、高 > 500px）：常规局面逐像素不变，只修两种极端局面的溢出（main 上即存在）
   1) 英文 + 手牌 5 张：行动栏英文版更宽（1.62 牌宽），底栏总宽 > 视口。
      底栏按手牌数 --n 重新取牌宽，且只会比原值小：手牌 ≤5 张的中文、≤4 张的英文与原来完全相同。
      自定义属性在声明处求值，所以由 --cw 派生的几个变量要在 #botRow 上重新声明一遍；
      面板高 --pnl-h 不重算（沿用 :root 的值，含 m5.css 窄屏 196px 下限），牌变小时面板高度不变。
   2) 展开“置灰原因”：原来在行动栏里原地展开，把 4 个行动键挤成两列、挤出面板；改为浮层。
   ===================================================================== */
@media (orientation: landscape) and (min-height: 501px) and (pointer: fine), (orientation: landscape) and (min-height: 501px) and (pointer: none) {
  #botRow {
    --cw: min(calc(172 * var(--u)), calc((100vw - 2 * var(--edge) - 12px) / 11.37), calc((100vw - 2 * var(--edge) - 12px) / (var(--n, 3) * 1.06 + 6.07 + var(--act-x, 0))));
    --bp: calc(var(--cw) * .116); --bg: calc(var(--cw) * .06); --pg: calc(var(--cw) * .093);
    --btfs: max(13px, calc(var(--cw) * .13)); --card-w: var(--cw); --card-h: calc(var(--cw) / .7146); --cap-h: calc(var(--cw) * .15);
    --ppx: var(--bp); --ppy: var(--bp); --ptg: calc(var(--cw) * .07); --pfs: var(--btfs);
  }
  html[lang="en"] #botRow { --act-x: .32; }
  #actionPanel .btn-row.acts { flex-wrap: nowrap; }
  #actionPanel details.reasons[open] .rsn-list { position: fixed; z-index: 45; right: max(12px, var(--edge)); bottom: calc(var(--pnl-h) + var(--bot-gap) + 10px); width: min(360px, 34vw); max-height: 45vh; overflow-y: auto; padding: 8px 12px; background: #1a110bf2; border: 2px solid #c9a24d; border-radius: 8px; box-shadow: 0 6px 18px #000c; color: #f0e2bd; line-height: 1.4; }
  #actionPanel details.reasons .rsn-list > div + div { margin-top: 4px; }
}
@media (orientation: landscape) and (min-height: 501px) and (max-width: 1400px) {
  html[lang="en"] #popPanel .panel-title { font-size: 12px; letter-spacing: 0; }
}

/* 轨道比可视区长（手机横屏常见，桌面在极长的路上也会出现）：被滚出去的一侧渐隐，不硬切半格。
   类名由 responsive.js initTrackFade 按滚动位置切换；路能完整放下时没有这两个类，版面不变 */
#app #trackScroll.fade-l { -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 calc(var(--cell-w, 40px) * .9)); mask-image: linear-gradient(90deg, transparent 0, #000 calc(var(--cell-w, 40px) * .9)); }
#app #trackScroll.fade-r { -webkit-mask-image: linear-gradient(270deg, transparent 0, #000 calc(var(--cell-w, 40px) * .9)); mask-image: linear-gradient(270deg, transparent 0, #000 calc(var(--cell-w, 40px) * .9)); }
#app #trackScroll.fade-l.fade-r { -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 calc(var(--cell-w, 40px) * .9), #000 calc(100% - var(--cell-w, 40px) * .9), transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 calc(var(--cell-w, 40px) * .9), #000 calc(100% - var(--cell-w, 40px) * .9), transparent 100%); }

/* ---------- 长按提示（responsive.js） ---------- */
#lpTip { position: fixed; z-index: 100001; max-width: min(320px, 80vw); padding: 6px 10px; border-radius: 8px; background: #1a110bf2; color: #f5ead0; border: 1px solid #c9a24d; box-shadow: 0 4px 14px #000c; font: 600 13px/1.35 "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; white-space: pre-line; pointer-events: none; }
#lpTip[hidden] { display: none; }

/* =====================================================================
   A. 短横屏（手机横屏，高 ≤ 500px）
   顶栏：Logo · 头像+分数小胶囊 · 新局
   中部：左侧人气竖条（≤6vw） | 轨道 | 右侧行动竖栏（贯穿中部与底栏，4 键 + ? + 日志）
   底栏：手牌（>3 张叠放） | 公共市场 3 + 牌库
   牌宽 --cw 取「底栏高 ≤ 40vh」与「宽度放得下 3 张手牌 + 4 张市场牌」两者的较小值。
   ===================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --sl: max(6px, env(safe-area-inset-left)); --sr: max(6px, env(safe-area-inset-right));
    --st: max(4px, env(safe-area-inset-top)); --sb: max(4px, env(safe-area-inset-bottom));
    --gp: 4px;
    --top-h: clamp(40px, calc(11 * var(--vh)), 46px);
    --pop-w: clamp(38px, 6vw, 50px);
    /* 行动栏宽：中文 4 个按钮都是两个字，略窄；英文要放下最长的「Promotion / Collection」，文字距右侧饰钉 ≥ 8px（见下方 html[lang=en]） */
    --act-w: clamp(116px, 13.6vw, 128px);
    --bp: 4px; --bg: 4px; --pfs: 12px; --ptg: 3px; --cap-h: 15px;
    --rx-ttl: calc(var(--pfs) * 1.2 + var(--ptg));
    --rx-fix: calc(var(--bp) + var(--rx-ttl) + var(--cap-h) + 4px + 6px + 6px);
    /* 底栏牌缩到原来（底栏高 40vh）的 82%，省下的高度给轨道（轨道在手机横屏是高度受限的） */
    --cw-h: calc(((40 * var(--vh) - var(--rx-fix)) * .7146 + 6px) * .82);
    --cw-w: calc((100vw - var(--sl) - var(--sr) - var(--act-w) - 3 * var(--gp) - 4 * var(--bp) - 8px - 5 * var(--bg)) / 7);
    --cw: max(56px, min(var(--cw-h), var(--cw-w), 92px));
    --card-w: var(--cw);
    --pnl-h: calc((var(--cw) - 6px) / .7146 + var(--rx-fix));
    --pm-wid: calc(4 * var(--cw) + 3 * var(--bg) + 2 * var(--bp) + 4px);
    --hand-in: calc(100vw - var(--sl) - var(--sr) - var(--act-w) - var(--pm-wid) - 2 * var(--gp) - 2 * var(--bp) - 4px);
    --fs: 12px;
  }
  #app {
    display: grid !important; gap: var(--gp) !important;
    padding: var(--st) var(--sr) var(--sb) var(--sl) !important;
    grid-template-columns: var(--pop-w) minmax(0, 1fr) var(--act-w);
    grid-template-rows: var(--top-h) minmax(0, 1fr) auto;
    /* 底栏：手牌与公共市场共用 hand 区（同一格里叠放定位），手牌宽度随张数变（和电脑版一样），公共市场紧跟其后 */
    grid-template-areas: "top top top" "pop market act" "hand hand act";
  }
  #app.has-portfolio {
    --pf-w: 154px;
    grid-template-columns: var(--pop-w) var(--pf-w) minmax(0, 1fr) var(--act-w);
    grid-template-areas: "top top top top" "pop pf market act" "hand hand hand act";
  }
  #app #portfolioPanel { grid-area: pf; padding: 3px 5px; }
  #app #portfolioPanel .pf-heading { min-height: 40px; margin-bottom: 0; }
  #app #portfolioPanel .avatar { width: 30px; }
  #app #portfolioPanel .pf-colors { gap: 4px; }
  #app #mainRow, #app #botRow { display: contents !important; }
  #app #top { grid-area: top; height: var(--top-h); gap: 6px; min-width: 0; }
  #app #popPanel { grid-area: pop; }
  #app #market { grid-area: market; --cell-min: 40px; --cell-max: .11; --cell-hk: 3.2; --cell-res: 6px; }
  #app #handArea { grid-area: hand; }
  #app #publicMarket { grid-area: hand; }
  #app #actionPanel { grid-area: act; }

  /* 顶栏 */
  #app #logo { width: clamp(70px, 11vw, 110px); }
  #app .logo-img { max-height: calc(var(--top-h) - 8px); }
  #app #scorePanel { gap: 6px !important; }
  #app #scorePanel .score-row { padding: 0 10px 0 3px !important; gap: 4px; height: var(--top-h); min-width: 44px; }
  #app #scorePanel .pbody { display: none !important; }
  #app #scorePanel .hc-mobile { display: inline-flex; align-items: center; }
  #app #scorePanel .avatar { width: calc(var(--top-h) - 8px) !important; height: calc(var(--top-h) - 8px) !important; }
  #app #scorePanel .tot { margin-left: 2px; font-size: 18px; }
  #app #btnNew { min-height: 40px; height: 40px; padding: 0 10px; font-size: 12px; line-height: 1.1; white-space: nowrap; }

  /* 人气：竖排小图标 + 数字 */
  #app #popPanel { align-self: start; width: var(--pop-w); padding: 4px 2px !important; gap: 2px; border-width: 2px; }
  #app #popPanel .panel-title, #app #popPanel .hint { display: none !important; }
  #app #popPanel .pop-list { gap: 2px; }
  #app #popPanel .pop-row { height: 28px; gap: 1px; padding: 0; justify-content: center; }
  #app #popPanel .pop-row .pic { width: 18px; height: 18px; }
  #app #popPanel .pop-row .pop-num { margin: 0; font-size: 14px; min-width: 1ch; text-align: right; }

  /* 轨道；放不下要横向滚动时，末尾多留一格（铺路「接在末尾」的箭头在最后一格之后）。
     由 responsive.js 按「轨道比可视区宽」切换 .ovf，而不是在选位置时才加：选完位置立刻去掉会让滚动位置跳一下 */
  #app #market { min-height: 0; }
  #app #trackScroll { padding: 0; }
  #app #trackWrap.ovf { padding-right: calc(var(--cell-w) * 1.1); }
  /* 触屏没有悬停：选位置时不需要在格子下方给悬停标签留 26px（style.css #trackWrap.placing），这段高度给格子（app.js fitCell 的 --cell-res） */
  #app #trackWrap.placing { padding-bottom: 0; }
  /* 新铺的牌：style.css 的 pop-in 从上方 26px、1.25 倍落下，矮轨道里会顶出上沿被裁；悬挂牌本身已有 pcfade 淡入 */
  #app #track .promo.pop-in { animation: none; }

  /* 底栏：手牌 / 公共市场 */
  #app #handArea, #app #publicMarket { height: var(--pnl-h) !important; max-height: none !important; align-self: end; }
  /* 和电脑版一样：手牌栏宽度 = 张数（至少 2）× 牌宽，最多到「公共市场放得下」为止（再多就叠放，见下方 margin-left）；
     手牌 + 公共市场连成一组、在行动栏左边居中，中间不留空。张数变化时宽度和位置都走 .25s 过渡
     （飞牌期间 #botRow.instant 关掉过渡，飞行目标按落定后的位置算，同电脑版）。--n 由 app.js 写在 #botRow 上 */
  #app #botRow {
    --hw: min(max(var(--peek-hand-min, 0px), calc(2 * var(--bp) + var(--n) * var(--cw) + (var(--n) - 1) * var(--bg) + 4px)), calc(var(--hand-in) + 2 * var(--bp) + 4px));
    --bx: max(0px, calc((100vw - var(--sl) - var(--sr) - var(--act-w) - 2 * var(--gp) - var(--hw) - var(--pm-wid)) / 2));
  }
  #app #botRow:has(#peekTokens:not([hidden])) { --peek-hand-min: 135px; }
  #app #peekTokens { margin-inline-start: 5px; }
  #peekTokens .peek-token-emblem { inline-size: 18px; }
  #peekTokens .peek-token-count { bottom: 0; min-width: 11px; height: 11px; padding-inline: 2px; font-size: 8px; }
  #app #handArea { justify-self: start; min-width: 0; width: var(--hw) !important; margin-left: var(--bx); }
  #app #publicMarket { justify-self: start; width: var(--pm-wid) !important; margin-left: calc(var(--bx) + var(--hw) + var(--gp)); }
  #app #botRow:not(.instant) > #handArea { transition: width .25s ease, margin-left .25s ease; }
  #app #botRow:not(.instant) > #publicMarket { transition: margin-left .25s ease; }
  #app #handArea .panel-title, #app #publicMarket .panel-title { font-size: var(--pfs) !important; }
  #app #hand { gap: 0 !important; }
  #app #hand .hcard + .hcard { margin-left: min(var(--bg), calc((var(--hand-in) - var(--cw)) / (var(--n) - 1) - var(--cw))); }
  #app #hand .hcard.sel { z-index: 7; }
  /* 标题与牌之间只有 3px：选中只靠金边与光晕，不上浮放大，免得压住标题 */
  /* 叠放时露出的是左半边：色带内容靠左，步数始终可见 */
  #app #handArea .hcard .cap, #app #publicMarket .pm-card .cap { height: var(--cap-h); font-size: 11px !important; }
  #app #handArea .hcard .cap { justify-content: flex-start !important; padding-left: 3px !important; }
  #app #hand .hint.empty-hand { font-size: 12px; padding: 4px; color: #f0e2bd; }
  #app #publicMarket .pm-card.deck .dkn { min-width: 18px; height: 18px; font-size: 11px; }

  /* 行动竖栏：4 键单列 ≥ 40px 高；置灰原因收进 ?；日志按钮在栏底 */
  /* 行动栏高度贴合内容（标题 + 4 键 + 底部一行 ? / 日志），贴底对齐，不再占满整列；? 与日志仍在栏底并排 */
  #app #actionPanel { width: auto !important; height: auto !important; max-height: none !important; padding: 5px 5px 51px !important; position: relative; align-self: end; }
  #app #actionPanel #actions { flex: 0 0 auto !important; }
  #app #actionPanel .panel-title { font-size: 12px !important; line-height: 1.2; margin: 0 0 2px !important; white-space: nowrap; justify-content: center; }
  #app #actionPanel #actions { padding: 0 !important; gap: 4px; overflow: visible; }
  #app #actionPanel #actions:not(.mode-edit) .btn-row.acts { flex: 0 0 auto !important; display: flex; flex-direction: column !important; gap: 6px !important; justify-content: flex-start !important; }
  /* 文字落在图标分隔线（≈30%）与右侧饰钉（≈91%）之间，两侧各留出几 px */
  #app #actionPanel #actions .btn-row.acts .btn.act { height: 40px !important; min-height: 40px !important; padding: 0 11% 0 34% !important; background-size: 100% 132%; }
  #app #actionPanel .btn.act .tt { font-size: 14px !important; letter-spacing: .02em; }
  /* 很矮的横屏（App 内浏览器有标题栏，可视高 ≤ 320px）：4 键 + 底部 ? / 日志放不下，省掉栏标题，免得 ? / 日志压住「收藏」 */
  @media (max-height: 320px) { #app #actionPanel .panel-title { display: none !important; } #app #actionPanel #actions:not(.mode-edit) .btn-row.acts { gap: 5px !important; } }
  html[lang="en"] #app #actionPanel .btn.act .tt { font-size: 11px !important; letter-spacing: 0; }
  html[lang="en"] #app #actionPanel #actions .btn-row.acts .btn.act { padding-left: 32% !important; }
  html[lang="en"] { --act-w: clamp(132px, 15.4vw, 146px); }
  #app #actions .btn-row:not(.acts) { gap: 4px; }
  #app #actions .btn-row:not(.acts) .btn { min-height: 40px; font-size: 13px; padding: 0 8px; }
  #app #actions .placehint { font-size: 12px; margin-bottom: 2px; }
  #app #actions .placebar #btnCancelPromote { min-height: 40px; }
  #app #actions .placewhy { font-size: 11px !important; padding: 2px; }
  #app #actionPanel .over-box { padding: 4px 0; gap: 6px; }
  #app #actionPanel .over-box .btn { min-height: 40px; min-width: 100%; font-size: 12px; }
  #app #actionPanel .over-box .hint { font-size: 11px; }
  /* 置灰原因：? 按钮 + 浮层 */
  #app #actionPanel details.reasons { display: block !important; position: absolute; left: 10px; bottom: 5px; margin: 0; padding: 0 !important; font-size: 12px !important; z-index: 40; }
  #app #actionPanel details.reasons summary { list-style: none; width: 40px; height: 40px; box-sizing: border-box; border-radius: 50%; display: flex; align-items: center; justify-content: center; font: 900 0/1 system-ui, sans-serif; color: transparent; background: #291f16; border: 2px solid #c9a24d; box-shadow: none; }
  #app #actionPanel details.reasons summary::-webkit-details-marker { display: none; }
  #app #actionPanel details.reasons summary::after { content: "?"; font: 800 16px/1 system-ui, sans-serif; color: #ffe9b0; }
  #app #actionPanel details.reasons summary:hover, #app #actionPanel details.reasons[open] summary { border-color: #ffe2a3; background: #463018; }
  #app #actionPanel details.reasons[open] summary::after { color: #fff0c1; }
  #app #actionPanel details.reasons .rsn-list { position: fixed; right: calc(var(--sr) + var(--act-w) + 6px); bottom: var(--sb); width: min(320px, 52vw); max-height: 70vh; overflow-y: auto; padding: 6px 10px; background: #1a110bf2; border: 2px solid #c9a24d; border-radius: 8px; box-shadow: 0 6px 18px #000c; color: #f0e2bd; line-height: 1.35; font-size: 12px; }
  #app #actionPanel details.reasons .rsn-list > div + div { margin-top: 3px; }

  /* 日志：折叠为行动栏底部的按钮，点开浮层 */
  #app #logPanel { grid-area: act; position: relative !important; align-self: end; justify-self: end; top: auto !important; right: auto !important; margin: 0 12px 7px 0; width: calc(var(--act-w) - 68px) !important; height: 42px; box-sizing: border-box; max-height: none !important; padding: 0 !important; z-index: 30; overflow: visible !important; opacity: 1; background: #1d140c !important; border: 1px solid #8a6a2f !important; border-radius: 8px; }
  /* ? 与日志是次要按钮：和行动键同高（40px）、并排一行，左右对齐行动键贴图的可见边（贴图两侧各有约 5px 透明边），边框 / 字号都比行动键轻 */
  #app #logPanel .panel-title { display: flex; align-items: center; justify-content: center; height: 100%; margin: 0 !important; font-size: 12px !important; font-weight: 600; color: #e6d3a3; }
  #app #logPanel .log-title { justify-content: space-between !important; gap: 2px; padding: 0 2px !important; font-size: 10px !important; }
  #app #logPanel .log-toggle { width: 20px; height: 24px; padding: 2px; }
  #app #logPanel .log-toggle svg { width: 14px; height: 14px; }
  #app #logPanel:not(.open) #log { display: none; }
  #app #logPanel.open { background: #2a1c10 !important; }
  /* 行动栏贴底后，日志浮层向左展开（右边距行动栏左边 6px、底边对齐；#logPanel 右边离栏右边 12px），不盖住行动键 */
  #app #logPanel.open #log { display: block; position: absolute; left: auto; top: auto; right: calc(var(--act-w) - 6px); bottom: -7px; width: min(420px, 60vw); max-height: calc(100 * var(--vh) - var(--top-h) - 70px); overflow-y: auto; padding: 6px 10px; background: #1a110bf5; border: 2px solid #c9a24d; border-radius: 8px; box-shadow: 0 6px 18px #000c; font-size: 12px !important; }
  #app #logPanel.open #log > div { display: block !important; }

  /* 游戏内提示（tutorial.js 的 .tu-tip）：收成顶栏空隙里的一行（标题 + 知道了），不压轨道 / 棋子 / 手牌 / 名牌 / 行动键；
     点一下展开全文（向下展开，用户主动查看时才盖住轨道）。位置由 responsive.js 写入 --tip-l / --tip-w */
  .tu-tip { left: var(--tip-l, 40vw) !important; top: var(--st) !important; right: auto !important; bottom: auto !important;
    width: auto; min-width: 0; max-width: var(--tip-w, 30vw); height: var(--top-h); padding: 0 3px 0 10px; gap: 6px;
    flex-direction: row; align-items: center; border-radius: 999px; font-size: 12px; line-height: 1.2; pointer-events: auto; cursor: pointer; animation: none; }
  .tu-tip::before { content: "💡 " attr(data-head) " ▾"; flex: 1 1 auto; min-width: 0; white-space: nowrap; font-weight: 800; }
  .tu-tip.rs-open::before { content: "💡 " attr(data-head) " ▴"; }
  .tu-tip > p { display: none; }
  .tu-tip.rs-open > p { display: block; position: absolute; right: 0; top: calc(100% + 6px); width: min(360px, 60vw); margin: 0; padding: 8px 10px; border-radius: 10px; background: linear-gradient(#f6ead0, #ead7ad); box-shadow: 0 6px 18px #000b, inset 0 0 0 2px #b8913f; font-size: 12.5px; line-height: 1.45; cursor: default; }
  .tu-tip .tu-tip-arrow { display: none; }
  .tu-tip .tu-tip-ok { flex: none; min-height: 34px; padding: 0 12px; font-size: 12px; align-self: center; }

  /* 状态浮条：允许换行，不截断 */
  #statusRow { top: calc(var(--top-h) + 10px); max-width: 80vw; }
  #statusRow.msg #banner { white-space: normal; font-size: 13px; }

  /* 弹窗 */
  .dialog { max-height: calc(100 * var(--vh) - 16px); max-width: calc(100vw - var(--sl) - var(--sr)); padding: 10px 14px; }
  .dialog h2 { font-size: 16px; margin-bottom: 4px; }
  .dialog th, .dialog td { padding: 2px 8px; }
  .dialog .row { margin: 6px 0; }
  .dialog .btn { min-height: 40px; }
  .dialog .mini img { height: clamp(56px, calc(22 * var(--vh)), 110px); }
}

/* =====================================================================
   B. 竖屏（平板竖屏 / 窄窗口；手机竖屏另有窄屏分区）
   顶栏两行：Logo · 新局 / 四张名牌整行
   中部：人气竖条 | 轨道（放大，日志浮在右上）
   底栏两行：手牌整行 / 公共市场 + 行动（2×2）
   ===================================================================== */
@media (orientation: portrait) {
  :root {
    --sl: max(6px, env(safe-area-inset-left)); --sr: max(6px, env(safe-area-inset-right));
    --st: max(6px, env(safe-area-inset-top)); --sb: max(6px, env(safe-area-inset-bottom));
    --gp: 6px;
    --top-h: clamp(44px, calc(5 * var(--vh)), 64px);
    --pop-w: clamp(46px, 7vw, 76px);
    --cw: max(56px, min(calc((100vw - var(--sl) - var(--sr) - 60px) / 5.5), calc(10.5 * var(--vh)), 176px));
    --card-w: var(--cw);
    --bp: clamp(8px, calc(var(--cw) * .09), 14px); --bg: clamp(5px, calc(var(--cw) * .055), 10px);
    --pfs: clamp(13px, calc(var(--cw) * .12), 20px); --ptg: 6px;
    --cap-h: clamp(16px, calc(var(--cw) * .15), 24px);
    --pm-wid: calc(4 * var(--cw) + 3 * var(--bg) + 2 * var(--bp) + 4px);
    --act-w: calc(100vw - var(--sl) - var(--sr) - var(--gp) - var(--pm-wid));
    --hand-in: calc(100vw - var(--sl) - var(--sr) - 2 * var(--bp) - 4px);
    --pnl-h: calc(var(--bp) + var(--pfs) * 1.2 + var(--ptg) + (var(--cw) - 6px) / .7146 + var(--cap-h) + 6px + 4px + var(--bp));
    --fs: clamp(12px, calc(1.3 * var(--vh)), 16px);
  }
  #app {
    display: grid !important; gap: var(--gp) !important;
    padding: var(--st) var(--sr) var(--sb) var(--sl) !important;
    grid-template-columns: var(--pop-w) minmax(0, 1fr) var(--act-w);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "top top top" "pop market market" "hand hand hand" "pm pm act";
  }
  #app.has-portfolio {
    --pf-w: clamp(160px, 23vw, 200px);
    grid-template-columns: var(--pop-w) var(--pf-w) minmax(0, 1fr) var(--act-w);
    grid-template-areas: "top top top top" "pop pf market market" "hand hand hand hand" "pm pm pm act";
  }
  #app #portfolioPanel { grid-area: pf; }
  #app #mainRow, #app #botRow { display: contents !important; }
  #app #top { grid-area: top; height: auto; flex-wrap: wrap; row-gap: var(--gp); align-items: center; }
  #app #popPanel { grid-area: pop; }
  #app #market { grid-area: market; --cell-min: 40px; --cell-max: .16; position: relative; }
  #app #trackWrap.ovf { padding-right: calc(var(--cell-w) * 1.1); }
  #app #handArea { grid-area: hand; }
  #app #publicMarket { grid-area: pm; }
  #app #actionPanel { grid-area: act; }

  /* 顶栏：Logo | 名牌 2×2（一排四张时每张不到 200px，名次 / 预估放不下） | 新局 */
  #app #top { flex-wrap: nowrap; gap: var(--gp); }
  #app #logo { height: 40px; width: clamp(90px, 15vw, 200px); }
  #app .logo-img { max-height: 40px; }
  #app #btnNew { margin-left: 0; min-height: 40px; max-width: 13vw; white-space: normal; line-height: 1.15; padding: 2px 8px; }
  #app #scorePanel { flex: 1 1 0 !important; min-width: 0; display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: row; grid-auto-rows: var(--top-h); gap: var(--gp) !important; }
  #app #scorePanel .score-row { height: var(--top-h); }
  #app #scorePanel .pbody { flex: 1 0 auto !important; min-width: auto; }
  /* 手牌数与预估同一行；放不下时由 app.js fitEst() 退成“预估 +N”（它靠行的 scrollWidth 判断，所以这里不裁切） */
  #app #scorePanel .sub { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
  #app #scorePanel .est { flex: 0 0 auto; overflow: visible; margin-left: 0; }

  /* 人气竖条 */
  #app #popPanel { align-self: start; width: var(--pop-w); padding: 6px 4px !important; }
  #app #popPanel .panel-title { font-size: 12px !important; text-align: center; white-space: nowrap; overflow: visible; }
  html[lang="en"] #app #popPanel .panel-title { font-size: 0 !important; height: 0; margin: 0; }
  #app #popPanel .pop-row { height: clamp(32px, calc(4.2 * var(--vh)), 60px); justify-content: center; gap: 4px; padding: 0; }
  #app #popPanel .pop-row .pic { width: clamp(22px, 3.4vw, 36px); height: clamp(22px, 3.4vw, 36px); }
  #app #popPanel .pop-row .pop-num { margin: 0; font-size: clamp(15px, 2.4vw, 24px); }

  /* 日志：轨道区右上角的折叠按钮（样式见 C 段），点开展开 */
  #app #logPanel { grid-area: market; position: absolute !important; top: 0 !important; right: 0 !important; }

  /* 底栏 */
  #app #handArea, #app #publicMarket, #app #actionPanel { height: var(--pnl-h) !important; max-height: none !important; }
  #app #handArea { width: auto !important; }
  #app #publicMarket { width: var(--pm-wid) !important; }
  #app #actionPanel { width: auto !important; }
  #app #hand { gap: 0 !important; }
  #app #hand .hcard + .hcard { margin-left: min(var(--bg), calc((var(--hand-in) - var(--cw)) / (var(--n) - 1) - var(--cw))); }
  #app #handArea .hcard .cap, #app #publicMarket .pm-card .cap { height: var(--cap-h); font-size: max(12px, calc(var(--cw) * .1)) !important; }
  #app #actionPanel .panel-title { font-size: var(--pfs) !important; white-space: nowrap; }
  #app #actionPanel #actions { padding-bottom: 0 !important; }
  #app #actionPanel #actions:not(.mode-edit) .btn-row.acts { flex: 0 0 auto !important; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px !important; }
  #app #actionPanel #actions .btn-row.acts .btn.act { height: clamp(42px, calc(var(--cw) * .4), 60px) !important; padding: 0 11% 0 33% !important; }
  #app #actionPanel .btn.act .tt { font-size: clamp(14px, calc(var(--cw) * .13), 19px) !important; }
  html[lang="en"] #app #actionPanel .btn.act .tt { font-size: clamp(11px, calc(var(--cw) * .095), 16px) !important; letter-spacing: 0; }
  html[lang="en"] #app #actionPanel #actions .btn-row.acts .btn.act { padding-left: 32% !important; }
  #app #actionPanel .panel-title { padding-right: 34px !important; }
  #app #actions .btn-row:not(.acts) .btn { min-height: 40px; }
  #app #actions .placebar #btnCancelPromote { min-height: 40px; }

  #statusRow { max-width: 90vw; }
  #statusRow.msg #banner { white-space: normal; }
}

/* =====================================================================
   C. 触屏横屏平板（iPad 横屏等，高 > 500px）：沿用桌面版面，只做三件事——
   牌放大（手牌超过 3 张时叠放，省出宽度给牌）、行动键 ≥ 40px 且 4 个都在、
   置灰原因收进 ? 浮层、日志折叠成按钮（窄屏下日志原本被截成半行）。
   只匹配 pointer: coarse，桌面鼠标窗口不受影响。
   ===================================================================== */
@media (pointer: coarse) and (orientation: landscape) and (min-height: 501px) {
  :root {
    --cw: min(calc(15 * var(--vh)), calc((100vw - 2 * var(--edge) - 48px) / 9.1), 176px);
    --pnl-h: calc(var(--cw) * 2.01 + 10px);
    --hand-in: calc(var(--cw) + (min(var(--n, 3), 3.5) - 1) * (var(--cw) + var(--bg)));
  }
  /* 英文行动栏更宽（m5.css: 1.62 × 牌宽） */
  html[lang="en"] { --cw: min(calc(15 * var(--vh)), calc((100vw - 2 * var(--edge) - 48px) / 9.45), 176px); }
  html[lang="en"] #app #popPanel .panel-title { font-size: 12px !important; letter-spacing: 0; }
  #app #handArea { width: calc(2 * var(--bp) + var(--hand-in) + 4px) !important; }
  #app #hand { gap: 0 !important; }
  #app #hand .hcard + .hcard { margin-left: min(var(--bg), calc((var(--hand-in) - var(--cw)) / (var(--n) - 1) - var(--cw))); }
  #app #hand .hcard.sel { z-index: 7; }
  #app #handArea .hcard .cap { justify-content: flex-start !important; padding-left: 5px !important; }
  #app #actionPanel .panel-title { padding-right: 34px !important; white-space: nowrap; }
  #app #actionPanel #actions .btn-row.acts { justify-content: space-evenly !important; }
  #app #actionPanel #actions .btn-row.acts .btn.act { height: max(40px, calc(var(--cw) * .32)) !important; }
  #app #actions .btn-row:not(.acts) .btn { min-height: 40px; }
  #app #actions .placebar #btnCancelPromote, #app #actions .placebar #btnConfirmPromote { min-height: 40px; }
  #app { --rsn-b: calc(var(--pnl-h) + var(--bot-gap) + 12px); }
}

/* 平板（触屏横屏 / 竖屏）：置灰原因收进行动栏右上角的 ? 按钮，点开为浮层 */
@media (pointer: coarse) and (orientation: landscape) and (min-height: 501px), (orientation: portrait) {
  #app #actionPanel { position: relative; }
  #app #actionPanel details.reasons { display: block !important; position: absolute; right: 2px; top: 2px; margin: 0; padding: 0 !important; z-index: 40; }
  #app #actionPanel details.reasons summary { list-style: none; width: 40px; height: 40px; box-sizing: border-box; border: 2px solid #c9a24d; border-radius: 50%; font-size: 0; color: transparent; background: #291f16; display: flex; align-items: center; justify-content: center; }
  #app #actionPanel details.reasons summary::-webkit-details-marker { display: none; }
  #app #actionPanel details.reasons summary::after { content: "?"; font: 900 16px/1 system-ui, sans-serif; color: #ffe9b0; }
  #app #actionPanel details.reasons summary:hover, #app #actionPanel details.reasons[open] summary { border-color: #ffe2a3; background: #463018; }
  #app #actionPanel details.reasons[open] summary::after { color: #fff0c1; }
  #app #actionPanel details.reasons .rsn-list { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: var(--rsn-b, calc(var(--pnl-h) + var(--sb, 6px) + 12px)); width: min(360px, 60vw); max-height: 50vh; overflow-y: auto; padding: 8px 12px; background: #1a110bf2; border: 2px solid #c9a24d; border-radius: 8px; box-shadow: 0 6px 18px #000c; color: #f0e2bd; font-size: 13px; line-height: 1.4; }
  #app #actionPanel details.reasons .rsn-list > div + div { margin-top: 4px; }
}

/* 平板（触屏横屏 / 竖屏）日志：折叠成 40px 高的按钮，点开浮层 */
@media (pointer: coarse) and (orientation: landscape) and (min-height: 501px), (orientation: portrait) {
  #app #logPanel { width: auto !important; min-width: 64px; height: auto; max-height: none !important; padding: 0 !important; overflow: visible !important; z-index: 30 !important; }
  #app #logPanel .panel-title { display: flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px; margin: 0 !important; font-size: 14px !important; }
  #app #logPanel .log-title { justify-content: space-between !important; gap: 4px; padding: 0 6px !important; font-size: 13px !important; }
  #app #logPanel .log-toggle { width: 20px; height: 24px; padding: 2px; }
  #app #logPanel:not(.open) #log { display: none; }
  #app #logPanel.open { width: min(460px, 42vw) !important; }
  #app #logPanel.open .panel-title { justify-content: flex-start; }
  #app #logPanel.open #log { display: block; max-height: calc(55 * var(--vh)); overflow-y: auto; padding: 0 12px 8px; font-size: 13px !important; }
  #app #logPanel.open #log > div { display: block !important; }
}

@media (orientation: landscape) and (max-height: 500px), (orientation: portrait) and (max-width: 500px) {
  #app #logPanel:not(.open) .log-toggle { display: none !important; }
  #app #logPanel:not(.open) .log-title { justify-content: center !important; padding-inline: 0 !important; }
  #app #logPanel:not(.open) .log-title-text { flex: 0 1 auto; }
}

/* =====================================================================
   D. 大厅（开局设置）
   触屏：单选 / 勾选的命中区 ≥ 40px 高。
   手机横屏：设计稿等比缩到 0.35 时文字（下限 12px）会挤进相邻单选，所以改为固定 --s = .52，
   隐去 Logo、行高 40px、标题牌缩小，整块在 360px 高内放得下；更矮时舞台可纵向滚动兜底。
   平板竖屏：按宽度放大，不再是屏幕中间一小块。
   ===================================================================== */
@media (pointer: coarse) {
  #modal.lobby .lb-r { min-height: 40px; }
  #modal.lobby .lb-chk { min-width: 40px; min-height: 40px; align-items: center; justify-content: center; }
  #modal.lobby .lb-range { height: 40px; }
}
@media (orientation: portrait) {
  #modal.lobby { --s: min(calc((100vw - 32px) / 1100), calc(100 * var(--vh) / 1080)); }
}
@media (orientation: portrait) and (max-width: 650px) {
  #modal.lobby:not(.ol) { --fs: 14px; }
  #modal.lobby:not(.ol) .lb-stage {
    justify-content: flex-start;
    overflow-y: auto;
    padding: max(72px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  #modal.lobby:not(.ol) .lb-logo { display: none; }
  #modal.lobby:not(.ol) .lb-panel {
    width: 100%;
    min-width: 0;
    margin-top: 20px;
    padding: 32px 18px 20px;
    box-sizing: border-box;
  }
  #modal.lobby:not(.ol) .lb-title { min-width: 190px; height: 40px; top: -18px; }
  #modal.lobby:not(.ol) .lb-title h2 { font-size: 16px; }
  #modal.lobby:not(.ol) .lb-rows { display: block; }
  #modal.lobby:not(.ol) .lb-row {
    display: flex;
    flex-wrap: wrap;
    height: auto;
    gap: 0 8px;
    padding: 5px 0;
    white-space: normal;
  }
  #modal.lobby:not(.ol) .lb-row > .lb-ic { flex: 0 0 18px; }
  #modal.lobby:not(.ol) .lb-label { flex: 1 0 calc(100% - 26px); padding: 0; line-height: 22px; }
  #modal.lobby:not(.ol) .lb-row .lb-r {
    flex: 0 0 calc(33.333% - 5.333px);
    min-width: 0;
    min-height: 40px;
    padding: 2px 0;
    box-sizing: border-box;
  }
  #modal.lobby:not(.ol) .lb-r span { white-space: normal; line-height: 1.3; }
  #modal.lobby:not(.ol) .lb-snd { flex: 1 1 100%; min-width: 0; gap: 8px; }
  #modal.lobby:not(.ol) .lb-chk { min-width: 40px; min-height: 40px; align-items: center; justify-content: center; }
  #modal.lobby:not(.ol) .lb-range { flex: 1; min-width: 0; height: 40px; }
  #modal.lobby:not(.ol) .lb-range::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8px; }
  #modal.lobby:not(.ol) .lb-range::-moz-range-thumb { width: 20px; height: 20px; }
  #modal.lobby:not(.ol) .lb-hint { flex: 1; min-width: 0; font-size: 12px; line-height: 1.5; white-space: normal; }
  #modal.lobby:not(.ol) .lb-btns { flex-wrap: wrap; gap: 8px; margin-top: 12px; }
  #modal.lobby:not(.ol) .lb-btns .lb-btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    min-height: 44px;
    height: auto;
    padding: 10px 12px;
    font-size: 14px;
    letter-spacing: 0;
  }
  #modal.lobby:not(.ol) .lb-btns .lb-primary { flex-basis: 100%; }
  #modal.lobby:not(.ol) .lb-online, #modal.lobby:not(.ol) .lb-journal {
    top: 12px;
    min-height: 44px;
    height: 44px;
    font-size: 12px;
    padding: 0 14px;
  }
  #modal.lobby:not(.ol) .lb-online { left: 12px; right: auto; }
  #modal.lobby:not(.ol) .lb-journal { right: 12px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #modal.lobby { --s: .52px; --fs: 13px; }
  :root:lang(en) #modal.lobby { --fs: 13px; }
  #modal.lobby .lb-stage { justify-content: safe center; overflow-y: auto; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  #modal.lobby .lb-logo { display: none; }
  #modal.lobby .lb-panel { margin-top: 14px; width: auto; max-width: calc(100vw - 16px); padding: 30px 24px 12px; }
  html.lb-has-panel_lobby #modal.lobby .lb-panel::before { border-image-width: 40px; }
  #modal.lobby .lb-gem { width: 44px; height: 40px; }
  #modal.lobby .lb-title { top: -14px; height: 40px; min-width: 180px; }
  html.lb-has-title_plaque #modal.lobby .lb-title { top: -14px; height: 40px; padding: 0 calc(31.5px + 12px); border-image-width: 0 31.5px; }
  #modal.lobby .lb-title h2 { font-size: 15px; margin: 0; }
  #modal.lobby .lb-rows { grid-template-columns: 20px max-content repeat(5, minmax(52px, max-content)) 1fr; column-gap: 12px; }
  #modal.lobby .lb-row { height: 40px; }
  #modal.lobby .lb-btns { margin-top: 8px; gap: 18px; }
  #modal.lobby .lb-resumable { gap: 10px; }
  #modal.lobby .lb-resumable .lb-secondary { min-width: 0; height: 36px; font-size: 12px; }
  #modal.lobby .lb-resumable .lb-primary { min-width: 180px; height: 44px; }
  #modal.lobby .lb-primary { font-size: 15px; }
  #modal.lobby .lb-secondary { height: 40px; font-size: 13px; }
  html.lb-has-btn_secondary #modal.lobby .lb-secondary { border-image-width: 0 18.4px; padding: 0 28px; }
  #modal.lobby .lb-extra .lb-guided { min-width: 170px; }
  #modal.lobby .lb-extra .lb-learning:not(.lb-guided) { min-width: 130px; height: 36px; font-size: 12px; }
  html.lb-has-btn_secondary #modal.lobby .lb-learning::before { border-image-width: 0 18.4px; }
  html.lb-has-btn_secondary #modal.lobby .lb-learning:not(.lb-guided)::before { border-image-width: 0 16.6px; }
  #modal.lobby .lb-toast { position: fixed; bottom: 8px; font-size: 13px; }
  #modal.lobby .lb-hint { font-size: 11px; white-space: normal; line-height: 1.15; }
}
/* 7 行设置（含“游戏内提示”）在 360–400px 高里放不下 40px 行高：行距收到 36px，
   单选 / 勾选的命中区仍是 40px（上下各探出 2px，不与相邻行的控件重叠） */
@media (orientation: landscape) and (max-height: 400px) {
  #modal.lobby .lb-panel { padding-top: 26px; padding-bottom: 8px; }
  #modal.lobby .lb-row { height: 36px; }
  #modal.lobby .lb-btns { margin-top: 4px; }
  #modal.lobby .lb-primary { height: 40px; }
}
@media (orientation: landscape) and (max-height: 370px) {
  #modal.lobby .lb-panel { margin-top: 8px; padding-top: 20px; padding-bottom: 4px; }
  #tutorial:not(.tu-asking) .tu-panel { height: calc(100vh - 37px); margin-top: 8px; padding-top: 24px; padding-bottom: 6px; }
}

/* 短横屏将八项设置分成两列，底部两组操作并排，保留完整触控高度。 */
@media (orientation: landscape) and (max-height: 500px) {
  #modal.lobby:not(.ol) .lb-stage { padding: 4px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left)); }
  #modal.lobby:not(.ol) .lb-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 12px;
    width: min(940px, 100%);
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 10px;
    padding: 28px 12px 6px;
  }
  #modal.lobby:not(.ol) .lb-rows { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
  #modal.lobby:not(.ol) .lb-row {
    grid-column: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: start;
    height: 56px;
    min-height: 0;
    box-sizing: border-box;
    gap: 0 4px;
    white-space: normal;
  }
  #modal.lobby:not(.ol) .lb-row > .lb-ic { width: 14px; height: 14px; }
  #modal.lobby:not(.ol) .lb-label { flex: 1 0 calc(100% - 18px); padding: 0; line-height: 15px; }
  #modal.lobby:not(.ol) .lb-r { flex: 1 1 0; min-width: 0; min-height: 40px; gap: 4px; font-size: 12px; }
  #modal.lobby:not(.ol) .lb-r span { white-space: normal; line-height: 1.15; }
  #modal.lobby:not(.ol) .lb-snd { flex: 1 1 100%; min-width: 0; height: 40px; gap: 8px; }
  #modal.lobby:not(.ol) .lb-chk { min-width: 40px; min-height: 40px; align-items: center; justify-content: center; }
  #modal.lobby:not(.ol) .lb-range { flex: 1; min-width: 0; width: auto; height: 40px; }
  #modal.lobby:not(.ol) .lb-btns { gap: 4px; margin-top: 4px; min-width: 0; }
  #modal.lobby:not(.ol) .lb-btns .lb-btn {
    flex: 1 1 0;
    min-width: 0;
    height: 40px;
    min-height: 40px;
    padding: 0 8px;
    font-size: 12px;
    letter-spacing: 0;
  }
  #modal.lobby:not(.ol) .lb-journal, #modal.lobby:not(.ol) .lb-online {
    top: 4px;
    height: 40px;
    min-height: 40px;
    padding: 0 12px;
    font-size: 12px;
  }
  #modal.lobby:not(.ol) .lb-online { left: max(8px, env(safe-area-inset-left)); right: auto; }
}

/* =====================================================================
   联机（src/ui/online.js / online.css）：大厅入口、联机大厅、等待房间
   手机横屏：沿用大厅的 --s=.52px，面板铺满宽度，表单行 40px（触控命中区），房间列表限高滚动；
   竖屏（平板竖屏 / 窄窗口）：两栏改成上下排列，4 人座位 2×2。
   ===================================================================== */
@media (pointer: coarse) {
  #modal.lobby .ol-input { min-height: 40px; }
  #modal.lobby .ol-link { min-height: 40px; min-width: 40px; }
  #modal.lobby .ol-chk { min-height: 40px; }
  #modal.lobby .lb-online, #modal.lobby .ol-room-join, #modal.lobby .ol-join .lb-btn, #modal.lobby .ol-codebox .lb-btn { min-height: 40px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #modal.lobby .lb-online { position: fixed; top: max(4px, env(safe-area-inset-top)); right: max(6px, env(safe-area-inset-right)); height: 40px; font-size: 12px; letter-spacing: 0; }
  html.lb-has-btn_secondary #modal.lobby .lb-online { border-image-width: 0 18.4px; padding: 0 22px; }
  #modal.lobby.ol .lb-panel.ol-panel { width: calc(100vw - 16px); max-width: none; margin-top: 12px; padding: 26px 18px 6px; }
  #modal.lobby.ol .ol-cols { gap: 18px; }
  #modal.lobby.ol .ol-h { margin-bottom: 2px; }
  #modal.lobby.ol .ol-h h3 { font-size: 14px; margin-bottom: 2px; }
  #modal.lobby.ol .ol-row { min-height: 40px; column-gap: 12px; row-gap: 0; }
  #modal.lobby.ol .ol-checks { column-gap: 22px; }
  #modal.lobby.ol .ol-lbl { min-width: 54px; }
  #modal.lobby.ol .ol-input { font-size: 14px; padding: 4px 8px; }
  #modal.lobby.ol .ol-rooms { min-height: 112px; max-height: calc(100 * var(--vh, 1vh) - 230px); }
  #modal.lobby.ol .ol-room { padding: 4px 8px; gap: 8px; }
  #modal.lobby.ol .ol-room .avatar { width: 34px; }
  #modal.lobby.ol .ol-join { margin-top: 4px; gap: 8px; }
  #modal.lobby.ol .ol-lineup { margin-top: 2px; font-size: 12px; }
  #modal.lobby.ol .ol-act { margin-top: 4px; }
  #modal.lobby.ol .ol-act .lb-primary, #modal.lobby.ol .ol-btns .lb-primary { min-width: 0; height: 40px; }
  #modal.lobby.ol .ol-adv { margin-top: 2px; }
  #modal.lobby.ol .ol-status { margin-top: 2px; font-size: 12px; }
  #modal.lobby.ol .ol-roominfo { padding-bottom: 6px; font-size: 13px; }
  #modal.lobby.ol .ol-seats { margin: 10px 0 4px; gap: 10px; }
  #modal.lobby.ol .ol-seat { padding: 8px 6px; gap: 4px; }
  #modal.lobby.ol .ol-seat .avatar { width: 64px; }
  #modal.lobby.ol .ol-btns { margin-top: 8px; gap: 14px; }
}
@media (orientation: portrait) {
  #modal.lobby.ol .lb-panel.ol-panel { width: calc(100vw - 24px); }
  #modal.lobby.ol .ol-cols { grid-template-columns: minmax(0, 1fr); row-gap: calc(28 * var(--s)); }
  #modal.lobby.ol .ol-rooms { min-height: calc(200 * var(--s)); max-height: calc(360 * var(--s)); }
  #modal.lobby.ol .ol-seats[data-n="4"] { --cols: 2; }
}
@media (orientation: portrait) and (max-width: 500px) {
  #modal.lobby.ol .lb-stage { overflow-y: auto; justify-content: safe center; }
}

/* ---------- 手机竖屏：完整牌桌与宽触控行动区 ---------- */
@media (orientation: portrait) and (max-width: 500px) {
  :root { --pop-w: clamp(44px, 13vw, 52px); --phone-panel-h: clamp(148px, var(--pnl-h), 172px); --phone-action-h: 148px; --sb: max(24px, calc(env(safe-area-inset-bottom) + 12px)); }
  #app {
    grid-template-columns: var(--pop-w) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) var(--phone-panel-h) var(--phone-panel-h) var(--phone-action-h);
    grid-template-areas: "top top" "pop market" "hand hand" "pm pm" "act act";
  }
  #app.has-portfolio {
    grid-template-columns: var(--pop-w) minmax(0, 1fr);
    grid-template-areas: "top top" "pop market" "hand hand" "pm pm" "act act";
  }
  #app #portfolioPanel {
    position: absolute;
    z-index: 40;
    top: calc(var(--st) + var(--top-h) + 6px);
    left: calc(var(--sl) + var(--pop-w) + var(--gp));
    width: min(170px, 44vw);
    max-height: max(0px, calc(100dvh - var(--st) - var(--top-h) - 2 * var(--phone-panel-h) - var(--phone-action-h) - 4 * var(--gp) - var(--sb)));
    background: #1a110bf2;
  }
  #app #portfolioPanel:has(details:not([open])) { width: 40px; }
  #app #logo { display: none; }
  #app #btnNew { max-width: none; padding: 2px 8px; font-size: 12px; }
  #app #scorePanel {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: var(--top-h);
    grid-auto-flow: column;
  }
  #app #scorePanel .score-row { min-width: 0; padding: 0 5px !important; gap: 3px; justify-content: center; }
  #app #scorePanel .avatar { width: 30px !important; height: 30px !important; }
  #app #scorePanel .pbody { display: none !important; }
  #app #scorePanel .hc-mobile { display: inline-flex; align-items: center; }
  #app #scorePanel .tot { margin-left: 0; font-size: 16px; }
  #app #popPanel { width: auto; max-height: 100%; overflow-y: auto; }
  #app #market { min-height: 0; }
  #app #handArea, #app #publicMarket {
    width: auto !important;
    height: var(--phone-panel-h) !important;
    max-height: none !important;
    min-width: 0;
  }
  #app #actionPanel { width: auto !important; height: var(--phone-action-h) !important; max-height: none !important; min-width: 0; }
  #app #actionPanel:has(#actions.mode-edit) { height: var(--phone-action-h) !important; min-height: 0; overflow-y: auto; }
  #app #actionPanel #actions.mode-edit > .panel-title { height: 30px !important; min-height: 30px !important; }
  #app #actionPanel #actions:is(.turn-confirmation, .mode-edit:has(.devbar)) {
    position: relative; flex: 1 1 auto; min-height: 0; box-sizing: border-box; padding-bottom: 8px;
  }
  #app #actionPanel #actions.mode-edit:has(.devbar) .action-controls,
  #app #actionPanel #actions.turn-confirmation .turn-confirmation-buttons {
    position: absolute; left: 0; bottom: 25%; width: 100%;
  }
  #app #actionPanel #actions.turn-confirmation { justify-content: flex-start; }
  #app #actions.mode-edit .action-controls .devbar { grid-column: 1; }
  #app #actions.mode-edit .action-controls > .local-turn-controls { grid-column: 2; }
  #app #actions.mode-edit .action-controls:has(> .devbar + .local-turn-controls:not([hidden])) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px 8px;
  }
  #app #actionPanel #actions.mode-edit .action-controls :is(.devbar, .local-turn-controls) .btn {
    box-sizing: border-box; width: 100%; max-width: none; height: 40px; min-height: 40px;
  }
  #app #actionPanel #actions.turn-confirmation .turn-confirmation-buttons {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; gap: 8px;
  }
  #app #actionPanel #actions.turn-confirmation .turn-confirmation-buttons .btn {
    box-sizing: border-box; width: 100%; height: 40px; min-height: 40px;
  }
  #app #actions:not(.mode-edit):not(.reward-controls):not(.turn-confirmation) > .local-turn-controls {
    position: absolute; top: 2px; right: 46px;
  }
  #app #handArea { max-width: none; }
  #app #publicMarket { max-width: none; }
  #app #publicMarket .pm-row { justify-content: center; gap: 4px; }
  #app #hand .hcard, #app #publicMarket .pm-card { scale: 1 .95; }
  #app #actionPanel { padding: 6px 8px; }
  #app #actionPanel .panel-title { padding-right: 36px !important; margin: 0 0 2px !important; font-size: 14px !important; }
  #app #actionPanel #actions:not(.mode-edit) .btn-row.acts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px !important;
    width: 100%;
  }
  #app #actionPanel #actions .btn-row.acts.collecting { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  #app #actionPanel #actions .btn-row.acts.collecting .btn.act { grid-column: span 2; }
  #app #actionPanel #actions .btn-row.acts.collecting #btnSkipCollect {
    grid-column: 3 / span 2;
    min-width: 0;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 4px;
    font-size: 12px;
    white-space: nowrap;
  }
  #app #actionPanel #actions .btn-row.acts .btn.act {
    width: 100%;
    min-width: 0;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 8px 0 30% !important;
  }
  #app #actionPanel .btn.act .tt { font-size: clamp(12px, 3.5vw, 15px) !important; letter-spacing: 0; }
  html[lang="en"] #app #actionPanel .btn.act .tt { font-size: clamp(11px, 3vw, 13px) !important; }
  #app #actionPanel details.reasons .rsn-list {
    bottom: calc(var(--phone-action-h) + var(--sb) + 6px);
    width: min(320px, 78vw);
    max-height: min(50vh, calc(100dvh - var(--phone-action-h) - var(--sb) - 12px));
  }
  #app #actionPanel #preview { max-height: 1.5em; overflow: hidden; padding: 0 2px; font-size: 10px; }
  .tu-tip { display: none !important; }
}
@media (orientation: portrait) and (max-width: 360px) {
  #app #scorePanel .score-row { padding: 0 2px !important; gap: 1px; }
  #app #scorePanel .avatar { width: clamp(18px, 6vw, 22px) !important; height: clamp(18px, 6vw, 22px) !important; }
  #app #scorePanel .tot { font-size: 12px; }
}
