/* quilt-preview.css: the zoomable viewer made by LSQuiltPreview.viewer() (assets/js/quilt-preview.js) and the preview
   studio layout around it (docs/DESIGN.md 5.31, 5.32). Every value comes from tokens.css; no color literals here.
     .lsqp-viewer.on-dark       the viewer root; the on-dark scope makes --text white and focus rings mustard (2.4)
     .lsqp-stage / .lsqp-pic    the dark stage and the zoomable picture; .lsqp-msg is a message over the stage
     .lsqp-bar                  the toolbar: a docked text bar, or the zoom pill with .is-pill (the viewer adds it
                                when the icon set is on the page: floating from 768px, docked below that and in a
                                viewer narrower than 440px; the viewer keeps the picture above a floating pill)
     .lsqp-thumbs / .lsqp-thumb saved previews under the stage (4:3, a "Saved" or "AI" badge)
     .studio .studio-stage .studio-panel .studio-section .studio-actions .stage-chip .pattern-chip   the studio (5.32)
   Old names kept as aliases until the pages use the shared components: .lsqp-swatches / .lsqp-swatch = .swatch-row /
   .swatch, .lsqp-shimmer = .skeleton, .lsqp-note = .hint (ls.css aliases .lsqp-range and .lsqp-progress).
   The stage is dark navy in both themes so the quilt stands out; everything fits a 320px phone. The viewer is a size
   container (lsqp-viewer) and, from 1024px, so is the studio's parent (lsqp-studio): a studio placed in a narrow column
   stacks instead of squeezing the stage. */

/* ---------- Viewer (5.31) ---------- */
.lsqp-viewer {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--stage-bg);
  box-shadow: var(--card-shadow);
  container: lsqp-viewer / inline-size;
}

.lsqp-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  height: clamp(260px, 62vh, 760px);
  background: radial-gradient(ellipse at 50% 40%, var(--on-navy-hover), transparent 70%), var(--stage-bg);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.lsqp-stage:is(:focus-visible, .is-focus) { outline: 3px solid var(--focus-ring); outline-offset: -3px; }
.lsqp-stage.is-dragging { cursor: grabbing; }
.lsqp-stage:has(> .lsqp-msg:not([hidden])) { cursor: default; }

.lsqp-viewer .lsqp-pic {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none !important;
  max-height: none !important;
  margin: 0;
  border: 0;
  transform-origin: 0 0;
  will-change: transform;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  box-shadow: var(--shadow-lg);
}

/* Loading: a soft moving sheen and the data-loading-text line, over the picture when busy() is on */
.lsqp-stage.is-loading::before,
.lsqp-shimmer::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: var(--z-raised);
  background: linear-gradient(100deg, transparent 30%, var(--skeleton-shine) 50%, transparent 70%);
  background-size: 250% 100%;
  animation: lsqp-shimmer var(--dur-shimmer) linear infinite;
  pointer-events: none;
}
.lsqp-stage.is-loading::after {
  content: attr(data-loading-text);
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: var(--z-raised);
  width: max-content;
  max-width: calc(100% - 2 * var(--space-4));
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--viewer-bar-bg);
  color: var(--text);
  font: var(--fw-semibold) var(--fs-body)/1.4 var(--font-body);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.lsqp-stage.is-loading:is(:not([data-loading-text]), [data-loading-text=""])::after { content: none; }
@keyframes lsqp-shimmer {
  from { background-position: 125% 0; }
  to { background-position: -125% 0; }
}

/* Messages over the stage (5.32 stage states: empty, error with "Try again") */
.lsqp-msg {
  position: absolute;
  inset: 0;
  z-index: var(--z-raised);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: color-mix(in srgb, var(--stage-bg) 80%, transparent);
  color: var(--text);
  font: var(--fw-semibold) var(--fs-body)/1.4 var(--font-body);
  text-align: center;
}
.lsqp-msg[hidden] { display: none; }
.lsqp-msg p { max-width: 36ch; margin: 0; }
.lsqp-msg .icon { color: var(--muted); }

