/* style.css, part 4 of 13: reflow at narrow widths (WCAG 1.4.10).
   A contiguous range of the pre-M7 style.css, linked from index.html in
   source order so the cascade is unchanged; see src/tokens.css. */

/* ============================================================
   REFLOW (quality bar row E4 — 1.4.10 Reflow, and row D1).

   400 % zoom on a 1280 px screen is a 320 px CSS viewport, so the same
   breakpoint that serves a phone has to serve a zoomed desktop: the layout
   goes to one column and nothing may scroll sideways. The sidebar's
   `clamp(500px, …)` floor is what used to force horizontal scrolling, so
   it is capped by the viewport at every width, not only under 768 px.
   ============================================================ */
.sidebar { max-width: 100vw; }

@media (max-width: 768px) {
    body { overflow: auto; }
    #app { flex-direction: column; height: auto; min-height: 100vh; }
    .sidebar {
        width: 100%;
        flex: none;
        max-height: none;
        overflow-y: visible;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.6);
        padding: 1.25rem;
        gap: 1rem;
        order: 2;
    }
    .canvas-container {
        order: 1;
        height: 46vh;
        min-height: 320px;
        flex: none;
    }
    .logo h1 { font-size: 1.8rem; }
    /* The sidebar is the page here, so its sticky children would pin to the
       document and cover the controls instead of following the stack. */
    .stack-nav { position: static; margin-left: 0; margin-right: 0; }
    /* The viewport is only 46vh here, so the dock is folded by default (see
       src/export-dock.js) and its pill is tucked in tighter. The strip needs
       no width rule — it already spans the canvas, and its two columns wrap
       to one on their own flex-basis. */
    .export-float { left: 10px; right: 10px; bottom: 10px; }
    .export-float[data-collapsed="true"] { max-width: calc(100% - 20px); }
    /* NO `top` HERE, and that is not a style choice. The hiding mechanism is
       transform: translateY(-140%), which only clears the viewport from
       top: 0 — at top t and height h the bottom edge lands at t − 0.4h. At
       48 px and 45 px that left 30 px of a LIVE link permanently over the
       top-left of the 3D model, so a tap near the viewer corner navigated
       away from it. Both links can share top: 0; only one is ever focused. */
    .skip-link:nth-of-type(2) { left: 0; }
}

/* Very narrow (a 320 px viewport is 1280 px at 400 % zoom): every grid that
   assumes three or four columns has to give up columns rather than overflow. */
@media (max-width: 420px) {
    .sidebar { padding: var(--space-air); }
    .shape-grid { grid-template-columns: repeat(3, 1fr); }
    .sketch-button-row, .sketch-tool-grid { grid-template-columns: repeat(2, 1fr); }
    .edge-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .edge-metrics { grid-template-columns: 1fr; }
    .artwork-piece-controls { grid-template-columns: 1fr; }
    .organic-sketch-actions { grid-template-columns: 1fr; }
    .export-dock-row { grid-template-columns: 1fr; }
    .color-row { flex-wrap: wrap; gap: 0.4rem; }
    /* The flex row is the <h2>, not the <summary> — see the summary markup
       note above. Wrapping the wrong element here left the settings summary
       squeezed to an ellipsis at 320 px instead of dropping to its own line. */
    .stack-section .section-title { flex-wrap: wrap; }
    .stack-section .section-meta { flex-basis: 100%; white-space: normal; }
    .stack-section .section-title::after { order: -1; margin-left: auto; }
    .logo h1 { font-size: 1.5rem; }
}

/* A short viewport (a laptop at 200 % zoom, or a landscape phone) cannot
   spare a permanently-parked strip at the top of the stack either. The export
   dock needs nothing here: it is capped at the canvas height and scrolls
   inside itself. */
@media (max-height: 620px) {
    .stack-nav { position: static; }
}
