/* Phone client (/mobile): the full-world landscape touch HUD. Every selector here starts
   with #mobile-shell, [data-hud="mobile"] or html:has(#mobile-shell), so nothing leaks onto
   the desktop /play page (the few carried-over legacy rules below keep their original
   selectors verbatim). Plain CSS, bronze tokens only. Phone root is 18px, so sizes are rem. */

/* ---- page: no scroll, no selection, no browser gestures ---------------------------------
   18px root whenever the mobile shell is on the page: every rem-based size (sheet pages +
   mobile kit) scales up for touch. CSS (not a layout <html> attribute) so it survives Turbo
   visits, which keep the original <html>. */
html:has(#mobile-shell) { font-size: 18px; overscroll-behavior: none; }
html:has(#mobile-shell) body {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
html:has(#mobile-shell) input,
html:has(#mobile-shell) textarea {
  user-select: text;
  -webkit-user-select: text;
}

/* ---- rotate card: portrait only -------------------------------------------------------- */
#mobile-shell #touch-rotate { display: none; }
@media (orientation: portrait) {
  #mobile-shell #touch-rotate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: calc(1.5rem + env(safe-area-inset-top)) calc(1.5rem + env(safe-area-inset-right))
             calc(1.5rem + env(safe-area-inset-bottom)) calc(1.5rem + env(safe-area-inset-left));
    text-align: center;
    background: var(--hud-bg);
    color: var(--hud-text);
  }
  #mobile-shell #touch-rotate .touch-rotate__title {
    font-size: 1.25rem; font-weight: 600; color: var(--hud-title);
  }
  #mobile-shell #touch-rotate .touch-rotate__body {
    font-size: 0.9rem; color: var(--hud-text-dim);
  }
}

/* ---- thumb zone ------------------------------------------------------------------------
   The move zone owns the bottom-left of the screen and is the joystick's real input surface:
   a touch anywhere in it plants the base under the thumb (TouchJoystick floats it with a CSS
   translate), so the zone takes pointer events and the browser must not scroll or zoom there.
   The base rests where .mobile-joystick below places it. */
#mobile-shell #touch-move-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: min(36vw, 18rem);
  height: min(62vh, 15rem);
  padding: 0 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
  pointer-events: auto;
  touch-action: none;
  z-index: 40;
}

/* Right-hand containers: empty hosts that later tasks fill. They never block the canvas
   themselves; only their children take touches. */
#mobile-shell #touch-cluster {
  position: absolute;
  right: calc(0.75rem + env(safe-area-inset-right));
  bottom: calc(0.75rem + env(safe-area-inset-bottom));
  width: 10.65rem;
  height: 10.65rem;
  z-index: 40;
  pointer-events: none;
}
#mobile-shell #touch-cluster > * { pointer-events: auto; }

/* ---- action cluster ---------------------------------------------------------------------
   One 10.65rem square anchored bottom-right; every child is absolutely placed in it, measured
   from the cluster's right/bottom edges. Attack (4.4rem) sits in the corner with its centre at
   (2.2, 2.2). The four visible skills (3.1rem) sit on a 6.9rem arc round that centre at 180, 150,
   120 and 90 degrees (left of Attack up to above it), which keeps >= 8px between neighbours.
   Swap sits in the gap between Attack and the lowest skill; Next / Clear target sit above
   Attack. The strip left of the cluster (potions, Auto) and the space above the target buttons
   stay free for later tasks. */
#mobile-shell[data-touch-dead] #touch-cluster,
#mobile-shell[data-touch-dead] #touch-potion-hp,
#mobile-shell[data-touch-dead] #touch-potion-mp,
#mobile-shell[data-touch-dead] #touch-auto { display: none; } /* a soul has nothing to press */

#mobile-shell #touch-skill-dock { position: absolute; inset: 0; pointer-events: none; }
#mobile-shell #touch-skill-dock #spellbar {
  position: absolute; inset: 0;
  display: block;
  pointer-events: none;
}
#mobile-shell #touch-skill-dock #spellbar .hud-slot {
  --hud-slot-size: 3.1rem;
  position: absolute;
  border-radius: 9999px;
  pointer-events: auto;
  touch-action: none;
}
#mobile-shell #spellbar .hotbar-key { display: none; }
/* cooldown: the desktop wipe is a 58 % black veil, which vanishes on a dark icon. On the round phone buttons the veil is a
   pale, clearly visible sweep and the seconds are bigger and bolder. The number itself still follows hotbar_state's threshold
   (empty, hence hidden, under 3 s). */
#mobile-shell #spellbar .cd-sweep {
  background: conic-gradient(from 0deg, color-mix(in srgb, var(--hud-text) 46%, transparent) var(--cd, 0%), transparent 0);
}
#mobile-shell #spellbar .hud-slot__cd {
  font-size: 0.95rem; font-weight: 800; color: var(--hud-text); z-index: 4;
  text-shadow: 0 1px 2px rgb(0 0 0 / 1), 0 0 4px rgb(0 0 0 / 1), 0 0 7px rgb(0 0 0 / 0.9);
}
/* four of eight show at a time: set 0 = slots 1-4, set 1 = slots 5-8 */
#mobile-shell[data-touch-set="0"] #spellbar .hud-slot:nth-child(n+5),
#mobile-shell[data-touch-set="1"] #spellbar .hud-slot:nth-child(-n+4) { display: none; }
#mobile-shell[data-touch-set="0"] #spellbar .hud-slot:nth-child(1),
#mobile-shell[data-touch-set="1"] #spellbar .hud-slot:nth-child(5) { right: 7.55rem; bottom: 0.65rem; }
#mobile-shell[data-touch-set="0"] #spellbar .hud-slot:nth-child(2),
#mobile-shell[data-touch-set="1"] #spellbar .hud-slot:nth-child(6) { right: 6.625rem; bottom: 4.1rem; }
#mobile-shell[data-touch-set="0"] #spellbar .hud-slot:nth-child(3),
#mobile-shell[data-touch-set="1"] #spellbar .hud-slot:nth-child(7) { right: 4.1rem; bottom: 6.625rem; }
#mobile-shell[data-touch-set="0"] #spellbar .hud-slot:nth-child(4),
#mobile-shell[data-touch-set="1"] #spellbar .hud-slot:nth-child(8) { right: 0.65rem; bottom: 7.55rem; }

/* Attack: the primary action, with a gold rim and painted context art. */
#mobile-shell #touch-attack {
  position: absolute; right: 0; bottom: 0;
  width: 4.4rem; height: 4.4rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.05rem;
  border-radius: 9999px;
  border: 2px solid var(--hud-frame-bright);
  background: radial-gradient(circle at 35% 30%, var(--hud-frame), var(--hud-bg-2) 72%);
  color: var(--hud-title);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.55), inset 0 1px 2px rgb(var(--hud-title-rgb) / 0.6);
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  touch-action: none; cursor: pointer;
}
#mobile-shell #touch-attack:active { filter: brightness(0.9); }
#mobile-shell #touch-attack [data-touch-attack-icon] { display: flex; }
#mobile-shell #touch-attack [data-icon-kind] { display: none; }
#mobile-shell #touch-attack[data-kind="attack"] [data-icon-kind="attack"],
#mobile-shell #touch-attack[data-kind="gather"] [data-icon-kind="gather"],
#mobile-shell #touch-attack[data-kind="talk"] [data-icon-kind="talk"],
#mobile-shell #touch-attack[data-kind="relic"] [data-icon-kind="relic"],
#mobile-shell #touch-attack[data-kind="close"] [data-icon-kind="close"] { display: flex; }
#mobile-shell #touch-attack .touch-attack__glyph { width: 1.7rem; height: 1.7rem; }

/* Swap, Next target, Clear target: 2rem round secondary buttons */
#mobile-shell #touch-swap,
#mobile-shell #touch-target-next,
#mobile-shell #touch-target-clear {
  position: absolute;
  width: 2rem; height: 2rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 9999px;
  border: 1px solid var(--hud-frame-bright);
  background: color-mix(in srgb, var(--hud-bg-2) 85%, transparent);
  color: var(--hud-title);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
  touch-action: none; cursor: pointer;
}
#mobile-shell #touch-target-clear[hidden] { display: none; }
#mobile-shell #touch-swap { right: 4.97rem; bottom: 0.2rem; gap: 0.1rem; }
#mobile-shell #touch-target-next { right: 0.2rem; bottom: 4.9rem; }
#mobile-shell #touch-target-clear { right: 2.65rem; bottom: 4.9rem; }
#mobile-shell .touch-small__glyph { width: 1rem; height: 1rem; }
#mobile-shell .touch-swap__pips { display: flex; gap: 0.2rem; }
#mobile-shell .touch-swap__pip {
  width: 0.28rem; height: 0.28rem; border-radius: 9999px;
  background: var(--hud-frame);
}
#mobile-shell .touch-swap__pip[data-on="true"] { background: var(--hud-title); }
/* a skill in the other set came off cooldown */
#mobile-shell .touch-swap__dot {
  position: absolute; top: -0.05rem; right: -0.05rem;
  width: 0.6rem; height: 0.6rem; border-radius: 9999px;
  background: var(--hud-title);
  border: 1px solid var(--hud-bg-2);
}
#mobile-shell .touch-swap__dot[hidden] { display: none; }
/* ---- quick potions + Auto pill ----------------------------------------------------------
   Two 2.3rem rounded squares on the bottom edge, immediately left of the cluster (whose leftmost
   skill ends 11.4rem from the screen edge): health nearest the thumb, mana beyond it, 0.5rem
   (9px) between neighbours. The Auto pill sits above the cluster at the right edge, clear of
   the skill arc. All three sit on the shell, not in #touch-bottom-center (the chat peek's). */
#mobile-shell #touch-potion-hp,
#mobile-shell #touch-potion-mp {
  position: absolute;
  bottom: calc(1.4rem + env(safe-area-inset-bottom));
  width: 2.3rem; height: 2.3rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 0.5rem;
  border: 1px solid var(--hud-frame-bright);
  background: color-mix(in srgb, var(--hud-bg-2) 85%, transparent);
  color: var(--hud-title);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
  z-index: 40;
  touch-action: none; cursor: pointer;
}
#mobile-shell #touch-potion-hp { right: calc(11.9rem + env(safe-area-inset-right)); }
#mobile-shell #touch-potion-mp { right: calc(14.7rem + env(safe-area-inset-right)); }
#mobile-shell .touch-potion__glyph { width: 1.1rem; height: 1.1rem; }
#mobile-shell .touch-potion__img {
  width: 1.7rem; height: 1.7rem;
  object-fit: contain; image-rendering: pixelated;
  pointer-events: none;
}
#mobile-shell .touch-potion__img[hidden],
#mobile-shell .touch-potion__qty[hidden] { display: none; }
#mobile-shell .touch-potion__qty {
  position: absolute; right: 0.1rem; bottom: 0;
  padding: 0 0.15rem;
  border-radius: 0.25rem;
  background: color-mix(in srgb, var(--hud-bg) 80%, transparent);
  color: var(--hud-title);
  font-size: 0.55rem; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
/* none in the bag: dim, still in place so the strip does not jump */
#mobile-shell #touch-potion-hp[aria-disabled="true"],
#mobile-shell #touch-potion-mp[aria-disabled="true"] { opacity: 0.4; }
/* its category cooldown is running: a dim overlay over the icon */
#mobile-shell #touch-potion-hp.is-cooling::after,
#mobile-shell #touch-potion-mp.is-cooling::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: rgb(0 0 0 / 0.55);
  pointer-events: none;
}
/* under 30 % health the health potion pulses danger red (the vignette's own rule) */
#mobile-shell #touch-potion-hp.is-urgent {
  border-color: var(--hud-danger);
  box-shadow: 0 0 0.6rem color-mix(in srgb, var(--hud-danger) 70%, transparent);
}
@media (prefers-reduced-motion: no-preference) {
  #mobile-shell #touch-potion-hp.is-urgent { animation: touch-potion-urgent 0.9s ease-in-out infinite; }
}
@keyframes touch-potion-urgent {
  0%, 100% { box-shadow: 0 0 0.2rem color-mix(in srgb, var(--hud-danger) 40%, transparent); }
  50% { box-shadow: 0 0 0.9rem 0.1rem var(--hud-danger); }
}

/* nothing to drink, or the press was refused: the same 240 ms red flash a denied hotbar slot gets */
#mobile-shell #touch-potion-hp.is-denied,
#mobile-shell #touch-potion-mp.is-denied {
  border-color: var(--hud-danger);
  box-shadow: 0 0 0 2px var(--hud-danger);
}
@media (prefers-reduced-motion: no-preference) {
  #mobile-shell #touch-potion-hp.is-denied,
  #mobile-shell #touch-potion-mp.is-denied { animation: touch-potion-denied 240ms ease-out; }
}
@keyframes touch-potion-denied { 0% { filter: brightness(1.6); } 100% { filter: brightness(1); } }
/* Auto pill: gold chrome when off; green (status data) when running */
#mobile-shell #touch-auto {
  position: absolute;
  right: calc(0.75rem + env(safe-area-inset-right));
  bottom: calc(11.9rem + env(safe-area-inset-bottom));
  width: 2.6rem; height: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9999px;
  border: 1px solid var(--hud-frame-bright);
  background: color-mix(in srgb, var(--hud-bg-2) 85%, transparent);
  color: var(--hud-title);
  font-size: 0.55rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
  z-index: 40;
  touch-action: none; cursor: pointer;
}
#mobile-shell #touch-auto::before { /* the pill is 25px tall: grow the hit area to a finger */
  content: ""; position: absolute; inset: -0.35rem -0.3rem;
}
#mobile-shell #touch-auto.is-active {
  border-color: var(--hud-accent);
  color: var(--hud-accent);
  background: color-mix(in srgb, var(--hud-accent) 16%, var(--hud-bg-2));
}

