/* The window system
   One set of rules for every menu, window and dialog: tokens per form factor, how a window sits on the screen, the
   title bar and its close button, the footer key hints, scroll areas, the focus ring, row heights, the dim under a
   modal window. ui/winsys.js keeps the keyboard inside the open window. Loaded after style.css / touch.css; the feature
   sheets load later and build on these tokens.
   Sizes: the HUD windows (menus, dialog, bag, settings, chat, Players) follow --k (--ui-scale: 1 at 1280x720, 1.25 at
   1080p, down to 0.8 on phones). The big fixed-size windows (shop, Friend Areas, jobs, Journal, Pokédex, Hall of Legends,
   the personality test) are drawn at their 720p size and zoomed by --wk (--k capped at 1.3; 1 on phones and tablets,
   where they fill the screen): inside them a viewport unit is --zvw / --zvh. */
:root {
  --wk: clamp(0.8, var(--k), 1.3);
  --zvw: calc(100vw / var(--wk)); --zvh: calc(var(--vh) / var(--wk));
  --win-dim: rgba(4, 8, 30, 0.55);                 /* the world under a modal window */
  --win-font: calc(16px * var(--k));               /* body text */
  --win-small: calc(13px * var(--k));              /* notes, subs, hints */
  --win-head: calc(11px * var(--k));               /* titles (the pixel font) */
  --row-h: calc(32px * var(--k));                  /* a cursor row */
  --win-x: calc(30px * var(--k));                  /* the close button */
  --maprow-h: 150px;                               /* the minimap row's height (set by hud.js): menus start under it */
}
html.touch { --row-h: 48px; --win-x: 44px; }
html.form-phone, html.form-tablet { --wk: 1; }
/* the house-style kit's unit: --k in the HUD windows, 1 on phones and inside a zoomed window */
:root { --ku: var(--k); }
html.form-phone, .win-zoom, .shop-win { --ku: 1; }
html.form-phone { --win-font: 16px; --win-small: 13px; --win-head: 10px; }
/* phones (--k 0.8): the pixel-font labels and the body text never fall under 10 / 9 / 15 px */
html.form-phone #dialog .dname, html.form-phone .notice .nbody b, html.form-phone #sos b, html.form-phone .bp-head, html.form-phone #cutscene .cs-name, html.form-phone .tt-head { font-size: 10px; }
html.form-phone .mitem .msub { font-size: 11.5px; }
html.form-phone .keycap { font-size: 10px; }
html.form-phone #dialog, html.form-phone .notice .nbody, html.form-phone #sos, html.form-phone #tooltip, html.form-phone .mitem { font-size: 15px; }
html.form-phone .pmd-menu .mtext, html.form-phone .tt-line, html.form-phone .bp-hint { font-size: 13px; }
/* a value: the numeral face, tabular, never broken */
.window .num, .pmd-menu .msub, .bp-grid .cnt, #sos .stime { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Keyboard: a gold focus ring on every control, the cursor row stays its own highlight */
.window :is(button, input, select, textarea, [tabindex]):focus-visible, .pmd-menu :is(button, input):focus-visible, .shop-row:focus-visible, .dxcard:focus-visible, .jnote:focus-visible, .lcard2:focus-visible, .sw-row:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px; box-shadow: none;
}
.window :is(button, input, select):focus:not(:focus-visible) { outline: none; }
/* the footer line of key hints: "↑↓ select · Enter: go · Esc: close" (the touch sheets say it with their buttons) */
.win-keys { flex: none; padding: 6px 2px 0; font-size: var(--win-small); color: var(--dim); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-keys b { color: var(--tx-hi, #e8ecff); font-weight: 400; }
html.touch .win-keys { display: none; }

/* the close button: one square in every window's corner, 44 px with touch */
.win-x, .pmd-menu .mclose, .bp-x, .set-x, .help-x, .sw-x, .jclose, .dxclose, .jb-close, .shop-x, .lclose {
  width: var(--win-x); height: var(--win-x); min-width: 0; min-height: 0; flex: none; padding: 0; margin: 0; border-radius: 6px; border: 2px solid var(--win-border); background: var(--bg-1, #0c1240); color: var(--tx-hi, #fff);
  font: calc(13px * var(--k)) var(--font); line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; touch-action: manipulation;
}
.sw-x, .bp-x, .set-x { margin-left: auto; }
.pmd-menu .mclose, .help-x { position: absolute; top: 6px; right: 6px; }
.win-x:hover, .pmd-menu .mclose:hover, .bp-x:hover, .set-x:hover, .help-x:hover, .sw-x:hover, .jclose:hover, .dxclose:hover, .jb-close:hover, .shop-x:hover, .lclose:hover { border-color: var(--gold); color: var(--gold); filter: none; }
/* inside a zoomed window the zoom does the scaling */
.jclose, .dxclose, .jb-close, .shop-x, .lclose { width: 36px; height: 36px; font-size: 16px; }
html.touch .jclose, html.touch .dxclose, html.touch .jb-close, html.touch .shop-x, html.touch .lclose { width: 44px; height: 44px; }

/* The dim under a modal window (fixed windows: a shadow the size of the screen) */
#settings, #help, html.touch #bagpanel, html.touch #social, html.touch.form-phone #pcard.open .sdetail, html.touch.form-phone #squad .scard.open + .sdetail {
  box-shadow: 0 0 0 200vmax var(--win-dim), var(--win-shadow, 0 0 0 2px #0a0e30, 0 6px 18px rgba(0, 0, 0, 0.5));
}
body.rom-ui #settings, body.rom-ui #help, body.rom-ui #bagpanel, body.rom-ui .pmd-menu, body.rom-ui #social { box-shadow: none; }
/* the sheets and the centred menus sit above the notices; the notices come back when they close */
html.touch #bagpanel, .pmd-menu { z-index: 36; }
html.touch #settings { z-index: 45; }
html.touch #social { z-index: 36; }

/* PMD cursor menus (ui.js menu): a centred window with the world dimmed under it. On the desktop ui.js pins its top once
   drawn (.pinned), so a menu that changes height grows down instead of jumping. Two exceptions on the desktop: a menu
   opened at a point (.at: the player menu) stays by the pointer, and the bag's item menus (.side) stay a panel at the
   right, under the minimap row, so the floor stays in view. Long labels end in "…" */
.pmd-menu { left: 50%; top: 50%; right: auto; transform: translate(-50%, -50%); animation: popc 0.12s ease-out; max-height: calc(var(--vh) - 32px - var(--sat) - var(--sab)); font-size: var(--win-font);
  box-shadow: 0 0 0 200vmax var(--win-dim), var(--win-shadow, 0 0 0 2px #0a0e30, 0 6px 18px rgba(0, 0, 0, 0.5)); }
html:not(.touch) .pmd-menu.pinned { transform: translateX(-50%); animation: popx 0.12s ease-out; }
@keyframes popx { from { transform: translateX(-50%) scale(0.97); opacity: 0; } }
html:not(.touch) .pmd-menu.side { z-index: 30; left: auto; right: calc(12px + var(--sar)); top: calc(var(--sat) + 14px + var(--maprow-h)); transform: none; animation: pop 0.12s ease-out;
  max-height: calc(var(--vh) - var(--sat) - 14px - var(--maprow-h) - var(--abar-h) - 24px - var(--sab)); box-shadow: var(--win-shadow, 0 0 0 2px #0a0e30, 0 6px 18px rgba(0, 0, 0, 0.5)); }
html:not(.touch) .pmd-menu.at { z-index: 30; transform: none; animation: pop 0.12s ease-out; box-shadow: var(--win-shadow, 0 0 0 2px #0a0e30, 0 6px 18px rgba(0, 0, 0, 0.5)); }
/* the header: the kit's .win-head in one row: the portrait (.win-face), the title (.win-h), the page as a chip, the one
   X; no OK / Back bar (a tap on a row picks it), no "Cancel" / "Close" row */
.pmd-menu .mhead { padding: 0 0 calc(8px * var(--ku)) calc(4px * var(--ku)); margin-bottom: calc(6px * var(--ku)); }
.pmd-menu .mhead .mtitle { padding: 0; margin: 0; border: 0; font-size: calc(11px * var(--ku)); line-height: 1.35; }
.pmd-menu .mhead .mtitle:empty { display: none; }
.pmd-menu .mhead .mclose { position: static; margin-left: auto; }
.pmd-menu .mface .mportrait { float: none; display: block; width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; }
.pmd-menu .mpage[hidden] { display: none; }
.pmd-menu .mfoot { display: flex; justify-content: flex-end; }   /* only menus with an `ok` button have one (numberInput) */
html.touch .pmd-menu .mhead { min-height: 44px; }
.pmd-menu .mtext { font-size: var(--win-small); line-height: 1.35; }
.pmd-menu .mhint { font-size: var(--win-small); }
.mitem { min-height: var(--row-h); padding-top: 2px; padding-bottom: 2px; }
.mitem .mlabel { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mitem .msub { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pmd-menu .mitems { scroll-padding: 4px 0; }
.pmd-menu .mitems .mitem { scroll-margin: 4px 0; }
/* the desktop footer: the keys (paged menus add "←→ page · F find") */
.pmd-menu .mkeys { display: block; flex: none; padding: 6px 8px 0 calc(22px * var(--k)); font-size: var(--win-small); color: var(--dim); border-top: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.2); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.touch .pmd-menu .mkeys { display: none; }
/* touch sheets: the list never shrinks under three rows (the text gives way instead), the title clears the close button */
html.touch .pmd-menu { top: 50% !important; max-height: calc(var(--vh) - 16px - var(--sat) - var(--sab)); }
html.touch .pmd-menu .mitems { flex: 1 1 auto; min-height: calc(3 * var(--row-h)); max-height: none; }
html.touch .pmd-menu .mtext { flex: 0 1 auto; min-height: 0; overflow-y: auto; max-height: calc(4 * 1.35em + 8px); }
html.touch .pmd-menu .mitem { padding-left: 8px; }
html.touch .pmd-menu .mitem .mlabel { white-space: normal; overflow-wrap: anywhere; }
html.touch .pmd-menu .mfoot { padding-top: 8px; border-top: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.2); margin-top: 6px; }
@media (max-height: 420px) {   /* phones held sideways: two text lines, no hint line */
  html.touch .pmd-menu .mtext { max-height: calc(2 * 1.35em + 4px); }
  html.touch .pmd-menu .mhint { display: none; }
  html.touch .pmd-menu .mitems { min-height: calc(2 * var(--row-h)); }
}
/* grid menus (the touch Menu): square tiles in the bag slot look (.gv-tile), a pixel icon over a short label, a badge in
   the corner; one tap opens a tile, the arrows move over the grid, the x closes. Tiles are --tile high and at least
   --tile wide. Phones: the sheet spans the screen, three tiles a row held upright, two rows held sideways. */
.pmd-menu.grid { --tile: calc(92px * var(--k)); width: min(calc(600px * var(--k)), calc(100vw - 16px - var(--sal) - var(--sar))); max-width: none; }
html.touch .pmd-menu.grid { width: min(calc(600px * var(--k)), calc(100vw - 24px - var(--sal) - var(--sar))) !important; }
html.form-phone.touch .pmd-menu.grid { width: calc(100vw - 24px - var(--sal) - var(--sar)) !important; }
html.form-phone .pmd-menu.grid { --tile: 92px; }
html.form-phone.landscape .pmd-menu.grid { --tile: 84px; }
.pmd-menu.grid .mitems { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr)); grid-auto-rows: var(--tile); gap: 8px; align-content: start; min-height: 0; padding: 4px 2px 6px; scroll-padding: 6px; }
.pmd-menu .mitem.mtile { position: relative; flex-direction: column; justify-content: center; gap: 4px; min-height: 0; padding: 6px 4px; border-radius: 0; white-space: normal; text-align: center;
  background: var(--slot); border: 2px solid var(--slot-line); box-shadow: inset 2px 2px 0 var(--bg-3, #3a4690), inset -2px -2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820); touch-action: manipulation; }
.pmd-menu .mtile .mt-ico { line-height: 0; }
.pmd-menu .mtile .mi { --want: calc(36px * var(--k)); display: block; }
html.form-phone .pmd-menu .mtile .mi { --want: 36px; }
.pmd-menu .mitem.mtile .mlabel { flex: none; max-width: 100%; font-size: var(--win-small); line-height: 1.15; white-space: normal; overflow-wrap: anywhere; }
.pmd-menu .mitem.mtile .msub { max-width: 100%; margin: -2px 0 0; padding: 0; font-family: var(--font); font-size: calc(var(--win-small) * 0.85); line-height: 1.1; }
.pmd-menu .mtile .hbadge { top: 4px; right: 4px; }
.pmd-menu .mtile:hover { border-color: var(--rim-hi, #8fa0ff); }
.pmd-menu .mtile.sel { background: var(--slot); border-color: var(--gold); box-shadow: inset 2px 2px 0 var(--bg-3, #3a4690), inset -2px -2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820), 0 0 0 3px var(--gold), 0 0 0 4px var(--bg-0, #050820); }
.pmd-menu .mtile:active { filter: brightness(1.2); }
html.touch .pmd-menu.grid .mfoot, .pmd-menu.grid .mfoot { display: none; }

/* the bank's digit steppers (numberInput) */
.dstep { width: calc(26px * var(--k)); height: calc(20px * var(--k)); font-size: calc(10px * var(--k)); }
html.touch .dstep { width: 44px; height: 44px; font-size: 13px; }
/* Notices: on a short screen (phones held sideways) two of them sit side by side, not off the bottom */
@media (max-height: 460px) { #notices { left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); transform: none; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-start; } }
/* Dialog box: answers are rows of the same height */
#dialog .dchoices .mitem { min-height: calc(26px * var(--k)); }
html.touch #dialog .dchoices .mitem { min-height: 44px; }
/* the selected answer (the dialog box, a cutscene's question): the inverted primary look in every style, as a row on the
   desktop and as a button with touch (a --bg-3 face under light cursor-row text would hide it) */
:is(#dialog .dchoices, #cutscene .cs-opts) .mitem.sel, html.touch :is(#dialog .dchoices, #cutscene .cs-opts) .mitem.sel {
  background: linear-gradient(var(--acc-1, #ffe88a), var(--acc-2, #e8b830)); border-color: var(--acc-1, #fff); color: var(--on-acc, #141832); box-shadow: none; }
:is(#dialog .dchoices, #cutscene .cs-opts) .mitem.sel .t { color: inherit !important; }

/* Bag: a title bar like every window, the hint under the grid */
.bp-head { font-size: var(--win-head); align-items: center; min-height: var(--win-x); margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.3); }
.bp-hint { font-size: var(--win-small); line-height: 1.35; }
.bp-grid .iname { font-size: calc(12px * var(--k)); }
html.touch .bp-hint { text-align: left; }

/* Settings on the house-style kit: the header, the categories as a rail at the left (a scrolling pill row on phones held
   upright), the open one's rows (label + hint | choices), the footer (keys | Reset keys on Controls). One window height
   for every category, so switching never makes it jump. --pad-y / --pad-x: the window's padding. */
#settings, #help, html.touch #help { --pad-y: calc(12px * var(--ku)); --pad-x: calc(16px * var(--ku)); display: flex; flex-direction: column; box-sizing: border-box; overflow: hidden;
  padding: var(--pad-y) var(--pad-x); font-size: calc(15px * var(--ku)); line-height: 1.35; }
#settings { width: min(calc(940px * var(--k)), calc(100vw - 24px - var(--sal) - var(--sar))); height: min(calc(580px * var(--k)), calc(var(--vh) - 24px - var(--sat) - var(--sab))); max-height: none; }
html.form-phone #settings, html.form-phone #help, html.form-phone.touch #help { --pad-y: 10px; --pad-x: 12px; width: calc(100vw - 16px - var(--sal) - var(--sar)); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
html.form-phone #settings { height: calc(var(--vh) - 16px - var(--sat) - var(--sab)); }
#settings .set-main { flex: 1 1 auto; min-height: 0; display: flex; gap: calc(16px * var(--ku)); }
#settings .win-tabs.rail { flex: none; width: calc(176px * var(--ku)); padding: 2px calc(14px * var(--ku)) 2px 2px; margin: 0; border-right: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.25); }
#settings .set-body { flex: 1 1 auto; min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 0 8px 4px 2px; }
#settings .set-note { margin: 0 0 8px; padding: 6px 10px; border: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.35); border-radius: 6px; background: color-mix(in srgb, var(--bg-1, rgb(8 14 60)) 55%, transparent); font-size: calc(13px * var(--ku)); min-height: 0; }
#settings .set-sec + .set-sec { margin-top: calc(12px * var(--ku)); }
#settings .set-sec > .win-sec { margin-bottom: 0; }
/* a row: label + hint | choices, a faint line between rows */
#settings .set-r2 { display: grid; grid-template-columns: minmax(0, calc(230px * var(--ku))) minmax(0, 1fr); align-items: center; gap: 6px calc(16px * var(--ku));
  margin: 0; padding: calc(9px * var(--ku)) 0; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.12); }
#settings .set-r2:last-child { border-bottom: 0; }
html.touch #settings .set-r2 { margin: 0; }   /* over touch.css's row margins */
#settings .set-r2.wide { grid-template-columns: minmax(0, 1fr); }
#settings .set-lw { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#settings .set-l { width: auto; font-size: calc(15px * var(--ku)); }
#settings .set-d { font-size: calc(13px * var(--ku)); line-height: 1.3; }
#settings .set-c { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
#settings .sbtn { min-height: calc(30px * var(--ku)); font-size: calc(14px * var(--ku)); }
html.touch #settings .sbtn { min-height: 44px; }
#settings .set-sub { margin: 4px 0 8px; font-size: calc(13px * var(--ku)); min-height: 0; }
/* Window style: the cards in a row on wide screens, each drawing a small window (.ws-pv) */
#settings .ws-grid { flex: 1 1 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(100px * var(--ku)), 1fr)); gap: calc(8px * var(--ku)); }
html.form-phone #settings .ws-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#settings .ws-btn { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 6px 6px 7px; min-height: 0; text-align: center; }
#settings .ws-btn .ws-pv { height: calc(44px * var(--ku)); }
/* the key bindings: the groups in balanced columns, a row per action (its name | its key caps, + to add one) */
#settings .set-grid { display: block; column-width: calc(280px * var(--ku)); column-gap: calc(24px * var(--ku)); }
#settings .set-group { break-inside: avoid; margin-bottom: calc(10px * var(--ku)); }
#settings .set-gt { font: calc(10px * var(--ku)) var(--head); color: var(--gold); margin: 0 0 2px; padding: 2px 0 4px; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.25); }
#settings .set-k { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: calc(32px * var(--ku)); padding: 1px 0; font-size: calc(14px * var(--ku)); white-space: nowrap; }
#settings .set-k > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#settings .kcs { flex: none; display: flex; gap: 4px; }
#settings .keycap, .win-kbd { display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; min-width: calc(28px * var(--ku)); height: calc(26px * var(--ku)); padding: 0 calc(7px * var(--ku));
  font: 600 calc(12px * var(--ku)) var(--font); line-height: 1; color: var(--tx-hi, #fff); background: var(--bg-1, #0a0e30); border: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.65); border-bottom-width: 3px; border-radius: 5px; white-space: nowrap; }
#settings .keycap { cursor: pointer; }
#settings .keycap .t { color: inherit !important; }
#settings .keycap.add { border-style: dashed; border-bottom-width: 1px; color: var(--tx-faint, #6a74a8); }
html.touch #settings .keycap { min-width: 44px; height: 44px; }
/* phones held upright: the rail is a row on top (the kit), the choices under their label */
html.form-phone.portrait #settings .set-main { flex-direction: column; gap: 6px; }
html.form-phone.portrait #settings .win-tabs.rail { width: auto; padding: 2px 2px 8px; border-right: 0; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.25); }
html.form-phone.portrait #settings .set-r2 { grid-template-columns: minmax(0, 1fr); }
/* phones on their side: a slim head, a narrower rail that still holds every category */
html.form-phone.landscape #settings { --pad-y: 8px; height: calc(var(--vh) - 12px - var(--sat) - var(--sab)); }
html.form-phone.landscape #settings .win-head { padding-bottom: 6px; margin-bottom: 6px; }
html.form-phone #settings .win-sub { display: none; }   /* cut to one line on a phone: the page says it */
html.form-phone.landscape #settings .win-tabs.rail { width: 150px; gap: 3px; padding: 0 10px 0 0; }
html.form-phone.landscape #settings .set-r2:not(.wide) { grid-template-columns: minmax(0, 170px) minmax(0, 1fr); }

/* Help on the kit: a centred window over the dim; tabs Controls / Screen / Tips; sections of rows (what | its keys, or a
   gesture with its icon) in balanced columns. */
#help, html.touch #help { position: fixed; left: 50%; top: 50%; right: auto; bottom: auto; transform: translate(-50%, -50%); z-index: 45; animation: popc 0.12s ease-out;
  width: min(calc(860px * var(--k)), calc(100vw - 24px - var(--sal) - var(--sar))); max-width: none; height: auto; max-height: calc(var(--vh) - 24px - var(--sat) - var(--sab));
  box-shadow: 0 0 0 200vmax var(--win-dim), var(--win-shadow, 0 0 0 2px #0a0e30, 0 6px 18px rgba(0, 0, 0, 0.5)); }
html.form-phone #help, html.form-phone.touch #help { max-height: calc(var(--vh) - 16px - var(--sat) - var(--sab)); }
html.touch #help > div { margin: 0; }   /* over touch.css's text-wall spacing */
#help .help-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 0 6px 4px 2px; }
#help .help-cols { column-width: calc(330px * var(--ku)); column-gap: calc(28px * var(--ku)); }
#help .help-sec { break-inside: avoid; margin-bottom: calc(12px * var(--ku)); }
#help .help-sec > .win-sec { margin: 0 0 2px; }
#help .help-row { display: flex; align-items: center; gap: 10px; min-height: calc(30px * var(--ku)); padding: 3px 0; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.1); }
#help .help-row:last-child { border-bottom: 0; }
#help .hr-ico { flex: none; width: calc(24px * var(--ku)); display: flex; justify-content: center; }
#help .hr-ico .pxi { --want: calc(20px * var(--ku)); }
#help .hr-l { flex: 1 1 auto; min-width: 0; color: var(--ink); }
#help .hr-l small { display: block; color: var(--dim); font-size: calc(13px * var(--ku)); }
#help .hr-k { flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 3px; max-width: 72%; color: var(--dim); font-size: calc(13px * var(--ku)); }
#help .hr-k em { font-style: normal; padding: 0 2px; }

/* The stats pop-up (a tap on the player card, a long-press on a squad card): a sheet on phones, the cards never grow into
   the controls */
.sdetail .sd-head { display: none; }
html.touch.form-phone #pcard.open .sdetail, html.touch.form-phone #squad .scard.open + .sdetail {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100vw - 24px - var(--sal) - var(--sar))); max-height: calc(var(--vh) - 24px - var(--sat) - var(--sab)); overflow-y: auto;
  margin: 0; padding: 12px 14px 14px; border: 2px solid var(--win-border); border-radius: 8px; background: linear-gradient(180deg, var(--win-a), var(--win-b)); z-index: 36; font-size: 15px; cursor: pointer;
}
html.touch.form-phone .sdetail .sd-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.3); font: 10px var(--head); color: var(--gold); }
html.touch.form-phone .sdetail .sd-head small { margin-left: auto; font: 13px var(--font); color: var(--dim); }
html.touch.form-phone .sdetail .sd-stats, html.touch.form-phone .sdetail .sd-moves, html.touch.form-phone .sdetail .sd-iq { font-size: 15px; }
html.touch.form-phone .sdetail .sd-move { min-height: 32px; }

/* The Players window: rows take the keyboard, a footer with the keys, subs never under 13 px */
#social .sw-row { scroll-margin: 4px 0; }
#social .sw-sub, #social .sw-where, #social .sw-lv, #social .pf-small, #social .pf-sub, #social .pf-where, #social .sw-pgt, #social .sw-note, #social .sw-h, #social .pf-h, #social .pf-st > span { font-size: var(--win-small); }
#social .sw-tag { font-size: max(10px, calc(11px * var(--k))); }
#social .sw-tag.sent { background: rgba(var(--hl-rgb, 255, 255, 255), 0.2); }
html.form-phone #social { font-size: 15px; }
#social .sw-foot .win-keys, #social .sw-keys { padding-top: 6px; }

/* The small tags of the fixed-size windows: never under 8 px of the pixel font */
.dxsky { font-size: 7px; }
.as-gen { font-size: 8px; }
.shop-row .own { font-size: 9px; }
/* phones: the jobs' action button stays in reach while the details scroll */
.jdetail .jgo { position: sticky; bottom: 0; z-index: 1; }
/* The fixed-size windows: zoomed on big screens (their sheets set `zoom: var(--wk)`); phones keep the full-screen layouts */
.win-zoom { zoom: var(--wk); --pxz: var(--wk); }

/* Grids and drag-and-drop (gridview.js, dnd.js)
   Pixel tiles: square corners, a 1-px dark outline, a 3-shade bevel (light top-left, dark bottom-right), whole-pixel
   sizes (--gv-w / --gv-h from gridview.js), no blur or gradient; animations step. */
.gv { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; min-height: 0; position: relative; }
.gv-in { display: grid; grid-template-columns: repeat(auto-fill, var(--gv-w, 64px)); grid-auto-rows: var(--gv-h, 64px); gap: var(--gv-gap, 6px); justify-content: center; align-content: start; padding: 4px; box-sizing: border-box; }
.gv-tile {
  position: relative; width: var(--gv-w, 64px); height: var(--gv-h, 64px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--slot); border: 2px solid var(--slot-line); border-radius: 0; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  box-shadow: inset 2px 2px 0 var(--bg-3, #1c2668), inset -2px -2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820);
}
.gv-tile:not(.empty):hover { border-color: var(--rim-hi, #8fa0ff); }
.gv-tile.empty { cursor: default; background: var(--bg-1, #0a0f38); border-color: var(--bg-3, #2c3878); box-shadow: inset 2px 2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820); }
.gv-tile.off .itm, .gv-tile.off .ico { filter: grayscale(1) brightness(0.55); }   /* a darker ramp, no see-through pixels */
.gv-tile .itm, .gv-tile .ico, .gv-tile .held-ico { flex: none; }
/* the corners: a count bottom-right, a mark top-left, a price strip along the bottom, a key cap top-right */
.gv-n { position: absolute; right: 3px; bottom: 1px; font: calc(12px * var(--k)) var(--num); color: var(--tx-hi, #fff); line-height: 1; text-shadow: -1px 0 #000, 1px 0 #000, 0 1px #000, 0 -1px #000; pointer-events: none; }
.gv-mark { position: absolute; left: 2px; top: 2px; line-height: 0; pointer-events: none; }
.gv-key { position: absolute; right: 2px; top: 1px; font: calc(10px * var(--k)) var(--pixel); color: var(--gold); line-height: 1; text-shadow: -1px 0 #000, 1px 0 #000, 0 1px #000, 0 -1px #000; pointer-events: none; }
.gv-tag { position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 4px 1px; background: var(--bg-1, #070a26); border-top: 1px solid var(--slot-line); font: calc(12px * var(--k)) var(--num); color: var(--gold); text-align: right; line-height: 1.1; white-space: nowrap; overflow: hidden; pointer-events: none; }
.gv-tag.no { color: var(--tx-bad, #ff9a7a); }
.gv-name { max-width: 100%; padding: 0 3px; font-size: calc(11px * var(--k)); line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
/* the selection frame: the tile's own rim turns gold, then a 1-px dark line, a 2-px gold ring and the dark outline; the
   ring blinks in two steps */
.gv-tile.sel { border-color: var(--gold); box-shadow: inset 2px 2px 0 var(--bg-3, #3a4690), inset -2px -2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820), 0 0 0 3px var(--gold), 0 0 0 4px var(--bg-0, #050820); z-index: 1; animation: gv-blink 1s steps(1) infinite; }
@keyframes gv-blink { 50% { box-shadow: inset 2px 2px 0 var(--bg-3, #3a4690), inset -2px -2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820), 0 0 0 3px #fff6c0, 0 0 0 4px var(--bg-0, #050820); } }
.gv-tile:focus-visible { outline: none; }
/* a grid with nothing to scroll (.fits): a finger on a tile never pans the page, so the press-and-hold drag is sure */
.gv.fits .gv-tile[data-drag] { touch-action: none; }
.gv-none { padding: 16px; color: var(--dim); font-size: var(--win-small); text-align: center; }
.gv-in > :not(.gv-tile) { grid-column: 1 / -1; }   /* an empty-list note spans the row */
@media (prefers-reduced-motion: reduce) { .gv-tile.sel { animation: none; } }

/* drag-and-drop: the ghost under the pointer, the targets that take it (a light ring), the one under the pointer (gold,
   two-step blink) */
.dnd-ghost {
  position: fixed; left: 0; top: 0; z-index: 2000; pointer-events: none; display: flex; align-items: center; justify-content: center;
  background: var(--slot); border: 2px solid var(--gold); box-shadow: 0 0 0 1px var(--bg-0, #050820), 3px 3px 0 1px var(--bg-0, #050820);
}
.dnd-ghost > * { pointer-events: none; }
.dnd-ghost.back { transition: transform 0.18s steps(3, end); }
html.dnd-on, html.dnd-on * { cursor: grabbing !important; }
/* the lifted tile: its item is in the ghost, so the slot shows empty (its key cap stays); a lifted row or squad place
   takes a darker ramp */
.gv-tile.dnd-src > :not(.kc):not(.gv-key) { visibility: hidden; }
.dnd-src:not(.gv-tile) { filter: grayscale(1) brightness(0.55); }
.tw-slot.dnd-src .tw-spt { visibility: hidden; }
.dnd-hold { animation: dnd-hold 0.3s steps(3, end) forwards; }
@keyframes dnd-hold { to { box-shadow: inset 2px 2px 0 var(--bg-3, #3a4690), inset -2px -2px 0 var(--bg-1, #070a26), 0 0 0 1px var(--bg-0, #050820), 0 0 0 3px var(--rim-hi, #8fa0ff), 0 0 0 4px var(--bg-0, #050820); } }
.dnd-can { outline: 2px solid var(--rim-hi, #8fa0ff); outline-offset: -2px; }
.dnd-over { outline: 2px solid var(--gold); outline-offset: -2px; animation: dnd-over 0.5s steps(1) infinite; }
@keyframes dnd-over { 50% { outline-color: #fff6c0; } }
.gv-tile.dnd-can, .gv-tile.dnd-over { outline-offset: -4px; }
.dnd-hit { animation: dnd-hit 0.3s steps(2, end); }
@keyframes dnd-hit { 0%, 49% { filter: brightness(1.8); } }
/* the bag on the grid: six slots a row (four on phones), the key caps above the tiles' corners */
.bp-grid.gv { display: block; max-height: calc(var(--vh) - 200px); }
.bp-grid .gv-in { padding: calc(10px * var(--k)) 8px 4px; justify-content: start; }
.bp-grid .gv-tile { padding-top: 4px; }
.bp-grid .gv-tile .kc { right: auto; left: -6px; }
/* a bag stack's count goes top-right: the name and the action strip own the bottom */
.bp-grid .gv-n, .tw-shelf .gv-n { top: 4px; bottom: auto; right: 5px; }
.bp-grid .gv-name { font-size: calc(11px * var(--k)); }
/* phones: a bag name gets two lines rather than "Oran Be…" */
html.form-phone .bp-grid .gv-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.05; overflow-wrap: anywhere; }
html.touch .bp-grid .gv-in { padding-top: 6px; }
.bp-grid .gv-tile.empty .kc { filter: brightness(0.5); }
.gv-own { position: absolute; right: 3px; top: 2px; font: calc(12px * var(--k)) var(--num); color: var(--dim); line-height: 1; text-shadow: -1px 0 #000, 1px 0 #000, 0 1px #000, 0 -1px #000; pointer-events: none; }
/* the Kecleon shop's shelf: icon on top, the name, the price tag along the bottom (the window zooms, so plain px) */
#shop .shop-list.gv { border-radius: 0; }
#shop .gv-tile { justify-content: flex-start; padding-top: 16px; gap: 4px; }
#shop .gv-name { font-size: 14px; max-width: 100%; }
.fac-win .gv-name { font-size: 13px; max-width: 100%; }   /* near the shop's: the swap tiles also hold a cost row with icons */
#shop .gv-tag, #shop .gv-own { font-size: 14px; }
/* inside a zoomed window (the shop's frame: shop, storage) the zoom scales: plain px, not × --k */
.shop-win .gv-n, .shop-win .gv-own, .shop-win .gv-tag { font-size: 14px; }
.shop-win .gv-key { font-size: 8px; }
#shop .gv-own.num { color: var(--dim); font-weight: 400; }
#shop .gv-mark .pxi { --want: 14px; }
#shop .shop-money small .pxi { --want: 14px; vertical-align: -2px; }

/* The house-style kit (winsys.js winHead, winTabs, winFoot, winBtn, winSec, winEmpty, winRow, kbd, the .win-split)
   A header (icon, title, a one-line sub, up to three chips, one X), pill tabs, a body (a list | its detail), a footer
   (key hints | actions). Every colour is a theme token, every size x --ku (the HUD windows' --k; 1 on phones and inside
   a zoomed window), so the pieces fit a HUD window and a zoomed one alike. */
.win-head { flex: none; display: flex; align-items: center; gap: calc(10px * var(--ku)); min-width: 0; padding: 0 0 calc(8px * var(--ku)); margin: 0 0 calc(8px * var(--ku));
  border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.3); }
.win-face { flex: none; width: calc(34px * var(--ku)); height: calc(34px * var(--ku)); display: flex; align-items: center; justify-content: center; box-sizing: border-box; overflow: hidden;
  border: 2px solid var(--win-border); border-radius: 6px; background: var(--bg-1, #0c1240); }
.win-face .pxi { --want: calc(24px * var(--ku)); }
.win-face img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.win-title { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.win-h { margin: 0; font: calc(12px * var(--ku)) var(--head); color: var(--gold); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-sub { margin: 0; font: calc(13px * var(--ku)) var(--font); color: var(--dim); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.win-chips { flex: none; display: flex; align-items: center; gap: calc(6px * var(--ku)); }
.win-chip { display: inline-flex; align-items: center; gap: 6px; box-sizing: border-box; min-height: calc(28px * var(--ku)); padding: 0 calc(10px * var(--ku)); white-space: nowrap;
  border: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.35); border-radius: 6px; background: color-mix(in srgb, var(--bg-1, rgb(8 14 60)) 55%, transparent);
  font: calc(12px * var(--ku)) var(--font); color: var(--dim); }
.win-chip b { font: 600 calc(15px * var(--ku)) var(--num); color: var(--tx-hi, #fff); }
.win-chip .pxi { --want: calc(14px * var(--ku)); }
.win-head .win-x { align-self: center; }
.win-zoom .win-x, .shop-win .win-x { width: 36px; height: 36px; }
html.touch :is(.win-zoom, .shop-win) .win-x { width: 44px; height: 44px; }
.win-back { flex: none; display: inline-flex; align-items: center; gap: 4px; box-sizing: border-box; min-height: var(--win-x); padding: 0 calc(10px * var(--ku)) 0 calc(6px * var(--ku));
  font: calc(14px * var(--ku)) var(--font); color: var(--ink); background: var(--slot); border: 2px solid var(--slot-line); border-radius: 6px; cursor: pointer; touch-action: manipulation; }
.win-back .pxi { --want: calc(12px * var(--ku)); }
.win-back:hover { border-color: var(--gold); }
html.touch .win-back { min-height: 44px; }
/* phones held upright: the chips go under the title */
html.form-phone.portrait .win-head { flex-wrap: wrap; row-gap: 6px; }
html.form-phone.portrait .win-chips { order: 9; flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; }

/* pill tabs: icon + label + count; a row that scrolls sideways with a fade on the side that has more, or a rail (a
   vertical list) on wide screens */
.win-tabs { flex: none; display: flex; gap: calc(6px * var(--ku)); min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; touch-action: pan-x;
  padding: 2px 2px calc(8px * var(--ku)); margin: 0 0 calc(4px * var(--ku)); }
.win-tabs::-webkit-scrollbar { display: none; }
/* a row of tabs never scrolls sideways: what doesn't fit goes on a second row, each tab keeps its own width and name;
   a rail stays a column */
.win-tabs:not(.rail) { flex-wrap: wrap; row-gap: 4px; overflow: visible; touch-action: auto; -webkit-mask-image: none !important; mask-image: none !important; }
.win-tabs.more-r { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); }
.win-tabs.more-l { -webkit-mask-image: linear-gradient(90deg, transparent, #000 44px); mask-image: linear-gradient(90deg, transparent, #000 44px); }
.win-tabs.more-l.more-r { -webkit-mask-image: linear-gradient(90deg, transparent, #000 44px, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(90deg, transparent, #000 44px, #000 calc(100% - 44px), transparent); }
.win-tab { flex: none; display: inline-flex; align-items: center; gap: calc(6px * var(--ku)); box-sizing: border-box; min-height: calc(36px * var(--ku)); padding: 0 calc(14px * var(--ku));
  border-radius: 999px; border: 2px solid var(--slot-line); background: var(--slot); color: var(--ink); font: calc(15px * var(--ku)) var(--font); white-space: nowrap; text-align: left; cursor: pointer; touch-action: manipulation; }
.win-tab:hover { border-color: var(--gold); }
.win-tab .pxi { --want: calc(16px * var(--ku)); }
.win-tab.on { background: linear-gradient(var(--acc-1, #ffe88a), var(--acc-2, #e8b830)); border-color: var(--acc-1, #fff); color: var(--on-acc, #141832); }
.win-n { font: 600 calc(12px * var(--ku)) var(--num); font-style: normal; line-height: 1.5; padding: 0 6px; border-radius: 999px; color: var(--gold); background: color-mix(in srgb, var(--bg-1, rgb(6 10 44)) 60%, transparent); }
.win-tab.on .win-n { color: inherit; background: rgba(var(--hl-rgb, 255, 255, 255), 0.25); }
.win-tab .wt-k { margin-left: auto; padding: 0; border: 0; background: none; font: calc(10px * var(--ku)) var(--pixel); color: inherit; opacity: 0.8; }
html.touch .win-tab { min-height: 44px; }
html.touch .win-tab .wt-k { display: none; }
.win-tabs.rail { flex-direction: column; overflow-x: hidden; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; padding: 2px; margin: 0; }
.win-tabs.rail .win-tab { width: 100%; border-radius: 8px; min-height: calc(40px * var(--ku)); padding: 0 calc(12px * var(--ku)); }
html.touch .win-tabs.rail .win-tab { min-height: 44px; }
html.form-phone.portrait .win-tabs.rail { flex-direction: row; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; }
html.form-phone.portrait .win-tabs.rail .win-tab { width: auto; border-radius: 999px; }

/* the body, the footer (key hints | actions; with touch only when it holds actions), buttons */
.win-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
.win-foot { flex: none; display: flex; align-items: center; gap: calc(10px * var(--ku)); min-width: 0; margin-top: calc(8px * var(--ku)); padding-top: calc(8px * var(--ku)); border-top: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.2); }
.win-foot .win-keys { flex: 1 1 auto; min-width: 0; padding: 0; font-size: calc(13px * var(--ku)); }
.win-acts { flex: none; display: flex; gap: calc(6px * var(--ku)); margin-left: auto; }
html.touch .win-foot.no-acts { display: none; }
.win-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; box-sizing: border-box; min-height: calc(34px * var(--ku)); min-width: calc(44px * var(--ku)); padding: 0 calc(14px * var(--ku));
  font: calc(15px * var(--ku)) var(--font); color: var(--ink); background: var(--slot); border: 2px solid var(--slot-line); border-radius: 6px; white-space: nowrap; cursor: pointer; touch-action: manipulation; }
.win-btn:hover { border-color: var(--gold); }
.win-btn .pxi { --want: calc(16px * var(--ku)); }
.win-btn.go { background: linear-gradient(var(--acc-1, #ffe88a), var(--acc-2, #e8b830)); border-color: var(--acc-1, #fff); color: var(--on-acc, #141832); font-weight: 600; }
.win-btn.bad { color: var(--tx-bad, #ff9a7a); border-color: var(--tx-bad, #ff9a7a); }
/* a figure or a coloured label inside the picked tab or a go button (a tab's count, the price in "Buy · 25 P") takes the
   button's ink in every style, so a window's own figure colour never lands on the accent. Any selected tab
   (role="tab") and any go button (.go), so no per-class list. */
:is([role="tab"][aria-selected="true"], button.go) :is(.num, .t) { color: inherit !important; }
.win-btn:disabled { opacity: 0.45; cursor: default; }
html.touch .win-btn { min-height: 44px; }

/* a section heading, an empty state, a list row (icon | label over its sub | a value), the list | detail split */
.win-sec { display: flex; align-items: center; gap: 8px; margin: calc(14px * var(--ku)) 0 calc(6px * var(--ku)); padding-bottom: calc(5px * var(--ku));
  font: calc(10px * var(--ku)) var(--head); font-weight: 400; line-height: 1.4; color: var(--gold); border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.25); }
.win-sec:first-child { margin-top: 0; }
.win-sec .pxi { --want: calc(16px * var(--ku)); }
.win-sec .ws-r { margin-left: auto; font: calc(13px * var(--ku)) var(--font); color: var(--dim); }
.win-empty { display: flex; align-items: center; justify-content: center; gap: 8px; padding: calc(20px * var(--ku)) 12px; color: var(--dim); font-size: calc(14px * var(--ku)); text-align: center; }
.win-empty .pxi { --want: calc(16px * var(--ku)); opacity: 0.7; }
.win-row { display: flex; align-items: center; gap: calc(10px * var(--ku)); width: 100%; box-sizing: border-box; min-height: calc(36px * var(--ku)); padding: calc(4px * var(--ku)) calc(10px * var(--ku));
  font: calc(15px * var(--ku)) var(--font); color: var(--ink); text-align: left; background: transparent; border: 0; border-bottom: 1px solid rgba(var(--rim-rgb, 201, 210, 255), 0.12); border-radius: 0; cursor: pointer; }
div.win-row { cursor: default; }
button.win-row:hover { background: rgba(var(--hl-rgb, 255, 255, 255), 0.06); }
.win-row.on { background: rgba(var(--hl-rgb, 255, 255, 255), 0.14); box-shadow: inset 3px 0 0 var(--gold); }
html.touch .win-row { min-height: 48px; }
.wr-ico { flex: none; display: flex; align-items: center; justify-content: center; width: calc(28px * var(--ku)); }
.wr-ico .pxi { --want: calc(20px * var(--ku)); }
.wr-ico img { width: calc(28px * var(--ku)); height: calc(28px * var(--ku)); image-rendering: pixelated; }
.wr-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.wr-l, .wr-s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wr-s { font-size: calc(13px * var(--ku)); color: var(--dim); }
.wr-v { flex: none; margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: calc(14px * var(--ku)); color: var(--tx-hi, #fff); }
.win-split { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, var(--split, 320px)) minmax(0, 1fr); gap: calc(12px * var(--ku)); }
.win-list, .win-detail { min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
html.form-phone.portrait .win-split { grid-template-columns: minmax(0, 1fr); }
html.form-phone.portrait .win-split:not([data-view="detail"]) > .win-detail, html.form-phone.portrait .win-split[data-view="detail"] > .win-list { display: none; }
