/* Monster Arc: Tiny Realms - mobile layout (2026-11-04).
   Active only when js/device.js puts data-ui="mobile" on <html> (phones/tablets, or the player chose "มือถือ").
   The PC layout in ui.css is untouched; every rule here is scoped to html[data-ui="mobile"].
   Landscape (main way to play): left thumb = floating joystick on the empty left side; right thumb = an action ring around a big
   attack button (dodge, 4 skills on an arc, a second skill page with ⇄, auto / target / talk); potions sit under the HP card;
   menus collapse into ☰ which opens a bottom sheet; panels become near-full-screen sheets.
   Portrait keeps the same ring and moves the small buttons above it.
   Visual polish (art for joystick / ring / burger icon) can replace the plain shapes later without touching layout. */

.m-only { display: none; }
.ui-pick { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; }
.ui-pick .lang-switch { margin: 0; }
.ui-pick-l { font-size: 13px; color: var(--muted); }
.ui-pick-n { flex-basis: 100%; text-align: center; font-size: 11.5px; color: var(--muted); }
#s-ui .ui-pick { justify-content: flex-start; } #s-ui .ui-pick-n { text-align: left; }

html[data-ui="mobile"] {
  --k: 1; --sr: var(--safe-r); --sb: var(--safe-b); --sl: var(--safe-l); --ui: .8;
}
html[data-ui="mobile"][data-form="tablet"] { --k: 1.15; --ui: .92; }

/* ---------- login / characters ---------- */
html[data-ui="mobile"] input, html[data-ui="mobile"] select { font-size: 16px; min-height: 46px; } /* 16px stops iOS zooming into fields */
html[data-ui="mobile"] .btn { min-height: 46px; }
html[data-ui="mobile"] .btn.small { min-height: 40px; }
html[data-ui="mobile"] .screen { align-items: safe center; padding: max(10px, var(--safe-l)) max(10px, var(--safe-r)) max(10px, var(--safe-b)); }
html[data-ui="mobile"] .login-card { gap: 10px; padding: 18px; }
html[data-ui="mobile"][data-orient="landscape"] .title-wrap { display: grid; width: min(780px, 100%); grid-template-columns: 1fr minmax(300px, 380px); grid-template-areas: "logo form" "lang form"; align-items: center; gap: 8px 26px; }
html[data-ui="mobile"][data-orient="landscape"] .title-wrap > .logo { grid-area: logo; }
html[data-ui="mobile"][data-orient="landscape"] .title-wrap > .lang-switch { grid-area: lang; margin: 0 auto; }
html[data-ui="mobile"][data-orient="landscape"] .title-wrap > form { grid-area: form; }
html[data-ui="mobile"][data-orient="landscape"][data-form="phone"] .logo-b img { height: 110px !important; }
html[data-ui="mobile"][data-orient="landscape"][data-form="phone"] .login-card .fine:last-child { display: none; }
html[data-ui="mobile"][data-orient="landscape"][data-form="phone"] .login-card { padding: 14px 16px; gap: 8px; }
html[data-ui="mobile"][data-orient="landscape"][data-form="phone"] .logo-c { font-size: 13px; }
html[data-ui="mobile"][data-orient="landscape"] .conn-state { left: calc(12px + var(--sl)); transform: none; }
html[data-ui="mobile"] .chars-card { width: 100%; max-height: calc(100dvh - 20px); padding: 14px 16px; gap: 10px; }
html[data-ui="mobile"] .chars-card > * { flex-shrink: 0; } /* the card scrolls instead of squashing the character list */
html[data-ui="mobile"] .class-pick { display: grid; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 96px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; }
html[data-ui="mobile"] .class-opt { scroll-snap-align: start; }
html[data-ui="mobile"][data-orient="landscape"] .char-list { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 150px; overflow-x: auto; }
html[data-ui="mobile"] .char-create .row { flex-wrap: nowrap; }

/* ---------- HUD: top left (status, potions, chat) ---------- */
html[data-ui="mobile"] #hud-status { left: calc(10px + var(--sl)); top: 8px; gap: 4px; }
html[data-ui="mobile"] .status-card { width: calc(206px * var(--k)); padding: 6px 10px 6px 6px; gap: 8px; border-radius: 16px; }
html[data-ui="mobile"] .portrait-ring { width: calc(42px * var(--k)); height: calc(42px * var(--k)); }
html[data-ui="mobile"] .bar { height: 12px; } html[data-ui="mobile"] .bar span { font-size: 9.5px; line-height: 12px; }
html[data-ui="mobile"] .pk-btn { min-height: 36px; height: 36px; }

