/* Release AU — Sticker Pack Builder as a pack studio (templates/sticker_pack_builder.html): a step bar, one focused
   panel per step (choose, arrange & name, format, build & download) and the "Your pack" tray, which is the sticky
   bar on phones. Library tiles, presets and result rows keep their styles in pages/stickers.css (shared with the
   3D stickers gallery). No blur or shadow filters: they cost low-end phones real layout and paint time. */
.spw { margin-bottom: 2rem; --spw-r: 22px; }
.spw [hidden] { display: none !important; }
.spw-app { border: 1px solid var(--border); border-radius: var(--spw-r); background: var(--surface-solid, var(--surface));
  box-shadow: var(--ae-hi, none), 0 1px 2px #00000033, 0 18px 44px #0000004d; }
html[data-theme="light"] .spw-app { box-shadow: var(--ae-hi, none), 0 1px 2px #1018280f, 0 18px 44px #10182814; }

/* header + steps */
.spw-top { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem 1rem; padding: .8rem clamp(.85rem, 2vw, 1.25rem); border-bottom: 1px solid var(--border); }
.spw-top-text { flex: 1 1 12rem; min-width: 0; }
.spw-kicker { margin: 0; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--link, var(--brand)); }
.spw-title { margin: .1rem 0 0; font-size: 1.05rem; font-weight: 700; }
.spw .spb-mode { min-height: 44px; }
.spw-top .spb-mode-hint { flex-basis: 100%; margin: 0; }
.spw-steps { list-style: none; margin: 0; padding: .6rem clamp(.6rem, 2vw, 1.1rem); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .4rem;
  border-bottom: 1px solid var(--border); }
.spw-step { width: 100%; min-height: 46px; display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border-radius: 14px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font: inherit; font-size: .86rem; font-weight: 600; text-align: start; cursor: pointer;
  transition: background-color var(--ae-med, .2s), color var(--ae-med, .2s); }
.spw-step:hover:not(:disabled) { color: var(--text); background: color-mix(in srgb, var(--text) 5%, transparent); }
.spw-step:disabled { opacity: .45; cursor: not-allowed; }
.spw-step:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.spw-step-n { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .76rem; font-weight: 700;
  background: color-mix(in srgb, var(--text) 9%, transparent); }
.spw-step-l { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spw-step[aria-current="step"] { color: var(--text); border-color: color-mix(in srgb, var(--brand) 45%, var(--border)); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.spw-step[aria-current="step"] .spw-step-n { background: var(--brand); color: var(--on-brand); }
.spw-steps li[data-done="1"] .spw-step-n { background: color-mix(in srgb, var(--brand) 30%, transparent); color: var(--text); }

/* body: the step panel + the tray */
.spw-body { display: grid; }
.spw-main { min-width: 0; padding: clamp(1rem, 2.4vw, 1.6rem); }
.spw-panel { display: grid; gap: .9rem; min-width: 0; align-content: start; }
.spw-h { margin: 0; font-size: clamp(1.2rem, 2.2vw, 1.5rem); line-height: 1.2; outline: none; }
.spw .spb-pick, .spw .spb-pack, .spw .spb-run { padding: 0; position: static; }
.spw .spb-results { max-height: none; overflow: visible; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.spw .spb-chosen { max-height: none; overflow: visible; }
.spw .spb-item { min-height: 56px; }
.spw .spb-icon { min-width: 44px; min-height: 44px; }
.spw-tray-note, .spw-pro-tip { margin: 0; }
.spw[data-mode="pro"] .spw-pro-tip { display: none; }
.spw .spb-make { width: 100%; }
.spw-edit { justify-self: start; min-height: 44px; }

.spw-tray-in { display: grid; gap: .7rem; align-content: start; }
.spw-tray { min-width: 0; padding: clamp(1rem, 2.4vw, 1.4rem); border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-solid, var(--surface)) 72%, var(--bg)); border-radius: 0 0 var(--spw-r) var(--spw-r); }
.spw-tray-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.spw-tray-h { margin: 0; font-size: .76rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.spw-tray-count { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.spw-tray-thumbs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: .35rem; }
.spw-tray-thumbs li { aspect-ratio: 1; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.spw-tray-thumbs li:first-child { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.spw-tray-thumbs img { width: 34px; height: 34px; object-fit: contain; }
.spw-tray-thumbs .spw-more { font-size: .8rem; font-weight: 700; color: var(--muted); }
.spw-tray-empty, .spw-tray-format, .spw-tray-msg { margin: 0; }
.spw-tray-format { font-weight: 700; font-size: .9rem; }
.spw-tray-format:empty, .spw-tray-msg:empty { display: none; }
.spw-tray-msg { color: #dc2626; font-weight: 600; font-size: .9rem; }
html[data-theme="dark"] .spw-tray-msg { color: #f87171; }
.spw-tray-actions { display: flex; gap: .5rem; }
.spw-tray-actions .btn-primary, .spw-tray-actions .btn-ghost { flex: 1 1 0; min-height: 48px; justify-content: center; font-weight: 700; border-radius: 14px; }
.spw-tray-actions .btn-primary:disabled { opacity: .5; cursor: not-allowed; }

@media (min-width: 1024px) {
  .spw-body { grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); }
  .spw-tray { border-top: 0; border-left: 1px solid var(--border); border-radius: 0 0 var(--spw-r) 0; }
  .spw-tray-in { position: sticky; top: 84px; }
  .spw[data-step="3"] .spw-make2 { display: none; }  /* desktop: Make pack sits under the formats */
}

/* phones: one step per screen; the tray is the sticky bar above the tab bar (count, cover strip, Back / Next) */
@media (max-width: 1023px) {
  .spw-tray { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 5; padding: .6rem .8rem .7rem;
    border-radius: 0 0 var(--spw-r) var(--spw-r); box-shadow: 0 -8px 18px #0000001f; background: var(--surface-solid, var(--surface)); }
  .spw-tray-in { gap: .45rem; grid-template-columns: auto minmax(0, 1fr); align-items: center; }
  .spw-tray-h, .spw-tray-empty, .spw-tray-format { display: none; }
  .spw-tray-head { grid-row: 1; grid-column: 1; }
  .spw-tray-thumbs { grid-row: 1; grid-column: 2; display: flex; overflow: hidden; gap: .25rem; }
  .spw-tray-thumbs li { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; }
  .spw-tray-thumbs img { width: 26px; height: 26px; }
  .spw-tray-msg, .spw-tray-actions { grid-column: 1 / -1; }
  .spw[data-step="3"] .spb-make { display: none; }  /* phones: Make pack is in the sticky bar */
  .spw[data-step="4"] .spw-tray { display: none; }
}
body.kbd-open .spw-tray { bottom: 0; }
@media (max-width: 768px) {
  .spw { margin-inline: -4px; }
  /* fixed rows: title, then Quick / Pro — text widths that settle after the fonts load must never re-wrap the header */
  .spw-top-text { flex-basis: 100%; }
  .spw-top .spb-mode-hint { min-height: 3.4em; min-height: 2lh; }  /* two lines kept: the hint re-wraps when the Latin web font arrives */
  .spw-steps { grid-template-columns: repeat(4, auto); justify-content: space-between; padding: .5rem .6rem; }
  .spw-step { padding: .3rem; gap: .4rem; min-height: 44px; }
  .spw-step:not([aria-current="step"]) .spw-step-l { display: none; }
  .spw-step[aria-current="step"] { padding-inline: .4rem .8rem; }
  .spw .spb-results { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { .spw-step { transition: none; } }
/* the draft bar (form memory) sits in the header; its status may shorten, never reflow the header */
.spw-fm { min-height: 44px; display: flex; align-items: center; min-width: 0; }
.spw-fm .fm-bar { margin: 0; flex-wrap: nowrap; padding-block: 0; min-width: 0; }
.spw-fm .fm-status { flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 22ch; }
.spw-fm .fm-btn, .spw-fm .fm-drafts { min-height: 44px; }
@media (max-width: 768px) { .spw-fm { flex-basis: 100%; order: 3; } .spw-fm .fm-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } }
/* mid-size desktops: the floating chat button would sit on the library — the "Ask AI" chip in the header takes over */
@media (min-width: 769px) and (max-width: 1519px) { body:has(.spw) .chat-fab:not(.is-open) { display: none; } }
@media (max-width: 768px), (min-width: 1520px) { .chat-chip-open { display: none; } }
