@media (max-width: 760px) {
  :root { --dock-h: 56px; }

  /* toolbar: one compact row that scrolls sideways */
  #toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.7rem;
    padding: calc(0.45rem + env(safe-area-inset-top, 0px)) 0.75rem 0.45rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar > * { flex-shrink: 0; }
  #toolbar h1 { font-size: 0.8rem; margin: 0; white-space: nowrap; }
  #toolbar .sep { height: 20px; }
  .tool-group label { font-size: 0.65rem; }
  .swatch { width: 26px; height: 26px; }
  button, .btn, .swatch, select { touch-action: manipulation; }

  /* tools: dock along the bottom (overrides any saved desktop drag position) */
  #tools-sidebar {
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    height: var(--dock-h);
    flex-direction: row;
    justify-content: space-around;
    padding: 4px 6px;
    z-index: 30;
  }
  #tools-sidebar-header { display: none; }
  #tools-sidebar .sidebar-sep { width: 1px; height: 28px; margin: 0 2px; }
  #tools-sidebar .tool-btn { width: 44px; height: 46px; }
  #fg-bg, .fgbg-sep { display: none; } /* no right-click on touch; colour comes from the top bar */
  .tool-group.mobile-color { display: flex; }
  #palette-panel { display: none !important; } /* phones use the top bar's colours */
  #history-panel { display: none !important; }
  .sep.mobile-color { display: block; }

  /* inspector: bottom sheet above the dock, opened with the gear */
  #preview-panel {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--dock-h) + 16px + env(safe-area-inset-bottom, 0px));
    width: auto;
    min-width: 0;
    max-height: 52vh;
    z-index: 25;
    border: 1px solid #2e2e2e;
    border-radius: 12px;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.6);
  }
  #inspector-collapse-btn, #inspector-collapse-btn.collapsed {
    right: 8px; top: 8px;
    width: 36px; height: 36px;
    border-radius: 8px;
    border-right: 1px solid #2e2e2e;
  }

  /* preview: compact window, top-left of the canvas area (placed by JS) */
  #preview-widget { width: 200px; }
  #preview-body { padding: 0.35rem 0.5rem 0.5rem; gap: 0.3rem; }
  #preview-win-header { padding-top: 0.25rem; padding-bottom: 0.25rem; }
  /* compact: image on the left, zoom and background controls stacked beside it */
  #preview-body {
    display: grid;
    grid-template-columns: 72px 1fr;
    grid-template-rows: auto auto;
    column-gap: 8px; row-gap: 6px;
    align-items: center;
  }
  #preview-viewport { grid-column: 1; grid-row: 1 / span 2; width: 72px; height: 72px; }
  #preview-header { grid-column: 2; grid-row: 1; gap: 4px; }
  #preview-bg-row { grid-column: 2; grid-row: 2; }
  #preview-zoom-slider { display: none; } /* − / + still zoom */
  #preview-zoom-label { font-size: 0.62rem; width: auto; flex: 1; }
  #preview-bg-row .ts-label { display: none; }
  #preview-bg-row .pv-seg { margin-left: 0; }

  /* rotation/reset pill sits at the bottom of the canvas area, clear of the preview */
  #view-badge { top: auto; bottom: 10px; }
  #view-badge.off { transform: translate(-50%, 8px); }

  /* canvas area starts right under the toolbar (its height is set to end above the dock) */
  #editor-panel { justify-content: flex-start; }

  /* the canvas handles touch itself (draw / pinch) — no page scrolling or zooming there */
  #grid-container { touch-action: none; }
  #tool-settings { max-width: calc(100vw - 16px); }
  #layers-panel.minimized { width: 150px !important; min-width: 0; } /* folded: fits beside the preview widget */
  #ts-minimize {
    display: flex; align-items: center; justify-content: center;
    margin-left: auto; width: 30px; height: 26px;
    background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 6px; color: #bbb; cursor: pointer;
  }
  #ts-minimize svg { transition: transform 0.2s; }
  #tool-settings.minimized #ts-minimize svg { transform: rotate(180deg); }
  #tool-settings.minimized .ts-section { display: none; }
  #tool-settings.minimized #tool-settings-header { margin-bottom: -0.55rem; border-bottom: none; border-radius: 8px; }
  #tool-settings.minimized { padding-bottom: 0.55rem; }
}
