/* ── Phones and tablets (touch screens only). Added 2026-10-07. ──
   Nothing here applies to a mouse/trackpad screen, so the desktop layout is unchanged.
   Loaded after the page's own styles so it can raise the sizes they set. */

@media (hover: none) and (pointer: coarse) {
  :root { --topbar-h: 56px; --chatbar-h: 50px; }

  /* top bar: one row that scrolls sideways, fading at the right edge as the hint;
     the last 48px stay empty for the account button */
  #topbar {
    gap: 12px;
    padding: 0 0 0 10px;
    border-right: 48px solid var(--panel);
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 80px), transparent calc(100% - 50px), transparent calc(100% - 48px), #000 calc(100% - 48px));
            mask-image: linear-gradient(to right, #000 calc(100% - 80px), transparent calc(100% - 50px), transparent calc(100% - 48px), #000 calc(100% - 48px));
  }
  #topbar::-webkit-scrollbar { display: none; }
  #topbar .actions { padding-right: 34px; }
  #topbar, #topbar label, .logo-text { font-size: 12px; }
  html.ct .grid-controls input[type=number], html.ct .layer-controls input[type=number] { width: 56px; height: 44px; font-size: 16px; }
  .layer-controls input[type=checkbox] { width: 22px; height: 22px; }
  .layer-controls label:has(input[type=checkbox]) { min-height: 44px; padding: 0 4px; }
  .btn, .tool-btn { min-height: 44px; }

  /* 3D view buttons */
  .view-btn { min-width: 44px; min-height: 44px; font-size: 14px; }
  #viewport-controls { gap: 6px; }
  #three-canvas { touch-action: none; }

  /* block palette */
  html.ct #block-search { height: 44px; font-size: 16px; }
  #toolbox-header { font-size: 12px; }
  #toolbox-categories { flex-wrap: nowrap; overflow-x: auto; gap: 4px; padding: 6px; scrollbar-width: none; }
  #toolbox-categories::-webkit-scrollbar { display: none; }
  .cat-btn { flex: none; min-width: 44px; min-height: 44px; font-size: 14px; padding: 2px 12px; }
  #toolbox-blocks { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .block-item { min-height: 64px; }
  .block-item span { font-size: 12px; max-width: 64px; }
  #mc-legal { font-size: 12px; }

  /* AI chat: a full-width bar along the bottom that opens as a sheet */
  #main { bottom: var(--chatbar-h); }
  #chat-panel { left: 0; right: 0; width: auto; height: min(60vh, 420px); border-left: 0; border-right: 0; }
  #chat-panel:not(.chat-open) { height: var(--chatbar-h); }
  #chat-header { min-height: calc(var(--chatbar-h) - 2px); }
  .chat-title { font-size: 12px; }
  /* keep the buttons clear of the small Privacy link the account script puts in the bottom-right corner */
  .chat-header-btns { margin-right: 66px; }
  #chat-input-row { padding-right: 74px; }
  .chat-header-btns button { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  html.ct #chat-input { min-height: 44px; font-size: 16px; }
  #chat-send { min-width: 44px; min-height: 44px; }
  html.ct #chat-settings input { min-height: 44px; font-size: 16px; }
}

/* portrait: 3D view on top, block palette underneath */
@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  #main { flex-direction: column; }
  #viewport { flex: 1 1 42%; min-height: 0; }
  #toolbox { width: auto; flex: 1 1 58%; min-height: 0; border-left: 0; border-top: 2px solid var(--border); }
}

/* landscape: palette stays on the right, a little wider */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #toolbox { width: 240px; }
  /* short screen: the whole palette scrolls, so the blocks are not squeezed to nothing */
  #toolbox { overflow-y: auto; }
  #toolbox-blocks { flex: none; overflow: visible; }
}
