/* 1TAKE Studios: app.css
   App-shell layout only (grids, panes, sticky/scroll rules). Component classes themselves (buttons, chips,
   folds, slate, sheet, option cards...) live in components.css; this file places them into each
   breakpoint's page. Colors only via var(--...) from tokens.css. No horizontal body scroll at any width:
   the shell grids use minmax(0, 1fr) for their flexible track and each scrolling pane scrolls inside itself.

   Ownership (per BUILD_CONTEXT.md and the split between the two layout agents):
   - @media (max-width: 767px)   -> mobile layout agent (public/assets/js/app/layout-mobile.js)
   - @media (min-width: 768px)   -> tablet + desktop layout agent (public/assets/js/app/layout-tablet-desktop.js)
                                     Rules here also apply at desktop widths (min-width is cumulative) unless
                                     overridden below 1181px.
   - @media (min-width: 1181px)  -> desktop-only overrides (three-pane shell), same agent as above.
*/

/* ==========================================================================================================
   MOBILE — @media (max-width: 767px)
   Owned by the mobile layout agent (layout-mobile.js). Nothing is added here by the tablet/desktop agent;
   this block is left as the clearly-marked spot for that agent's rules.
   ========================================================================================================== */
@media (max-width: 767px) {
  html, body {
    overflow-x: hidden;
  }

  .app-mobile {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  /* ---------- Header: sticky, wraps on narrow widths ---------- */
  .app-mobile #app-header {
    position: sticky;
    top: 0;
    z-index: 15;
    flex-wrap: wrap;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
  }
  .app-mobile #app-header > .label { white-space: nowrap; flex: none; font-size: 11px; }
  .app-mobile #app-header > .chip { flex: none; white-space: nowrap; }
  .app-mobile #app-header > .chip:not(.chip-accent) { display: none; }
  .app-mobile #app-header .btn { padding-inline: var(--s-2); font-size: var(--fs-1); min-height: 44px; white-space: nowrap; }
  .app-mobile #app-header #saved-btn { margin-left: auto; }
  .app-mobile #app-header #theme-toggle { display: none; }
  .app-mobile #app-header .locked-note { display: none; }

  /* ---------- The current fold: scrolls internally between header and action bar ---------- */
  .app-mobile .fold-screen {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: var(--s-4) var(--s-4) calc(var(--s-9) + 44px + env(safe-area-inset-bottom));
  }

  .app-mobile .fold-screen .fold[data-collapsed="true"] .fold-header {
    min-height: var(--tap-min);
  }

  /* Style (12 cards) and ratio (4 cards) stay inline; everything else with >4 options is lifted into a
     sheet by layout-mobile.js. Two columns for both, so 12 style cards read as a tidy grid and the 4 ratios
     land as a 2x2 block. */
  .app-mobile .fold-screen .option-grid,
  .app-mobile .fold-screen .ratio-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ---------- "Tap to choose" summary row: replaces a wrapped inline option-grid ---------- */
  .mobile-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    width: 100%;
    min-height: var(--tap-min);
    padding: var(--s-3) var(--s-4);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--r-control);
    text-align: left;
    color: var(--ink);
    transition: border-color var(--t-hover) var(--ease);
  }

  .mobile-picker-row:hover,
  .mobile-picker-row:focus-visible {
    border-color: var(--ink-2);
  }

  .mobile-picker-value {
    font-size: var(--fs-3);
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-picker-chevron {
    flex-shrink: 0;
    color: var(--muted);
    font-size: var(--fs-4);
    line-height: 1;
  }

  /* ---------- Sheet content on mobile: single-column option cards, 44px min height ---------- */
  .sheet:not([data-side="right"]) .option-grid,
  .sheet:not([data-side="right"]) .ratio-grid {
    grid-template-columns: 1fr;
  }

  .sheet:not([data-side="right"]) .option-card,
  .sheet:not([data-side="right"]) .ratio-card {
    min-height: var(--tap-min);
  }

  .sheet:not([data-side="right"]) .sheet-body {
    padding-bottom: calc(var(--s-4) + env(safe-area-inset-bottom));
  }

  /* ---------- Persistent mini "See your prompt" button (folds 0-5, once a result exists) ---------- */
  .mobile-mini-preview {
    position: fixed;
    right: var(--s-4);
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 18;
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    min-height: 36px;
    padding: var(--s-2) var(--s-4);
    background: var(--accent);
    color: var(--accent-ink);
    border: 0;
    border-radius: var(--r-pill);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--fs-2);
    box-shadow: var(--shadow-panel);
  }

  .mobile-mini-preview[hidden] {
    display: none;
  }

  /* ---------- Fold transitions (Next/Back buttons and swipe alike) ---------- */
  .fold-enter-forward {
    animation: vph-fold-in-forward 200ms var(--ease);
  }

  .fold-enter-back {
    animation: vph-fold-in-back 200ms var(--ease);
  }

  @keyframes vph-fold-in-forward {
    from { transform: translateX(16px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
  }

  @keyframes vph-fold-in-back {
    from { transform: translateX(-16px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
  }
}

/* ==========================================================================================================
   TABLET + DESKTOP — @media (min-width: 768px)
   Two-pane shell (.app-tablet): fold stack + sticky live-preview slate. Also the shared rules both the
   tablet two-pane and desktop three-pane shells use (sticky/scrolling panes, fold-ahead muting, the
   generate-under-fold button, saved-row layout, and the inline searchSelect popover fix).
   ========================================================================================================== */
@media (min-width: 768px) {
  #app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-5);
    border-bottom: 1px solid var(--rule);
    background: var(--surface);
  }

  #app-header .btn {
    margin-left: auto;
  }

  #app-header .btn + .btn {
    margin-left: 0;
  }

  .app-tablet {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
    gap: var(--s-5);
    max-width: 1180px;
    margin-inline: auto;
    padding: var(--s-5);
  }

  /* Fold stack pane: left on tablet, center on desktop. */
  .pane-folds {
    min-width: 0;
    max-width: 720px;
  }

  /* Sticky progress (ticks + "Step N of 6") pinned to the top of the fold-stack pane as it scrolls. */
  .progress-sticky {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--ground);
    padding-block: var(--s-3);
    margin-bottom: var(--s-2);
    border-bottom: 1px solid var(--rule);
  }

  /* Folds ahead of the current one: title only, muted. Behind: check + summary (handled in JS). */
  .fold-ahead {
    opacity: 0.55;
  }

  .generate-under-fold {
    display: flex;
    width: 100%;
    margin-top: var(--s-4);
  }

  /* Right pane (live preview slate on both breakpoints) and the desktop rail: both scroll inside
     themselves and stay pinned while the center column scrolls past them. */
  .sticky-pane {
    position: sticky;
    top: var(--s-4);
    max-height: calc(100vh - var(--s-4) * 2);
    overflow-y: auto;
    min-width: 0;
  }

  .pane-preview {
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
  }

  /* searchSelect's inline popover list is position:absolute; its wrapper needs a positioned ancestor
     (components.css does not set this -- only relevant on tablet/desktop, mobile renders it in a sheet). */
  .field-search-wrap {
    position: relative;
  }

  /* ---- Saved prompts: shared row layout for the desktop rail and the tablet slide-over ---- */
  .saved-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2);
    min-width: 0;
    padding: var(--s-2);
    border-radius: var(--r-control);
    transition: background-color var(--t-hover) var(--ease);
  }

  .saved-row:hover {
    background: var(--inset);
  }

  .saved-row-main {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
    flex: 1;
    text-align: left;
  }

  .saved-row-name {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    font-size: var(--fs-3);
    color: var(--ink);
  }

  .saved-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1);
    flex-shrink: 0;
  }

  /* Hover-reveal actions only where hover is a real pointer affordance; touch/tablet keeps them visible. */
  @media (hover: hover) and (pointer: fine) {
    .saved-row-actions {
      opacity: 0;
      transition: opacity var(--t-hover) var(--ease);
    }
    .saved-row:hover .saved-row-actions,
    .saved-row:focus-within .saved-row-actions {
      opacity: 1;
    }
  }
}