/* ---- aiming a ground spell ---------------------------------------------------------------
   TouchHud sets data-touch-aim="drag"|"sticky" on the shell while controller.aim is live. The
   other cluster buttons dim (the joystick stays fully usable), a hint pill names the spell, and
   a dashed danger circle takes the release / tap that aborts. */
#mobile-shell #spellbar .hud-slot--ground::after {
  content: "";
  position: absolute; top: 0.2rem; right: 0.35rem;
  width: 0.4rem; height: 0.4rem; border-radius: 9999px;
  background: var(--hud-title);
  box-shadow: 0 0 0 1px var(--hud-bg-2);
  pointer-events: none;
}
#mobile-shell[data-touch-aim] #touch-attack,
#mobile-shell[data-touch-aim] #touch-swap,
#mobile-shell[data-touch-aim] #touch-target-next,
#mobile-shell[data-touch-aim] #touch-target-clear,
#mobile-shell[data-touch-aim] #touch-potion-hp,
#mobile-shell[data-touch-aim] #touch-potion-mp,
#mobile-shell[data-touch-aim] #touch-auto,
#mobile-shell[data-touch-aim] #spellbar .hud-slot:not(.hud-slot--aiming) { opacity: 0.3; }
#mobile-shell #touch-aim-hint,
#mobile-shell #touch-aim-cancel { display: none; }
#mobile-shell[data-touch-aim] #touch-aim-hint {
  display: block;
  position: absolute;
  top: calc(0.5rem + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  max-width: 50vw;
  padding: 0.35rem 0.9rem;
  border-radius: 9999px;
  border: 1px solid var(--hud-frame-bright);
  background: color-mix(in srgb, var(--hud-bg) 85%, transparent);
  color: var(--hud-title);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
  z-index: 45;
}
#mobile-shell[data-touch-aim] #touch-aim-cancel {
  display: flex; align-items: center; justify-content: center;
  position: absolute;
  top: calc(0.5rem + env(safe-area-inset-top));
  right: calc(0.5rem + env(safe-area-inset-right));
  width: 4.6rem; height: 4.6rem;
  border-radius: 9999px;
  border: 2px dashed var(--hud-danger);
  background: color-mix(in srgb, var(--hud-danger) 18%, var(--hud-bg));
  color: var(--hud-danger);
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  touch-action: none; cursor: pointer;
  z-index: 45;
}
#mobile-shell #touch-aim-cancel[data-hot="true"] { background: color-mix(in srgb, var(--hud-danger) 45%, var(--hud-bg)); color: var(--hud-title); }
/* ---- top right + bottom centre ----------------------------------------------------------
   #touch-top-right is the 7.4rem x 2.1rem strip immediately LEFT of the round 4.2rem minimap
   (the one-line quest tracker sits under it): Chat, Bag, Menu, 2.1rem each with 0.55rem
   between (and 0.5rem to the minimap): every neighbour keeps >= 8px between drawn boxes. #touch-bottom-center is the lane between the joystick base and the potion strip,
   at the very bottom (the cast bar and the error line sit above it): the chat peek. */
#mobile-shell #touch-top-right {
  position: absolute;
  top: calc(0.5rem + env(safe-area-inset-top));
  right: calc(5.2rem + env(safe-area-inset-right));
  display: flex; gap: 0.55rem;
  width: 7.4rem; height: 2.1rem;
  z-index: 40;
  pointer-events: none;
}
#mobile-shell #touch-top-right > * { pointer-events: auto; }
#mobile-shell[data-touch-aim] #touch-top-right { opacity: 0.3; }
#mobile-shell #touch-bottom-center {
  position: absolute;
  left: calc(11.6rem + env(safe-area-inset-left));
  right: calc(17.4rem + env(safe-area-inset-right));
  bottom: calc(0.5rem + env(safe-area-inset-bottom));
  z-index: 40;
  pointer-events: none;
}
#mobile-shell #touch-bottom-center > * { pointer-events: none; }

#mobile-shell .touch-topbtn {
  position: relative; flex: 0 0 auto;
  width: 2.1rem; height: 2.1rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 0.5rem;
  border: 1px solid var(--hud-frame-bright);
  background: color-mix(in srgb, var(--hud-bg-2) 85%, transparent);
  color: var(--hud-title);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
  touch-action: manipulation; cursor: pointer;
}
#mobile-shell .touch-topbtn::before { /* 38px square: grow the hit area to a finger */
  content: ""; position: absolute; inset: -0.35rem -0.25rem; /* up and down, and half the 0.55rem gap sideways (less a hair): the hit areas never overlap */
}
#mobile-shell .touch-topbtn:active { filter: brightness(0.85); }
#mobile-shell .touch-topbtn__count {
  margin-top: -0.05rem;
  font-size: 0.5rem; font-weight: 600; line-height: 0.6rem; letter-spacing: 0;
  color: var(--hud-text-dim); font-variant-numeric: tabular-nums;
}
#mobile-shell .touch-topbtn__count:empty { display: none; }
#mobile-shell .touch-topbtn__count[data-full="true"] { color: var(--hud-danger); }
#mobile-shell .touch-topbtn__badge { /* unread count on Chat */
  position: absolute; top: -0.35rem; left: -0.35rem; /* the outer corner: the right one reaches into the gap to Bag */
  min-width: 0.95rem; height: 0.95rem; padding: 0 0.2rem; box-sizing: border-box;
  border-radius: 9999px;
  border: 1px solid var(--hud-bg-2);
  background: var(--hud-danger); color: var(--hud-bg-2);
  font-size: 0.55rem; font-weight: 700; line-height: 0.85rem; text-align: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
/* Menu: a gold dot while any tile carries a badge, a red one while the socket is down (red wins) */
#mobile-shell #touch-menu-btn::after {
  content: ""; position: absolute; top: -0.2rem; right: -0.2rem;
  width: 0.6rem; height: 0.6rem; border-radius: 9999px;
  background: var(--hud-title); border: 1px solid var(--hud-bg-2);
  transform: scale(0); pointer-events: none;
}
#mobile-shell #touch-menu-btn[data-badge="true"]::after { transform: scale(1); }
#mobile-shell #touch-menu-btn[data-conn="down"]::after { background: var(--hud-danger); transform: scale(1); }

/* chat peek: the last three lines, no box, fading over 8 s (each line carries a negative animation-delay
   equal to its age, so a repaint never replays the fade of the older lines) */
#mobile-shell #touch-chat-peek {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem;
  margin: 0; padding: 0; list-style: none;
}
#mobile-shell .touch-peek__line {
  max-width: 100%;
  font-size: 0.65rem; line-height: 1.2; font-weight: 500;
  color: var(--hud-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.95), 0 0 3px rgb(0 0 0 / 0.75);
}
#mobile-shell .touch-peek__name { font-weight: 700; }
@media (prefers-reduced-motion: no-preference) {
  #mobile-shell .touch-peek__line { animation: touch-peek 8s linear both; }
}
@keyframes touch-peek {
  0% { opacity: 0; }
  2% { opacity: 1; }
  88% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- panel host ----------------------------------------------------------------------------
   data-touch-panel on the shell is "" | side | full | menu (touch_panel_controller). While any panel is
   up the action cluster, potions, Auto and the chat peek step aside; full / menu cover the screen, so the
   joystick goes too. Side keeps the joystick, vitals and target frame live over the visible world. */
#mobile-shell { --t-panel-w: 48vw; --t-rail-w: 3.1rem; }
#mobile-shell:is([data-touch-panel="side"], [data-touch-panel="full"], [data-touch-panel="menu"]) :is(#touch-cluster, #touch-potion-hp, #touch-potion-mp, #touch-auto, #touch-bottom-center) { display: none; }
#mobile-shell:is([data-touch-panel="full"], [data-touch-panel="menu"]) #touch-move-zone { display: none; }

/* side panels: the overlay windows, docked right at 48 % width and full height, the rail inside their left padding */
#mobile-shell #ov-win-inventory:not(.hidden),
#mobile-shell #ov-win-equipment:not(.hidden),
#mobile-shell #ov-win-quests:not(.hidden),
#mobile-shell #stats-window:not(.hidden),
#mobile-shell .game-window:not(.game-window--dialog, #dialogue, #stats-window):not(.hidden) {
  position: fixed;
  top: 0 !important; bottom: 0 !important; right: 0 !important; left: auto !important;
  z-index: 44 !important;
  display: flex; flex-direction: column;
  box-sizing: border-box; width: var(--t-panel-w); max-width: none; height: auto; margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) var(--t-rail-w);
  border-width: 0 0 0 1px; border-radius: 0;
  background: var(--hud-bg);
  box-shadow: -0.5rem 0 1.25rem rgb(0 0 0 / 0.5);
  transform: none !important; opacity: 1 !important; transition: none !important; /* game_window's open animation: ours is below */
  touch-action: pan-y;
}
@media (prefers-reduced-motion: no-preference) {
  #mobile-shell #ov-win-inventory:not(.hidden),
  #mobile-shell #ov-win-equipment:not(.hidden),
  #mobile-shell #ov-win-quests:not(.hidden),
  #mobile-shell #stats-window:not(.hidden),
  #mobile-shell .game-window:not(.game-window--dialog, #dialogue, #stats-window):not(.hidden) { animation: touch-panel-in 180ms ease-out; }
}
@keyframes touch-panel-in { from { translate: 100% 0; } to { translate: 0 0; } }
/* the other floating windows (journal, Auto, ...) are side panels without the rail */
#mobile-shell .game-window:not(.game-window--dialog, #dialogue, #stats-window):not(.hidden) { padding-left: 0; }

/* the title bars: a plain 2.8rem strip with a 2.8rem close button (the desktop plate that hangs over the edge is cut off here) */
#mobile-shell [data-ov-drag],
#mobile-shell .game-window:not(.game-window--dialog) .game-window-titlebar,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-titlebar {
  position: relative; flex: none; box-sizing: border-box;
  display: flex; align-items: center; justify-content: flex-start;
  min-height: 2.8rem; padding: 0 3rem 0 0.75rem;
  border-radius: 0; border-bottom: 1px solid var(--hud-frame);
  background: linear-gradient(var(--hud-bg-2), var(--hud-bg));
  cursor: default; touch-action: none;
}
#mobile-shell [data-ov-drag] > span,
#mobile-shell .game-window:not(.game-window--dialog) .game-window-title,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-title {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--hud-title);
}
#mobile-shell .game-window:not(.game-window--dialog) .game-window-plate,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-plate {
  position: static; transform: none; padding: 0; max-width: none;
  background: none; border: 0; box-shadow: none;
}
#mobile-shell [data-ov-drag] > button,
#mobile-shell .game-window:not(.game-window--dialog) .game-window-x,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-x {
  position: absolute; top: 0; right: 0; transform: none;
  width: 2.8rem; height: 2.8rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--hud-text-dim); font-size: 1.6rem; line-height: 1;
  touch-action: manipulation;
}
#mobile-shell [data-ov-drag] > button:active,
#mobile-shell .game-window:not(.game-window--dialog) .game-window-x:active,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-x:active { color: var(--hud-title); }
#mobile-shell .game-window:not(.game-window--dialog) .game-window-x svg,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-x svg { width: 1.2rem; height: 1.2rem; }
/* the scrolling bodies: a normal vertical swipe scrolls them (the page's touch-action is none) */
#mobile-shell #ov-win-inventory-body,
#mobile-shell #ov-win-equipment-body,
#mobile-shell #ov-win-quests-body,
#mobile-shell .game-window:not(.game-window--dialog) .game-window-body,
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-body {
  flex: 1 1 auto; min-height: 0; max-height: none !important; /* a smart-docked window caps its body inline */
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  touch-action: pan-y;
}

/* the rail: the panels' own switcher, inside the panel's left padding */
#mobile-shell #touch-rail,
#mobile-shell #touch-world-catch { display: none; }
#mobile-shell[data-touch-panel="side"] #touch-rail {
  position: fixed; top: 0; bottom: 0; right: calc(var(--t-panel-w) - var(--t-rail-w)); z-index: 46;
  display: flex; flex-direction: column; align-items: center; gap: 0.45rem;
  box-sizing: border-box; width: var(--t-rail-w);
  padding: calc(0.3rem + env(safe-area-inset-top)) 0.2rem calc(0.3rem + env(safe-area-inset-bottom));
  background: linear-gradient(90deg, var(--hud-bg-2), var(--hud-bg));
  border-right: 1px solid var(--hud-frame);
  touch-action: none;
}
#mobile-shell .touch-rail__btn {
  flex: 0 0 auto; position: relative;
  width: 2.5rem; height: 2.5rem;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 0.5rem;
  background: transparent; cursor: pointer;
  touch-action: manipulation;
}
/* the social pages under a divider; the divider is the group's own top border, gone when both buttons are */
#mobile-shell .touch-rail__group {
  display: flex; flex-direction: column; align-items: center; gap: 0.45rem;
  margin-top: 0.05rem; padding-top: 0.5rem; border-top: 1px solid var(--hud-frame); align-self: stretch;
}
html:has(#mobile-shell) body[data-features-off~="party"][data-features-off~="guilds"] .touch-rail__group { display: none; }
#mobile-shell .touch-rail__btn[aria-pressed="true"] {
  border-color: var(--hud-frame-bright);
  background: rgb(var(--hud-title-rgb) / 0.12);
  box-shadow: inset 0 0 0.5rem rgb(var(--hud-title-rgb) / 0.12);
}
#mobile-shell .touch-rail__btn:active { filter: brightness(0.85); }
#mobile-shell .touch-rail__icon { width: 1.8rem; height: 1.8rem; object-fit: contain; pointer-events: none; }
#mobile-shell .touch-rail__btn[aria-pressed="false"] .touch-rail__icon { opacity: 0.7; }

