/* ==========================================================================================
   devices.css — multi-device layer (loaded last). Desktop Chrome / Edge / Firefox / Safari, iPad and Android tablets
   in landscape, phones in landscape (代表验收覆盖至 568×320 CSS px). js/ui/device.js puts the feature classes on <html>
   (sp-touch, sp-coarse, sp-hover / sp-no-hover, sp-fs, sp-standalone, sp-reduced-motion) — never UA sniffing.

   1. no page zoom / scroll / pull-to-refresh while playing (touch-action, overscroll-behavior, callouts)
   2. safe-area insets (notches, rounded corners, home indicator): the HUD and every screen stay inside them while the
      board and the backdrops stay full-bleed
   3. touch: every small control gets an invisible ≥ 44 px hit area (::before, no layout change); on short touch
      screens (phones) the most used controls also grow visually
   4. reduced motion extras; fullscreen button
   ========================================================================================== */

:root {
  --sa-t: max(0px, calc(env(safe-area-inset-top, 0px) + var(--fit-t, 0px)));
  --sa-r: max(0px, calc(env(safe-area-inset-right, 0px) + var(--fit-r, 0px)));
  --sa-b: max(0px, calc(env(safe-area-inset-bottom, 0px) + var(--fit-b, 0px)));
  --sa-l: max(0px, calc(env(safe-area-inset-left, 0px) + var(--fit-l, 0px)));
  --tap-min: 44px;
  --sp-vv-top: 0px;
  --sp-vv-left: 0px;
  --sp-vv-bottomGap: 0px;
  --sp-vv-width: 100vw;
  --sp-vv-height: 100vh;
  --sp-ui-height: calc(var(--sp-vv-height) - var(--sa-t) - var(--sa-b));
}
@supports (height: 100svh) { :root { --sp-vv-height: 100svh; } }
@supports (height: 100dvh) {
  :root { --sp-vv-height: 100dvh; }
  /* WebView 旋转/退出键盘后，百分比高度可能仍跟随旧的初始包含块。 */
  .screen.gm { position: fixed; bottom: auto; height: 100dvh; }
}

/* ---- 1. gestures ------------------------------------------------------------------------------------------------- */
html, body { overscroll-behavior: none; }
/* pan only: no pinch-zoom / double-tap zoom anywhere (scrollable lists still scroll); the field canvas uses none */
html { touch-action: pan-x pan-y; }
body { -webkit-touch-callout: none; }
button, a, label, summary, [role="button"], [role="tab"], [role="option"], .scard, .lvcard, .dband, .bond, .pavatar { touch-action: manipulation; }
img { -webkit-user-drag: none; }
.gm__field, .gm__field canvas, .ff, .fwheel, .fwheel__dia { touch-action: none; }
/* the DOM fallback board drags with pointer events too */
.ff-piece, .ff-slot, .ff-tile { touch-action: none; -webkit-user-select: none; user-select: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; }

/* ---- 2. safe areas ------------------------------------------------------------------------------------------------ */
/* the in-match HUD layer sits inside the safe area; the field (canvas) below it stays full-bleed */
.gm__hud { top: var(--sa-t); right: var(--sa-r); bottom: var(--sa-b); left: var(--sa-l); }
/* the selected unit's underframe (ui/underframe.js) is placed at the tile's CLIENT px (view.tileScreen) inside the HUD
   layer: step back over the HUD's safe-area offset so it stays on its unit on a notched phone */
.gm__hud > .uframe { margin-left: calc(-1 * (var(--sa-l) + var(--sp-vv-left))); margin-top: calc(-1 * (var(--sa-t) + var(--sp-vv-top))); }
/* the shop bar keeps its place at the bottom edge (it may reach into the home-indicator strip): raised by the bottom
   inset it covered ~3/4 of the bench pads 2–9 on a notched phone (user playtest #4 item 1), and a bench piece is
   pressed / dropped on by its tile. The prep camera keeps the bench clear of the bar (ui/fieldHost.js hudBands →
   render/projection.js clearHud, user playtest #5 item 9). Its right edge stays inside the inset (the notch / rounded
   corner). */