/* ==========================================================================================================
   DESKTOP ONLY — @media (min-width: 1181px)
   Three-pane shell (.app-desktop): saved rail + fold stack + live preview slate with Studio blocks.
   ========================================================================================================== */
@media (min-width: 1181px) {
  .app-desktop {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 420px;
    align-items: start;
    gap: var(--s-5);
    max-width: 1600px;
    margin-inline: auto;
    padding: var(--s-5);
  }

  .rail-pane {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
  }
}

/* Craft floor: 44px tap targets on every action inside the slate and sheets on touch layouts. */
@media (max-width: 767px) {
  .app-mobile .slate .btn, .app-mobile .sheet .btn, .app-mobile .sheet .btn-sm, .app-mobile .slate-actions .btn, .app-mobile .btn-ghost, .app-mobile label.chip { min-height: 44px; }
  .app-mobile .action-bar .ticks-label { white-space: nowrap; font-size: 10px; }

  /* The v3 segmented progress bar is wider than the old thin exposure ticks it replaced. At
     the narrowest supported width (~360-390px), the default .btn horizontal padding (24px a
     side, sized for a full-width buy button) leaves too little room for Back + segments +
     Next in the action bar's auto/1fr/auto grid. Tighten just these two buttons and the
     segment width so all three fit without pushing Next off-screen. */
  .app-mobile .action-bar .btn {
    padding-inline: var(--s-3);
  }
  .app-mobile .action-bar .tick {
    width: 16px;
  }
}