/* hotbar becomes a full-screen layer; each slot is placed on its own (main.js tags them data-k / data-p) */
html[data-ui="mobile"] #hud-bar { position: fixed; inset: 0; transform: none; display: block; background: none; box-shadow: none; padding: 0; max-width: none; pointer-events: none; }
html[data-ui="mobile"] #hud-bar .sep, html[data-ui="mobile"] #hud-bar .slot .key { display: none; }
html[data-ui="mobile"] #hud-bar .slot { position: absolute; pointer-events: auto; box-shadow: 0 3px 10px rgba(83, 87, 108, .16); }
html[data-ui="mobile"] #hud-bar .slot.skill { width: calc(56px * var(--k)); height: calc(56px * var(--k)); border-radius: 50%; border: 3px solid rgba(255, 248, 232, .96); }
html[data-ui="mobile"] #hud-bar .slot.skill .cd { border-radius: 50%; transform-origin: center; }
html[data-ui="mobile"] #hud-bar .slot.pot { width: calc(44px * var(--k)); height: calc(44px * var(--k)); border-radius: 12px; left: calc(10px + var(--sl)); top: calc(126px * var(--k)); }
html[data-ui="mobile"] #hud-bar .slot.pot[data-p="1"] { left: calc(60px * var(--k) + var(--sl)); }
html[data-ui="mobile"] #hud-bar .slot.pot[data-p="2"], html[data-ui="mobile"] #hud-bar .slot.pot[data-p="3"] { display: none; }
html[data-ui="mobile"] .chat-bubble { display: inline-flex !important; left: calc(110px * var(--k) + var(--sl)); top: calc(126px * var(--k)); bottom: auto; height: calc(44px * var(--k)); min-height: 44px; }
html[data-ui="mobile"] #hud-chat { display: none; left: calc(10px + var(--sl)); top: 8px; bottom: auto; width: min(380px, 56vw); --chat-lines: 4; z-index: 8; pointer-events: auto; }
html[data-ui="mobile"] #hud-chat.open { display: block; }
html[data-ui="mobile"] #hud-chat.open .chat-form { display: flex; }

/* ---------- HUD: top right (buttons + minimap, quest beside it) ---------- */
html[data-ui="mobile"] #btn-menu { display: inline-flex; }
html[data-ui="mobile"] #btn-menu .burger, html[data-ui="mobile"] #btn-menu .burger::before, html[data-ui="mobile"] #btn-menu .burger::after { display: block; width: 18px; height: 2.5px; border-radius: 2px; background: var(--ink); position: relative; }
html[data-ui="mobile"] #btn-menu .burger::before, html[data-ui="mobile"] #btn-menu .burger::after { content: ''; position: absolute; left: 0; }
html[data-ui="mobile"] #btn-menu .burger::before { top: -6px; } html[data-ui="mobile"] #btn-menu .burger::after { top: 6px; }
html[data-ui="mobile"] #hud-topright { right: calc(10px + var(--sr)); top: 8px; }
html[data-ui="mobile"] .map-pill, html[data-ui="mobile"] .mm-zoom { display: none; }
html[data-ui="mobile"] #hud-minimap { width: calc(96px * var(--k)); border-width: 4px; }
html[data-ui="mobile"][data-orient="landscape"] #hud-topright { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto auto 1fr; gap: 6px; align-items: start; justify-items: end; }
html[data-ui="mobile"][data-orient="landscape"] .top-row { grid-column: 1; grid-row: 1; }
html[data-ui="mobile"][data-orient="landscape"] .mm-row { grid-column: 2; grid-row: 1 / span 4; }
html[data-ui="mobile"][data-orient="landscape"] #hud-quest { grid-column: 1; grid-row: 2; position: static; transform: none; width: calc(186px * var(--k)); max-width: none; padding: 5px 10px; display: block; }
html[data-ui="mobile"][data-orient="landscape"] #hud-quest.hidden { display: none; }
html[data-ui="mobile"][data-orient="landscape"] #hud-quest .q-ch, html[data-ui="mobile"][data-orient="landscape"] #hud-quest .q-hint { display: none; }
html[data-ui="mobile"][data-orient="landscape"] #hud-quest .q-title { margin: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html[data-ui="mobile"][data-orient="landscape"] #hud-daily { grid-column: 1; grid-row: 3; position: static; width: calc(186px * var(--k)); min-height: 28px; padding: 3px 10px; }
html[data-ui="mobile"][data-orient="landscape"][data-form="phone"] .gold-line { display: none; }
html[data-ui="mobile"][data-orient="landscape"] .gold-line { grid-column: 1; grid-row: 4; }
html[data-ui="mobile"][data-orient="landscape"] #hud-party { grid-column: 1 / span 2; }