/* a tap on the world beside a side panel only closes it (touch_panel_controller#worldTap). It sits above the canvas and
   below every HUD piece (z 20+), the joystick zone (40) and the panel (44). */
#mobile-shell[data-touch-panel="side"] #touch-world-catch {
  display: block; position: fixed; top: 0; bottom: 0; left: 0; right: var(--t-panel-w);
  z-index: 10; touch-action: none;
}

/* full-screen surfaces: the menu and the page host share a header */
#mobile-shell #touch-menu,
#mobile-shell #touch-page {
  position: fixed; left: 0; right: 0; z-index: 60;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  color: var(--hud-text);
}
#mobile-shell #touch-menu { top: 0; bottom: 0; background: color-mix(in srgb, var(--hud-bg) 96%, transparent); }
/* the page tracks the visual viewport, so the chat log stays above the on-screen keyboard */
#mobile-shell #touch-page { top: var(--touch-vt, 0px); height: var(--touch-vh, 100dvh); background: var(--hud-bg); }
#mobile-shell #touch-menu:not(.hidden),
#mobile-shell #touch-page:not(.hidden) { display: flex; flex-direction: column; }
#mobile-shell .touch-sheet__head {
  position: relative; flex: none; box-sizing: border-box;
  display: flex; align-items: center;
  min-height: 2.8rem; padding: 0 3rem 0 0.9rem;
  border-bottom: 1px solid var(--hud-frame);
  background: linear-gradient(var(--hud-bg-2), var(--hud-bg));
}
#mobile-shell .touch-sheet__title {
  font-size: 0.85rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--hud-title);
}
#mobile-shell .touch-sheet__x {
  position: absolute; top: 0; right: 0.1rem;
  width: 2.8rem; height: 2.8rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--hud-text-dim); cursor: pointer; touch-action: manipulation;
}
#mobile-shell .touch-sheet__x:active { color: var(--hud-title); }
#mobile-shell .touch-sheet__x-glyph { width: 1.3rem; height: 1.3rem; }

/* menu: six columns of big tiles with the game's own icons */
#mobile-shell .touch-menu__grid {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-auto-rows: minmax(4.4rem, 6rem);
  align-content: center; align-content: safe center; /* `safe`: with a fourth row (the Install tile) the top row stays reachable instead of being centred off-screen */
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
}
/* While the Install tile is showing there are 19 tiles: seven columns keep them on three rows (the grid
   scrolls, but the menu is easier when nothing hides below the fold). It goes when the app is installed. */
#mobile-shell .touch-menu__grid:has(.touch-tile[data-pwa-install-tile]:not([hidden])) { grid-template-columns: repeat(7, minmax(0, 1fr)); }
#mobile-shell .touch-tile {
  position: relative; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.3rem;
  padding: 0.3rem 0.2rem;
  border: 1px solid var(--hud-frame); border-radius: 0.6rem;
  background: linear-gradient(var(--hud-bg), var(--hud-bg-2));
  color: var(--hud-title);
  box-shadow: inset 0 1px 0 rgb(var(--hud-title-rgb) / 0.08), 0 1px 3px rgb(0 0 0 / 0.5);
  cursor: pointer; touch-action: manipulation;
}
#mobile-shell .touch-tile:active { border-color: var(--hud-frame-bright); filter: brightness(1.2); }
#mobile-shell .touch-tile:disabled { opacity: 0.4; cursor: default; }
#mobile-shell .touch-tile[hidden] { display: none; }
#mobile-shell .touch-tile__icon { width: 2.4rem; height: 2.4rem; object-fit: contain; pointer-events: none; }
#mobile-shell .touch-tile__label {
  max-width: 100%; font-size: 0.65rem; font-weight: 600; line-height: 1.1; text-align: center;
  color: var(--hud-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#mobile-shell .touch-tile__badge {
  position: absolute; top: -0.35rem; right: -0.3rem;
  min-width: 1.05rem; height: 1.05rem; padding: 0 0.25rem; box-sizing: border-box;
  border-radius: 9999px; border: 1px solid var(--hud-bg-2);
  background: var(--hud-danger); color: var(--hud-bg-2);
  font-size: 0.6rem; font-weight: 700; line-height: 0.95rem; text-align: center; font-variant-numeric: tabular-nums;
}
#mobile-shell .touch-menu__foot {
  flex: none; box-sizing: border-box;
  display: flex; align-items: center; gap: 0.75rem;
  min-height: 2.8rem; padding: 0.25rem 0.9rem;
  border-top: 1px solid var(--hud-frame);
  background: var(--hud-bg-2);
  font-size: 0.65rem; color: var(--hud-text-dim);
}
#mobile-shell .touch-menu__who { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mobile-shell .touch-menu__who strong { color: var(--hud-title); font-weight: 600; }
#mobile-shell .touch-menu__conn { flex: none; font-variant-numeric: tabular-nums; }
#mobile-shell .touch-menu__conn-label { color: var(--hud-text-dim); }
#mobile-shell .touch-menu__conn-label::after { content: ":"; }
#mobile-shell .touch-menu__signout { margin: 0; }
#mobile-shell .touch-menu__link {
  flex: none; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  min-height: 2.2rem; padding: 0 0.8rem;
  border: 1px solid var(--hud-frame); border-radius: 0.5rem;
  background: transparent; color: var(--hud-title);
  font-size: 0.7rem; font-weight: 600; text-decoration: none; white-space: nowrap;
  cursor: pointer; touch-action: manipulation;
}
#mobile-shell .touch-menu__link:active { border-color: var(--hud-frame-bright); filter: brightness(1.2); }

/* page host: server pages in #nav-frame, or the chat under its Chat / Friends sub-tabs */
#mobile-shell .touch-page__tabs:not(.hidden) {
  flex: none; display: flex; gap: 0.5rem; padding: 0 0.75rem;
  border-bottom: 1px solid var(--hud-frame); background: var(--hud-bg-2);
}
#mobile-shell .touch-page__body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#mobile-shell .touch-page__chat:not(.hidden) { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 0.5rem 0.75rem; }
#mobile-shell #mobile-chat-dock { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: flex-end; }
#mobile-shell .touch-page__frame:not(.hidden) {
  flex: 1 1 auto; min-height: 0; display: block; padding: 0.75rem;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
}

/* ---- in-frame HUD ----------------------------------------------------------------------
   The desktop HUD nodes ride inside #game-frame on the phone and are laid out here, from CSS
   only (the markup is shared with /play). Three columns:
     left    vitals card (11rem) > buff chips > party rows
     centre  war strip + Emperium bar > target frame > dungeon HUD > boss bar > announce lane >
             prompts   (one stack; each slot's top is the sum of the heights above it)
     right   round minimap, then the one-line quest tracker left of it. The strip LEFT of the
             minimap (7.2rem x 2.1rem, top edge) belongs to #touch-top-right (Chat / Bag / Menu).
   Rules:
   - Never set `display` on a node the game toggles with .hidden / .flex (unlayered beats the
     Tailwind utilities, which would pin it on screen). Layout inside those nodes is fine.
   - The stack is positioned by custom properties. A slot that is on screen contributes its
     height through a :has() rule; the --y-* values below are plain sums of those heights.
   - The base `.war-live` rules in application.css pin #target-bar / #emperium-bar /
     #dungeon-hud `top` with !important in @layer components, and cascade layers REVERSE for
     !important, so nothing here can win on `top` while a war is live. Those three nodes get
     `top` for the normal case and a margin-top that cancels the pinned value under .war-live. */
[data-hud="mobile"] #game-frame {
  --m-top: calc(0.5rem + env(safe-area-inset-top));
  --m-left: calc(0.5rem + env(safe-area-inset-left));
  --m-right: calc(0.5rem + env(safe-area-inset-right));
  --m-glass: color-mix(in srgb, var(--hud-bg-2) 74%, transparent);
  --m-glass-strong: color-mix(in srgb, var(--hud-bg-2) 88%, transparent);
  --m-glass-solid: color-mix(in srgb, var(--hud-bg) 96%, transparent); /* prompts: nameplates must not ghost through */
  /* the free centre column: viewport minus the left column (11.5rem) and the right strip (12.7rem) on both sides of the centre line,
     and kept clear of the joystick zone's right edge (36vw) below it */
  --m-mid-w: clamp(9.5rem, min(calc(100vw - 26rem - 2 * max(env(safe-area-inset-left), env(safe-area-inset-right))), calc(100vw - 2 * min(36vw, 18rem) - 0.6rem)), 13rem);
  /* bottom-centre lane between the joystick zone and the action cluster (cast bar, error line, field panel) */
  --m-lane-x: calc((min(36vw, 18rem) + 100% - 11.4rem - env(safe-area-inset-right)) / 2);
  --m-lane-w: min(14rem, calc(100% - min(36vw, 18rem) - 12.4rem - env(safe-area-inset-right)));

  /* heights of the stack slots that are on screen (0 otherwise; set by the :has() rules below) */
  --o-aim: 0rem; --o-war: 0rem; --o-emp: 0rem; --o-tgt: 0rem; --o-tcast: 0rem;
  --o-dun: 0rem; --o-boss: 0rem; --o-rel: 0rem; --o-woe: 0rem; --o-dbn: 0rem; --o-inv: 0rem;
  --o-rdy: 0rem; --o-trd: 0rem; --o-rly: 0rem;
  --y-war: calc(var(--m-top) + var(--o-aim));
  --y-emp: calc(var(--y-war) + var(--o-war));
  --y-tgt: calc(var(--y-emp) + var(--o-emp));
  --y-dun: calc(var(--y-tgt) + var(--o-tgt) + var(--o-tcast));
  --y-boss: calc(var(--y-dun) + var(--o-dun));
  --y-ann: calc(var(--y-boss) + var(--o-boss));
  --y-dbn: calc(var(--y-ann) + var(--o-rel) + var(--o-woe));
  --y-prm: calc(var(--y-dbn) + var(--o-dbn));
  --y-rdy: calc(var(--y-prm) + var(--o-inv));
  --y-trd: calc(var(--y-rdy) + var(--o-rdy));
  --y-rly: calc(var(--y-trd) + var(--o-trd));
  --y-lrt: calc(var(--y-rly) + var(--o-rly));

  /* left column: card height is fixed by the row heights below; extras add their own rows */
  --o-fac: 0rem; --o-san: 0rem; --o-car: 0rem; --o-buf: 0rem;
  --y-buf: calc(var(--m-top) + 3.45rem + var(--o-fac) + var(--o-san) + var(--o-car) + 0.25rem);
  --y-pty: calc(var(--y-buf) + var(--o-buf));
}
[data-hud="mobile"][data-touch-aim] #game-frame { --o-aim: 1.9rem; } /* the aim hint pill owns the top-centre */
[data-hud="mobile"] #game-frame.war-live { --o-war: 1.7rem; }
[data-hud="mobile"] #game-frame:has(#emperium-bar:not(.hidden)) { --o-emp: 0.65rem; }
[data-hud="mobile"] #game-frame:has(#target-bar:not(.hidden)) { --o-tgt: 2.5rem; }
[data-hud="mobile"] #game-frame:has(#target-cast:not(.hidden)) { --o-tcast: 1.15rem; }
[data-hud="mobile"] #game-frame:has(#dungeon-hud:not(.hidden)) { --o-dun: 3.6rem; }
[data-hud="mobile"] #game-frame:has(#boss-bar:not(.hidden)) { --o-boss: 1.9rem; }
[data-hud="mobile"] #game-frame:has(#relic-banner:not(.hidden)) { --o-rel: 2.3rem; }
[data-hud="mobile"] #game-frame:has(#woe-banner:not(.hidden)) { --o-woe: 2.3rem; }
[data-hud="mobile"] #game-frame:has(#dungeon-banner:not(.hidden)) { --o-dbn: 2.3rem; }
[data-hud="mobile"] #game-frame:has(#faction-row:not(.hidden)) { --o-fac: 1.35rem; }
[data-hud="mobile"] #game-frame:has(#sanctuary-badge:not(.hidden)) { --o-san: 1.3rem; }
[data-hud="mobile"] #game-frame:has(#relic-carry-badge:not(.hidden)) { --o-car: 1.3rem; }
[data-hud="mobile"] #game-frame:has(#buff-stack > div) { --o-buf: 1.55rem; }

