/* Desktop layout system (mouse + keyboard). Loaded last. Phones and tablets (html.touch: mobile.css, js/mobile.js) are
   not touched: every rule below sits behind (hover: hover) and (pointer: fine) and html:not(.touch).

   1. Scale. The interface is drawn in CSS pixels made for a 1080p window. js/uiscale.js sets --ui-scale from the
      window (0.9 at 720p · 1 at 1080p · 1.27 at 1440p · up to 1.75 at 4K, times Settings > Interface size) and the
      interface layers below are zoomed by it, so a button is the same share of the screen on every monitor.
      Inside a zoomed layer 1vh / 1vw would be scale× too long, so the stylesheets use var(--uvh) / var(--uvw) /
      var(--udvh): plain viewport units by default, divided by the scale inside a zoomed layer.
   2. Safe frame. On ultrawide monitors (wider than 2:1) the HUD corners move in to a centred 2:1 frame (--hud-x), so
      the party, chat, minimap and menu stay near where the player looks instead of 1.7 m apart.
   3. Tokens. One margin (--hud-m), one gap (--hud-gap), one key-cap size (--key) and one set of hover / pressed /
      focus states for every HUD button. */
:root {
  --ui-scale: 1;
  --uvh: 1vh; --uvw: 1vw; --udvh: 1dvh;
  --hud-m: 12px;        /* HUD margin from the window edge */
  --hud-gap: 8px;       /* gap between HUD blocks */
  --hud-x: 12px;        /* left / right HUD inset (grows on ultrawide) */
  --key: 18px;          /* key-cap badge size */
}

