.phone-only { display: none; }
.nav-item > i { align-items: center; }
.nav-item > .desktop-only:is(i) { display: flex; }

@media (max-width: 700px), (max-width: 960px) and (max-height: 500px) and (pointer: coarse) {
  #root {
    --map-top: calc(54px + env(safe-area-inset-top));
    --map-bottom: calc(62px + env(safe-area-inset-bottom));
    --sheet-edge: max(14px, env(safe-area-inset-left));
    --sheet-right: max(14px, env(safe-area-inset-right));
    --portrait-size: 58px;
    position: relative;
    min-height: 0;
    isolation: isolate;
  }
  .phone-only { display: inline-flex; }
  .topbar .desktop-only, .topbar .nav-item > i.desktop-only { display: none; }
  .workbench, .map-block { position: absolute; inset: 0; }
  .workbench { display: block; padding: 0; }
  .map-block { border: 0; border-radius: 0; }
  .topbar {
    position: absolute; inset: 0 0 auto; z-index: 3;
    height: var(--map-top);
    padding: env(safe-area-inset-top) var(--sheet-right) 0 var(--sheet-edge);
    background: var(--bar);
  }
  .brand img { width: auto; height: 46px; }
  .topbar .utilities { margin-left: auto; gap: 2px; }
  .topbar .guide-button { align-items: center; justify-content: center; width: 44px; min-height: 44px; }
  .topbar .net.offline { display: inline-flex; gap: 4px; }
  .topbar nav {
    position: fixed; inset: auto 0 0; z-index: 3;
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
    height: var(--map-bottom); margin: 0;
    padding: 4px var(--sheet-right) calc(4px + env(safe-area-inset-bottom)) var(--sheet-edge);
    background: var(--bar); border-top: var(--hair);
  }
  .topbar .nav-item {
    position: relative; flex-direction: column; gap: 2px;
    padding: 4px; min-width: 44px; min-height: 44px; background: transparent;
  }
  .topbar .nav-item[aria-current="page"]::before {
    content: ""; position: absolute; inset: -4px auto auto; width: 32px; height: 3px;
    border-radius: 0 0 var(--r1) var(--r1); background: var(--accent);
  }
  .nav-item svg { width: 20px; height: 20px; }
  .topbar .nav-item span { position: static; clip-path: none; width: auto; height: auto; font-size: 13px; }
  .foot { display: none; }
  .cartouche { top: calc(var(--map-top) + 14px); left: var(--sheet-edge); }
  .north { top: calc(var(--map-top) + 15px); right: var(--sheet-right); }
  .map-caption { top: calc(var(--map-top) + 77px); left: var(--sheet-edge); }
  .map-tools { top: calc(var(--map-top) + 69px); bottom: auto; right: var(--sheet-right); }
  .map-tools button { width: 44px; height: 44px; }
  .map-scale { right: var(--sheet-right); bottom: calc(var(--map-bottom) + 14px); }

  #map-overlay { left: var(--sheet-edge); bottom: calc(var(--map-bottom) + 12px); }
  #map-overlay:empty { display: none; }
  .map-portrait {
    display: grid; place-items: center; position: relative;
    width: var(--portrait-size); height: var(--portrait-size); padding: 2px;
    border: 2px solid var(--kind); border-radius: 50%; background: var(--bar);
    box-shadow: var(--shadow);
  }
  .map-portrait .avatar { width: 100%; height: 100%; border-radius: 50%; object-position: 50% 32%; }
  .portrait-badge {
    position: absolute; right: -4px; bottom: -1px;
    width: 23px; height: 23px; display: grid; place-items: center;
    background: var(--kind); border: 2px solid var(--bar); border-radius: 50%; color: var(--ink);
  }

  .desk { display: none; position: absolute; z-index: 2; overscroll-behavior: contain; }
  [data-mobile-view="contacts"] .desk, [data-mobile-view="journal"] .desk {
    display: block; inset: var(--map-top) 0 var(--map-bottom);
    background: var(--bg); border: 0; border-radius: 0;
  }
  #desk-content { min-height: 0; padding: 20px var(--sheet-right) 20px var(--sheet-edge); }
  .desk .type-chip svg { display: inline; }
  .desk-intro .dispatch-filters { margin-block: 8px 0; }
  .desk-intro .random { min-height: 44px; }
  .contact-list { grid-template-columns: 1fr; }
  .directory-row { position: relative; background: var(--card); border: var(--hair); border-radius: var(--r2); }
  .directory-row .contact-card {
    display: flex; align-items: center; width: calc(100% - 46px); gap: 12px;
    border: 0; padding: 9px; background: transparent;
  }
  .directory-row .contact-card > .avatar { width: 49px; height: 52px; border-radius: var(--r2); }
  .directory-row .contact-copy { gap: 3px; padding: 0; }
  .directory-row strong { font-size: 21px; }
  .directory-row .type-chip, .directory-row .contact-copy small { font-size: 12px; }
  .contact-about summary {
    position: absolute; right: 1px; top: 10px; width: 44px; height: 44px;
    display: grid; place-items: center; color: var(--secondary); cursor: pointer;
  }
  .contact-about summary::-webkit-details-marker { display: none; }
  .contact-about summary:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; }
  .contact-about > div { border-top: var(--hair); padding: 12px; font-size: 14px; line-height: 1.55; }
  .contact-about > div strong { font: 700 14px var(--body); }
  .contact-about p { color: var(--secondary); margin-top: 4px; }

  [data-mobile-view="thread"] .desk {
    display: block; left: var(--sheet-edge); right: var(--sheet-right);
    bottom: calc(var(--map-bottom) + var(--portrait-size) + 22px);
    max-width: 23rem; max-height: min(49%, 26rem); border-radius: var(--r3);
    background: var(--card); box-shadow: var(--shadow); scroll-padding: 8px;
  }
  [data-mobile-view="thread"]::after {
    content: ""; position: absolute; z-index: 2; pointer-events: none;
    left: calc(var(--sheet-edge) + 22px); bottom: calc(var(--map-bottom) + var(--portrait-size) + 16px);
    width: 12px; height: 12px; background: var(--card); transform: rotate(45deg);
    border-right: var(--hair); border-bottom: var(--hair);
  }
  [data-mobile-view="thread"] #desk-content { padding: 9px 14px 12px; }
  [data-mobile-view="thread"] .message { margin: 0; padding: 0; background: transparent; border: 0; }
  [data-mobile-view="thread"] .message header { min-height: 36px; font-size: 14px; }
  .bubble-close { width: 44px; height: 44px; margin: -6px -6px -5px auto; color: var(--secondary); }
  [data-mobile-view="thread"] .message p { font-size: 16px; line-height: 1.5; margin: 4px 0 8px; }
  [data-mobile-view="thread"] .thread-actions { margin: 12px 0 0; }
  [data-mobile-view="thread"] .thread-actions button { min-height: 44px; }
  [data-mobile-view="thread"] .reply { margin: 8px 0; }
  #toast { top: calc(var(--map-top) + 12px); bottom: auto; }
}
@media (max-height: 500px) and (pointer: coarse) and (max-width: 960px) {
  #root { --portrait-size: 46px; --map-bottom: calc(50px + env(safe-area-inset-bottom)); }
  [data-mobile-view="thread"] .desk { max-width: min(26rem, 65%); max-height: calc(100% - var(--map-top) - var(--map-bottom) - 85px); }
  .map-tools { top: calc(var(--map-top) + 42px); }
}