/* ---- top-left: vitals card ------------------------------------------------------------- */
[data-hud="mobile"] #hud-top-left { top: var(--m-top); left: var(--m-left); gap: 0; }
[data-hud="mobile"] #vitals-card {
  box-sizing: border-box;
  width: 11rem;
  gap: 0.15rem;
  padding: 0.25rem 0.4rem;
  border-radius: 0.5rem;
  border-color: var(--hud-frame);
  background: var(--m-glass-strong); /* 88 %: world nameplates must not bleed through the header at 667px */
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
}
/* level badge + thin XP line; the clock, online / ping badges, XP text and the admin compass are gone */
[data-hud="mobile"] #vitals-card > div:has(#xp-bar) { height: 0.9rem; gap: 0.3rem; }
[data-hud="mobile"] #vitals-card > div:has(#xp-bar) > span:first-child {
  min-width: 0; height: 0.9rem; padding: 0 0.3rem;
  font-size: 0.6rem; line-height: 0.9rem; white-space: nowrap;
}
[data-hud="mobile"] #vitals-card #xp-bar { min-width: 0; }
[data-hud="mobile"] #vitals-card > div:has(#xp-bar) > div { height: 0.3rem; }
[data-hud="mobile"] #xp-text,
[data-hud="mobile"] #clock,
[data-hud="mobile"] #online-badge,
[data-hud="mobile"] #ping-badge,
[data-hud="mobile"] #vitals-card > div:has(#xp-bar) > button { display: none; }
/* HP / MP: label + bar, the numbers written over the right end of the bar */
[data-hud="mobile"] #vitals-card > div:has(#vit-hp),
[data-hud="mobile"] #vitals-card > div:has(#vit-mp) {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  align-items: center;
  gap: 0;
}
[data-hud="mobile"] #vitals-card > div:has(#vit-hp) { height: 0.95rem; }
[data-hud="mobile"] #vitals-card > div:has(#vit-mp) { height: 0.8rem; }
[data-hud="mobile"] #vitals-card > div:has(#vit-hp) > span:first-child,
[data-hud="mobile"] #vitals-card > div:has(#vit-mp) > span:first-child { width: auto; font-size: 0.6rem; line-height: 1; }
[data-hud="mobile"] #vitals-card > div:has(#vit-hp) > div,
[data-hud="mobile"] #vitals-card > div:has(#vit-mp) > div { grid-column: 2; grid-row: 1; width: auto; height: 100%; }
[data-hud="mobile"] #vit-hp-text,
[data-hud="mobile"] #vit-mp-text {
  grid-column: 2; grid-row: 1; justify-self: end;
  width: auto; padding-right: 0.3rem;
  font-size: 0.6rem; font-weight: 600; line-height: 1;
  color: var(--hud-text);
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.9);
  pointer-events: none;
}
/* faction chips, sanctuary and relic-carry badges: one short row each under the bars */
[data-hud="mobile"] #faction-row { height: 1.2rem; flex-wrap: nowrap; gap: 0.25rem; overflow: hidden; }
[data-hud="mobile"] #faction-row #faction-emblem { height: 0.95rem; width: auto; }
[data-hud="mobile"] #faction-row .hud-chip { gap: 0.1rem; padding: 0 0.2rem; font-size: 0.55rem; line-height: 0.95rem; white-space: nowrap; }
[data-hud="mobile"] #sanctuary-badge,
[data-hud="mobile"] #relic-carry-badge { box-sizing: border-box; height: 1.15rem; padding: 0 0.3rem; align-items: center; overflow: hidden; }
[data-hud="mobile"] #sanctuary-badge > span:last-child,
[data-hud="mobile"] #relic-carry-badge .block { display: none; } /* the long "what it means" lines live in the tooltip */
[data-hud="mobile"] #sanctuary-badge > span,
[data-hud="mobile"] #relic-carry-badge span span { font-size: 0.6rem; line-height: 1; white-space: nowrap; }
[data-hud="mobile"] #relic-carry-badge > span { display: block; min-width: 0; }
[data-hud="mobile"] #sanctuary-badge svg,
[data-hud="mobile"] #relic-carry-badge svg { width: 0.8rem; height: 0.8rem; margin: 0; }

/* buffs: a row of icon chips directly under the card (seconds and detail live in the status panel) */
[data-hud="mobile"] #buff-stack {
  top: var(--y-buf); left: var(--m-left);
  --tw-translate-y: 0px;
  width: 11rem; height: 1.4rem;
  flex-direction: row; flex-wrap: nowrap; gap: 0.2rem;
}
[data-hud="mobile"] #buff-stack > div {
  flex: 0 0 auto; box-sizing: border-box;
  width: 1.4rem; height: 1.4rem; padding: 0; gap: 0;
  justify-content: center;
  border-radius: 0.3rem;
  background: var(--m-glass);
  box-shadow: none;
}
[data-hud="mobile"] #buff-stack > div:nth-child(n+8) { display: none; }
[data-hud="mobile"] #buff-stack > div > img { width: 1.15rem; height: 1.15rem; }
[data-hud="mobile"] #buff-stack > div > div { display: none; }
[data-hud="mobile"] #buff-stack > div > span { font-size: 0.55rem; min-width: 0.85rem; height: 0.85rem; line-height: 0.85rem; }

/* party: slim rows (name, level, HP line), at most four. They stay clear of the joystick base
   by rounding the column down to whole rows; the column sits ABOVE the move zone (z 41) so a
   row is still tappable where the zone's top edge reaches it. */
[data-hud="mobile"] #dock-party { top: var(--y-pty); left: var(--m-left); z-index: 41; width: 11rem; }
[data-hud="mobile"] #party-frames {
  gap: 0.15rem;
  overflow: hidden;
  max-height: 5.05rem;
  max-height: clamp(0rem, calc(round(down, 100vh - 11.2rem - var(--y-pty) + 0.15rem, 1.3rem) - 0.15rem), 5.05rem);
}
[data-hud="mobile"] .party-frame {
  position: relative; flex: 0 0 auto; box-sizing: border-box;
  height: 1.15rem; padding: 0 0.4rem; gap: 0.3rem;
  border-radius: 0.35rem;
  background: var(--m-glass);
  box-shadow: none;
}
[data-hud="mobile"] .party-frame__portrait,
[data-hud="mobile"] .party-frame__bar--mp,
[data-hud="mobile"] .party-frame__rally,
[data-hud="mobile"] .party-frame__lvl { display: none; }
[data-hud="mobile"] .party-frame > .min-w-0 { align-self: stretch; display: flex; align-items: center; padding-bottom: 0.4rem; } /* the name rides above the HP line */
[data-hud="mobile"] .party-frame__line { flex: 1; min-width: 0; font-size: 0.65rem; line-height: 1; gap: 0.25rem; }
[data-hud="mobile"] .party-frame__tag { font-size: 0.55rem; }
[data-hud="mobile"] .party-frame__bar--hp {
  position: absolute; left: 0.3rem; right: 0.3rem; bottom: 0.08rem;
  height: 0.18rem; margin: 0;
}

/* ---- top-centre: war strip, target, dungeon, boss, announce lane ------------------------- */
[data-hud="mobile"] #war-timer {
  top: calc(var(--m-top) + var(--o-aim));
  box-sizing: border-box; width: var(--m-mid-w); height: 1.6rem;
  justify-content: space-between; gap: 0.4rem; padding: 0 0.5rem;
  border-radius: 0.4rem; background: var(--m-glass-strong);
}
[data-hud="mobile"] #war-timer span { font-size: 0.65rem; line-height: 1; white-space: nowrap; }
[data-hud="mobile"] #emperium-bar {
  top: var(--y-emp);
  width: var(--m-mid-w); height: 0.55rem;
}
[data-hud="mobile"] #game-frame.war-live #emperium-bar { margin-top: calc(var(--y-emp) - 6.25rem); }
[data-hud="mobile"] #target-bar {
  top: var(--y-tgt);
  box-sizing: border-box; width: var(--m-mid-w); min-height: 2.2rem;
  flex-wrap: wrap; align-content: center; column-gap: 0.4rem; row-gap: 0.2rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem; background: var(--m-glass-strong);
}
[data-hud="mobile"] #game-frame.war-live #target-bar { margin-top: calc(var(--y-tgt) - 2.75rem); }
/* row 1: the name (full width, so "Name Lvl 14" survives the narrow column); row 2: HP line + the numbers */
[data-hud="mobile"] #target-name { flex: 1 1 100%; min-width: 0; max-width: none; font-size: 0.7rem; line-height: 1.1; }
[data-hud="mobile"] #target-bar > div:has(#target-hp) { order: 2; flex: 1 1 0; min-width: 0; width: auto; height: 0.5rem; }
[data-hud="mobile"] #target-hp-text { order: 3; flex: none; font-size: 0.6rem; line-height: 0.9rem; color: var(--hud-text-dim); }
[data-hud="mobile"] .hud-castbar--target { height: 1rem; }
[data-hud="mobile"] .hud-castbar--target .hud-castbar__label { font-size: 0.65rem; }

[data-hud="mobile"] #dungeon-hud {
  top: var(--y-dun);
  box-sizing: border-box; width: var(--m-mid-w);
}
[data-hud="mobile"] #game-frame.war-live #dungeon-hud { margin-top: calc(var(--y-dun) - 6rem); }
[data-hud="mobile"] #dungeon-hud:not(.hidden) {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 0.4rem; row-gap: 0.2rem; align-items: center;
  padding: 0.25rem 0.5rem 0.25rem;
  border-radius: 0.5rem; background: var(--m-glass-strong);
}
/* row 1: progress text + run timer; row 2: the progress line, the Leave button at its right */
[data-hud="mobile"] #dungeon-hud > div:nth-child(1) { grid-column: 1 / -1; grid-row: 1; font-size: 0.62rem; line-height: 1; gap: 0.3rem; white-space: nowrap; }
[data-hud="mobile"] #dungeon-progress-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
[data-hud="mobile"] #dungeon-hud > div:nth-child(2) { grid-column: 1; grid-row: 2; height: 0.4rem; }
[data-hud="mobile"] #dungeon-leave {
  grid-column: 2; grid-row: 2; margin: 0;
  box-sizing: border-box; width: 3.7rem; min-height: 2.3rem; padding: 0 0.25rem;
  font-size: 0.65rem; line-height: 1.05; text-align: center; /* "Leave dungeon" wraps onto two lines */
}
[data-hud="mobile"] #boss-bar {
  top: var(--y-boss); left: calc(50% - var(--m-mid-w) / 2);
  box-sizing: border-box; width: var(--m-mid-w); gap: 0.2rem;
  padding: 0.2rem 0.5rem; border-radius: 0.5rem; background: var(--m-glass-strong);
}
[data-hud="mobile"] #boss-bar > div:first-child { font-size: 0.65rem; line-height: 1.1; gap: 0.3rem; }
[data-hud="mobile"] #boss-bar svg { width: 0.75rem; height: 0.75rem; }
[data-hud="mobile"] #boss-enrage { flex: none; font-size: 0.55rem; letter-spacing: 0; }
[data-hud="mobile"] #boss-bar > div:last-child { height: 0.5rem; }

[data-hud="mobile"] #announce-lane { top: var(--y-ann); width: var(--m-mid-w); gap: 0.3rem; }
[data-hud="mobile"] #relic-banner,
[data-hud="mobile"] #woe-banner {
  box-sizing: border-box; width: 100%; max-height: 2rem; overflow: hidden;
  padding: 0.2rem 0.5rem; border-radius: 0.4rem;
  font-size: 0.65rem; line-height: 1.15;
}
[data-hud="mobile"] #dungeon-banner {
  top: var(--y-dbn); box-sizing: border-box; width: var(--m-mid-w); max-height: 2rem; overflow: hidden;
  padding: 0.2rem 0.5rem; border-radius: 0.4rem; font-size: 0.65rem; line-height: 1.15;
}

/* ---- prompts: compact cards under the stack, centred, never near the bottom zones --------
   party invite / LFG ready (JS-built .party-invite-dialog, inside the aria-live wrapper),
   ready check, trade invite, rally prompt, loot roll. Fixed heights so they can stack. */