/* ---------- menu: ☰ opens a bottom sheet ---------- */
html[data-ui="mobile"] #hud-menu { display: none; }
html[data-ui="mobile"] #hud.menu-open #hud-menu { display: grid; position: fixed; left: 50%; top: auto; bottom: 0; transform: translateX(-50%); width: min(620px, 100vw); z-index: 9; pointer-events: auto;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; padding: 14px calc(14px + var(--sr)) calc(14px + var(--sb)) calc(14px + var(--sl));
  background: var(--cream); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-l); animation: m-sheet .18s ease-out; }
html[data-ui="mobile"] #hud.menu-open .menu-btn { flex-direction: column; gap: 4px; width: auto; min-height: 72px; padding: 8px 4px; justify-content: center; background: var(--paper); border-radius: 16px; }
html[data-ui="mobile"] #hud.menu-open .menu-btn img { width: 32px; height: 32px; flex: none; object-fit: contain; }
html[data-ui="mobile"] #hud.menu-open .menu-btn span { display: block; font-size: 12px; }
html[data-ui="mobile"] #hud.menu-open .mbadge { left: auto; right: 10px; top: 6px; }
html[data-ui="mobile"] #menu-scrim { display: none; position: fixed; inset: 0; background: rgba(43, 36, 56, .22); z-index: 8; pointer-events: auto; }
html[data-ui="mobile"] #hud.menu-open #menu-scrim { display: block; }
@keyframes m-sheet { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- right thumb: action ring (positions measured from the bottom-right corner, scaled by --k) ---------- */
html[data-ui="mobile"] #hud-actions { position: fixed; right: 0; bottom: 0; width: 0; height: 0; }
html[data-ui="mobile"] .act { position: fixed; display: flex; align-items: center; justify-content: center; }
html[data-ui="mobile"] .act.big { width: calc(96px * var(--k)); height: calc(96px * var(--k)); right: calc(28px * var(--k) + var(--sr)); bottom: calc(28px * var(--k) + var(--sb)); font-size: 16px; }
html[data-ui="mobile"] #btn-dodge { width: calc(60px * var(--k)); height: calc(60px * var(--k)); right: calc(160px * var(--k) + var(--sr)); bottom: calc(16px * var(--k) + var(--sb)); }
html[data-ui="mobile"] .act.small { width: calc(44px * var(--k)); height: calc(44px * var(--k)); border-radius: 50%; font-size: 11px; }
html[data-ui="mobile"] #btn-skpage { display: flex; right: calc(224px * var(--k) + var(--sr)); bottom: calc(54px * var(--k) + var(--sb)); font-size: 18px; }
html[data-ui="mobile"] #btn-skpage.hidden { display: none; }
html[data-ui="mobile"] #btn-skpage.on { background: var(--sel); color: #3f7464; }
html[data-ui="mobile"] #btn-interact { width: calc(52px * var(--k)); height: calc(52px * var(--k)); right: calc(226px * var(--k) + var(--sr)); bottom: calc(116px * var(--k) + var(--sb)); font-size: 13px; }
html[data-ui="mobile"] #btn-auto { right: calc(286px * var(--k) + var(--sr)); bottom: calc(30px * var(--k) + var(--sb)); }
html[data-ui="mobile"] #btn-target { right: calc(286px * var(--k) + var(--sr)); bottom: calc(90px * var(--k) + var(--sb)); }
/* skills: page 1 = data-k 0-3, page 2 (⇄) = data-k 4-7 on the same arc: 165°, 135°, 105°, 75° at r=118 around the attack button */
html[data-ui="mobile"] #hud-bar .slot.skill:is([data-k="0"], [data-k="4"]) { right: calc(162px * var(--k) + var(--sr)); bottom: calc(79px * var(--k) + var(--sb)); }
html[data-ui="mobile"] #hud-bar .slot.skill:is([data-k="1"], [data-k="5"]) { right: calc(131px * var(--k) + var(--sr)); bottom: calc(131px * var(--k) + var(--sb)); }
html[data-ui="mobile"] #hud-bar .slot.skill:is([data-k="2"], [data-k="6"]) { right: calc(79px * var(--k) + var(--sr)); bottom: calc(162px * var(--k) + var(--sb)); }
html[data-ui="mobile"] #hud-bar .slot.skill:is([data-k="3"], [data-k="7"]) { right: calc(18px * var(--k) + var(--sr)); bottom: calc(162px * var(--k) + var(--sb)); }
html[data-ui="mobile"] #hud-bar:not(.page2) .slot.skill:is([data-k="4"], [data-k="5"], [data-k="6"], [data-k="7"]),
html[data-ui="mobile"] #hud-bar.page2 .slot.skill:is([data-k="0"], [data-k="1"], [data-k="2"], [data-k="3"]),
html[data-ui="mobile"] #hud-bar .slot.skill:not([data-k]), html[data-ui="mobile"] #hud-bar .slot.skill[data-k="8"], html[data-ui="mobile"] #hud-bar .slot.skill[data-k="9"] { display: none; }

/* ---------- left thumb: joystick hint where the stick usually starts (the real stick still appears wherever the thumb lands) ---------- */
html[data-ui="mobile"] #joy-ghost { display: block; position: fixed; left: calc(22vw + var(--sl)); bottom: calc(80px + var(--sb)); width: 112px; height: 112px; margin: 0 0 -56px -56px; border-radius: 50%;
  background: rgba(255, 248, 232, .16); box-shadow: inset 0 0 0 2px rgba(255, 248, 232, .45); pointer-events: none; transition: opacity .2s; }