.gm__hud > .shopbar { bottom: calc(.2rem - var(--sa-b)); }
.gm > .spov { left: calc(2.8rem + var(--sa-l)); right: var(--sa-r); }
/* every other screen is laid out inside the safe area (the app backdrop fills the notch strip) */
.screen:not(.gm) { padding: var(--sa-t) var(--sa-r) var(--sa-b) var(--sa-l); }
.guide, .awayov { padding: var(--sa-t) var(--sa-r) var(--sa-b) var(--sa-l); }
/* (in a match the toasts sit under the top bar: components.css .sp-in-match .toast-host already adds --sa-t) */
html:not(.sp-in-match) .toast-host { margin-top: var(--sa-t); }
.conn-banner { margin-bottom: var(--sa-b); }
.rotate-hint { padding: calc(24px + var(--sa-t)) calc(24px + var(--sa-r)) calc(24px + var(--sa-b)) calc(24px + var(--sa-l)); }

/* ---- 3. touch targets ---------------------------------------------------------------------------------------------- */
/* An invisible hit area of at least --tap-min around small controls on touch screens: centred, never smaller than the
   control, no layout change. Only controls that do not use ::before themselves are listed. */
:where(.sp-coarse) :where(.tapx, .gtop__exit, .gtop__iconbtn, .enemybtn, .readybtn, .gm__gear, .fsbtn, .ewheel__btn, .ewheel__nav,
  .toolbtn, .funds__collapse, .team__btn, .effect, .bslot .bond, .vswitch__arrow, .edrawer__close, .dpanel__close, .bpop__close,
  .modal__close, .uf__btn, .chud__back, .tabs__tab, .btn, .pill-btn, .title-guide, .stephead__guide, .set-toggle, .set-seg button) {
  position: relative;
}
.sp-coarse :is(.tapx, .gtop__exit, .gtop__iconbtn, .enemybtn, .readybtn, .gm__gear, .fsbtn, .ewheel__btn, .ewheel__nav,
  .toolbtn, .funds__collapse, .team__btn, .effect, .bslot .bond, .vswitch__arrow, .edrawer__close, .dpanel__close, .bpop__close,
  .modal__close, .uf__btn, .chud__back, .tabs__tab, .btn, .pill-btn, .title-guide, .stephead__guide, .set-toggle, .set-seg button)::before {
  content: '';
  position: absolute; left: 50%; top: 50%; z-index: 0;
  width: max(100%, var(--tap-min)); height: max(100%, var(--tap-min));
  transform: translate(-50%, -50%);
  background: transparent; border: 0; box-shadow: none; clip-path: none; pointer-events: auto;
}
/* 盟约栏下方紧贴顶排模型：触控扩展只加宽，不向上下空白延伸；图标和名称仍可打开详情。 */
.sp-coarse .gm__bonds .bslot .bond::before { top: 0; height: 100%; transform: translateX(-50%); }
/* The 交流 panel's pager (‹ dots ›) sits in the strip under the emote cells (panel y 1.97–2.31rem, css/emotes.css). Its
   hit areas stay inside that strip and never overlap each other: a centred 44 px area of ‹ / › covered the centres of
   the bottom-left / bottom-right emotes (a tap there turned the page or hit the disabled ‹), and 28 px dot areas 0.21rem
   apart covered the neighbouring dot (a tap on dot N opened page N+1). ‹ / › grow outwards (away from the dots), the
   dots only up to half the gap. Selectors ≥ the specificity of the generic hit-area rule above. */
.sp-coarse .ewheel__panel .ewheel__nav::before { top: .03rem; bottom: -.15rem; height: auto; transform: none; }
.sp-coarse .ewheel__panel .ewheel__nav.is-prev::before { left: auto; right: 0; }
.sp-coarse .ewheel__panel .ewheel__nav.is-next::before { left: 0; right: auto; }
.sp-coarse .ewheel__dot::before { inset: -.02rem -.05rem -.2rem; width: auto; height: auto; transform: none; }

/* Phones in landscape (short touch screens: 1rem ≈ 40 px here): the most used controls grow a little so they are
   comfortable to hit and to read, without changing the official layout. */