[data-hud="mobile"] #game-frame:has([data-controller="party-invite"] .party-invite-dialog) { --o-inv: 6.1rem; }
[data-hud="mobile"] #game-frame:has([data-controller="lfg-ready"] .party-invite-dialog) { --o-inv: 6.1rem; }
[data-hud="mobile"] #game-frame:has([data-controller="party-invite"] .party-invite-dialog):has([data-controller="lfg-ready"] .party-invite-dialog) { --o-inv: 12.2rem; }
[data-hud="mobile"] #game-frame:has(#ready-check:not(.hidden)) { --o-rdy: 6.1rem; }
[data-hud="mobile"] #game-frame:has(#trade-invite:not(.hidden)) { --o-trd: 4.6rem; }
[data-hud="mobile"] #game-frame:has(#rally-prompt:not(.hidden)) { --o-rly: 5.6rem; }
[data-hud="mobile"] #game-frame > div[aria-live="assertive"] { top: var(--y-prm); width: var(--m-mid-w); gap: 0.3rem; }
[data-hud="mobile"] .party-invite-dialog,
[data-hud="mobile"] #ready-check,
[data-hud="mobile"] #trade-invite,
[data-hud="mobile"] #rally-prompt,
[data-hud="mobile"] #loot-roll {
  box-sizing: border-box; width: var(--m-mid-w);
  padding: 0.35rem 0.5rem;
  border-radius: 0.5rem;
  background: var(--m-glass-solid);
  overflow: hidden;
}
[data-hud="mobile"] .party-invite-dialog { height: 5.8rem; }
[data-hud="mobile"] #ready-check { top: var(--y-rdy); height: 5.8rem; }
[data-hud="mobile"] #trade-invite { top: var(--y-trd); height: 4.3rem; }
[data-hud="mobile"] #rally-prompt { top: var(--y-rly); height: 5.3rem; }
[data-hud="mobile"] #loot-roll { top: var(--y-lrt); left: calc(50% - var(--m-mid-w) / 2); right: auto; height: 6.1rem; font-size: 0.65rem; }
[data-hud="mobile"] .party-invite-dialog p,
[data-hud="mobile"] #ready-check p,
[data-hud="mobile"] #trade-invite p,
[data-hud="mobile"] #rally-prompt p { margin-bottom: 0.15rem; font-size: 0.7rem; line-height: 1.15; }
[data-hud="mobile"] .party-invite-dialog p.text-xs,
[data-hud="mobile"] #ready-check-count,
[data-hud="mobile"] #rally-prompt p.text-xs,
[data-hud="mobile"] #loot-roll-timer { font-size: 0.65rem; }
[data-hud="mobile"] #ready-check-members { display: none; }
[data-hud="mobile"] .party-invite-dialog .party-invite-dialog__track,
[data-hud="mobile"] #ready-check .hud-countdown,
[data-hud="mobile"] #loot-roll .hud-countdown { margin: 0.2rem 0 0.35rem; }
[data-hud="mobile"] .party-invite-dialog .hud-btn,
[data-hud="mobile"] #ready-check .hud-btn,
[data-hud="mobile"] #trade-invite .hud-btn,
[data-hud="mobile"] #rally-prompt .hud-btn,
[data-hud="mobile"] #loot-roll .hud-btn { min-height: 2.4rem; padding: 0 0.3rem; font-size: 0.72rem; white-space: nowrap; }
[data-hud="mobile"] #trade-invite > div,
[data-hud="mobile"] #loot-roll > div:last-child { gap: 0.4rem; }
[data-hud="mobile"] #loot-roll > div:first-child { margin-bottom: 0.15rem; }
[data-hud="mobile"] #loot-roll .hud-slot { --hud-slot-size: 1.8rem; }
[data-hud="mobile"] #loot-roll .hud-slot img { max-width: 100%; max-height: 100%; }
[data-hud="mobile"] #loot-roll #loot-roll-name { font-size: 0.7rem; }
[data-hud="mobile"] #loot-roll .hud-btn { flex: 1; }

/* a soul: the countdown owns the middle of the screen */
[data-hud="mobile"] #soul-countdown {
  top: 50%; --tw-translate-y: -50%;
  box-sizing: border-box; max-width: var(--m-mid-w); padding: 0.4rem 0.9rem; border-radius: 0.5rem;
  font-size: 0.8rem; line-height: 1.2; white-space: normal;
  background: var(--m-glass-strong);
}

/* ---- top-right: round minimap + one-line quest tracker -------------------------------- */
[data-hud="mobile"] #minimap { top: var(--m-top); right: var(--m-right); width: 4.2rem; height: 4.2rem; }
[data-hud="mobile"] #minimap-canvas {
  display: block !important; /* a "minimized" flag set on desktop (shared localStorage) must not blank the phone's map */
  box-sizing: border-box; width: 100%; height: 100%;
  border-radius: 9999px; border: 2px solid var(--hud-frame);
}
[data-hud="mobile"][data-touch-aim] #minimap { visibility: hidden; } /* the Cancel circle takes its place while aiming */
[data-hud="mobile"] #minimap > button { display: none !important; } /* minimize / restore: the map is always up */
[data-hud="mobile"] #minimap > div[style] { /* map level band chip, hung under the circle (inline-styled by the minimap) */
  position: absolute !important; left: 50% !important; right: auto !important; top: calc(100% + 0.1rem) !important; bottom: auto !important;
  transform: translateX(-50%);
  padding: 0 0.35rem !important; border-radius: 9999px !important;
  font-size: 0.6rem !important; line-height: 0.9rem !important; white-space: nowrap;
}
[data-hud="mobile"] #community-leave {
  top: calc(var(--m-top) + 4.5rem); right: calc(var(--m-right) + 4.6rem); /* left of the minimap, under the tracker */
  min-height: 2rem; padding: 0 0.6rem; font-size: 0.65rem;
}
/* one line: the first tracked quest, its title and its first objective's count (tap the title for the journal) */
[data-hud="mobile"] #quest-tracker {
  top: calc(var(--m-top) + 2.4rem); right: calc(var(--m-right) + 4.6rem);
  width: min(9.5rem, calc(50vw - 5.4rem - env(safe-area-inset-right) - var(--m-mid-w) / 2));
  gap: 0;
}
[data-hud="mobile"] #quest-tracker > :nth-child(n+2) { display: none; } /* the other tracked quests and "+N more" */
[data-hud="mobile"] #quest-tracker .quest-tracker__card {
  display: flex; align-items: center; gap: 0.3rem;
  box-sizing: border-box; height: 2rem; padding: 0 0.5rem;
  border-radius: 0.4rem; background: var(--m-glass);
  box-shadow: none;
}
[data-hud="mobile"] #quest-tracker .quest-tracker__head { flex: 1; min-width: 0; margin: 0; }
[data-hud="mobile"] #quest-tracker .quest-tracker__compass,
[data-hud="mobile"] #quest-tracker .quest-tracker__x,
[data-hud="mobile"] #quest-tracker .quest-tracker__objtext,
[data-hud="mobile"] #quest-tracker .quest-tracker__return,
[data-hud="mobile"] #quest-tracker .quest-tracker__line:not(:first-child) { display: none; }
[data-hud="mobile"] #quest-tracker .quest-tracker__title {
  display: block; width: 100%; min-height: 2rem;
  font-size: 0.65rem; line-height: 2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
[data-hud="mobile"] #quest-tracker .quest-tracker__body { flex: none; }
[data-hud="mobile"] #quest-tracker .quest-tracker__line { display: block; }
[data-hud="mobile"] #quest-tracker .quest-tracker__count { font-size: 0.65rem; }

/* ---- bottom-centre: self cast bar and the error line, in the lane between the thumbs --------
   (above the potion buttons, below the AUTO pill; the farm field panel pushes both up) */
[data-hud="mobile"] .hud-castbar--self {
  left: var(--m-lane-x); bottom: calc(4.4rem + env(safe-area-inset-bottom));
  width: var(--m-lane-w);
}
[data-hud="mobile"] #error-line {
  top: auto; left: var(--m-lane-x);
  bottom: calc(5.85rem + env(safe-area-inset-bottom));
  max-width: var(--m-lane-w);
}
[data-hud="mobile"] .error-line__pill { padding: 0.2rem 0.6rem; font-size: 0.7rem; white-space: normal; text-align: center; }
html:has(#mobile-shell):has(.field-panel--mobile:not(.hidden)) [data-hud="mobile"] .hud-castbar--self { bottom: calc(11.4rem + env(safe-area-inset-bottom)); }
html:has(#mobile-shell):has(.field-panel--mobile:not(.hidden)) [data-hud="mobile"] #error-line { bottom: calc(12.85rem + env(safe-area-inset-bottom)); }

/* ---- carried over from application.css (unchanged) -------------------------------------
   Sizes are rem-based on purpose: the mobile layout sets an 18px root so the whole kit (and
   every sheet page) scales up together. */
#mobile-shell .mobile-joystick {
  /* absolute (not relative): this rule loads after Tailwind's utilities, so a
     .absolute class on the element would lose the cascade — position lives here. */
  position: absolute;
  left: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  width: 12rem; height: 12rem;
  border-radius: 9999px;
  border: 2px solid color-mix(in srgb, var(--hud-frame) 70%, transparent);
  /* Flat fill, no backdrop-filter (C8): a blur over the live canvas re-samples the whole
     WebGL layer under it every frame on a phone GPU. A touch more tint stands in for it. */
  background: color-mix(in srgb, var(--hud-bg) 38%, transparent);
}
#mobile-shell .mobile-joystick__nub {
  position: absolute; inset: 0; margin: auto;
  width: 4.25rem; height: 4.25rem;
  border-radius: 9999px;
  border: 1px solid var(--hud-frame);
  background: color-mix(in srgb, var(--hud-bg-2) 70%, transparent);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.5);
  will-change: transform; /* moved at pointer rate by TouchJoystick */
}
/* Short (landscape phone) screens: smaller joystick. */
@media (max-height: 520px) {
  #mobile-shell .mobile-joystick { width: 10rem; height: 10rem; }
  #mobile-shell .mobile-joystick__nub { width: 3.5rem; height: 3.5rem; }
}
/* Narrow (portrait phone) screens: smaller joystick. */
@media (max-width: 480px) {
  #mobile-shell .mobile-joystick { width: 9rem; height: 9rem; }
  #mobile-shell .mobile-joystick__nub { width: 3.25rem; height: 3.25rem; }
}
/* The Chat / Friends sub-tabs of the chat page. */
#mobile-shell .mobile-subtab {
  min-height: 2.4rem; padding: 0 0.9rem;
  font-size: 0.8rem; font-weight: 600;
  color: var(--hud-text-dim); cursor: pointer; touch-action: manipulation;
  border-bottom: 2px solid transparent;
}
#mobile-shell .mobile-subtab[aria-selected="true"] {
  color: var(--hud-title);
  border-bottom-color: var(--hud-title);
}

/* Edge-to-edge canvas — no card chrome around the world on mobile. */
[data-hud="mobile"] #game-root { border-radius: 0; border: none; }

/* Mobile sheet readability: the smallest guild rows get an extra step up
   (flagged in device testing — the XP line was the hardest to read). */
[data-hud="mobile"] .guild-card__xp-head { font-size: 0.75rem; }
[data-hud="mobile"] .guild-card__section-title { font-size: 0.72rem; }
[data-hud="mobile"] .guild-roster__head,
[data-hud="mobile"] .guild-roster__class { font-size: 0.65rem; }

/* Farm field panel (shown inside a house when standing on a field), mobile. Body-mounted, so it
   carries its own marker class and the html:has(#mobile-shell) prefix. It sits bottom-centre in
   the lane between the joystick zone and the action cluster, above the potion buttons, and
   raises the cast bar / error line out of its way while it is up (see the in-frame HUD block). */
html:has(#mobile-shell) .field-panel--mobile {
  /* The -translate-x-1/2 utility keeps centring it on `left`; only the anchor moves. */
  left: calc((min(36vw, 18rem) + 100% - 11.4rem - env(safe-area-inset-right)) / 2);
  right: auto;
  bottom: calc(4.4rem + env(safe-area-inset-bottom));
  width: min(calc(100vw - min(36vw, 18rem) - 12.4rem - env(safe-area-inset-right)), 20rem);
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border-radius: 0.5rem;
  background: color-mix(in srgb, var(--hud-bg) 92%, transparent);
}
html:has(#mobile-shell) .field-panel--mobile > div:first-child { margin-bottom: 0.25rem; }
html:has(#mobile-shell) .field-panel--mobile > div:first-child span:first-child { font-size: 0.7rem; }
html:has(#mobile-shell) .field-panel--mobile #field-panel-status { font-size: 0.7rem; margin-bottom: 0.25rem; }
html:has(#mobile-shell) .field-panel--mobile #field-panel-actions { gap: 0.4rem; }
html:has(#mobile-shell) .field-panel--mobile #field-panel-actions .hud-btn {
  min-height: 2.4rem; padding: 0.4rem 0.7rem; font-size: 0.75rem;
}
html:has(#mobile-shell) .field-panel--mobile #field-panel-close {
  min-width: 2rem; min-height: 2rem; font-size: 1.25rem; padding: 0;
}
/* Mobile seed picker: chips replace the native select (its popup can overflow
   the viewport in webviews); the hidden select stays the value carrier. */
html:has(#mobile-shell) .field-panel--mobile #field-panel-seed { display: none; }

/* Mobile chat sheet: the docked #chat fills the sheet and its log grows
   (desktop's h-20 floor + layoutStage growth don't apply here). Channel tabs
   (General/Party/Guild/+/DM ✕) are JS-built with desktop-scale classes —
   resize them here to touch targets. */
[data-hud="mobile"] #chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
[data-hud="mobile"] #chat-log { height: auto; flex: 1 1 0; font-size: 0.85rem; }
[data-hud="mobile"] #chat-tabs { gap: 0.375rem; padding: 0.25rem 0.25rem 0.375rem; }
[data-hud="mobile"] #chat-tabs .chat-tab { font-size: 0.9rem; padding: 0.4rem 0.9rem; }
[data-hud="mobile"] #chat-tabs > button:not(.chat-tab) { font-size: 1.1rem; padding: 0.3rem 0.7rem; } /* the "+" */

/* ---- panel contents, phone-sized ----------------------------------------------------------------
   The item card, the NPC dialogue card, the full-screen game dialogs and the small dialogs built in JS. The rules for
   a window that toggles `.hidden` set display only under :not(.hidden), never on the bare node. */

/* a game modal is up: the action cluster, potions, Auto and the chat peek step aside (the dialogue card needs the room) */
#mobile-shell[data-touch-modal]:not([data-touch-modal=""]) :is(#touch-cluster, #touch-potion-hp, #touch-potion-mp, #touch-auto, #touch-bottom-center) { display: none; }

/* ---- item card: docked at the bottom of the open side panel (game_controller#showItemCard) ---- */
#mobile-shell #touch-item-card { display: none; }
#mobile-shell #touch-item-card:not([hidden]) {
  position: fixed; right: 0; bottom: 0; z-index: 45;
  box-sizing: border-box; width: calc(var(--t-panel-w) - var(--t-rail-w)); max-height: 52%;
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.45rem calc(0.7rem + env(safe-area-inset-right)) calc(0.45rem + env(safe-area-inset-bottom)) 0.7rem;
  background: var(--hud-bg-2);
  border-top: 1px solid var(--hud-frame-bright);
  box-shadow: 0 -0.5rem 1rem rgb(0 0 0 / 0.55);
  touch-action: pan-y;
}
/* the panel's scroll area ends above the card (the card's height is measured into --t-card-h) */
#mobile-shell[data-touch-card] :is(#ov-win-inventory-body, #ov-win-equipment-body) {
  margin-bottom: calc(var(--t-card-h, 0px) - env(safe-area-inset-bottom));
}
#mobile-shell .touch-card__x {
  position: absolute; top: 0; right: calc(0.1rem + env(safe-area-inset-right));
  width: 2.4rem; height: 2.4rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--hud-text-dim); cursor: pointer; touch-action: manipulation;
}
#mobile-shell .touch-card__x:active { color: var(--hud-title); }
#mobile-shell .touch-card__x-glyph { width: 1.1rem; height: 1.1rem; }
/* The card is capped at about half the screen: the name row (sticky) and the action buttons stay put, and the stat block
   between them scrolls, snapping to whole rows so none is left cut in half. */
#mobile-shell .touch-card__info {
  flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  scroll-snap-type: y proximity; scroll-padding-top: 2.6rem;
}
#mobile-shell .touch-card__info .item-tip > * { scroll-snap-align: start; }
#mobile-shell .touch-card__info .item-tip__head { position: sticky; top: 0; z-index: 1; background: var(--hud-bg-2); padding-bottom: 0.2rem; }
/* the shared card shell, flattened: the panel is the frame */
#mobile-shell .touch-card__info .item-tip {
  min-width: 0; max-width: none; padding: 0;
  background: none; border: 0; box-shadow: none;
  font-size: 0.7rem; line-height: 1.35;
}
#mobile-shell .touch-card__info .item-tip__head { padding-right: 2.2rem; gap: 0.6rem; }
#mobile-shell .touch-card__info .item-tip__icon .hud-slot { --hud-slot-size: 2.1rem; }
#mobile-shell .touch-card__info .item-tip__name { font-size: 0.9rem; line-height: 1.2; }
#mobile-shell .touch-card__info .item-tip__type { margin-top: 0; font-size: 0.68rem; }
#mobile-shell .touch-card__info .item-tip__rule { margin: 0.25rem 0; }
#mobile-shell .touch-card__actions { flex: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
#mobile-shell .touch-card__actions .hud-btn:last-child:nth-child(odd) { grid-column: 1 / -1; }
#mobile-shell .touch-card__actions .hud-btn {
  min-height: 2.7rem; padding: 0 0.6rem;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
  touch-action: manipulation;
}