html[data-ui="mobile"] #joy-ghost i { position: absolute; left: 34px; top: 34px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 248, 232, .45); }
html[data-ui="mobile"] #hud.joying #joy-ghost, html[data-ui="mobile"] #hud.menu-open #joy-ghost, html[data-ui="mobile"] #hud:has(.panel) #joy-ghost { opacity: 0; }
html[data-ui="mobile"] #joy { width: 120px; height: 120px; margin: -60px 0 0 -60px; }
html[data-ui="mobile"] #joy-knob { left: 36px; top: 36px; }

/* ---------- panels: near full-screen sheets ---------- */
html[data-ui="mobile"] .panel { width: calc(100vw - 16px - var(--sl) - var(--sr)); max-width: 760px; height: calc(100dvh - 16px); max-height: none; border-radius: 18px; }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] .panel { width: 100vw; height: 100dvh; border-radius: 0; padding-bottom: var(--sb); }
html[data-ui="mobile"] .panel header .x { width: 46px; height: 46px; }
html[data-ui="mobile"] .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
html[data-ui="mobile"] .tabs button { flex: none; min-height: 42px; }

/* ---------- misc ---------- */
html[data-ui="mobile"] #toasts { top: 56px !important; }
html[data-ui="mobile"] #hud-exp { bottom: calc(3px + var(--sb)); }
html[data-ui="mobile"] #whisper { bottom: calc(240px + var(--sb)); }
html[data-ui="mobile"][data-orient="landscape"] #whisper { bottom: auto; top: 60px; }

/* ---------- portrait phones: same ring, small buttons above it; top-right stays a column ---------- */
html[data-ui="mobile"][data-orient="portrait"] #btn-interact { right: calc(170px * var(--k) + var(--sr)); bottom: calc(246px * var(--k) + var(--sb)); }
html[data-ui="mobile"][data-orient="portrait"] #btn-auto { right: calc(114px * var(--k) + var(--sr)); bottom: calc(244px * var(--k) + var(--sb)); }
html[data-ui="mobile"][data-orient="portrait"] #btn-target { right: calc(62px * var(--k) + var(--sr)); bottom: calc(244px * var(--k) + var(--sb)); }
html[data-ui="mobile"][data-orient="portrait"] #joy-ghost { left: calc(26vw + var(--sl)); bottom: calc(120px + var(--sb)); }
html[data-ui="mobile"][data-orient="portrait"] #hud-quest, html[data-ui="mobile"][data-orient="portrait"] #hud-daily { width: calc(170px * var(--k)); }
html[data-ui="mobile"] #rotate-hint { display: none; }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] #rotate-hint { display: block; position: fixed; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(43, 36, 56, .8); color: #f6eedc;
  padding: 8px 16px; border-radius: 14px; font-size: 13px; pointer-events: none; white-space: nowrap; animation: m-hint 7s forwards; z-index: 4; }
@keyframes m-hint { 0%, 80% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] .status-card { width: 178px; }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] #btn-full { display: none; }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] .top-row { gap: 5px; }

