/* The phone layout, laid out as old-school mobile is: the game fills the screen,
   the tabs run down both edges and open over it, and the minimap sits top right.
   Every rule here needs body.mobile, which only a phone is given, so the desktop
   page is untouched. */

.mobile-only { display: none; }
body.mobile button.mobile-only { display: block; }

body.mobile {
  --left: env(safe-area-inset-left, 0px);
  --right: env(safe-area-inset-right, 0px);
  --below: env(safe-area-inset-bottom, 0px);
  --top: env(safe-area-inset-top, 0px);
  --edge: 46px; /* a column of tabs and the gap beside it */
  --side-panel: 206px;
  touch-action: manipulation; overscroll-behavior: none;
  -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
body.mobile #game { touch-action: none; }
body.mobile main { right: 0; left: 0; }
body.mobile aside { display: contents; }
body.mobile #hover, body.mobile #fps, body.mobile .mapzoom, body.mobile #expand, body.mobile #hotkeysOpen { display: none; }
/* Phones zoom in on a box with small writing in it. */
body.mobile input:not([type="range"]) { font-size: 16px; }

/* ---------- top right: the minimap ---------- */
body.mobile #mapbox { position: fixed; z-index: 3; top: calc(var(--top) + 3px); right: calc(var(--right) + 6px); margin: 0; }
body.mobile #minimap { width: 112px; height: 112px; border-width: 3px; }
body.mobile #compass { top: -2px; left: -12px; width: 36px; height: 36px; }
body.mobile #compass canvas { width: 36px; height: 36px; }

/* ---------- top left: the orbs ---------- */
body.mobile #orbs { position: fixed; z-index: 3; top: calc(var(--top) + 4px); left: calc(var(--left) + var(--edge) + 4px); gap: 5px; }
body.mobile .orb { width: 38px; height: 38px; }
body.mobile .orb canvas { width: 24px; height: 24px; }
body.mobile #online { position: fixed; z-index: 1; top: calc(var(--top) + 120px); right: calc(var(--right) + var(--edge) + 4px); font-size: 10px; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000; padding: 5px 6px; margin-top: -5px; }

/* ---------- the tabs, down both edges ---------- */
body.mobile #tabs, body.mobile #tabs2 { position: fixed; z-index: 7; bottom: calc(var(--below) + 3px); width: 42px; margin: 0; padding: 2px; flex-direction: column; gap: 1px; border: 2px solid #1e1a14; border-radius: 6px; background: #2b251dd9; }
body.mobile #tabs button, body.mobile #tabs2 button { flex: none; height: min(40px, calc((100vh - 140px) / 5)); height: min(40px, calc((100dvh - 140px) / 5)); border: 1px solid #1e1a14; border-radius: 4px; }
body.mobile #tabs { right: calc(var(--right) + 2px); }
body.mobile #tabs2 { left: calc(var(--left) + 2px); }
body.mobile .tabs canvas { max-height: 100%; width: auto; }
/* The left column has the chat button above it, so there is room to spare. */
body.mobile #tabs2 button { height: min(40px, calc((100vh - 70px) / 5)); height: min(40px, calc((100dvh - 70px) / 5)); }
body.mobile #chatToggle { position: fixed; z-index: 7; top: calc(var(--top) + 4px); left: calc(var(--left) + 2px); width: 42px; height: 40px; display: grid; place-items: center; padding: 0; background: linear-gradient(#5c5142, #40382c); border: 2px solid #1e1a14; border-radius: 6px; }
body.mobile #chatToggle canvas { width: 28px; height: 28px; }
body.mobile.chatting #chatToggle { background: linear-gradient(#9c3b2c, #6a2318); }

/* ---------- the panel a tab opens ---------- */
body.mobile:not(.drawer) #panel, body.mobile:not(.drawer) #footer { display: none; }
body.mobile #panel, body.mobile #footer {
  position: fixed; z-index: 7; flex: none; width: var(--side-panel);
  bottom: calc(var(--below) + 3px); right: calc(var(--right) + var(--edge) + 2px);
  height: min(380px, calc(100vh - 6px)); height: min(380px, calc(100dvh - 6px)); min-height: 0;
  overscroll-behavior: contain;
}
/* A panel on the left stops short of the orbs. */
body.mobile.drawer-left #panel, body.mobile.drawer-left #footer {
  right: auto; left: calc(var(--left) + var(--edge) + 2px);
  height: min(380px, calc(100vh - 50px - var(--top))); height: min(380px, calc(100dvh - 50px - var(--top)));
}
body.mobile #panel.inventory { grid-template-rows: repeat(7, minmax(30px, 36px)); }
body.mobile #panel.inventory > .slot { min-height: 0; padding: 0; }
body.mobile #panel.inventory > .slot canvas { max-height: 100%; width: auto; }
body.mobile .belt { margin-top: 3px; }
body.mobile #footer { gap: 6px; padding: 8px; }
body.mobile #praybar { position: fixed; z-index: 2; bottom: calc(var(--below) + 3px); right: calc(var(--right) + var(--edge) + 4px); margin: 0; background: none; border: 0; pointer-events: none; }
body.mobile #praybar .none { display: none; }
body.mobile #praybar button { pointer-events: auto; flex: none; width: 36px; }