@media (max-height: 600px) and (pointer: coarse), (max-height: 600px) and (any-pointer: coarse) {
  .readybtn { height: max(.56rem, 34px); }
  .toolbtn { min-height: max(.5rem, 30px); }
  .gm__gear { width: max(.56rem, 34px); height: max(.56rem, 34px); }
  /* ⚙ / 📖 / ⛶ keep their desktop proportion (half the button) instead of an 11 px glyph in the grown button */
  .gm__corner .gm__gear .icon { width: max(.28rem, 17px); height: max(.28rem, 17px); }
  .gtop__exit { min-width: max(.56rem, 34px); min-height: max(.56rem, 34px); }
  .gtop__iconbtn.has-sprite, .enemybtn.has-sprite { height: max(.46rem, 26px); width: calc(max(.46rem, 26px) * 35 / 29); }
  .gtop__iconbtn.has-sprite.is-wide, .enemybtn.has-sprite.is-wide { width: calc(max(.46rem, 26px) * 61 / 29); }
  .gtop__iconbtn:not(.has-sprite), .enemybtn:not(.has-sprite) { height: max(.46rem, 26px); min-width: max(.46rem, 26px); }
  .ewheel__panel { scale: 1.3; transform-origin: 0 100%; }
  .fwheel__cancel { min-height: 30px; }
  .set-toggle, .set-seg button { height: max(.38rem, 30px); }
  /* a taller range input whose visible track stays thin: transparent borders are part of the hit area */
  .set-range { height: 30px; border: 11px solid transparent; border-left-width: 0; border-right-width: 0; background-clip: padding-box; box-shadow: inset 0 0 0 1px var(--line-2); }
  .field--lg .field__box { height: max(.68rem, 40px); }
}

/* ---- 4. misc ------------------------------------------------------------------------------------------------------ */
.fsbtn { display: grid; place-items: center; padding: 0; background: rgba(8, 11, 10, .85); border: 1px solid var(--line-2); color: var(--text-lo); transition: color var(--t-fast), border-color var(--t-fast); }
.fsbtn .icon { width: .26rem; height: .26rem; }
.fsbtn:hover, .fsbtn[aria-pressed="true"] { color: var(--mint-400); border-color: var(--mint-700); }
.title-fs { width: .4rem; height: .4rem; margin-left: .06rem; }
/* standalone / fullscreen: the browser bars are gone, nothing to reserve */
.sp-standalone .rotate-hint__micro::after { content: ' · PWA'; }

/* reduced motion: camera-free UI pieces that animate continuously stop (the global rule in theme.css shortens the rest) */
@media (prefers-reduced-motion: reduce) {
  .team__status.is-gold, .ff-tile--gate, .title-bg__sweep, .boot__hex { animation: none !important; }
}
.sp-reduced-motion .team__status.is-gold, .sp-reduced-motion .ff-tile--gate { animation: none; }

/* (the shop cards have no ⓘ corner: its invisible 44 px touch area — the 30 px override here lost on specificity to the
   generic rule above — covered the bottom-right quarter of a phone's 67 × 97 px card and half of its 确认购买 strip, so
   the confirming tap re-opened the detail instead; user playtest #6 item 10) */

/* Narrow viewports (< 768 CSS px: the root scale is clamped at 40 px, so the layout is narrower than the 19.2 rem
   design): the shop bar would cover the corner's ⚙ / 📖 / ⛶ buttons — they wrap into a row above the 交流 button. */
/* The left-docked detail card then ends above that two-row corner (.24rem + 交流 + .1rem gap + ⚙ row + .1rem): at its
   desktop bottom (1.02rem) it hid ⚙ / 📖 / ⛶. (gameLogic panelSlots keeps the taller desktop slot: conservative.) */
@media (max-width: 767px) {
  .gm__corner { flex-wrap: wrap-reverse; align-content: flex-start; width: max(72px, calc(3 * .56rem + .2rem)); }
  .dpanel:not(.dpanel--right) { bottom: calc(.44rem + max(1.51rem, 72px) * 55 / 151 + .56rem); }
}
@media (max-width: 767px) and (pointer: coarse), (max-width: 767px) and (any-pointer: coarse) {
  .gm__corner { width: max(96px, calc(3 * max(.56rem, 34px) + .2rem)); }
  .dpanel:not(.dpanel--right) { bottom: calc(.44rem + max(1.51rem, 96px) * 55 / 151 + max(.56rem, 34px)); }
}
/* With the shop folded (收起) no bar covers the corner: one row again, so the folded shop's prep camera, which keeps the
   bench above the corner's hit areas (ui/fieldHost.js hudBands), grows the board on narrow phones too (public issue #5). */
@media (max-width: 767px) {
  .gm.is-collapsed .gm__corner { flex-wrap: nowrap; width: auto; }
}

/* Short landscape phones (≤ 460 CSS px tall, 1rem = 40 px): the lobby's two columns are compressed so the
   创建同盟 button and the join panel stay on screen without scrolling. The detail card's header is shorter (no
   romanised name, a shorter portrait) so the operator's own effect (特质) under it stays in view even in the short card
   docked above the shop bar (user playtest #3 item 8). */