/* ---------- task 16 art (Codex, 2026-11-04): @2x PNGs in assets/ui/mobile, shown at half size ---------- */
html[data-ui="mobile"] #btn-attack { background: var(--atk-ico, none) center / 50% no-repeat, url('../assets/ui/mobile/attack-ring.png') center / 100% no-repeat; box-shadow: none; }
html[data-ui="mobile"] #btn-attack span { display: none; }
html[data-ui="mobile"] #hud[data-cls="mage"] { --atk-ico: url('../assets/ui/mobile/attack-mage.png'); }
html[data-ui="mobile"] #hud[data-cls="greatsword"] { --atk-ico: url('../assets/ui/mobile/attack-greatsword.png'); }
html[data-ui="mobile"] #hud[data-cls="summoner"] { --atk-ico: url('../assets/ui/mobile/attack-summoner.png'); }
html[data-ui="mobile"] #hud[data-cls="crossbows"] { --atk-ico: url('../assets/ui/mobile/attack-crossbows.png'); }
html[data-ui="mobile"] #hud[data-cls="daggers"] { --atk-ico: url('../assets/ui/mobile/attack-daggers.png'); }
html[data-ui="mobile"] #hud[data-cls="naga"] { --atk-ico: url('../assets/ui/mobile/attack-naga.png'); }
html[data-ui="mobile"] #btn-dodge { background: url('../assets/ui/mobile/dodge.png') center / 100% no-repeat; box-shadow: none; overflow: visible; color: #53576c; font-weight: 500; }
html[data-ui="mobile"] #hud-bar .slot.skill { border: 0; }
html[data-ui="mobile"] #hud-bar .slot.skill::after { content: ''; position: absolute; inset: 0; background: url('../assets/ui/mobile/skill-frame.png') center / 100% no-repeat; pointer-events: none; z-index: 1; }
html[data-ui="mobile"] #btn-menu { background: url('../assets/ui/mobile/menu.png') center / 100% no-repeat, var(--cream); }
html[data-ui="mobile"] #btn-menu .burger { display: none; }
html[data-ui="mobile"] #btn-auto, html[data-ui="mobile"] #btn-target, html[data-ui="mobile"] #btn-skpage { font-size: 0 !important; color: transparent; }
html[data-ui="mobile"] #btn-auto { background: url('../assets/ui/mobile/auto.png') center / 100% no-repeat, rgba(255, 248, 232, .96); }
html[data-ui="mobile"] #btn-auto.on { background: url('../assets/ui/mobile/auto-on.png') center / 100% no-repeat, #bdded0; }
html[data-ui="mobile"] #btn-target { background: url('../assets/ui/mobile/target.png') center / 100% no-repeat, rgba(255, 248, 232, .96); }
html[data-ui="mobile"] #btn-target.on { background: url('../assets/ui/mobile/target-on.png') center / 100% no-repeat, var(--rose); }
html[data-ui="mobile"] #btn-skpage { background: url('../assets/ui/mobile/skpage.png') center / 100% no-repeat, rgba(255, 248, 232, .96); }
html[data-ui="mobile"] #btn-skpage.on { background: url('../assets/ui/mobile/skpage.png') center / 100% no-repeat, var(--sel); }
html[data-ui="mobile"] #joy-ghost, html[data-ui="mobile"] #joy { background: url('../assets/ui/mobile/joy-base.png') center / 100% no-repeat; box-shadow: none; }
html[data-ui="mobile"] #joy-ghost { opacity: .55; }
html[data-ui="mobile"] #joy-ghost i, html[data-ui="mobile"] #joy-knob { background: url('../assets/ui/mobile/joy-knob.png') center / 100% no-repeat; }
html[data-ui="mobile"] #hud.menu-open #hud-menu { padding-top: 26px; }
html[data-ui="mobile"] #hud.menu-open #hud-menu::before { content: ''; position: absolute; left: 50%; top: 8px; width: 60px; height: 12px; margin-left: -30px; background: url('../assets/ui/mobile/sheet-handle.png') center / 100% no-repeat; }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] #rotate-hint { padding: 8px 16px 8px 56px; background: url('../assets/ui/mobile/rotate-phone.png') 10px center / 40px no-repeat, rgba(43, 36, 56, .8); }