@media (hover: hover) and (pointer: fine) {
  /* ---------- 1. scale ---------- */
  html:not(.touch) #hud, html:not(.touch) #battle-ui, html:not(.touch) #notify-lane,
  html:not(.touch) .dlg, html:not(.touch) .dlg-yesno, html:not(.touch) .dlg-choices, html:not(.touch) .sum-sheet {
    zoom: var(--ui-scale, 1);
    --uvh: calc(1vh / var(--ui-scale, 1)); --uvw: calc(1vw / var(--ui-scale, 1)); --udvh: calc(1dvh / var(--ui-scale, 1));
  }
  /* name tags live in the 3D label layer (placed by transforms, so not zoomed): only their text grows */
  html:not(.touch) .nametag { font-size: calc(11px * var(--ui-scale, 1)); }
  html:not(.touch) .nametag .title { font-size: calc(9px * var(--ui-scale, 1)); }
  html:not(.touch) .nametag.wild .nm, html:not(.touch) .nametag.mon .nm { font-size: calc(10px * var(--ui-scale, 1)); }
  html:not(.touch) .bubble { font-size: calc(12px * var(--ui-scale, 1)); max-width: calc(200px * var(--ui-scale, 1)); }
  /* floating numbers are placed in screen px from the 3D view: the battle's sit on <body>, the overworld's inside the
     HUD layer (its zoom is undone so the position holds); both grow with the scale */
  html:not(.touch) .bt-float { scale: var(--ui-scale, 1); }
  html:not(.touch) #hud .float-text { zoom: calc(1 / var(--ui-scale, 1)); scale: var(--ui-scale, 1); }

  /* ---------- 3. key caps: one size and look on moves, ball, hotbar and the menu dock ---------- */
  html:not(.touch) .move .key, html:not(.touch) .hb .key, html:not(.touch) #ball-btn .key, html:not(.touch) .mi-big .kbd {
    min-width: var(--key); width: auto; height: var(--key); padding: 0 4px; border-radius: 5px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 10.5px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35);
  }
  html:not(.touch) .hb .key { left: 3px; top: 3px; }
  html:not(.touch) #ball-btn .key { bottom: -6px; }
  html:not(.touch) .mi-big .kbd { right: -4px; bottom: -4px; }

  /* ---------- buttons: hover, pressed, keyboard focus ---------- */
  /* menu dock: a plate under the tile on hover, the name + key in a tooltip, a clear pressed state */
  html:not(.touch) .mn-primary .mi { padding: 3px; border-radius: 14px; transition: transform var(--t) var(--ease), background var(--t); }
  html:not(.touch) .mn-primary .mi:hover, html:not(.touch) .mn-primary .mi:focus-visible { background: var(--surface-2); }
  html:not(.touch) .mn-primary .mi:active { background: rgba(255, 255, 255, .16); }
  html:not(.touch) .mi-big .mi-label { bottom: calc(100% + 12px); padding: 5px 10px; font-size: 12.5px; box-shadow: var(--shadow-sm); z-index: 2; }
  html:not(.touch) .mi-big .mi-label[data-key]::after {
    content: attr(data-key); margin-left: 7px; padding: 1px 5px; border-radius: 4px; background: rgba(255, 255, 255, .92); color: #13204a; font-size: 10.5px; font-weight: 900; }
  html.no-keys .mi-big .mi-label::after { content: none !important; }
  html:not(.touch) .hb:hover { border-color: var(--line-2); background: var(--surface-2); transform: translateY(-1px); }
  html:not(.touch) .hb:active { transform: scale(.94); }
  html:not(.touch) .move:hover:not(:disabled) { border-color: color-mix(in srgb, var(--c, var(--accent)) 70%, #fff 0%); transform: translateY(-1px); }
  html:not(.touch) .move:active:not(:disabled) { transform: scale(.96); }
  html:not(.touch) #ball-btn:hover { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255, 207, 74, .25), var(--shadow); }
  html:not(.touch) .pm { cursor: pointer; }
  html:not(.touch) .pm:hover { border-color: var(--line-2); background: rgba(22, 34, 68, .92); }
  html:not(.touch) .pm.lead:hover { border-color: var(--gold); }
  html:not(.touch) #minimap { transition: border-color var(--t), box-shadow var(--t); }
  html:not(.touch) #minimap:hover { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(122, 168, 255, .25), var(--shadow-sm); }
  /* the minimap opens the map: say so, with its key */
  html:not(.touch):not(.no-keys) .mm-title::after {
    content: 'M'; float: right; min-width: var(--key); height: var(--key); margin: -1px -2px 0 0; display: grid; place-items: center; border-radius: 5px;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 10.5px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35); }
  html:not(.touch):not(.no-keys) .mm-title { padding-left: calc(8px + var(--key)); }   /* keeps the place name centred */

  /* ---------- move bar: names never run under the type orb or wrap to a second line ---------- */
  html:not(.touch) .mv-name { white-space: nowrap; }
  html:not(.touch) .mv-name, html:not(.touch) .mv-name small { overflow: hidden; text-overflow: ellipsis; }

  /* ---------- chat ---------- */
  /* compact ticker: reads as a control (hover), and shows the key that opens it */
  html:not(.touch) #chat[data-state="compact"] .chat-card { transition: border-color var(--t), background var(--t); }
  html:not(.touch) #chat[data-state="compact"] .chat-card:hover { border-color: var(--line-2); background: rgba(10, 17, 40, .72); }
  html:not(.touch):not(.no-keys) #chat[data-state="compact"] .chat-head::before {
    content: 'Enter'; align-self: center; margin-right: 3px; height: var(--key); padding: 0 5px; display: grid; place-items: center; border-radius: 5px;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 10px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35); }
  html:not(.touch):not(.no-keys) #chat[data-state="compact"] .msg:first-child { padding-right: 96px; }
  /* expanded: tighter channel pills so World · Local · Guild · Trade · System fit without scrolling */
  html:not(.touch) #chat[data-state="expanded"] .ct { padding: 5px 7px; }
  html:not(.touch) .chat-ibtn:active { transform: scale(.92); }
  html:not(.touch) #chat-form button:hover { filter: brightness(1.1); }
  html:not(.touch) #chat-form button:active { transform: scale(.94); }

  /* ---------- windows: Esc on the close button, visible thin scrollbars ---------- */
  html:not(.touch) .modal-x { position: relative; }
  html:not(.touch) .modal-x:active { transform: scale(.94); }
  html:not(.touch):not(.no-keys) #panel-root .modal-x::after {
    content: 'Esc'; position: absolute; right: -4px; bottom: -6px; height: 15px; padding: 0 4px; display: grid; place-items: center; border-radius: 4px;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 9px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35); pointer-events: none; }
  html:not(.touch) .modal-body, html:not(.touch) #chat-log, html:not(.touch) .mn-more { scrollbar-width: thin; scrollbar-color: rgba(170, 195, 255, .35) transparent; }
}

