/* ============ Touch screens and phones ============ */
#addBtn, #scrim { display: none; }
#canvas { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* any touch screen: a "+" button stands in for Tab */
@media (pointer: coarse) {
  #addBtn { display: inline-grid; color: var(--accent); }
  [data-tip]::after { display: none !important; } /* hover tooltips would stick after a tap */
}

@media (max-width: 640px) {
  /* the side cards float over the map instead of narrowing it */
  body, body.sb-collapsed, body.panel-open { --li: 0px; --ri: 0px; }
  #addBtn { display: inline-grid; color: var(--accent); }
  .resizer { display: none; }

  /* projects: a drawer with a scrim behind it */
  #sidebar {
    left: 8px; top: calc(8px + env(safe-area-inset-top)); bottom: calc(8px + env(safe-area-inset-bottom));
    width: min(300px, calc(100vw - 56px)); z-index: 40;
  }
  #scrim {
    display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(10, 12, 18, .32);
    opacity: 1; transition: opacity .3s;
  }
  body.sb-collapsed #scrim { opacity: 0; pointer-events: none; }
  #sbOpen { left: 10px; top: calc(10px + env(safe-area-inset-top)); }

  /* a note opens as a sheet from the bottom; the map stays visible above it */
  #panel {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 70dvh;
    border-radius: 20px 20px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(calc(100% + 20px)); opacity: 1;
  }
  #panel.open { transform: none; }
  #panel::before { left: 50%; right: auto; width: 40px; margin-left: -20px; top: 7px; height: 4px; border-radius: 4px; opacity: .45; background: var(--text-3); }
  .panel-head { padding-top: 16px; touch-action: none; } /* the grab bar: swipe down closes the card */
  #panel.sheet-drag { transition: none; }
  .link-input { font-size: 16px; height: 32px; } /* under 16px iOS zooms the whole page on focus */

  /* toolbar: pinch replaces the zoom buttons, the shortcut list makes no sense without keys */
  #toolbar { bottom: calc(10px + env(safe-area-inset-bottom)); max-width: calc(100vw - 16px); }
  #zoomOut, #zoomIn, #zoomLabel, #helpBtn { display: none; }
  #toolbar .icon-btn { width: 38px; height: 38px; }
  .tb-sel .sel-count { display: none; }

  /* top row: projects button on the left, view switch on the right */
  #viewSwitch { top: calc(10px + env(safe-area-inset-top)); right: 10px; }
  #viewSwitch button, #viewSwitch .seg-thumb { width: 70px; }
  #viewSwitch button svg.i { display: none; } /* four views: the labels alone fit */
  #filterPill { top: calc(60px + env(safe-area-inset-top)); max-width: calc(100vw - 24px); }
  #gantt { left: 8px; right: 8px; top: calc(58px + env(safe-area-inset-top)); bottom: calc(64px + env(safe-area-inset-bottom)); --gl: 150px; }
  .g-top, body.sb-collapsed .g-top { padding: 0 10px; gap: 6px; }
  .g-top .g-btn span { display: none; }
  #ganttScale button, #ganttScale .seg-thumb { width: 58px; }
  .g-meta { display: none; }
  #searchBar { bottom: calc(62px + env(safe-area-inset-bottom)); }
  #toasts { bottom: calc(64px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); }
  #hint { max-width: calc(100vw - 32px); }

  /* 16px inputs keep iOS from zooming the page on focus */
  input, textarea, #pBody, .p-title, #searchInput { font-size: 16px; }
  .modal { max-height: calc(100dvh - 24px); overflow: auto; }
}
