/* ==========================================================================================
   devices.css — multi-device layer (loaded last). Desktop Chrome / Edge / Firefox / Safari, iPad and Android tablets
   in landscape, phones in landscape (≥ 740×360 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: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --tap-min: 44px;
}

/* ---- 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); }
.gm__side { top: var(--sa-t); right: var(--sa-r); bottom: var(--sa-b); left: var(--sa-l); } /* the left player list's layer (screens/game.js) */
/* 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)); margin-top: calc(-1 * var(--sa-t)); }
/* 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) { top: var(--sa-t); right: var(--sa-r); bottom: var(--sa-b); left: 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; 准备就绪 and the shop's
   冻结 / 刷新 draw their sprite plate in ::before (hud-art.css, shop-art.css), so theirs is ::after — this file loads last
   with the same specificity, and its `border: 0` / `background` wiped the plates on every touch screen.
   A hit area that reaches over a NEIGHBOUR's box takes that neighbour's presses (a later sibling's area is drawn above
   the earlier box): the 难度 buttons answered as 经典 / 休闲 under them, 关闭 as 韩语 beside it, a bond chip as 敌方信息.
   So each group says where its areas may grow (inherited custom properties): --tap-w / --tap-h 100% = not sideways /
   not vertically; --tap-top 0% + --tap-ty 0% = downwards only, 100% + -100% = upwards only (--tap-left / --tap-tx the
   same sideways). The groups are listed after this rule; test/ui/devices.e2e.test.js 「touch areas never take a neighbour's press」 sweeps every screen. */
:where(.sp-coarse) :where(.tapx, .gtop__exit, .gtop__iconbtn, .enemybtn, .readybtn, .gm__gear, .fsbtn, .ewheel__btn, .ewheel__nav,
  .toolbtn, .funds__collapse, .team__btn, .bslot .bond, .vswitch__arrow, .edrawer__close, .dpanel__close, .bpop__close,
  .modal__close, .tabs__tab, .btn, .pill-btn, .title-guide, .stephead__guide, .set-toggle, .set-seg button,
  .dpick__opt, .guide__close) {
  position: relative;
}
.sp-coarse :is(.readybtn, .toolbtn)::after,
.sp-coarse :is(.tapx, .gtop__exit, .gtop__iconbtn, .enemybtn, .gm__gear, .fsbtn, .ewheel__btn, .ewheel__nav,
  .funds__collapse, .team__btn, .bslot .bond, .vswitch__arrow, .edrawer__close, .dpanel__close, .bpop__close,
  .modal__close, .tabs__tab, .btn, .pill-btn, .title-guide, .stephead__guide, .set-toggle, .set-seg button,
  .dpick__opt, .guide__close):where(:not(.readybtn, .toolbtn))::before {
  content: '';
  position: absolute; left: var(--tap-left, 50%); top: var(--tap-top, 50%); z-index: 0;
  width: max(100%, var(--tap-w, var(--tap-min))); height: max(100%, var(--tap-h, var(--tap-min)));
  transform: translate(var(--tap-tx, -50%), var(--tap-ty, -50%));
  background: transparent; border: 0; box-shadow: none; clip-path: none; pointer-events: auto;
}
/* the exit button: upwards only (it stands in the screen's corner). Its area reached over the player list under it, so a
   press on the own row left the match on a small phone */
.gtop__exit { --tap-top: 100%; --tap-ty: -100%; }
/* rows of buttons that touch: no sideways growth (难度 / 规则, 关闭 · 韩语 · 日语, tabs, the corner's ⋯ ⚙ 📖 ⛶, the room's
   统计 · 设置 · 玩法说明); the 交流 panel inside the corner keeps its own pager areas (below) */
.set-seg, .dpick, .tabs, .gm__corner, .rs-tools { --tap-w: 100%; }
/* the corner sits on the bottom edge: its buttons grow downwards only — opened, ⚙ 📖 ⛶ reach the shop's 调度中心 card
   and first card (or, on a narrow phone where they wrap above 交流, the left player list) */
.gm__corner { --tap-top: 0%; --tap-ty: 0%; }
.ewheel__panel { --tap-w: var(--tap-min); }
/* the top bar's 本局信息 / 敌方信息 sit on the screen's top edge with the bond chips 4 px under them: upwards, and
   down only into that gap */