/* Short screens (a landscape phone is 375-390px tall): the bag's kind tabs stay on ONE line (they scroll sideways when they
   do not fit), and while an item card is up the bag hides what the player is not using - the capacity / expand / sort row and
   the search field - so at least two whole bag rows stay above the card. Closing the card (data-touch-card goes) brings
   them back. */
@media (max-height: 400px) {
  #mobile-shell #ov-win-inventory-body #bag-kind-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; gap: 0.25rem; margin-bottom: 0.25rem; scrollbar-width: none; }
  #mobile-shell #ov-win-inventory-body #bag-kind-tabs .bag-tab { flex: 0 0 auto; white-space: nowrap; }
  #mobile-shell[data-touch-card] #ov-win-inventory-body :is(div:has(> #bag-search), div:has(> .ov-dup-title)) { display: none; }
  /* the card itself, a little tighter, so a plain consumable's name, type and price all fit without a row cut at the edge */
  #mobile-shell #touch-item-card:not([hidden]) { gap: 0.2rem; padding-top: 0.3rem; padding-bottom: calc(0.3rem + env(safe-area-inset-bottom)); }
  #mobile-shell .touch-card__actions { gap: 0.4rem; }
  #mobile-shell .touch-card__info .item-tip__icon .hud-slot { --hud-slot-size: 1.9rem; }
  #mobile-shell .touch-card__info .item-tip__head { padding-bottom: 0.1rem; }
  #mobile-shell .touch-card__info .item-tip__rule { margin: 0.05rem 0; }
  #mobile-shell .touch-card__info { scroll-padding-top: 2.4rem; }
}

/* ---- NPC dialogue: a card along the bottom, clear of the joystick ------------------------------------------------
   Portrait left, the NPC's words right, then the choices, quest and shop sections full width. The card scrolls as one
   surface (the shop lists do not scroll on their own inside it). The action cluster and potions are hidden while it is
   up (data-touch-modal above), so the card has the bottom of the screen. */
#mobile-shell #dialogue:not(.hidden) {
  position: fixed;
  top: auto !important; bottom: calc(0.5rem + env(safe-area-inset-bottom)) !important;
  left: auto !important; right: calc(0.5rem + env(safe-area-inset-right)) !important; margin: 0;
  z-index: 47 !important;
  display: flex; flex-direction: column;
  /* 70 % wide, but never over the move zone: the thumb stays free to walk away (which closes the dialogue) */
  box-sizing: border-box; max-width: none; max-height: 62%;
  width: min(70vw, 38rem, calc(100vw - min(36vw, 18rem) - 1rem - env(safe-area-inset-left) - env(safe-area-inset-right)));
  transform: none !important; opacity: 1 !important; transition: none !important; /* game_window's open animation */
  touch-action: pan-y;
}
#mobile-shell #dialogue .game-window-titlebar { min-height: 2.4rem; }
#mobile-shell #dialogue .game-window-x { width: 2.4rem; height: 2.4rem; }
#mobile-shell #dialogue .game-window-body { padding: 0.4rem 0.75rem 0.6rem; }
#mobile-shell #dialogue .dlg-body { display: grid; grid-template-columns: 3.6rem minmax(0, 1fr); column-gap: 0.75rem; align-items: start; padding: 0; }
#mobile-shell #dialogue .dlg-body:has(#dlg-portrait.hidden) { grid-template-columns: minmax(0, 1fr); }
#mobile-shell #dialogue .dlg-header { display: contents; }
#mobile-shell #dialogue .dlg-portrait { grid-column: 1; grid-row: 1 / span 2; width: 3.4rem; height: 3.4rem; }
#mobile-shell #dialogue .dlg-portrait__sprite { width: 2.7rem; height: 2.7rem; }
#mobile-shell #dialogue .dlg-role { grid-column: 2; grid-row: 1; margin: 0; padding: 0 0 0.1rem; }
#mobile-shell #dialogue .dlg-text { grid-column: 2; grid-row: 2; padding: 0 0 0.5rem; font-size: 0.8rem; line-height: 1.4; }
#mobile-shell #dialogue .dlg-body:has(#dlg-portrait.hidden) :is(.dlg-role, .dlg-text) { grid-column: 1; }
#mobile-shell #dialogue .dlg-section { grid-column: 1 / -1; padding: 0.5rem 0; }
#mobile-shell #dialogue #dlg-shop { gap: 0.75rem; }
#mobile-shell #dialogue :is(#dlg-buy, #dlg-sell) { max-height: none; overflow: visible; }
/* choices, quest rows and the shop's buy / sell controls: finger-sized, full width */
#mobile-shell #dialogue .dlg-choice { min-height: 2.7rem; padding: 0 0.8rem; font-size: 0.8rem; justify-content: flex-start; text-align: left; }
#mobile-shell #dialogue :is(#dlg-quest, #dlg-refine, #dlg-jeweler, #dlg-station, #dlg-travel) .hud-btn { min-height: 2.7rem; font-size: 0.8rem; }
#mobile-shell #dialogue .quest-board__row { min-height: 2.7rem; }
#mobile-shell #dialogue :is(#dlg-buy, #dlg-sell) .hud-btn { min-height: 2.7rem; }
/* a non-stackable item is one plain button row (no x1/x10 steppers): the row itself is the action */
#mobile-shell #dialogue :is(#dlg-buy, #dlg-sell) > button { min-height: 2.7rem; }
#mobile-shell #dialogue :is(#dlg-buy, #dlg-sell) .hud-btn span:first-child { font-size: 0.8rem; }
#mobile-shell #dialogue :is(#dlg-buy, #dlg-sell) .hud-btn span:last-child:not(:first-child) { font-size: 0.65rem; }

/* ---- game dialogs that take the screen: Settings, the hotbar editor and the three pickers --------------
   Full-screen (safe-area padded) with a flat header and one scrolling body. The small confirm dialogs keep their
   centred card. The backdrop is flex + p-4 from its utilities; only its padding changes. */
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal):not(.hidden) {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--hud-bg);
}
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window {
  display: flex; flex-direction: column;
  box-sizing: border-box; width: 100%; max-width: none; height: 100%; max-height: none;
  border: 0; border-radius: 0; box-shadow: none;
}
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .game-window-foot { flex: none; }
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window > .hud-tabs { flex: none; overflow-x: auto; touch-action: pan-x; }
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .hud-tab { min-height: 2.4rem; }
#mobile-shell :is(#settings-modal, #hotbar-editor, #dungeon-modal, #castle-modal, #relic-modal) > .game-window .hud-btn { min-height: 2.7rem; }

/* castle picker: the Castle War logo is an inline 8rem tall image (game_controller#openCastlePicker); capped on the phone so at
   least two castle rows show on a 375px screen */
#mobile-shell #castle-list > img { height: 4.5rem !important; }

/* ---- hotbar editor: two labelled sets of four, the palettes beside them ---------------------------------
   Slots 1-4 are Set 1 and 5-8 Set 2, matching the Swap button. The editor's JS draws eight cells in one row; the
   grid below folds them into two rows, each under its label (data-set-label-one / -two on the slots node, read by
   attr() on the node's own pseudo-elements). Tap a slot then a palette entry, or the other way round. */
#mobile-shell #hotbar-editor .game-window-body > .flex-col {
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "slots spells" "trash spells" "trash items";
  column-gap: 1.25rem; row-gap: 0.3rem; align-items: start;
}
#mobile-shell #hotbar-editor [data-hb="slots"] {
  grid-area: slots;
  display: grid; grid-template-columns: repeat(4, 2.7rem); gap: 0.5rem; row-gap: 0.4rem; justify-content: start;
}
#mobile-shell #hotbar-editor [data-hb="slots"]::before,
#mobile-shell #hotbar-editor [data-hb="slots"]::after {
  grid-column: 1 / -1;
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--hud-text-dim);
}
#mobile-shell #hotbar-editor [data-hb="slots"]::before { content: attr(data-set-label-one); grid-row: 1; }
#mobile-shell #hotbar-editor [data-hb="slots"]::after { content: attr(data-set-label-two); grid-row: 3; margin-top: 0.3rem; }
#mobile-shell #hotbar-editor [data-hb="slots"] > :nth-child(-n+4) { grid-row: 2; }
#mobile-shell #hotbar-editor [data-hb="slots"] > :nth-child(n+5) { grid-row: 4; }
#mobile-shell #hotbar-editor [data-hb="slots"] > div { width: 2.7rem; height: 2.7rem; touch-action: manipulation; }
#mobile-shell #hotbar-editor [data-hb="slots"] > div > span { font-size: 0.6rem; } /* the key label */
#mobile-shell #hotbar-editor [data-hb="trash"] { grid-area: trash; align-self: start; display: flex; align-items: center; justify-content: center; min-height: 2.6rem; padding: 0 0.6rem; font-size: 0.7rem; }
#mobile-shell #hotbar-editor .game-window-body > .flex-col > div:nth-child(3) { grid-area: spells; }
#mobile-shell #hotbar-editor .game-window-body > .flex-col > div:nth-child(4) { grid-area: items; }
#mobile-shell #hotbar-editor :is([data-hb="spells"], [data-hb="items"]) { gap: 0.35rem; }
#mobile-shell #hotbar-editor :is([data-hb="spells"], [data-hb="items"]) > div { width: 2.7rem; height: 2.7rem; touch-action: manipulation; }
/* the slot waiting for an entry, and the entry waiting for a slot */
#mobile-shell #hotbar-editor [data-armed],
#mobile-shell #hotbar-editor [data-picked] { border-color: var(--hud-title); box-shadow: 0 0 0 2px var(--hud-title); }

/* ---- world map: the whole screen, one finger pans ------------------------------------------------------ */
#mobile-shell #minimap-overlay:not(.hidden) {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--hud-bg);
}
#mobile-shell #minimap-overlay > .game-window {
  box-sizing: border-box; width: 100%; height: 100%; max-width: none !important; max-height: none !important;
  border: 0; border-radius: 0; box-shadow: none;
}
#mobile-shell #minimap-overlay .game-window-body { flex: 1 1 auto; min-height: 0; max-height: none; padding: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
#mobile-shell #minimap-overlay .game-window-titlebar {
  position: relative; flex: none; box-sizing: border-box;
  display: flex; align-items: center; justify-content: flex-start;
  min-height: 2.8rem; padding: 0 3rem 0 0.75rem;
  border-radius: 0; border-bottom: 1px solid var(--hud-frame);
}
#mobile-shell #minimap-overlay .game-window-plate { position: static; transform: none; padding: 0; max-width: none; background: none; border: 0; box-shadow: none; }
#mobile-shell #minimap-overlay .game-window-title { font-size: 0.8rem; letter-spacing: 0.12em; }
#mobile-shell #minimap-overlay .game-window-x {
  position: absolute; top: 0; right: 0; transform: none;
  width: 2.8rem; height: 2.8rem; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; line-height: 1; touch-action: manipulation;
}