/* ---------- 2. safe frame (wide desktop layouts only: the narrow-window layouts in style.css keep their own edges) ---------- */
@media (hover: hover) and (pointer: fine) and (min-width: 901px) {
  html:not(.touch) #hud { --hud-x: max(var(--hud-m), calc((100 * var(--uvw) - 200 * var(--uvh)) / 2)); }
  html:not(.touch) #party, html:not(.touch) #chat, html:not(.touch).q-under #quests { left: var(--hud-x); }
  html:not(.touch) #top-right, html:not(.touch) #menu, html:not(.touch) #hotbar { right: var(--hud-x); }
  html:not(.touch) #battle-ui { --hud-x: max(16px, calc((100 * var(--uvw) - 200 * var(--uvh)) / 2)); }
  html:not(.touch) #battle-ui.lay-desktop .bt-panel.foe { left: var(--hud-x); }
  html:not(.touch) #battle-ui.lay-desktop .bt-panel.me, html:not(.touch) #battle-ui.lay-desktop .bt-speed { right: var(--hud-x); }
  html:not(.touch) #battle-ui.lay-desktop .bt-bottom { left: var(--hud-x); right: var(--hud-x); }
  /* expanded chat: as wide as the room left of the move bar allows (the five channels fit) */
  html:not(.touch) #chat[data-state="expanded"] { width: clamp(240px, calc(var(--mb-left, 384px) - var(--hud-x) - 12px), 400px); }
}
/* the move buttons: a little wider where the 2 × 2 block has the room (long names: Flamethrower, Thunderbolt) */
@media (hover: hover) and (pointer: fine) and (min-width: 1181px) {
  html:not(.touch) .move { width: 188px; }
}

