/* Landscape phones: broad windows, internal scrolling, no stacked half-sheets.
   Mobile is landscape only: held upright, a full screen asks to turn the phone. */
#orientation-hint { display: none; }
@media (pointer: coarse) and (orientation: portrait) {
  #orientation-hint { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 20px; padding: 32px; text-align: center;
    background: #112229; color: var(--cream); font: 20px/1.5 var(--title); }
  #orientation-hint img { width: 64px; height: 64px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  :root { --safe-l: max(12px, env(safe-area-inset-left)); --safe-r: max(12px, env(safe-area-inset-right));
    --safe-t: max(8px, env(safe-area-inset-top)); --safe-b: max(8px, env(safe-area-inset-bottom)); }
  body #hud { top: var(--safe-t); left: var(--safe-l); width: 224px; padding: 6px; }
  body #hud-portrait { width: 36px; height: 42px; }
  body #hud-icon { width: 54px; height: 60px; top: -9px; }
  body .hud-side { width: 164px; gap: 4px; }
  body #hud-name { font-size: 14px; }
  body .hud-info { margin: 5px 0 0 48px; font-size: 10px; }
  body #side { top: var(--safe-t); right: var(--safe-r); width: 132px; gap: 3px; }
  body #minimap { width: 76px; height: 76px; }
  body #map-wrap { padding: 2px; }
  body #cam-turn { gap: 8px; margin-top: 0; }
  body #cam-turn button { width: 44px; height: 44px; }
  body .map-info .chip { font-size: 10px; padding: 3px 5px; }
  body .map-info .chip:has(#pos), body #goal { display: none; }
  body #quest-track { max-height: 64px; overflow-y: auto; }
  body #quest-track .qt { font-size: 10px; padding: 5px; }
  body #micro { left: var(--safe-l); right: auto; bottom: var(--safe-b); padding: 3px; gap: 0; }
  body #micro .skill.small { width: 48px; height: 52px; padding-bottom: 16px; }
  body #micro .picto { width: 26px; height: 26px; }
  body #micro kbd, body #actions kbd, body .menu-tools kbd { display: none; }
  body #actions { left: auto; right: var(--safe-r); bottom: var(--safe-b); transform: none; padding: 8px; width: auto; }
  body #actions .slots { display: flex; gap: 6px; }
  body #actions .skill, body #actions .spell, body #actions .potion, body #actions #hunt { width: 44px; height: 44px; min-width: 44px; }
  body #actions .sp3d { width: 36px; height: 36px; }
  body #spells, body #potions { gap: 4px; }
  body #potions { padding-left: 6px; }
  body #hunt { margin: 0; }
  body #chat { left: var(--safe-l); bottom: 72px; width: 210px; font-size: 10px; }
  body #chat #log { max-height: 30px; }
  body #chat:focus-within #log { max-height: 100px; }
  body #chat-input { font-size: 16px; min-height: 44px; padding: 6px; }
  body #target-frame { left: 248px; top: var(--safe-t); bottom: auto; transform: scale(.8); transform-origin: top left; }
  body #party { top: 100px; left: var(--safe-l); width: 150px; }
  body #inventory, body #journal, body #spellbook, body #friends, body #auction, body #mailbox,
  body #forge, body #trade, body #dialogue {
    position: fixed; top: var(--safe-t); bottom: var(--safe-b); left: max(var(--safe-l), calc((100vw - 880px) / 2));
    right: max(var(--safe-r), calc((100vw - 880px) / 2)); width: auto; max-width: none;
    max-height: none; transform: none; padding: 12px; z-index: 60; overflow-y: auto;
  }
  body .plaque { font-size: 21px; margin-bottom: 10px; padding-bottom: 12px; min-height: 42px; }
  body #inventory .close, body #journal .close, body #spellbook .close, body #friends .close,
  body #auction .close, body #mailbox .close, body #forge .close, body #trade .close {
    position: sticky; float: right; align-self: flex-end; flex-shrink: 0; top: 0; right: 0;
    width: 44px; height: 44px; margin: 0 0 -44px; z-index: 5;
  }
  body .btn, body .choice, body #inv-detail button, body .swatch { min-height: 44px; }
  body .swatch { min-width: 44px; }
  body #inventory { overflow: hidden; }
  body #inventory .inv-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; overflow: hidden; }
  body #inventory .inv-cols .scroll { height: 100%; overflow-y: auto; min-height: 0; }
  body #inventory .bag { grid-template-columns: repeat(5,minmax(44px,1fr)); }
  body #inventory .item { min-width: 44px; min-height: 44px; }
  body #inv-detail { position: absolute; inset: 0; width: auto; max-height: none; z-index: 6; padding: 16px;
    border: 0; overflow-y: auto; }
  body #inventory:has(#inv-detail:not([hidden])) > :not(#inv-detail) { visibility: hidden; }
  body #inv-detail .btns { position: sticky; bottom: -16px; margin: 12px -16px -16px; padding: 10px 16px;
    background: #12242a; border-top: var(--edge); z-index: 2; }
  body #inv-detail .shut { order: -1; }
  body #dialogue { max-width: 680px; margin: 0 auto; }
  body.inv-open #auction, body.inv-open #forge, body.inv-open #trade {
    top: var(--safe-t); bottom: var(--safe-b); left: var(--safe-l); right: 54%; width: auto; max-height: none; max-width: none;
  }
  body.inv-open:has(#auction:not([hidden])) #inventory,
  body.inv-open:has(#forge:not([hidden])) #inventory,
  body.inv-open:has(#trade:not([hidden])) #inventory { top: var(--safe-t); bottom: var(--safe-b); left: 47%; right: var(--safe-r); width: auto; }
  body.inv-open:has(:is(#auction,#forge,#trade):not([hidden])) #inventory .inv-cols { grid-template-columns: 1fr; overflow-y: auto; }
  body.inv-open:has(:is(#auction,#forge,#trade):not([hidden])) #inventory .scroll { height: auto; overflow: visible; }
  body.inv-open:has(:is(#auction,#forge,#trade):not([hidden])) #inventory .inv-side { order: -1; }
  body:has(:is(#inventory,#journal,#spellbook,#friends,#auction,#mailbox,#forge,#trade,#dialogue):not([hidden]))::before {
    content: ''; position: fixed; inset: 0; background: #06131cb8; z-index: 55;
  }
  body #game-menu { z-index: 70; }
  body .menu-box { width: 520px; padding: 16px; max-height: calc(100dvh - 16px); overflow-y: auto; }
  body .menu-tools { grid-template-columns: repeat(4,1fr); padding: 4px 0; }
  body #settings { z-index: 80; }
  body #settings .settings-box { padding: 16px; }
  body #editor { top: var(--safe-t); bottom: var(--safe-b); right: var(--safe-r); left: auto; width: 380px; max-height: none; padding: 14px; overflow-y: auto; }
  body #editor .actions { position: sticky; bottom: -14px; background: #12242a; padding: 10px 0; z-index: 2; }
  body #select { padding: 14px var(--safe-l); flex-direction: row; align-items: center; justify-content: space-evenly; gap: 24px; }
  body .select-brand { width: 34%; margin: 0; }
  body .select-title { font-size: 38px; }
  body .select-box { width: 440px; max-height: calc(100dvh - 28px); overflow-y: auto; padding: 14px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  body #inventory .bag { grid-template-columns: repeat(auto-fill, minmax(44px, 52px)); gap: 6px; }
  body .doll { grid-template-columns: 44px 1fr 44px; }
  body .doll .col { gap: 5px; }
  body .doll .col .item { width: 44px; height: 44px; }
  body #doll-icon { max-height: 170px; object-fit: contain; }
  body #inv-detail .btns .shut { flex: 0 0 auto; min-width: 88px; }
}

/* Thumb fan: attack at the anchor, four abilities along its outer arc. */
@media (orientation: landscape) and (max-height: 600px) {
  body #hud { width: 174px; padding: 4px 6px; background: #11252bd0; border-color: #bca36b25; }
  body .hud-main { gap: 7px; }
  body #hud-portrait { width: 26px; height: 32px; border: 0; background: none; }
  body #hud-icon { width: 39px; height: 46px; left: -6px; top: -7px; }
  body #hud-level { font-size: 9px; padding: 1px 3px; left: -2px; bottom: -2px; }
  body .hud-side { width: 126px; gap: 3px; }
  body #hud-name { font: 12px/1.1 var(--body); }
  body #hud-class { width: 13px; height: 13px; }
  body .hud-who { margin-bottom: 0; }
  body .hud-info { margin: 4px 0 0 33px; gap: 5px; }
  body .hud-info .chip { font-size: 8px; padding: 0; }
  body .hbar .track { height: 9px; }
  body .hbar.mana .track { height: 7px; }
  body .hbar .track>span, body .hbar.mana .track>span { font-size: 8px; }
  body #target-frame { left: 196px; }
  body #cam-turn { gap: 4px; margin-top: -2px; }
  body #cam-turn button { width: 30px; height: 28px; min-width: 0; min-height: 0; padding: 0;
    font-size: 15px; border-color: #bca36b30; background: #11252ba8; box-shadow: none; }
  body .map-info .chip { font: 400 9px/1.3 var(--body); color: #b5c2bb; padding: 2px 4px;
    border: 0; background: #10232b70; box-shadow: none; text-shadow: 0 1px 2px #000; }
  body .map-info .chip b, body .map-info .chip span { font-weight: 400; }
  body .map-info .picto { width: 11px; height: 11px; }
  body #chat { width: 168px; bottom: 70px; font-size: 9px; opacity: .8; }
  body #chat #log { max-height: 24px; font-size: 9px; line-height: 1.3; }
  body #chat-input { min-height: 28px; height: 28px; padding: 4px 7px; border-width: 1px; background: #10232b90; font-size: 12px; }
  body #chat:focus-within { width: min(320px, 48vw); opacity: 1; z-index: 10; }
  body #chat:focus-within #log { max-height: 90px; font-size: 12px; }
  body #chat-input:focus { min-height: 40px; height: 40px; font-size: 16px; }
  body #actions { width: 230px; height: 166px; padding: 0; border: 0; background: none; box-shadow: none;
    pointer-events: none; overflow: visible; }
  body #actions .slots { position: relative; width: 100%; height: 100%; display: block; }
  body #actions .skill, body #actions .spell, body #actions .potion { pointer-events: auto;
    border-radius: 50%; box-shadow: 0 3px 10px #06131c70, inset 0 1px #fff2; touch-action: manipulation; }
  body #actions #attack-slot { position: absolute; left: 166px; top: 96px; width: 64px; height: 64px;
    background: radial-gradient(circle at 40% 30%, #456a62, #163139 75%); border: 2px solid #cfb67f; }
  body #attack-slot .picto { width: 42px; height: 42px; }
  body #spells { display: contents; }
  body #actions .spell { position: absolute; width: 46px; height: 46px; min-width: 46px; }
  body #spells .spell:nth-child(1) { left: 74px; top: 116px; }
  body #spells .spell:nth-child(2) { left: 82px; top: 62px; }
  body #spells .spell:nth-child(3) { left: 126px; top: 14px; }
  body #spells .spell:nth-child(4) { left: 180px; top: 0; }
  body #actions .spell .sp3d { width: 34px; height: 34px; }
  body #actions .spell .cost { top: 5px; right: 6px; font-size: 8px; }
  body #actions .spell .lock { font-size: 9px; padding-bottom: 7px; }
  body #potions { position: absolute; left: 16px; bottom: 4px; display: flex; flex-direction: column; gap: 8px; padding: 0; border: 0; }
  body #actions .potion { width: 40px; height: 40px; min-width: 40px; }
  body #actions .potion .sp3d { width: 28px; height: 28px; }
  body #actions #hunt { position: absolute; left: 18px; top: 20px; width: 28px; height: 28px; min-width: 28px; opacity: .75; pointer-events: none; }
  body #hunt-icon { width: 22px; height: 22px; }
  body #xpline { left: 76px; right: 2px; bottom: -3px; height: 2px; opacity: .65; }
  body #action-hint { left: auto; right: 0; bottom: 174px; transform: none; max-width: 240px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  body #actions #potions .potion { position: relative; inset: auto; flex: none; }
  body .map-info .chip.zone, body #zone { font: 400 9px/1.3 var(--body); color: #b5c2bb; }
}
