/* Hootscape mobile.css — the phone layout at ≤640 px wide (DESIGN_BRIEF §3.3: 390x844 portrait reference).
   Bottom 5-tab bark bar + stone bottom sheets, 44 px touch targets, VT323 20 px minimum, no horizontal scroll.
   Landscape phones (≥640 wide) keep the compact (1280x800) arrangement from ui.css with a 240 px rail.
   Requires theme.css + ui.css + panels.css; #game is the size container (container-name: game). */

@container game (max-width: 640px) {
  /* custom properties go on #game's children: a container query never matches the container itself */
  #game > * {
    --fs-body: 20px; --fs-header: 22px; --fs-orb: 20px; --fs-min: 20px; --tile: 24px;
    --ticker-w: 272px; --ticker-h: 36px;
    --minimap-w: 96px; --minimap-h: 100px; --eye-disc: 88px; --eye-cx: 44px; --eye-cy: 52px;
    --orb: 28px; --orb-roost: 28px;
    --party-w: 190px; --party-row: 30px;
    --toast-w: 278px; --toast-h: 44px;
    --slot-w: 72px; --slot-h: 56px;
    --chat-line: 22px; --chat-tabs: 44px; --chat-input: 44px;
    --modal-w: calc(100cqw - 32px); --modal-h: auto;
    --tabbar-h: 56px; --sheet-top: 320px; --sheet-gutter: 16px;
    font-size: var(--fs-body);
  }

  /* ---- HUD ---- */
  #ticker { left: 8px; top: 8px; }
  .ticker { width: var(--ticker-w); height: var(--ticker-h); font-size: var(--fs-body); }
  #hover { left: 8px; top: 48px; width: 272px; height: 28px; display: flex; align-items: center; padding: 0 6px; background: rgba(36,30,22,.55); border: 1px solid var(--stone-lo); }
  #hover:empty { display: none; }
  .hover-text { font-size: var(--fs-body); overflow: hidden; text-overflow: ellipsis; }
  #party { left: 8px; top: 136px; width: var(--party-w); }
  #hud-minimap { left: calc(100cqw - 96px); right: auto; top: 8px; width: var(--minimap-w); height: var(--minimap-h); }
  .eye { left: 0; top: 0; }
  .compass { left: 0; top: 0; width: 24px; height: 24px; font-size: var(--fs-min); z-index: 2; }
  .btn-map, .hud-clock { display: none; }
  #orbs { left: 206px; right: auto; top: 100px; width: 176px; height: 28px; }
  #orbs .orb { top: 0; }
  #orbs .orb-hp { left: 0; } #orbs .orb-prayer { left: 37px; } #orbs .orb-run { left: 74px; } #orbs .orb-spec { left: 111px; } #orbs .orb-roost { left: 148px; top: 0; }
  .orb-fill { inset: 4px; }
  .orb-num { position: absolute; right: auto; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: 0; height: auto; padding: 0; background: none; border: 0; box-shadow: none; border-radius: 0; z-index: 2; font-size: var(--fs-orb); color: var(--txt-white); text-shadow: 1px 0 0 var(--outline-ink), -1px 0 0 var(--outline-ink), 0 1px 0 var(--outline-ink), 0 -1px 0 var(--outline-ink); }
  .orb-icon { display: none; }
  .orb-roost .orb-icon { display: flex; inset: 6px; } .orb-roost .orb-num { display: none; }
  #xpdrops { left: 50%; right: auto; top: 90px; width: 240px; transform: translateX(-50%); }
  #toasts { left: 8px; top: 8px; width: var(--toast-w); z-index: 9; }
  .toast { width: 100%; height: var(--toast-h); }

  /* ---- Rail → bottom bar + bottom sheets ---- */
  #rail { display: none; }
  #tabbar { display: flex; left: 0; right: 0; bottom: 0; width: 100%; height: var(--tabbar-h); z-index: 12; background-color: var(--bark); background-image: var(--bark-grain); border-top: 2px solid var(--bark-grain-hi); box-shadow: 0 -1px 0 var(--stone-lo); }
  #tabbar .tabbar-tab { flex: 1 1 0; min-width: 44px; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--txt-orange); font-size: var(--fs-body); line-height: 1; text-shadow: 1px 1px 0 var(--outline-ink); cursor: pointer; border-right: 1px solid var(--bark-grain-lo); -webkit-tap-highlight-color: transparent; }
  #tabbar .tabbar-tab:last-child { border-right: 0; }
  #tabbar .tabbar-tab .icon { width: 24px; height: 24px; image-rendering: pixelated; }
  #tabbar .tabbar-tab.active { color: var(--txt-yellow); background-color: var(--stone-fill); background-image: var(--noise); box-shadow: inset 0 2px 0 var(--amber); }
  #tabbar .tabbar-tab.unread::after { content: ""; position: absolute; top: 6px; right: 10px; width: 8px; height: 8px; background: var(--txt-yellow); box-shadow: 0 0 0 1px var(--outline-ink); }
  #tabbar .tabbar-tab { position: relative; }

  #sheet-root { display: block; left: 0; right: 0; top: var(--sheet-top); bottom: var(--tabbar-h); z-index: 11; pointer-events: none; }
  .sheet { position: absolute; inset: 0; display: flex; flex-direction: column; pointer-events: auto; overflow: hidden; transform: translateY(100%); transition: transform 160ms ease-out; }
  .sheet.open { transform: none; }
  .sheet-handle { flex: 0 0 24px; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; }
  .sheet-handle::before { content: ""; width: 48px; height: 6px; background: var(--bark-grain-hi); border: 1px solid var(--stone-lo); border-radius: 3px; }
  .sheet-title { flex: 0 0 32px; display: flex; align-items: center; justify-content: space-between; padding: 0 var(--sheet-gutter); font-family: var(--font-display); font-size: var(--fs-header); color: var(--txt-orange); text-shadow: 1px 1px 0 var(--outline-ink); }
  .sheet-title .btn { min-height: 32px; }
  .sheet-body { flex: 1 1 auto; min-height: 0; padding: 0 var(--sheet-gutter) 8px; overflow-y: auto; overflow-x: hidden; }
  .sheet .panel { width: 100%; height: auto; border: 0; box-shadow: none; background: none; }
  .sheet .panel-title { display: none; }
  .sheet .panel-body { height: auto; padding: 0; }
  .sheet .panel-footer { position: static; margin-top: 8px; }
  .sheet .inv-grid { grid-template-columns: repeat(4, var(--slot-w)); grid-auto-rows: var(--slot-h); }
  .sheet .slot .icon, .sheet .slot-icon { width: 48px; height: 48px; }
  .sheet .skills-grid { grid-template-columns: repeat(3, 112px); grid-auto-rows: 48px; }
  .sheet .skill-cell { padding: 0 8px; }
  .sheet .prayer-grid, .sheet .spell-grid, .sheet .emote-grid { grid-template-columns: repeat(5, 64px); grid-auto-rows: 56px; }
  .sheet .doll { transform-origin: top center; }
  .sheet .quest-list .row, .sheet .friend-row, .sheet .track-list .row, .sheet .ach-row { height: 44px; }
  .sheet .subtab { min-height: 44px; }
  .more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px 0; }
  .more-grid .more-tab { height: 88px; padding: 4px 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--txt-orange); font-size: var(--fs-body); line-height: 1; text-align: center; text-shadow: 1px 1px 0 var(--outline-ink); cursor: pointer; }
  .more-grid .more-tab:active, .more-grid .more-tab.active { color: var(--txt-yellow); border-color: var(--stone-lo) var(--stone-hi) var(--stone-hi) var(--stone-lo); }
  .more-grid .more-tab .icon { width: 32px; height: 32px; }

  /* ---- Chat: 2-line ticker above the bar; tap expands to a 50% sheet ---- */
  #chat { display: none; }
  #chat-ticker { display: flex; align-items: flex-end; left: 0; right: 0; bottom: var(--tabbar-h); width: 100%; height: 48px; z-index: 10; padding: 2px 8px; background: var(--chat-paper); border-top: 2px solid var(--stone-lo); box-shadow: inset 0 1px 0 var(--chat-paper); overflow: hidden; cursor: pointer; }
  #chat-ticker .chat-line { height: 22px; line-height: 22px; font-size: var(--fs-body); }
  #chat.open { display: flex; left: 0; right: 0; top: 50cqh; bottom: var(--tabbar-h); width: 100%; height: auto; max-height: none; z-index: 13; }
  #chat.open + #chat-ticker, #chat.open ~ #chat-ticker { display: none; }
  .chat-tabs { height: var(--chat-tabs); flex-basis: var(--chat-tabs); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .chat-tabs::-webkit-scrollbar { display: none; }
  .chat-tab { flex: 0 0 auto; min-width: 72px; padding: 0 12px; }
  .chat-input { height: var(--chat-input); flex-basis: var(--chat-input); }
  .chat-input input { font-size: var(--fs-body); }
  .chat-grip { display: none; }

  /* ---- Right-click menu as a bottom sheet (long-press 400 ms) ---- */
  #menu-root .menu { left: 0 !important; right: 0; top: auto !important; bottom: var(--tabbar-h); min-width: 0; width: 100%; max-height: 60cqh; overflow-y: auto; border-width: 2px 0 0; z-index: 30; }
  #menu-root .menu-head { height: 36px; padding: 0 16px; font-size: var(--fs-header); }
  #menu-root .menu-item { height: 44px; padding: 0 16px; border-bottom: 1px solid var(--menu-head); font-size: var(--fs-body); }
  #menu-root .menu-item:last-child { border-bottom: 0; }

  /* ---- Modals: full-width stone, dim behind, scrollable body ---- */
  #modal-root { align-items: flex-start; padding: 120px 16px 72px; }
  .modal { width: 100%; height: auto; max-height: calc(100cqh - 192px); }
  .modal-tall { height: auto; }
  .modal-body { overflow-y: auto; }
  .bank-grid, .shop-grid { grid-template-columns: repeat(4, var(--slot-w)); }
  .modal-foot { flex: 0 0 auto; padding: 8px; }
  .bank-search { flex: 1 1 100%; width: auto; }
  .ticker .ticker-route { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .inv-grid { gap: 2px 8px; margin-top: 4px; }
  .ticker .ticker-label, .ticker .ticker-count { display: none; }
  .ticker .ticker-route { flex: 1 1 auto; white-space: nowrap; }
  #xpdrops .xp-drop { left: 0; right: 0; justify-content: center; }
  /* the sheet is the stone; panels inside it are plain content (no second set of knots or a second owl) */
  .sheet .panel::before, .sheet .panel::after, .sheet .panel > .knots, .sheet .panel > .corner-owl { display: none; }
  .trade-screen { grid-template-columns: 1fr; }
  .trade-grid { grid-template-columns: repeat(4, var(--slot-w)); }
  .questscroll { width: 100%; height: auto; grid-template-columns: 1fr; }
  .questscroll-art { display: none; }
  .levelup-title { font-size: 24px; }
  .dialogue { width: 100%; height: auto; min-height: 200px; bottom: var(--tabbar-h); grid-template-columns: 72px 1fr; z-index: 13; }
  .dialogue-option { min-height: 44px; align-items: center; }
  .worldmap { padding: 0; border: 0; }
  .worldmap-title, .worldmap-close { top: 8px; }
  .worldmap-close { right: 8px; z-index: 2; }
  .worldmap-title { left: 16px; transform: none; font-size: 22px; }
  .banner { font-size: 20px; top: 24%; white-space: normal; max-width: calc(100cqw - 32px); text-align: center; }

  /* ---- Touch targets ≥ 44 px, text ≥ 20 px ---- */
  .btn { min-height: 44px; padding: 0 16px; }
  .btn-sq { width: 44px; min-width: 44px; }
  .modal-close { width: 36px; height: 36px; }
  .tab { min-width: 44px; height: 44px; }
  .subtab, .bank-tab, .chat-tab, .setting, .board-row, .planner-step, .party-list .row { min-height: 44px; }
  .check i { width: 24px; height: 24px; }
  .slider { height: 20px; }
  .slider::-webkit-slider-thumb { width: 24px; height: 32px; }
  .field { height: 44px; }
  .tooltip { font-size: var(--fs-body); max-width: calc(100cqw - 32px); }
  .menu, .menu-item, .hover-text, .chat-line, .party-member .pm-name, .party-member .pm-dist, .slot .qty, .skill-cell .lvl, .tab-key, .chat-tab .filter, .menu-item .lvl, .menu-item .key { font-size: var(--fs-body); }
  .tab-key { display: none !important; }
  .party-member { grid-template-rows: 16px 10px; height: 30px; }
  .corner-owl { right: 13px; bottom: 1px; }
}

/* Landscape phone / small tablet (641–900 wide): compact arrangement with a 240 px rail (§3.3) */
@container game (min-width: 641px) and (max-width: 900px) {
  #game > * { --rail-w: 240px; --tab-w: 34px; --tab-h: 36px; --minimap-w: 200px; --minimap-h: 176px; --eye-disc: 120px; --eye-cx: 116px; --eye-cy: 76px; --chat-w: 400px; --chat-h: 160px; --fs-body: 20px; --fs-min: 20px;
             --xp-right: 244px; --toast-x: 16px; --toast-w: calc(100cqw - var(--minimap-w) - 100px); }
  /* nine channels do not fit 400px: the tab row scrolls sideways like the phone sheet */
  .chat-tabs { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .chat-tabs::-webkit-scrollbar { display: none; }
  .chat-tab { flex: 0 0 auto; padding: 0 8px; }
  #rail { top: 216px; height: calc(100cqh - 216px); } /* compact orb column (ends y214) stays clear of the rail */
  #rail .panel { overflow-y: auto; }
  .btn-map { left: 156px; top: 136px; }
  .hud-clock { left: 156px; }
  .btn { min-height: 44px; }
}

/* Safe areas on notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  @container game (max-width: 640px) {
    #tabbar { height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
    #chat-ticker, #sheet-root, #chat.open, #menu-root .menu, .dialogue { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  }
}

/* Coarse pointers anywhere (tablets in the compact layout): keep targets tappable */
@media (pointer: coarse) {
  .btn, .menu-item, .subtab, .chat-tab { min-height: 44px; }
  .menu-item { height: auto; padding: 0 10px; }
}