/* ---------- profile chip + wallet (top left): one 54px row, the two currency pills together as tall as the chip ---------- */
@media (hover: hover) and (pointer: fine) {
  html:not(.touch) .pf-row { gap: var(--hud-gap); align-items: center; }
  html:not(.touch) .pf-chip { height: 54px; gap: 10px; padding: 4px 16px 4px 5px; border-radius: 27px; }
  html:not(.touch) .pf-ava { width: 44px; height: 44px; }
  html:not(.touch) .pf-ava .ic { width: 26px; height: 26px; }
  html:not(.touch) .pf-txt { gap: 3px; line-height: 1.15; }
  html:not(.touch) .pf-name { font-size: 15px; }
  html:not(.touch) .pf-sub { font-size: 12px; gap: 9px; }
  html:not(.touch) .pf-bdg .ic { width: 14px; height: 14px; }
  /* money over diamonds: same icon size, the digits right-aligned in one column (money leaves the "+" column free),
     full numbers that never wrap or get cut */
  html:not(.touch) .pf-wallet { flex: none; gap: 4px; min-width: 92px; }
  html:not(.touch) .pf-cur { height: 25px; gap: 5px; padding: 0 4px 0 5px; border-radius: 13px; font-size: 13px; }
  html:not(.touch) .pf-cur b { overflow: visible; text-overflow: clip; padding: 0 1px; }
  html:not(.touch) .pf-cur .wl-cur, html:not(.touch) .pf-cur .dia { width: 17px; height: 17px; }
  html:not(.touch) .pf-cur .wl-cur { font-size: 10px; }
  html:not(.touch) .pf-plus { width: 17px; height: 17px; font-size: 14px; }
  html:not(.touch) .pf-cur.money { padding-right: 26px; }
  html:not(.touch) .pf-cur::after { inset: -2px 0; }
  html:not(.touch) .pf-mall { width: 66px; height: 54px; border-radius: 17px; }
  html:not(.touch) .pf-mall .ic-tile { width: 31px; height: 31px; }

  /* ---------- chat key hints: Enter in the open world, "/" while a battle, a dialogue or a cutscene uses Enter ---------- */
  html:not(.touch):not(.no-keys) .chat-bubble::after {
    content: 'Enter'; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%); height: 16px; padding: 0 5px; display: grid; place-items: center; border-radius: 5px;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 10px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35); pointer-events: none; }
  html:not(.touch):not(.no-keys) body.battle-active .chat-bubble::after, html.dlg-open:not(.touch):not(.no-keys) .chat-bubble::after, html:not(.touch):not(.no-keys) body.cinema .chat-bubble::after,
  html:not(.touch):not(.no-keys) body.battle-active #chat[data-state="compact"] .chat-head::before, html.dlg-open:not(.touch):not(.no-keys) #chat[data-state="compact"] .chat-head::before { content: '/'; min-width: var(--key); }
}
/* the guidance column (profile row + quest lines) has room for the larger row on wide layouts */
@media (hover: hover) and (pointer: fine) and (min-width: 901px) {
  html:not(.touch) #quests { width: clamp(240px, calc(var(--tr-left, 900px) - var(--party-right, 240px) - 24px), 384px); }
  html:not(.touch).q-under #quests { width: min(384px, calc(var(--tr-left, 400px) - var(--hud-x) - 12px)); }
}

/* ---------- mid-size windows (901 to 1280 px wide) ---------- */
/* When the HUD's own width (window width / scale) is under 1170px the centred move bar and the menu dock no longer fit
   side by side on the bottom row: the dock steps up above the move bar (one switch, no overlap in between). */
@media (hover: hover) and (pointer: fine) and (min-width: 901px) and (max-width: 1280px) {
  html:not(.touch) #menu { bottom: clamp(88px, calc((1170px - 100 * var(--uvw)) * 999), 140px); }
}
@media (hover: hover) and (pointer: fine) and (min-width: 901px) and (max-width: 1100px) {
  html:not(.touch) #menu { bottom: clamp(80px, calc((1170px - 100 * var(--uvw)) * 999), 140px); }
  html:not(.touch) #hud:not(:has(#hotbar .hb:not(.empty))) #menu { bottom: clamp(12px, calc((1170px - 100 * var(--uvw)) * 999), 140px); }
  /* the slim 128px move buttons: room for the longest move names */
  html:not(.touch) .move { padding-left: 29px; padding-right: 6px; }
  html:not(.touch) .move .key { left: 5px; }
  html:not(.touch) .mv-name { font-size: 12px; }
}