#mobile-shell #minimap-overlay .minimap-loading { margin: 0; font-size: 0.85rem; color: var(--hud-text-dim); }

/* ---- the small dialogs built in JS (destroy confirm, split / quantity, typed confirm) -----------------
   Appended to <body> above everything (z 96), so they sit over the side panel and the item card. Centred, buttons
   and inputs finger-sized, inputs at 16px+ so iOS does not zoom the page. A dialog with a text field sits at the
   top instead of the middle: the on-screen keyboard takes the lower half of a landscape phone. */
html:has(#mobile-shell) [data-qty-modal] { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); touch-action: manipulation; }
html:has(#mobile-shell) [data-qty-modal]:has(input) { align-items: flex-start; padding-top: calc(0.75rem + env(safe-area-inset-top)); }
html:has(#mobile-shell) [data-qty-modal] .hud-dialog {
  box-sizing: border-box; width: min(20rem, calc(100vw - 2rem)); max-height: calc(100vh - 1.5rem); overflow-y: auto;
  padding: 0.8rem 1rem; font-size: 0.85rem;
}
html:has(#mobile-shell) [data-qty-modal] .hud-dialog :is(p, label) { font-size: 0.85rem; }
html:has(#mobile-shell) [data-qty-modal] .hud-btn { min-height: 2.7rem; padding: 0 1.1rem; font-size: 0.85rem; }
html:has(#mobile-shell) [data-qty-modal] input[type="number"],
html:has(#mobile-shell) [data-qty-modal] input[type="text"] { box-sizing: border-box; min-height: 2.7rem; padding: 0 0.6rem; font-size: 1rem; }
html:has(#mobile-shell) [data-qty-modal] input[type="number"] { width: 4.5rem; }
html:has(#mobile-shell) [data-qty-modal] input[type="range"] { height: 0.5rem; margin: 0.7rem 0; touch-action: pan-x; }
html:has(#mobile-shell) [data-qty-modal] input[type="range"]::-webkit-slider-thumb { width: 1.7rem; height: 1.7rem; }

/* ---- bag, stats and quest panels: finger-sized controls ---------------------------------------------- */
#mobile-shell #hud-inventory { --hud-slot-size: 2.55rem; }
#mobile-shell #ov-win-inventory-body :is(input[type="search"], input[type="text"]) { min-height: 2.2rem; font-size: 0.9rem; }
#mobile-shell #ov-win-inventory-body :is(.hud-tab, [role="tab"]) { min-height: 2.2rem; padding: 0 0.55rem; font-size: 0.75rem; }
#mobile-shell #stats-window :is([id^="alloc-plus-"], [id^="alloc-minus-"]) { width: 2rem; height: 2rem; padding: 0; font-size: 1.1rem; }
#mobile-shell #stats-window :is([id^="alloc-plus-"], [id^="alloc-minus-"]) { touch-action: none; }
#mobile-shell :is(#ov-win-quests-body, #quest-journal) .hud-btn { min-height: 2.2rem; padding: 0 0.7rem; font-size: 0.75rem; }
#mobile-shell #ov-win-quests-body [data-action*="openJournal"] { min-height: 2.2rem; }

/* the journal: a narrower list beside the detail, each pane scrolling on its own inside the side panel */
#mobile-shell #quest-journal .game-window-body { overflow: hidden; }
#mobile-shell #quest-journal .journal { height: 100%; min-height: 0; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
#mobile-shell #quest-journal :is(.journal-nav, .journal-detail) { min-height: 0; max-height: none; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
#mobile-shell #quest-journal .journal-detail { padding: 0.75rem 0.85rem; font-size: 0.8rem; }
#mobile-shell #quest-journal .journal-nav__row { min-height: 2.4rem; padding: 0.4rem 0.5rem; font-size: 0.75rem; }

/* ---- server pages in the page host (#touch-page > turbo-frame#nav-frame) ----------------------------------------
   Party / Find Group, Friends, Guild (roster, bank, daily vault, castle), Mail, Rankings, Market, Class, Feedback and
   the character inspect page are the same ERB as on the desktop. Nothing is redrawn: this only brings their controls
   up to a finger. Primary actions >= 2.4rem (43px), tabs and chips >= 2.1rem, secondary row buttons >= 2.4rem square,
   every text field at >= 1rem (18px) so iOS does not zoom the page on focus, and nothing that matters waits for :hover. */
#mobile-shell #touch-page :is(.hud-btn, .hud-btn--sm) { min-height: 2.4rem; padding-inline: 0.9rem; font-size: 0.8rem; touch-action: manipulation; }
#mobile-shell #touch-page :is(.hud-tab, .mail-tab, .market-tab) { min-height: 2.4rem; padding-inline: 0.8rem; display: inline-flex; align-items: center; touch-action: manipulation; }
#mobile-shell #touch-page :is(.hud-chip, .hud-btn--chip):is(a, button) { min-height: 2.1rem; padding-inline: 0.7rem; display: inline-flex; align-items: center; font-size: 0.72rem; touch-action: manipulation; }
#mobile-shell #touch-page :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="hidden"], [type="submit"], [type="button"]), select, textarea) {
  box-sizing: border-box; min-height: 2.4rem; font-size: 1rem;
}
#mobile-shell #touch-page textarea { min-height: 4.5rem; }
/* the bronze input look for every text field and select a server page brings (the native control chrome is dropped; the
   select's arrow is drawn from two token-coloured gradients) */
#mobile-shell #touch-page :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="hidden"], [type="submit"], [type="button"], [type="color"]), select, textarea) {
  min-height: 2.4rem; font-size: 1rem; padding: 0.3rem 0.7rem;
  color: var(--hud-text); background-color: var(--hud-bg-2);
  border: 1px solid var(--hud-frame); border-radius: 0.375rem;
}
#mobile-shell #touch-page :is(input, select, textarea):focus { outline: none; border-color: var(--hud-frame-bright); }
#mobile-shell #touch-page select:is([class], :not([class])) { /* (the :is() lifts it to the field rule's specificity; it comes later) */
  -webkit-appearance: none; appearance: none; padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--hud-text-dim) 50%), linear-gradient(135deg, var(--hud-text-dim) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; /* whole pixels, so the two halves of the arrow meet cleanly */
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
/* the market's tab strip needs air before the filter row */
#mobile-shell #touch-page .market-panel > .hud-tabs { margin-bottom: 0.9rem; }
#mobile-shell #touch-page .market-filter { row-gap: 0.55rem; }
#mobile-shell #touch-page input:is([type="submit"], [type="button"]) { min-height: 2.4rem; padding-inline: 0.9rem; font-size: 0.8rem; }
#mobile-shell #touch-page summary { min-height: 2.2rem; display: flex; align-items: center; touch-action: manipulation; }
/* the per-row icon buttons (friend actions, roster menu): a finger-sized square, the glyph keeps its size */
#mobile-shell #touch-page :is(.friends-act, .guild-roster__menu-btn) {
  min-width: 2.4rem; min-height: 2.4rem; display: inline-flex; align-items: center; justify-content: center; touch-action: manipulation;
}
/* a ranking row's name is a link: the whole line is the target */
#mobile-shell #touch-page table a { display: inline-flex; align-items: center; min-width: 2.4rem; min-height: 2.4rem; touch-action: manipulation; }
/* Find Group's role pills (a label around a hidden radio) */
#mobile-shell #touch-page .role-toggle__label { min-height: 2.2rem; padding-inline: 0.7rem; font-size: 0.78rem; touch-action: manipulation; }
#mobile-shell #touch-page :is(.friends-card__add) { padding: 0 1rem; }
/* checkboxes and radios that stand on their own are 44px targets through their label's padding, not by growing the box */
#mobile-shell #touch-page label:has(> input:is([type="checkbox"], [type="radio"]):not(.sr-only)) { min-height: 2.2rem; display: inline-flex; align-items: center; gap: 0.5rem; }
/* tables and wide boards scroll inside their own box instead of widening the page */
#mobile-shell #touch-page :is(table, .guild-roster) { max-width: 100%; }
/* the escrow (i): hover-only on the desktop, so here the explanation is always on the page, under its icon */
#mobile-shell #touch-page .market-info[data-tip] {
  width: auto; height: auto; min-width: 1.1rem; padding: 0.15rem 0.5rem; border-radius: 0.5rem;
  display: inline-flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; text-align: left; cursor: default;
}
#mobile-shell #touch-page .market-info[data-tip]::after,
#mobile-shell #touch-page .market-info[data-tip]:hover::after {
  content: attr(data-tip); position: static; width: auto; max-width: 100%; padding: 0; border: 0; box-shadow: none; background: none;
  color: var(--hud-text-dim); font-size: 0.7rem; line-height: 1.3;
}

/* a dialogue with no portrait (an NPC whose sprite is unknown) has no role line either: let the text and the sections flow
   in order instead of the sections jumping above the text */
#mobile-shell #dialogue .dlg-body:has(#dlg-portrait.hidden) :is(.dlg-role, .dlg-text) { grid-row: auto; }
/* the craftsman's note inside an NPC dialogue: a desktop-only service on the phone */
#mobile-shell #dialogue .dlg-desktop-only {
  margin: 0; padding: 0.2rem 0; border: 0; background: none;
  color: var(--hud-text-dim); font-size: 0.72rem; font-style: italic; text-align: left;
}

/* the player menu (long-press on another player): thumb-sized rows that never leave the screen */
html:has(#mobile-shell) .hud-menu { max-height: calc(100dvh - 0.5rem); overflow-y: auto; overscroll-behavior: contain; min-width: 11rem; touch-action: pan-y; }
html:has(#mobile-shell) .hud-menu__item { min-height: 2.5rem; padding-inline: 0.9rem; gap: 0.7rem; font-size: 0.85rem; }
html:has(#mobile-shell) .hud-menu__glyph, html:has(#mobile-shell) .hud-menu__glyph svg { width: 1.15rem; height: 1.15rem; }

/* ---- settings on the phone ------------------------------------------------------------------------------------
   The Touch block is hidden by default (its utility class) and shown here; the Keyboard and Controller tabs, the HUD
   layout radios and the window-position reset are desktop-only and do not exist on the phone (game#showSettingsTab
   never selects a tab marked data-desktop-only). */
#mobile-shell [data-desktop-only] { display: none !important; }
#mobile-shell [data-touch-only] { display: flex; flex-direction: column; gap: 0.75rem; }
#mobile-shell [data-touch-only] label { min-height: 2.7rem; cursor: pointer; touch-action: manipulation; }
#mobile-shell [data-touch-only] label:has(> input[role="switch"]) { padding: 0 0.25rem; } /* the whole row is the switch's tap target */

/* ---- touch preferences: left-handed mirror, large buttons, large joystick -----------------------------------
   TouchHud stamps data-touch-left (present = on), data-touch-buttons and data-touch-joystick ("normal" | "large") on the
   shell from Settings > Touch.
   Large is x1.2 (x1.1 on a screen 380px tall or less, where x1.2 would push the Auto pill into the minimap's level
   label). The action cluster is scaled about its screen-edge corner; the potions and the Auto pill are sized and placed
   from the same --t-s, so the strip beside the cluster keeps its gaps. The joystick base and nub grow in place.
   Left-handed swaps the two BOTTOM zones: the move zone goes right; the cluster, potions and Auto go left, and what
   lives between or above them follows (chat peek lane, cast bar and error line lane, farm field panel, the NPC
   dialogue card, the party column's height limit). The cluster's arc is positioned from its right edge, so the mirror is a
   flip of those offsets (never a scaleX on the container, which would mirror the icons). Side panels, the minimap column
   and the top strip stay put; Auto joins the potion row on the left because the column above the cluster is the party
   frames'. Variables: --t-s the button scale; --t-ext how far the cluster reaches in from its edge; --t-pot how far the
   potion strip (and Auto, on the left) reaches beyond that; --t-jx how far the joystick base reaches from its edge;
   --t-jb the base's size; --t-party-b the height the party column leaves free at the bottom. */
#mobile-shell {
  --t-s: 1; --t-jb: 10rem; --t-jx: 11.6rem; --t-party-b: 11.2rem;
  --t-ext: calc(0.75rem + 10.65rem * var(--t-s));
  --t-pot: calc(1.4rem + 4.6rem * var(--t-s));
}
#mobile-shell[data-touch-buttons="large"] { --t-s: 1.2; }
#mobile-shell[data-touch-joystick="large"] { --t-jb: 12rem; --t-jx: 13.6rem; --t-party-b: 13.2rem; }
@media (max-height: 380px) {
  #mobile-shell[data-touch-buttons="large"] { --t-s: 1.1; }
  #mobile-shell[data-touch-joystick="large"] { --t-jb: 11rem; --t-jx: 12.6rem; --t-party-b: 12.2rem; }
}

/* large joystick: the base and nub at --t-jb (x1.2 of the 10rem a short screen gets; 14.4rem and 5.1rem on a tall one) */
#mobile-shell[data-touch-joystick="large"] .mobile-joystick { width: 14.4rem; height: 14.4rem; }
#mobile-shell[data-touch-joystick="large"] .mobile-joystick__nub { width: 5.1rem; height: 5.1rem; }
@media (max-height: 520px) {
  #mobile-shell[data-touch-joystick="large"] .mobile-joystick { width: var(--t-jb); height: var(--t-jb); }
  #mobile-shell[data-touch-joystick="large"] .mobile-joystick__nub { width: calc(var(--t-jb) * 0.35); height: calc(var(--t-jb) * 0.35); }
}
@media (max-width: 480px) {
  #mobile-shell[data-touch-joystick="large"] .mobile-joystick { width: 10.8rem; height: 10.8rem; }
  #mobile-shell[data-touch-joystick="large"] .mobile-joystick__nub { width: 3.9rem; height: 3.9rem; }
}
#mobile-shell[data-hud="mobile"]:is([data-touch-joystick="large"], [data-touch-left]) #party-frames {
  max-height: clamp(0rem, calc(round(down, 100vh - var(--t-party-b) - var(--y-pty) + 0.15rem, 1.3rem) - 0.15rem), 5.05rem);
}

/* large buttons */
#mobile-shell[data-touch-buttons="large"] #touch-cluster { transform: scale(var(--t-s)); transform-origin: right bottom; }
#mobile-shell[data-touch-buttons="large"] :is(#touch-potion-hp, #touch-potion-mp) { width: calc(2.3rem * var(--t-s)); height: calc(2.3rem * var(--t-s)); }
#mobile-shell[data-touch-buttons="large"] #touch-potion-hp { right: calc(var(--t-ext) + 0.5rem + env(safe-area-inset-right)); }
#mobile-shell[data-touch-buttons="large"] #touch-potion-mp { right: calc(var(--t-ext) + 1rem + 2.3rem * var(--t-s) + env(safe-area-inset-right)); }
#mobile-shell[data-touch-buttons="large"] #touch-auto {
  bottom: calc(var(--t-ext) + 0.5rem + env(safe-area-inset-bottom));
  width: calc(2.6rem * var(--t-s)); height: calc(1.4rem * var(--t-s)); font-size: calc(0.55rem * var(--t-s));
}

/* the peek lane sits between the zones, so it follows either preference; where it would shrink below about 5rem (a phone
   under 720px wide with large buttons, or left-handed with Auto in the potion row) it is not drawn: the Chat button
   still carries the unread badge */
#mobile-shell:is([data-touch-buttons="large"], [data-touch-joystick="large"]) #touch-bottom-center {
  left: calc(var(--t-jx) + env(safe-area-inset-left));
  right: calc(var(--t-ext) + var(--t-pot) + env(safe-area-inset-right));
}
#mobile-shell[data-touch-buttons="large"] #game-frame {
  --m-lane-x: calc((min(36vw, 18rem) + 100% - var(--t-ext) - env(safe-area-inset-right)) / 2);
  --m-lane-w: min(14rem, calc(100% - min(36vw, 18rem) - var(--t-ext) - 1rem - env(safe-area-inset-right)));
}
@media (max-width: 720px) {
  #mobile-shell:is([data-touch-buttons="large"], [data-touch-left]) #touch-bottom-center { display: none; }
}