/* ---------- Toolbar, text mode: docked under the stage ---------- */
.lsqp-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--navy);
  color: var(--text);
}
.lsqp-btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 40px;
  min-height: 40px;
  margin: 0;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: var(--fw-bold) var(--fs-small)/1 var(--font-body);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
}
@media (hover: hover) {
  .lsqp-btn:is(:hover, .is-hover):not(:disabled, [aria-disabled="true"]) { background: var(--surface-3); }
}
.lsqp-btn:is(:focus-visible, .is-focus) { outline: 3px solid var(--focus-ring); outline-offset: 1px; }
.lsqp-btn:is(:disabled, [aria-disabled="true"]) { opacity: .45; cursor: default; }
.lsqp-btn .icon { pointer-events: none; }
.lsqp-zoom {
  min-width: 5ch;
  padding: 0 var(--space-1);
  color: var(--muted);
  font: var(--fw-bold) var(--fs-small)/1 var(--font-body);
  font-variant-numeric: tabular-nums;
  text-align: center;
  cursor: default;
  user-select: none;
}
.lsqp-btn-dl { margin-left: auto; border-color: var(--mustard); background: var(--mustard); color: var(--navy); }
@media (hover: hover) {
  .lsqp-btn-dl:is(:hover, .is-hover):not(:disabled, [aria-disabled="true"]) { border-color: var(--mustard-light); background: var(--mustard-light); }
}
@media (max-width: 767.98px), (pointer: coarse) {
  .lsqp-btn { min-width: 44px; min-height: 44px; }
}
@media (max-width: 599.98px) {
  .lsqp-bar:not(.is-pill) .lsqp-btn-dl { flex: 1 1 100%; margin-left: 0; }
}