/* ---------- chat: a few lines along the bottom until it is opened ---------- */
body.mobile #chat, body.mobile #chatForm, body.mobile #chatTabs { position: absolute; left: calc(var(--left) + var(--edge) + 4px); width: min(440px, calc(100% - var(--left) - var(--right) - 100px)); margin: 0; }
body.mobile:not(.chatting) #chatForm, body.mobile:not(.chatting) #chatTabs { display: none; }
body.mobile:not(.chatting) #chat { z-index: 1; bottom: calc(var(--below) + 3px); width: min(340px, calc(100% - var(--left) - var(--right) - 150px)); height: 46px; padding: 1px 6px; overflow: hidden; font-size: 10px; line-height: 14px; background: #cbb98fb0; border: 0; border-radius: 4px; pointer-events: none; }
body.mobile:not(.chatting) #chat button { pointer-events: auto; }
/* Opened, it sits at the top, clear of the keyboard. */
body.mobile.chatting #chatForm { z-index: 5; top: calc(var(--top) + 46px); bottom: auto; }
body.mobile.chatting #chat { z-index: 5; top: calc(var(--top) + 86px); bottom: auto; height: min(150px, calc(100vh - 160px - var(--top))); height: min(150px, calc(100dvh - 160px - var(--top))); font-size: 12px; background: #cbb98ff2; touch-action: pan-y; }
body.mobile.chatting #chatTabs { z-index: 5; top: calc(var(--top) + 86px + min(150px, 100vh - 160px - var(--top)) + 3px); top: calc(var(--top) + 86px + min(150px, 100dvh - 160px - var(--top)) + 3px); bottom: auto; }
body.mobile.chatting #chatTabs { display: grid; grid-template-columns: repeat(10, auto); gap: 2px; }
body.mobile.chatting #chatTabs button { min-width: 0; padding: 5px 0; font-size: 9px; }
/* The open chatbox shows the same lines. */
body.mobile.chatting #pmbox { display: none; }
body.mobile #chatName { margin: 0; }

/* ---------- what floats over the view ---------- */
body.mobile #pmbox { left: calc(var(--left) + var(--edge) + 4px); bottom: 54px; max-width: calc(100% - var(--left) - var(--right) - 100px); }
body.mobile #cluetrack:not([hidden]) ~ #pmbox { bottom: 112px; }
body.mobile #pmbox button { font-size: 11px; }
body.mobile #chat button.pm { pointer-events: auto; }
body.mobile #onlinebox li .choice { padding: 8px 10px; }
body.mobile #banner, body.mobile #foe { top: calc(var(--top) + 48px); left: calc(var(--left) + var(--edge) + 4px); }
body.mobile #boosts { top: calc(var(--top) + 48px); left: calc(var(--left) + var(--edge) + 4px); max-width: 45%; }
body.mobile #foe:not([hidden]) ~ #boosts { top: calc(var(--top) + 130px); }
body.mobile #slayertrack, body.mobile #cavetrack, body.mobile #barrowstrack { right: calc(var(--right) + 136px); max-width: 34%; font-size: 11px; }
body.mobile #slayertrack, body.mobile #cavetrack { top: calc(var(--top) + 84px); }
body.mobile #barrowstrack { top: calc(var(--top) + 112px); }
body.mobile #slayertrack[hidden] ~ #barrowstrack { top: calc(var(--top) + 84px); }
body.mobile #cluetrack { left: calc(var(--left) + var(--edge) + 4px); bottom: 54px; max-width: 55%; }
body.mobile #update { left: calc(var(--left) + var(--edge) + 4px); bottom: 100px; }
body.mobile #wild { right: calc(var(--right) + var(--edge) + 4px); bottom: 46px; }
body.mobile #news { top: calc(var(--top) + 112px); }
body.mobile #levelup { bottom: 54px; max-height: 60%; z-index: 8; }
body.mobile #amount { top: calc(var(--top) + 18%); bottom: auto; z-index: 9; }
body.mobile #amount input { display: inline-block; vertical-align: middle; }
body.mobile #amount button.mobile-only { display: inline-block; vertical-align: middle; margin: 6px 0 0 6px; padding: 8px 14px; color: #fff; }