@media (max-height: 460px) {
  .dhead__art { height: 1.66rem; }
  .dhead__en { display: none; }
  .lobby-body { padding-top: .2rem; padding-bottom: .2rem; gap: .36rem; }
  .mode-cards { margin-bottom: .2rem; }
  .mode-card { min-height: 0; gap: .12rem; padding: .22rem .26rem .2rem; }
  .mode-card__icon { width: .66rem; height: .66rem; }
  .mode-card__name { font-size: .4rem; }
  .mode-card__points, .diff-card__effects, .tips, .create-box__hint { display: none; }
  .diff-list { gap: .1rem; }
  .diff-card { padding-top: .12rem; padding-bottom: .12rem; }
  .sp-coarse .diff-card { padding-top: .08rem; padding-bottom: .08rem; }
  .create-box { margin-top: .18rem; }
  .create-box .btn--xl { height: .8rem; }
}

/* #27：共享实际可视边界；棋盘全出血，不通过缩放页面压缩字体。 */
.gm__hud {
  top: calc(var(--sp-vv-top) + var(--sa-t));
  bottom: calc(var(--sp-vv-bottomGap) + var(--sa-b));
  left: calc(var(--sp-vv-left) + var(--sa-l));
  right: calc(100% - var(--sp-vv-left) - var(--sp-vv-width) + var(--sa-r));
}
/* Backgrounds fill the visible screen; only content is inset for notches and the home indicator. */
.screen:not(.gm) {
  top: var(--sp-vv-top);
  left: var(--sp-vv-left);
  right: auto;
  bottom: auto;
  width: var(--sp-vv-width);
  height: var(--sp-vv-height);
  padding: var(--sa-t) var(--sa-r) var(--sa-b) var(--sa-l);
}
.modal, .guide {
  inset: auto;
  top: var(--sp-vv-top); left: var(--sp-vv-left);
  width: var(--sp-vv-width); height: var(--sp-vv-height);
  padding: calc(8px + var(--sa-t)) calc(8px + var(--sa-r)) calc(8px + var(--sa-b)) calc(8px + var(--sa-l));
}
.modal .modal__box {
  max-width: 100%; max-height: calc(var(--sp-ui-height) - 16px);
  min-height: 0;
}
.modal__head, .modal__actions { flex: none; }
.modal__body { min-height: 0; overscroll-behavior: contain; }
.guide__box { max-width: 100%; max-height: 100%; min-height: 0; }
.guide__head, .guide__foot { flex: none; }
.guide__stage { min-height: 0; overflow: auto; }
.guide__page { width: min(calc(var(--sp-vv-width) - var(--sa-l) - var(--sa-r) - 40px), calc((var(--sp-ui-height) - 100px) * 16 / 9)); }
.guide__stage--text { max-height: none; }