/* ---------- Toolbar, pill mode (.is-pill): floating over the stage from 768px, docked navy bar below ---------- */
.lsqp-bar.is-pill {
  flex-wrap: nowrap;
  gap: 2px;
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--viewer-bar-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 768px) {
  .lsqp-bar.is-pill { position: absolute; left: 50%; bottom: var(--space-3); z-index: var(--z-overlay-local); transform: translateX(-50%); }
}
.lsqp-bar.is-pill .lsqp-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}
@media (hover: hover) {
  .lsqp-bar.is-pill .lsqp-btn:is(:hover, .is-hover):not(:disabled, [aria-disabled="true"]) { background: var(--on-navy-press); }
}
.lsqp-bar.is-pill .lsqp-btn:is(:focus-visible, .is-focus) { outline-offset: -3px; }
.lsqp-bar.is-pill .lsqp-btn.lsqp-btn-text { width: auto; min-width: 52px; padding: 0 var(--space-3); border-radius: var(--radius-pill); }
.lsqp-bar.is-pill .lsqp-btn.lsqp-btn-dl { margin-left: 0; background: var(--mustard); color: var(--navy); }
@media (hover: hover) {
  .lsqp-bar.is-pill .lsqp-btn.lsqp-btn-dl:is(:hover, .is-hover):not(:disabled, [aria-disabled="true"]) { background: var(--mustard-light); }
}
.lsqp-bar.is-pill .lsqp-btn.lsqp-btn-dl:is(:focus-visible, .is-focus) { outline-offset: 1px; }   /* a mustard ring can't sit on the mustard fill */
@media (max-width: 767.98px), (pointer: coarse) {
  .lsqp-bar.is-pill .lsqp-btn:not(.lsqp-btn-text) { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
  .lsqp-bar.is-pill .lsqp-btn.lsqp-btn-text { height: 44px; min-height: 44px; }
}
@media (max-width: 767.98px) {
  .lsqp-bar.is-pill {
    flex-wrap: wrap;
    justify-content: space-between;
    row-gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: 0;
    background: var(--navy);
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@media (max-width: 479.98px) {
  .lsqp-bar.is-pill { padding-inline: var(--space-1); }
  .lsqp-bar.is-pill .viewer-sep { display: none; }
  .lsqp-bar.is-pill .lsqp-zoom { min-width: 4ch; padding: 0; }
  .lsqp-bar.is-pill .lsqp-btn.lsqp-btn-text { min-width: 44px; padding: 0 var(--space-2); }
}
@media (max-width: 359.98px) {
  .lsqp-bar.is-pill { justify-content: center; }   /* the narrowest phones: a control that wraps sits centred */
}
/* A viewer narrower than the pill needs (a side column, a small dialog) docks it under the stage, as on phones */
@container lsqp-viewer (max-width: 439.98px) {
  .lsqp-bar.is-pill {
    position: static;
    flex-wrap: wrap;
    justify-content: space-between;
    row-gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: 0;
    background: var(--navy);
    box-shadow: none;
    transform: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@container lsqp-viewer (max-width: 359.98px) {
  .lsqp-bar.is-pill { justify-content: center; padding-inline: var(--space-1); }
  .lsqp-bar.is-pill .viewer-sep { display: none; }
  .lsqp-bar.is-pill .lsqp-zoom { min-width: 4ch; padding: 0; }
}

/* ---------- Saved previews under the stage ---------- */
.lsqp-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-3);
  min-width: 0;
}
.lsqp-thumb {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-standard);
}
.lsqp-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
@media (hover: hover) {
  .lsqp-thumb:is(:hover, .is-hover) { border-color: var(--border-hover); }
}
.lsqp-thumb:is(:focus-visible, .is-focus) { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.lsqp-thumb :is(.lsqp-tag, .badge) { position: absolute; left: var(--space-2); top: var(--space-2); background: var(--viewer-bar-bg); color: var(--white); }
.lsqp-thumb .lsqp-tag {
  display: inline-flex;
  align-items: center;
  height: var(--badge-h);
  padding: 0 var(--badge-px);
  border-radius: var(--radius-pill);
  font: var(--fw-bold) var(--fs-caption)/1 var(--font-body);
}
.lsqp-thumb :is(.lsqp-tag, .badge).is-ai { background: var(--mustard); color: var(--navy); }
@media (max-width: 599.98px) {
  .lsqp-stage { height: clamp(220px, 55vh, 560px); }
  .lsqp-thumbs { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); }
}

/* ---------- Legacy names (aliases of the shared components) ---------- */
.lsqp-swatches { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.lsqp-swatch {
  --sw: var(--surface-3);
  position: relative;
  display: inline-block;
  flex: none;
  width: var(--sw-size, 44px);
  height: var(--sw-size, 44px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px var(--swatch-edge);
  cursor: pointer;
  vertical-align: middle;
}
.lsqp-swatch:is([aria-checked="true"], [aria-pressed="true"], .is-on) {
  box-shadow: inset 0 0 0 1px var(--swatch-edge), 0 0 0 2px var(--surface), 0 0 0 4px var(--selected);
}
.lsqp-swatch:is([aria-checked="true"], [aria-pressed="true"], .is-on)::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--selected) var(--icon-check) center / 11px no-repeat;
  box-shadow: 0 0 0 2px var(--surface);
}
.lsqp-swatch:is(:focus-visible, .is-focus) { outline: 3px solid var(--focus-ring); outline-offset: 5px; }
.lsqp-shimmer { position: relative; display: block; overflow: hidden; isolation: isolate; background: var(--skeleton); border-radius: var(--radius-sm); }
.lsqp-note { margin: var(--space-1) 0 0; color: var(--faint); font-size: var(--fs-caption); line-height: 1.45; }

/* ---------- Quilt preview studio (5.32) ---------- */
.studio { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-6); }
.studio-stage { position: relative; min-width: 0; }
.studio-stage > .lsqp-thumbs { margin-top: var(--space-4); }
@media (min-width: 1024px) {
  .studio { grid-template-columns: minmax(0, 1fr) var(--studio-panel-w); align-items: start; }
  .studio-stage { position: sticky; top: calc(var(--sticky-top) + var(--space-4)); }
  .studio-stage .lsqp-stage { height: clamp(360px, calc(100dvh - var(--sticky-top) - 180px), 820px); }
}
@media (min-width: 768px) and (max-width: 1023.98px) {
  .studio-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .studio-section:first-child, .studio-actions { grid-column: 1 / -1; }
  .studio-section:nth-of-type(even):last-of-type { grid-column: 1 / -1; }   /* a last section left alone on its row spans it, so its rule runs the full width */
}
@media (max-width: 767.98px) {
  .studio-stage .lsqp-stage { height: auto; aspect-ratio: 4 / 3; max-height: 56vh; }
}
/* From 1024px the studio's parent is a size container: a studio placed in a narrow column (a record page's main
   column) stacks the stage over the controls, as on a tablet, instead of squeezing the stage beside the panel. */
@media (min-width: 1024px) {
  :has(> .studio) { container: lsqp-studio / inline-size; }
}
@container lsqp-studio (max-width: 819.98px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
  .studio-stage { position: relative; top: auto; }
  .studio-stage .lsqp-stage { height: auto; aspect-ratio: 4 / 3; max-height: 70vh; }
}
@container lsqp-studio (min-width: 600px) and (max-width: 819.98px) {
  .studio-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .studio-section:first-child, .studio-actions { grid-column: 1 / -1; }
  .studio-section:nth-of-type(even):last-of-type { grid-column: 1 / -1; }   /* a last section left alone on its row spans it, so its rule runs the full width */
}
.studio-panel { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--card-shadow); }
.studio-section { min-width: 0; padding: var(--space-5); border-bottom: 1px solid var(--border); }
.studio-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.studio-section-head h3 { margin: 0; font: var(--fw-heavy) var(--fs-h4)/1.3 var(--font-body); }
.studio-section-head .value { color: var(--muted); font-size: var(--fs-caption); }
.studio-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
}
@media (max-width: 767.98px) {
  /* On phones the studio sets body.is-task-flow (the portal tab bar hides) and ui.js measures this bar into --flow-bar-h (5.29). */
  .studio-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-sticky);
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
    border-radius: 0;
    box-shadow: var(--shadow);
  }
  .studio-actions .btn-primary { flex: 1 1 100%; }
}
.stage-chip {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: var(--z-overlay-local);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: calc(100% - 2 * var(--space-3));
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--stage-chip-bg);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font: var(--fw-bold) var(--fs-caption)/1.2 var(--font-body);
  pointer-events: none;
}
.stage-chip > :is(span, strong) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-chip .swatch { --sw-size: 24px; }
.pattern-chip {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.pattern-chip img { width: 56px; aspect-ratio: 1; object-fit: contain; border-radius: var(--radius-xs); background: var(--white); }
/* The name gets two lines before the ellipsis: pattern names like "New School Cool Turtle" don't fit one line of a panel */
.pattern-chip .name {
  display: -webkit-box;
  overflow: hidden;
  font-weight: var(--fw-heavy);
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.pattern-chip .meta { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--fs-caption); }
.pattern-chip.is-empty { grid-template-columns: 1fr; place-items: center; min-height: 72px; border-style: dashed; border-color: var(--border-strong); }
@media (max-width: 479.98px) {
  /* Phones: "Change" moves under the name, so the name and its badges get the chip's width */
  .pattern-chip:not(.is-empty) { grid-template-columns: 56px minmax(0, 1fr); }
  .pattern-chip:not(.is-empty) > .btn { grid-column: 2; justify-self: start; }
}

/* ---------- Motion and print ---------- */
@media (prefers-reduced-motion: reduce) {
  .lsqp-stage.is-loading::before, .lsqp-shimmer::before { animation: none; }
  .lsqp-btn, .lsqp-thumb { transition: none; }
}
@media print {
  .lsqp-bar, .lsqp-stage.is-loading::before, .lsqp-stage.is-loading::after { display: none; }
  .lsqp-viewer { box-shadow: none; }
}