.gtop__iconbtn, .enemybtn { --tap-top: 100%; --tap-ty: calc(-100% + 5px); }
/* the 设置 tabs: 8 px over the 语言 select on a phone, with only the dialog's title above them — the same */
.set-tabs { --tap-top: 100%; --tap-ty: calc(-100% + 5px); }
/* stacked pairs: the lower one grows down — an empty seat card's 添加 AI 队友 under its 邀请, the 自选 preset slots over
   编辑; the strategy draft's 查看禁用 / 技能与模组 (full-width, between the order list's avatars and the tip) stay as drawn */
.rseat__add, .draft-preset__edit, .draft-detail__btns { --tap-top: 0%; --tap-ty: 0%; }
.draft-order__info, .draft-order__loadout { --tap-h: 100%; }
/* buttons under a block they must not reach into: a dialog's footer (the scrolled body above it), the title's 玩法说明 /
   ⚙ / ⛶ (under 开始) and 服务器信息 (under ⛶) */
.modal__actions, .title-conn__tools, .title-links { --tap-top: 0%; --tap-ty: 0%; }
/* 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); }
  .gm__corner .seat-reserve { 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__meta.has-mode { --exit-h: max(.64rem, .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); }
  /* the title's emblem shrinks to make room for the button row under the login box (关于本服务器), as the Chinese fork
     servers do on phones (maintainer decision 2026-10-13) */
  .title-screen .emblem { gap: .16rem; margin-bottom: .1rem; }
  .title-screen .emblem__svg { width: .74rem; height: .8rem; }
  .title-screen .emblem__bracket { width: .1rem; height: .96rem; }
  /* the 盟约 logo (screens/title.js FilmLogo) takes the same room: its film-sized inline sizes would push it off the top */
  .title-screen .emblem--logo { gap: .04rem !important; }
  .title-screen .emblem--logo .emblem__logo { width: 1.07rem !important; }
  .title-screen .emblem--logo .emblem__bracket { width: .09rem !important; height: .96rem !important; }
  /* a later season's logo as the title (screens/title.js): its top left the screen at 44vh */
  .title-screen .title-logo { height: 30vh; margin-bottom: 0; }
}

/* ---- 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, .title-settings { width: .4rem; height: .4rem; margin-left: .06rem; }
/* local patch: on touch screens the two title buttons (upstream #183 added the gear beside 全屏) are tiny (16 px at
   844×390) and their --tap-min hit areas overlapped, so the full-screen button's area took every tap on the gear —
   bigger buttons with a gap so each one's own centre is its own */
.sp-coarse .title-fs, .sp-coarse .title-settings { width: max(.4rem, 28px); height: max(.4rem, 28px); margin-left: max(.06rem, 14px); }
/* …and the login box grows by what those two buttons grew, so the connection row under 开始 stays on one line */
.sp-coarse .title-screen { --login-w: calc(4.9rem + 2 * (max(.4rem, 28px) - .4rem + max(.06rem, 14px) - .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)); }
  /* wrapped above 交流 / ⋯, the opened tools do not grow over that row; ⋯ (over 交流, under the player list) grows
     to the right, over the board */
  .gm__tools { --tap-h: 100%; }
  .gm__more { --tap-h: 100%; --tap-w: var(--tap-min); --tap-left: 0%; --tap-tx: 0%; }
  .dpanel:not(.dpanel--right) { bottom: calc(.44rem + max(1.51rem, 96px) * 55 / 151 + max(.56rem, 34px)); }
}
/* Phones (short or narrow touch screens): ⚙ / 📖 / ⛶ fold behind one ⋯ button (screens/game.js toolsOpen, folded by
   default; a tool's tap folds them again) — three 34 px buttons with 44 px touch areas covered the bottom row of the
   机变 cards (the corner sits above that screen, phase-art.css .is-over-choice) and the bench's near pads; the 交流 /
   chat buttons stay (maintainer request 2026-10-12). Opened, they line up as before. */
@media (max-height: 600px) and (pointer: coarse), (max-height: 600px) and (any-pointer: coarse),
  (max-width: 767px) and (pointer: coarse), (max-width: 767px) and (any-pointer: coarse) {
  .gm__more { display: grid; }
  .gm__tools:not(.is-open) { display: none; }
}
/* 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: .34rem; }
  .mode-cards { gap: .14rem; }
  .mode-card { padding: .2rem .18rem .18rem; }
  .mode-card__points, .diff-card__effects, .create-box__hint { display: none; }
  .diff-list { gap: .1rem; }
  .diff-card { padding-top: .12rem; padding-bottom: .12rem; }
  .create-box { margin-top: .18rem; }
  .create-box .btn--xl { height: .8rem; }
}