/* ================= round 3 ================= */
/* ---------- quick ball switch (js/hudextras.js #ball-swap): the round swap button phones have, at the Ball button's upper left ---------- */
@media (hover: hover) and (pointer: fine) {
  html:not(.touch) #ball-swap:not([hidden]) {
    display: grid; place-items: center; position: absolute; z-index: 1; left: calc(50% - var(--ball-r, 46px) - 8px); top: -8px; width: 38px; height: 38px; padding: 0; border-radius: 50%;
    color: #fff; background: radial-gradient(circle at 50% 35%, #2a4489, #101b3c 72%); border: 1px solid var(--line-2); box-shadow: var(--shadow-sm);
    transition: transform var(--t) var(--ease), border-color var(--t); }
  html:not(.touch) #ball-swap .ic { width: 20px; height: 20px; }
  html:not(.touch) #ball-swap:hover { border-color: var(--gold); transform: translateY(-1px); }
  html:not(.touch) #ball-swap:active { transform: scale(.92); }
  html:not(.touch) #ball-swap .key {
    position: absolute; left: -7px; bottom: -5px; min-width: var(--key); height: var(--key); padding: 0 4px; border-radius: 5px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 10.5px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35); }
  html.no-keys #ball-swap .key { display: none !important; }
  /* hover / keyboard focus: every kind of ball in the Bag with its count, the one in hand in gold */
  html:not(.touch) #ball-swap .bs-pop {
    position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%) translateY(4px); display: grid; gap: 2px; padding: 6px; width: max-content; border-radius: 12px;
    background: var(--ink); border: 1px solid var(--line-2); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity var(--t), transform var(--t); }
  html:not(.touch) #ball-swap:hover .bs-pop, html:not(.touch) #ball-swap:focus-visible .bs-pop { opacity: 1; transform: translateX(-50%); }
  html:not(.touch) .bs-row { display: flex; align-items: center; gap: 7px; padding: 3px 8px 3px 4px; border-radius: 8px; font: 800 12.5px/1 Nunito, system-ui, sans-serif; color: #dfe8ff; }
  html:not(.touch) .bs-row.on { background: rgba(255, 207, 74, .14); color: var(--gold); }
  html:not(.touch) .bs-ball { width: 20px; height: 20px; display: block; flex: none; }
  html:not(.touch) .bs-row em { margin-left: auto; padding-left: 10px; font-style: normal; font-variant-numeric: tabular-nums; color: #fff; }
  body.sf-on #ball-swap { display: none !important; }   /* the Safari Zone: Safari Balls only, nothing to switch */

  /* ---------- the open chat: its two header buttons read as buttons (minimise, hide) ---------- */
  html:not(.touch) #chat[data-state="expanded"] .chat-head .chat-ibtn { color: #dbe5ff; background: var(--surface); }
  html:not(.touch) #chat[data-state="expanded"] .chat-head .chat-ibtn:hover { color: #fff; background: var(--surface-2); }
  html:not(.touch) #chat[data-state="expanded"] #chat-hide:hover { background: rgba(255, 95, 107, .3); }
}

/* ---------- top-left cluster (wide desktop layouts): one top bar, the party column under it, the quest tracker beside the party ----------
   Row 1, the top bar: profile chip, wallet, Mall, the running Mall offer.
   Under it: the party column (left) and, to its right, the quest tracker (a header that folds it to one line) and
   the tutorial / controls cards. #quests is the frame of the cluster: it starts at the screen corner and lets clicks
   through, its own blocks take them. Nothing here depends on measured edges any more, so nothing jumps. */
@media (hover: hover) and (pointer: fine) and (min-width: 901px) {
  html:not(.touch) #hud { --party-w: 216px; --bar-h: 54px; --track-w: 320px; }
  html:not(.touch) #quests, html:not(.touch).q-under #quests {
    left: var(--hud-x); top: var(--hud-m); width: max-content; max-width: calc(var(--tr-left, 900px) - var(--hud-x) - 12px);
    max-height: none; overflow: visible; gap: var(--hud-gap); pointer-events: none; }
  html:not(.touch) #quests .phud { gap: var(--hud-gap); align-items: flex-start; pointer-events: none; }
  html:not(.touch) #quests .phud > *, html:not(.touch) #quests > :not(.phud) { pointer-events: auto; }
  html:not(.touch) #quests .phud > :not(.pf-row), html:not(.touch) #quests > :not(.phud) { margin-left: calc(var(--party-w) + var(--hud-gap)); width: var(--track-w); align-self: flex-start; }
  html:not(.touch) #hud:has(#party:empty) #quests .phud > :not(.pf-row), html:not(.touch) #hud:has(#party:empty) #quests > :not(.phud) { margin-left: 0; }
  html:not(.touch) #party { left: var(--hud-x); top: calc(var(--hud-m) + var(--bar-h) + var(--hud-gap)); width: var(--party-w); gap: 6px; }

  /* the quest tracker: a small header that folds it down to its first line (js/hudextras.js; remembered) */
  html:not(.touch) .qw-head {
    display: flex; align-items: center; justify-content: space-between; height: 26px; padding: 0 8px 0 11px; border-radius: 13px; cursor: pointer;
    background: var(--panel); border: 1px solid var(--line-2); color: var(--muted); box-shadow: var(--shadow-sm);
    font: 900 11px/1 Nunito, system-ui, sans-serif; letter-spacing: .8px; text-transform: uppercase; transition: color var(--t), border-color var(--t); }
  html:not(.touch) .qw-head:hover { color: #fff; border-color: var(--accent-2); }
  html:not(.touch) .qw-head .ic { width: 15px; height: 15px; transition: transform var(--t) var(--ease); }
  html:not(.touch) .phud.qw-min .qw-head .ic { transform: rotate(-90deg); }
  html:not(.touch) #quests .phud > .qw { margin-top: -3px; }
  html:not(.touch) .phud.qw-min .qw .qw-row:nth-child(n+2) { display: none; }
  html:not(.touch) .phud:has(.qw:empty) .qw-head { display: none; }

  /* the running Mall offer (Black PokéFriday) in the top bar, beside the Mall button; the small chip by the minimap steps aside */
  html:not(.touch) .pf-promo:not([hidden]) {
    display: inline-flex; align-items: center; gap: 8px; flex: none; height: 40px; padding: 0 15px 0 9px; border-radius: 20px; cursor: pointer; white-space: nowrap;
    color: #ffc440; border: 1.5px solid rgba(255, 196, 64, .85); background: linear-gradient(#1d1a22, #0b0b10); box-shadow: var(--shadow-sm), 0 0 12px rgba(255, 196, 64, .22);
    font: 900 13.5px/1 Nunito, system-ui, sans-serif; letter-spacing: .01em; transition: transform var(--t) var(--ease), box-shadow var(--t); }
  html:not(.touch) .pf-promo .bb { width: 24px; height: 24px; flex: none; background: var(--black-ball) center / contain no-repeat; }
  html:not(.touch) .pf-promo:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm), 0 0 16px rgba(255, 196, 64, .45); }
  html:not(.touch) .pf-promo:active { transform: scale(.97); }
  html:not(.touch) #cos-hud .cos-promo { display: none !important; }
  html:not(.touch) #cos-hud:not(:has(.cos-lure:not(.cos-promo):not([hidden]))),
  html:not(.touch) .top-buttons:not(:has(> :not(#cos-hud))):not(:has(.cos-lure:not(.cos-promo):not([hidden]))) { display: none; }
}

/* the Ball button is smaller on mid-size and narrow windows (style.css): the switch keeps to its upper-left edge */
@media (hover: hover) and (pointer: fine) and (max-width: 1100px) { html:not(.touch) #movebar { --ball-r: 40px; } }
@media (hover: hover) and (pointer: fine) and (max-width: 900px) { html:not(.touch) #movebar { --ball-r: 34px; } html:not(.touch) #ball-swap:not([hidden]) { width: 34px; height: 34px; } }
/* the open chat in a battle or cutscene: its close button carries the Esc key */
@media (hover: hover) and (pointer: fine) {
  html:not(.touch) body.battle-active #chat-hide, html:not(.touch) body.cinema #chat-hide { position: relative; }
  html:not(.touch):not(.no-keys) body.battle-active #chat[data-state="expanded"] #chat-hide::after, html:not(.touch):not(.no-keys) body.cinema #chat[data-state="expanded"] #chat-hide::after {
    content: "Esc"; position: absolute; right: -4px; bottom: -7px; height: 15px; padding: 0 4px; display: grid; place-items: center; border-radius: 4px;
    background: rgba(255, 255, 255, .92); color: #13204a; font: 900 9px/1 Nunito, system-ui, sans-serif; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .35); pointer-events: none; }
}