/* P5: app footer (Facebook group / Flow video links, commercial-use license line). */
.app-footer {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-4);
  border-top: 1px solid var(--rule);
}

.app-footer-license {
  margin: 0;
}

/* brand logo in the app header */
.app-logo { height: 26px; width: auto; display: block; flex: none; }
#app-header .app-logo { margin-right: 4px; }


/* ==========================================================================================================
   LIGHT SHELL (landing-grade): page backdrop, white frame, logo header, card rhythm. All breakpoints.
   ========================================================================================================== */
html[data-theme="light"] body, body { background: var(--page-bg, var(--ground)); }
#app { max-width: 1180px; margin: 0 auto; background: var(--surface); min-height: 100vh; box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.06), 0 30px 80px rgba(60, 20, 5, 0.10); }
@media (min-width: 1181px) { #app { border-radius: 0 0 24px 24px; margin-bottom: 32px; } }
#app-header { background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.app-logo { cursor: pointer; }
.option-card { border-radius: 14px; }
.option-card-thumb { border-radius: 10px; }
.card { border-radius: 16px; }
.fold-screen .label, .home .label { font-size: 13px; font-weight: 700; }

/* ---- Home ---- */
.home { display: flex; flex-direction: column; min-height: 100vh; }
.home #app-header { position: sticky; top: 0; z-index: 15; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-4); }
.home-spacer { flex: 1 1 auto; }
.home-wrap { padding: var(--s-4); max-width: 900px; width: 100%; margin: 0 auto; }
.home-card { padding: 18px 16px; }
.home .section-tag { display: inline-block; background: var(--badge); color: var(--badge-ink); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; padding: 4px 10px; border-radius: 20px; margin-bottom: 8px; }
.home-title { font-family: var(--font-display); font-size: 26px; font-weight: 800; line-height: 1.1; margin: 0 0 4px; letter-spacing: -0.02em; }
.home-h2 { font-family: var(--font-display); font-size: 20px; font-weight: 800; margin: 0 0 6px; }
.home-lede { margin: 0 0 14px; }
.home-form { display: flex; flex-direction: column; gap: 14px; }
.home-styles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.home-style { position: relative; padding: 0; border: 2px solid var(--rule); border-radius: 12px; overflow: hidden; background: var(--surface); cursor: pointer; font: inherit; text-align: left; }
.home-style img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.home-style span { position: absolute; left: 6px; bottom: 6px; background: rgba(255, 255, 255, 0.94); color: var(--ink); font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 20px; }
.home-style.is-on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240, 78, 35, 0.2); }
.home-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.home-actions .btn { min-height: 52px; }
.home-saved { display: grid; gap: 12px; }
.home-saved-card { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; border: 1px solid var(--rule); border-radius: 14px; padding: 10px; background: var(--surface); }
.home-saved-thumb { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; }
.home-saved-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.home-saved-body b { font-size: 15px; }
.home-saved-meta { font-size: 12px; color: var(--muted); }
.home-saved-text { font-size: 12.5px; color: var(--ink-2); margin: 0; line-height: 1.45; }
.home-quick { display: grid; gap: 10px; }
.home-quick-card { display: flex; flex-direction: column; gap: 4px; text-align: left; font: inherit; cursor: pointer; text-decoration: none; color: var(--ink); }
.home-quick-card b { font-size: 15px; }
@media (min-width: 640px) {
  .home-styles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .home-actions { flex-direction: row; }
  .home-actions .btn-primary { flex: 1; }
  .home-saved { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 860px) {
  .home-wrap { padding: 28px 36px; }
  .home-card { padding: 24px; }
  .home-title { font-size: 32px; }
  .home-styles { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* Collapsed fold rows on the phone stepper: icon, title, check, then the summary on ONE muted line.
   The old space-between layout floated the title to the middle once the icon arrived. */
@media (max-width: 767px) {
  .app-mobile .fold-header { justify-content: flex-start; gap: 10px; padding: 12px 14px; min-height: 56px; }
  .app-mobile .fold-title { flex: none; font-size: 17px; }
  .app-mobile .fold-check { flex: none; color: var(--good); font-weight: 800; }
  .app-mobile .fold[data-collapsed="true"] .fold-summary { flex: 1 1 auto; min-width: 0; text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .app-mobile .fold[data-collapsed="false"] .fold-header { min-height: 60px; }
  .app-mobile .fold[data-collapsed="false"] .fold-title { font-size: 22px; }
  .app-mobile .fold { border-bottom: 1px solid var(--rule); }
  .app-mobile .fold-ico { width: 30px; height: 30px; margin-right: 0; }
  /* Action bar: the Next/Try another label must never clip; shrink the tick rail first. */
  .app-mobile .action-bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; }
  .app-mobile .action-bar .btn { white-space: nowrap; padding-inline: 14px; }
  .app-mobile .action-bar .ticks { justify-content: center; min-width: 0; overflow: hidden; }
  .app-mobile .action-bar .tick { width: 12px; }
  .app-mobile .action-bar .ticks-label { display: none; }
}

/* Phone header on one compact row: logo, plan chip, Home / Saved / Scene Builder. The Facebook link
   lives on Home and in the footer, not in the wizard chrome. */
@media (max-width: 767px) {
  .app-mobile #app-header { flex-wrap: nowrap; gap: 6px; padding: 6px 10px; }
  .app-mobile #app-header .app-logo { height: 22px; }
  .app-mobile #app-header > .chip.chip-accent { font-size: 10px; padding: 2px 7px; }
  .app-mobile #app-header .btn { min-height: 36px; padding-inline: 8px; font-size: 12px; }
  .app-mobile #app-header a[href*="facebook"] { display: none; }
  .app-mobile #app-header #saved-btn { margin-left: 0; }
  .app-mobile .fold-header { min-height: 48px; padding: 8px 12px; }
  .app-mobile .fold[data-collapsed="true"] .fold-title { font-size: 15px; }
  .app-mobile .fold-ico { width: 26px; height: 26px; }
  .app-mobile .fold-ico svg { width: 15px; height: 15px; }
}

@media (max-width: 767px) { .app-mobile .strip { margin: 8px 10px 0; } }
@media (min-width: 768px) { .pane-folds .strip { margin: 0 0 14px; } }