/* ---------- windows: bank, shop and the rest ---------- */
body.mobile #window, body.mobile #window.book, body.mobile #window.dressing {
  position: fixed; z-index: 6; inset: calc(var(--top) + 3px) calc(var(--right) + var(--edge) + 2px) calc(var(--below) + 3px) calc(var(--left) + var(--edge) + 2px);
  overscroll-behavior: contain;
}
/* An open panel takes its side of the screen, and the window moves over. */
body.mobile.drawer #window { right: calc(var(--right) + var(--edge) + var(--side-panel) + 4px); }
body.mobile.drawer.drawer-left #window { right: calc(var(--right) + var(--edge) + 2px); left: calc(var(--left) + var(--edge) + var(--side-panel) + 4px); }
/* A finger dragged down the bank scrolls it. */
body.mobile .slot.movable { touch-action: pan-y; }
body.mobile .book-list { width: 112px; }
body.mobile .offers { gap: 4px; }
body.mobile .recipe { grid-template-columns: 44px 1fr auto auto auto auto; gap: 3px; }

/* ---------- menus ---------- */
body.mobile #menu { max-height: calc(100vh - 8px); max-height: calc(100dvh - 8px); max-width: calc(100vw - 8px); overflow-y: auto; overscroll-behavior: contain; font-size: 14px; }
body.mobile #menu .row { padding: 8px 12px; white-space: normal; }
body.mobile #menu .title { padding: 5px 12px; }

/* ---------- the side pages and the world map ---------- */
body.mobile.lookup-open, body.mobile.wiki-open { padding: 0; }
body.mobile #lookup, body.mobile #bosswiki { padding-top: calc(var(--top) + 8px); overscroll-behavior: contain; }
body.mobile #worldmap { padding: 0; grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
body.mobile #worldmap .sheet { width: 100%; height: 100%; padding: calc(var(--top) + 5px) 5px 5px; gap: 4px; }
body.mobile #worldmap header { gap: 4px; min-width: 0; }
body.mobile #worldmap header b { display: none; }
body.mobile #worldmap header span.places { flex-wrap: nowrap; min-width: 0; overflow-x: auto; }
body.mobile #worldmap header span.places .choice { flex: none; padding: 6px 9px; }
body.mobile .mapview p { display: none; }
body.mobile #legend { width: 130px; }

/* ---------- held upright ---------- */
@media (orientation: portrait) {
  body.mobile #banner, body.mobile #foe, body.mobile #boosts { top: calc(var(--top) + 130px); }
  body.mobile #foe:not([hidden]) ~ #boosts { top: calc(var(--top) + 212px); }
  body.mobile #slayertrack, body.mobile #cavetrack { top: calc(var(--top) + 130px); right: calc(var(--right) + 6px); max-width: 36%; }
  body.mobile #barrowstrack { top: calc(var(--top) + 176px); right: calc(var(--right) + 6px); max-width: 36%; }
  body.mobile #slayertrack[hidden] ~ #barrowstrack { top: calc(var(--top) + 130px); }
  body.mobile #news { top: calc(var(--top) + 176px); }
  body.mobile #online { right: calc(var(--right) + 6px); top: calc(var(--top) + 108px); }
  body.mobile #minimap { width: 96px; height: 96px; }
  body.mobile #orbs { gap: 3px; }
  body.mobile .orb { width: 36px; height: 36px; border-width: 2px; }
  body.mobile #hpbar span { font-size: 8px; }
  body.mobile #compass { left: -6px; width: 30px; height: 30px; }
  body.mobile #compass canvas { width: 30px; height: 30px; }
  /* There is no room side by side, so a window goes above the panel. */
  body.mobile.drawer #window, body.mobile.drawer.drawer-left #window {
    left: calc(var(--left) + var(--edge) + 2px); right: calc(var(--right) + var(--edge) + 2px); bottom: calc(var(--below) + min(380px, 55vh) + 6px);
  }
  body.mobile.drawer #panel, body.mobile.drawer #footer { height: min(380px, 55vh); }
  body.mobile #legend { width: auto; }
  body.mobile.chatting #chatTabs { grid-template-columns: repeat(5, 1fr); }
}