/* left-handed: the bottom zones swap sides */
#mobile-shell[data-touch-left] { --t-pot: calc(1.9rem + 7.2rem * var(--t-s)); --t-party-b: calc(0.95rem + 10.65rem * var(--t-s)); }
#mobile-shell[data-touch-left] #touch-move-zone { left: auto; right: 0; padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) 0; }
#mobile-shell[data-touch-left] .mobile-joystick { left: auto; right: 1rem; }
#mobile-shell[data-touch-left] #touch-cluster { right: auto; left: calc(0.75rem + env(safe-area-inset-left)); transform-origin: left bottom; }
#mobile-shell[data-touch-left] #touch-attack { right: auto; left: 0; }
#mobile-shell[data-touch-left] #touch-swap { right: auto; left: 4.97rem; }
#mobile-shell[data-touch-left] #touch-target-next { right: auto; left: 0.2rem; }
#mobile-shell[data-touch-left] #touch-target-clear { right: auto; left: 2.65rem; }
#mobile-shell[data-touch-left][data-touch-set="0"] #spellbar .hud-slot:nth-child(1),
#mobile-shell[data-touch-left][data-touch-set="1"] #spellbar .hud-slot:nth-child(5) { right: auto; left: 7.55rem; }
#mobile-shell[data-touch-left][data-touch-set="0"] #spellbar .hud-slot:nth-child(2),
#mobile-shell[data-touch-left][data-touch-set="1"] #spellbar .hud-slot:nth-child(6) { right: auto; left: 6.625rem; }
#mobile-shell[data-touch-left][data-touch-set="0"] #spellbar .hud-slot:nth-child(3),
#mobile-shell[data-touch-left][data-touch-set="1"] #spellbar .hud-slot:nth-child(7) { right: auto; left: 4.1rem; }
#mobile-shell[data-touch-left][data-touch-set="0"] #spellbar .hud-slot:nth-child(4),
#mobile-shell[data-touch-left][data-touch-set="1"] #spellbar .hud-slot:nth-child(8) { right: auto; left: 0.65rem; }
#mobile-shell[data-touch-left] :is(#touch-potion-hp, #touch-potion-mp) { width: calc(2.3rem * var(--t-s)); height: calc(2.3rem * var(--t-s)); }
#mobile-shell[data-touch-left] #touch-potion-hp { right: auto; left: calc(var(--t-ext) + 0.5rem + env(safe-area-inset-left)); }
#mobile-shell[data-touch-left] #touch-potion-mp { right: auto; left: calc(var(--t-ext) + 1rem + 2.3rem * var(--t-s) + env(safe-area-inset-left)); }
#mobile-shell[data-touch-left] #touch-auto {
  right: auto; left: calc(var(--t-ext) + 1.5rem + 4.6rem * var(--t-s) + env(safe-area-inset-left));
  bottom: calc(1.4rem + 0.45rem * var(--t-s) + env(safe-area-inset-bottom));
  width: calc(2.6rem * var(--t-s)); height: calc(1.4rem * var(--t-s)); font-size: calc(0.55rem * var(--t-s));
}
#mobile-shell[data-touch-left] #touch-bottom-center {
  left: calc(var(--t-ext) + var(--t-pot) + env(safe-area-inset-left));
  right: calc(var(--t-jx) + env(safe-area-inset-right));
}
#mobile-shell[data-touch-left] #touch-chat-peek { align-items: flex-end; }
#mobile-shell[data-touch-left] #game-frame {
  --m-lane-x: calc((var(--t-ext) + env(safe-area-inset-left) + 100% - min(36vw, 18rem)) / 2);
  --m-lane-w: min(14rem, calc(100% - min(36vw, 18rem) - var(--t-ext) - 1rem - env(safe-area-inset-left)));
}
/* the dialogue card follows the free side; the shop and quest sections inside it do not care */
#mobile-shell[data-touch-left] #dialogue:not(.hidden) { left: calc(0.5rem + env(safe-area-inset-left)) !important; right: auto !important; }
html:has(#mobile-shell[data-touch-left]) .field-panel--mobile {
  left: calc((var(--t-ext) + env(safe-area-inset-left) + 100% - min(36vw, 18rem)) / 2);
  width: min(calc(100vw - min(36vw, 18rem) - var(--t-ext) - 1rem - env(safe-area-inset-left)), 20rem);
}
html:has(#mobile-shell[data-touch-buttons="large"]:not([data-touch-left])) .field-panel--mobile {
  left: calc((min(36vw, 18rem) + 100% - var(--t-ext) - env(safe-area-inset-right)) / 2);
  width: min(calc(100vw - min(36vw, 18rem) - var(--t-ext) - 1rem - env(safe-area-inset-right)), 20rem);
}
/* a chosen radio pill reads at a glance: a gold-tinted fill besides the brighter border the desktop gives it */
#mobile-shell #settings-modal label:has(> input[type="radio"]:checked) {
  background: color-mix(in srgb, var(--hud-title) 14%, var(--hud-bg-2));
  border-color: var(--hud-frame-bright);
}

/* toasts: top-centre, just under the target-frame stack, so a toast never sits on the action cluster, the potions, the chat
   input, the side-panel buttons or the item card (and left-handed mode needs no mirror: the centre column is the same).
   The dock is not inside #game-frame, so it re-adds the heights the stack slots contribute (the same numbers as the --o-* rules
   above) from :has() on the controller element. At most two cards (game_controller#showToast) and the pointer passes through. */
[data-hud="mobile"] {
  --tt-aim: 0rem; --tt-war: 0rem; --tt-emp: 0rem; --tt-tgt: 0rem; --tt-tcast: 0rem; --tt-dun: 0rem; --tt-boss: 0rem; --tt-ban: 0rem;
}
[data-hud="mobile"][data-touch-aim] { --tt-aim: 1.9rem; }
[data-hud="mobile"]:has(#game-frame.war-live) { --tt-war: 1.7rem; }
[data-hud="mobile"]:has(#emperium-bar:not(.hidden)) { --tt-emp: 0.65rem; }
[data-hud="mobile"]:has(#target-bar:not(.hidden)) { --tt-tgt: 2.5rem; }
[data-hud="mobile"]:has(#target-cast:not(.hidden)) { --tt-tcast: 1.15rem; }
[data-hud="mobile"]:has(#dungeon-hud:not(.hidden)) { --tt-dun: 3.6rem; }
[data-hud="mobile"]:has(#boss-bar:not(.hidden)) { --tt-boss: 1.9rem; }
[data-hud="mobile"]:has(:is(#relic-banner, #woe-banner, #dungeon-banner):not(.hidden)) { --tt-ban: 2.3rem; }
[data-hud="mobile"] #toasts,
[data-hud="mobile"] #toasts-top {
  top: calc(0.5rem + env(safe-area-inset-top) + var(--tt-aim) + var(--tt-war) + var(--tt-emp) + var(--tt-tgt) + var(--tt-tcast) + var(--tt-dun) + var(--tt-boss) + var(--tt-ban) + 0.4rem);
  bottom: auto; left: 50%;
  width: max-content; max-width: clamp(9.5rem, calc(100vw - 26rem), 15rem);
  pointer-events: none;
}
/* The PM notice (#toasts-top) takes the top slot; while one is up the generic dock steps down one card (~2.6rem). */
[data-hud="mobile"]:has(#toasts-top > .toast-card) #toasts { margin-top: 2.6rem; }
[data-hud="mobile"] #toasts .toast-card,
[data-hud="mobile"] #toasts-top .toast-card {
  pointer-events: none; min-width: 0; max-width: 100%; font-size: 0.72rem; line-height: 1.2; padding: 0.3rem 0.55rem 0.3rem 0.7rem;
}
/* Only a clickable card (the PM notice opens its conversation) takes taps; every other phone toast stays click-through. */
[data-hud="mobile"] #toasts .toast-card--click,
[data-hud="mobile"] #toasts-top .toast-card--click { pointer-events: auto; }

/* Feedback: the big illustration would take half of a landscape phone's height before the first control */
@media (max-height: 460px) {
  #mobile-shell #touch-page .feedback-intro__art { display: none; }
}

/* ---- install dialog -----------------------------------------------------------------------
   The Menu's "Install app" tile opens the install card (shared/_pwa_install, surface: game) as a
   centred HUD dialog over the menu. It is never shown on its own, so it can never sit on the HUD.
   The card's own look is phone_pages.css (.pwa-install__*); this is only where it stands. */
html:has(#mobile-shell) .pwa-install--game {
  position: fixed; inset: 0; z-index: 210;
  display: flex; align-items: center; justify-content: center;
  padding: calc(0.75rem + env(safe-area-inset-top)) calc(0.75rem + env(safe-area-inset-right))
           calc(0.75rem + env(safe-area-inset-bottom)) calc(0.75rem + env(safe-area-inset-left));
  background: color-mix(in srgb, var(--hud-bg-2) 78%, transparent);
}
html:has(#mobile-shell) .pwa-install--game[hidden] { display: none; }
html:has(#mobile-shell) .pwa-install--game .pwa-install__card {
  max-width: 28rem; padding: 0.9rem; gap: 0.6rem 0.8rem;
  box-shadow: 0 0.75rem 2.5rem color-mix(in srgb, var(--hud-bg-2) 85%, transparent);
}
html:has(#mobile-shell) .pwa-install--game .pwa-install__title,
html:has(#mobile-shell) .pwa-install--game .pwa-install__body,
html:has(#mobile-shell) .pwa-install--game .pwa-install__steps { font-size: 0.9rem; }
html:has(#mobile-shell) .pwa-install--game .pwa-install__actions .pwa-install__btn { min-height: 2.75rem; font-size: 0.9rem; }

/* Painted phone controls retain the existing button hit areas and state hooks. */
#mobile-shell .touch-control-art {
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}
#mobile-shell #touch-attack .touch-attack__art { width: 2.65rem; height: 2.65rem; }
#mobile-shell .touch-swap__art { width: 1.25rem; height: 1.25rem; }
#mobile-shell .touch-target__art { width: 1.5rem; height: 1.5rem; }
#mobile-shell .touch-topbtn__art { width: 1.65rem; height: 1.65rem; }
#mobile-shell .touch-topbtn:has(.touch-topbtn__count:not(:empty)) .touch-topbtn__art { width: 1.25rem; height: 1.25rem; }
#mobile-shell .touch-potion__glyph.touch-control-art { width: 1.7rem; height: 1.7rem; }
#mobile-shell .touch-potion__glyph[hidden] { display: none; }
#mobile-shell .touch-rotate__art { width: 8rem; height: 8rem; }
