/* ==========================================================================
   zz_studio_preview_scale.css — the studio preview stage scaled as a whole
   (UX backlog 3.2 / D-8 on the phone, 2026-09-14; generalised to every width by
   3.4 stage 4 / finding F-3.4-2, 2026-09-15; the height budget below is 4.3 /
   D-64, 2026-09-15).

   `assets/studio_preview_scale.js` measures the stage's layout box (the build
   viewport — the inline width written by
   pages/new_content/callbacks/preview_shell.py) against its wrap
   (.sp-preview-stage-wrap = min(column, build width)) and, when the render must
   shrink to fit, writes on the wrap the class `sp-preview-scaled` plus
     --sp-preview-scale            the factor (≤ 1)
     --sp-preview-stage-clamp-h    the scaled height (a transform keeps the layout
                                   box, so the wrap is clamped to the visual height)
     --sp-preview-stage-offset-x   centres a height-capped stage in a wider wrap
   With the class absent nothing here changes the geometry — an unscaled stage
   (the build width fits the column) carries no transform at all. The fullscreen
   shell (`.is-open`) is excluded: it builds for the measured viewport.

   --sp-preview-height-reserve (4.3 / D-64) is the second half of that measure: the
   px of the FIRST SCREEN below the stage that are NOT the stage — the transport bar,
   the figure card's own bottom padding, the fixed overlays of the band, and a little
   breathing room. The script caps the stage at
       viewport height − the stage's layout top − this reserve
   so the play bar is always on screen, on every width. It replaces the phone-only
   "at most 50 % of the viewport height" constant of 3.2 (D-8), which on a 390×844
   phone left the stage 237 px wide inside a 352 px column while the Export band ate
   the bottom of the screen (measured, tmp/ux_4_3/probe.py `ux43_before`).
   Per band, matching what actually sits below the stage — and only where "the first
   screen" is a meaningful frame at all. A value the script cannot parse as px (`none`)
   means NO height cap, exactly as before 4.3.
   ========================================================================== */

#new-content-shell .sp-preview-stage-wrap {
  /* ≥1181 (desktop): transport bar 58 + figure-card padding ~24 + breathing 24.
     The Export CTA is pinned to the right panel's box there, never under the canvas. */
  --sp-preview-height-reserve: 106px;
}

/* 641–1180 (tablet): the panels STACK — the inspector is below the canvas and the page
   is one long scroll, so there is no first screen to fit and a budget here would only
   shrink the stage inside a wide column (measured at 1024×800 and 700×900: 219 px and
   178 px wide). This band keeps the pre-4.3 behaviour: fit the width, never the height. */
@media (max-width: 1180px) {
  #new-content-shell .sp-preview-stage-wrap {
    --sp-preview-height-reserve: none;
  }
}

/* ≤640 (phone): surface gap 4 + transport 58 (its 6px margin-top zeroed) + the
   canvas column's 8px bottom padding + bottom nav 57 + 3 breathing = 130.
   No Export band here since 4.3 / D-63 — the CTA is a pill in the studio topbar
   (assets/zz_studio_export_cta.css), which is what buys the stage its extra height.
   UX 4.4 (2026-09-15): 140 → 130. The 140 budgeted chrome the phone column does not
   actually draw — measured at 390×844 the stage's 502px left 14px of pure air between
   the figure card and the transport and 3px below the column (tmp/ux_4_4/probe.py
   `ux44_before`); the phone band removes that air, this is its half. */
@media (max-width: 640px) {
  #new-content-shell .sp-preview-stage-wrap {
    --sp-preview-height-reserve: 130px;
  }
}

/* the wrap is clamped to the scaled height; overflow hidden also makes the flex
   item's automatic minimum 0, so the clamp wins in the column */
#new-content-shell .sp-preview-fullscreen-shell:not(.is-open) .sp-preview-stage-wrap.sp-preview-scaled {
  max-height: var(--sp-preview-stage-clamp-h, none);
  min-height: 0;
  overflow: hidden;
}

/* the whole stage scaled from its top-left corner (the layout box starts at the
   wrap's left edge and overflows it — the translate centres the visual box); the
   graph, the overlays and the editor boxes inside keep their native layout size */
#new-content-shell .sp-preview-fullscreen-shell:not(.is-open) .sp-preview-stage-wrap.sp-preview-scaled > #retail-graph-stage {
  transform: translateX(var(--sp-preview-stage-offset-x, 0px)) scale(var(--sp-preview-scale, 1));
  transform-origin: top left;
}