/* Chat grows upward from its bottom edge on touch screens too. */
html[data-ui="mobile"] #hud-chat { top:auto; bottom:calc(110px * var(--k) + var(--sb)); width:min(380px, calc(100vw - 24px - var(--sl) - var(--sr))); }
html[data-ui="mobile"] #chat-resize { height:24px; }
html[data-ui="mobile"] .chat-tabs button { min-height:32px; }
/* party frames beside the status card: half its width each, 2 x 2 (2026-11-05) */
html[data-ui="mobile"] #hud-party { grid-template-columns: repeat(2, calc(103px * var(--k))); gap: 3px; }
html[data-ui="mobile"] #hud-party .pf { padding: 3px 7px 4px; font-size: calc(10.5px * var(--k)); min-height: 0; border-radius: 9px; }
/* portrait phones have no room beside the card (minimap on the right): the grid goes under the card, same width */
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] .status-row { flex-direction: column; gap: 4px; }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] #hud-party { grid-template-columns: repeat(2, 87px); }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] #hud:has(#hud-party:not(.hidden)) .chat-bubble { top: calc(126px * var(--k) + 104px); } /* stays clear of the party grid and its settings header */
html[data-ui="mobile"] #hud-party .ph { height: max(26px, calc(22px * var(--k))); font-size: calc(10px * var(--k)); border-radius: 8px; }
html[data-ui="mobile"] #hud-party .ph-gear { font-size: 14px; min-width: 38px; }

/* mobile chat (2026-11-05, owner): flush with the bottom edge, rides on top of the on-screen keyboard (--kb from
   visualViewport in hud.js), shrinks to fit the space above the keyboard, and has a close button */
html[data-ui="mobile"] #chat-close { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; font-size: 15px; color: var(--ink); }
html[data-ui="mobile"] #hud-chat { top: auto; bottom: calc(var(--kb, 0px) + var(--sb) + 4px); z-index: 30; max-height: calc(var(--vvh, 100dvh) - 8px); }
html[data-ui="mobile"] #hud-chat.kb #chat-resize, html[data-ui="mobile"] #hud-chat.kb .chat-tabs [data-ch], html[data-ui="mobile"] #hud-chat.kb #chat-expand { display: none; }
html[data-ui="mobile"] #hud-chat.kb .chat-tabs { justify-content: flex-end; padding-top: 2px; }
html[data-ui="mobile"] #hud-chat.kb .chat-log { height: min(var(--chat-height, 6em), max(3em, calc(var(--vvh, 100dvh) - 120px))); }
/* iOS zooms into any text box under 16px on focus, which slid the whole game sideways/up */
html[data-ui="mobile"] #hud-chat input, html[data-ui="mobile"] #hud-chat select { font-size: 16px; }
/* owner 2026-11-05: the open chat must stay small and always bottom-left so it never covers the play area */
html[data-ui="mobile"] #hud-chat { left: calc(6px + var(--sl)); right: auto; width: min(330px, 44vw); }
html[data-ui="mobile"][data-orient="portrait"] #hud-chat { width: min(330px, calc(100vw - 12px - var(--sl) - var(--sr))); }
html[data-ui="mobile"] #hud-chat .chat-log { height: min(var(--chat-height, 4.5em), 24dvh); }
html[data-ui="mobile"] #hud-chat .chat-tabs { padding: 2px 4px 0; gap: 2px; } html[data-ui="mobile"] #hud-chat .chat-tabs button { min-height: 28px; padding: 2px 7px; }
html[data-ui="mobile"] #hud-chat .chat-form select, html[data-ui="mobile"] #hud-chat .chat-form input, html[data-ui="mobile"] #hud-chat .chat-send { min-height: 36px; }

/* Relative grid items anchor fold controls without moving the mobile HUD grid. */
html[data-ui="mobile"][data-orient] #hud-quest, html[data-ui="mobile"][data-orient] #hud-daily { position: relative; top: auto; left: auto; right: auto; bottom: auto; transform: none; padding-right: 44px; }
html[data-ui="mobile"][data-orient] #hud-quest.is-folded, html[data-ui="mobile"][data-orient] #hud-daily.is-folded { width: 44px; max-width: 44px; height: 44px; min-height: 44px; padding: 0; justify-self: end; }

/* Same compact PK / HP / MP / chat row, anchored by normal document flow. */
html[data-ui="mobile"] #hud-status { --status-card-width: calc(206px * var(--k)); }
html[data-ui="mobile"][data-form="phone"][data-orient="portrait"] #hud-status { --status-card-width: 188px; }
html[data-ui="mobile"] #hud-status .status-card { width: var(--status-card-width); }