@media (max-height: 600px) and (pointer: coarse) {
  /* 实体触控尺寸代替互相覆盖的隐形扩展，分组内间隙保留。 */
  .title-screen .btn, .topbar .btn, .modal__actions .btn, .create-box .btn, .room-fill .btn, .room-bar .btn,
  .gm__gear, .toolbtn, .funds__collapse, .shopbar-tab__btn, .readybtn, .gtop__exit,
  .set-toggle, .set-seg button, .dpick__opt, .guide__chapter, .guide__close {
    min-height: 40px; font-size: max(12px, .18rem);
  }
  .sp-coarse :is(.title-screen .btn, .topbar .btn, .modal__actions .btn, .create-box .btn, .room-fill .btn, .room-bar .btn,
    .gm__gear, .toolbtn, .funds__collapse, .readybtn, .gtop__exit, .gtop__iconbtn, .enemybtn,
    .set-toggle, .set-seg button, .tabs__tab)::before { content: none; }
  .gm__corner { width: 136px; max-width: 45%; gap: 8px; flex-wrap: wrap-reverse; }
  .gm__corner .gm__gear { width: 40px; height: 40px; flex: none; }
  /* 玩家列表只占工具栏上方的空间；人数增加时滚动，不覆盖交流、设置或馈赠。 */
  .sp-coarse .gm .team, .sp-coarse .gm .team.team--multi {
    max-height: max(0px, calc(100% - 2.36rem - var(--sp-team-bottom, 144px)));
    overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; pointer-events: auto;
  }
  .sp-coarse .gm .team > * { flex-shrink: 0; }
  .gm.is-collapsed .gm__corner { width: auto; max-width: calc(100% - 160px); overflow-x: auto; }
  .sp-keyboard .gm__corner { flex-wrap: nowrap; width: 136px; overflow-x: auto; }
  .gm__hud > .shopbar { bottom: 8px; max-width: calc(100% - var(--sp-corner-width, 136px) - 32px); }
  .shopbar__row { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding-top: 12px; }
  .shopbar__row > *, .shopbar__cards > *, .shopbar__item > * { flex-shrink: 0; }
  .shopbar__tools { max-width: 100%; }
  .funds__collapse { padding: 4px 8px; }
  .topbar { height: auto; min-height: 52px; gap: 8px; padding: 4px 8px; grid-template-columns: auto minmax(0, 1fr) auto; }
  .room-screen .topbar { height: auto; }
  .topbar__left, .topbar__center, .topbar__right { min-width: 0; }
  .topbar__right { max-width: 52vw; overflow-x: auto; gap: 8px; }
  .topbar__right > * { flex-shrink: 0; }
  .topbar .micro, .topbar .me-chip, .room-ping, .invite__label { display: none; }
  .topbar__title { font-size: max(14px, .3rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lobby-body { padding: 8px 12px 56px; gap: 16px; }
  .lobby-body > * { min-width: 0; }
  .create-box .btn--xl { height: 44px; }
  .room-fill { padding: 4px 8px; }
  .room-bar { height: auto; min-height: 56px; grid-template-columns: minmax(0, 1fr) auto; padding: 4px 8px; }
  .room-bar__center { display: none; }
  .room-bar__left { overflow-x: auto; }
  .dpick { flex: none; }
  .dpick__opt { padding-inline: 8px; }
  .modal__head { padding: 8px 12px; }
  .modal__actions { gap: 8px; flex-wrap: wrap; padding: 8px 12px; }
  .modal__actions .btn { min-width: 0; height: auto; padding: 6px 12px; }
  .modal__body { font-size: max(12px, .18rem); }
  .set-row { grid-template-columns: minmax(90px, 1fr) minmax(0, 1.5fr) auto; gap: 8px; }
  .set-seg { flex-wrap: wrap; gap: 4px; }
  .guide__chapter { min-width: 64px; padding-inline: 8px; }
  .guide__close { width: 40px; height: 40px; }
  .guide__chapters { min-width: 0; overflow-x: auto; }
  .guide__chapters > * { flex: none; }
  .guide__dots { overflow-x: auto; max-width: 100%; }
  .guide__dot { flex: none; width: 24px; height: 32px; background-clip: content-box; border-block: 12px solid transparent; }
  .guide__dot.is-on { width: 32px; }
  .guide__foot { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .guide__label { display: none; }
  .spectator-bar { flex-wrap: nowrap; overflow-x: auto; }
  .spectator-bar > * { flex-shrink: 0; }
  .result__main { grid-template-columns: minmax(0, 210px) minmax(0, 1fr); gap: 12px; padding: 12px; }
  .result__hero { overflow-y: auto; padding-top: 0; }
  .result__hero > * { flex-shrink: 0; }
  .result__foot { position: sticky; bottom: 0; background: rgba(8, 11, 10, .96); padding-top: 8px; }
  .result__foot .btn { min-height: 44px; font-size: 14px; }
  .rcard__head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .rcard__mid, .rcard__title { grid-column: 1 / -1; }
  .rcard__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


.set-fit { display: flex; flex-direction: column; gap: .06rem; }
.set-fit__row { grid-template-columns: minmax(0, 1.5rem) auto minmax(.8rem, 1fr) auto minmax(.36rem, auto); gap: .1rem; }
.set-fit__step { flex: none; width: .4rem; min-width: 28px; height: .34rem; min-height: 26px; padding: 0; border: 1px solid var(--line-2); background: rgba(0, 0, 0, .3); cursor: pointer; }
.set-fit__step:disabled { opacity: .35; cursor: default; }

.set-fit__row .set-row__val { min-width: 4ch; text-align: right; }

/* Keep edge and control-size sliders together despite compact settings' three-column rows. */
.settings-modal .set-fit .set-fit__row {
  grid-template-columns: minmax(0, 1fr) auto minmax(64px, 1.4fr) auto minmax(4ch, auto);
  gap: .1rem;
}
.settings-modal .set-fit__row .set-row__label { min-width: 0; overflow-wrap: anywhere; }
.settings-modal .set-fit__row .set-row__label .micro { white-space: normal; }
