/* ============================================================
   Pure Design Projects · Try-On Studio
   Built on top of v3/styles.css design tokens.
   ============================================================ */

.try-on-body {
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  /* Guard against rogue horizontal overflow from absolute children, the
     cart drawer, or negative-margin catalog strips. Without this, a phone
     viewport can end up showing the layout in a half-width column with a
     dead zone on the right. */
  overflow-x: hidden;
}

/* Use the global .site-header treatment (sticky + glass + border) from
   styles.css. The .try-on-header modifier is kept as a hook in case we
   need page-specific tweaks, but inherits the base header styling so the
   try-on page reads as a continuous part of the main site. */
.try-on-header {
  /* No overrides — sticky/blur/border come from .site-header in styles.css */
}

.try-on-main {
  /* Cap content width tighter than the site's general --max-width so the
     two-column stage doesn't feel sparse on a 27" monitor. */
  max-width: min(var(--max-width), 1100px);
  margin: 0 auto;
  padding: clamp(1.25rem, 0.8rem + 1.4vw, 2.25rem) var(--gutter) clamp(3rem, 2rem + 4vw, 6rem);
}

/* ---------- Intro ---------- */
.try-on-intro {
  max-width: 56ch;
  margin: 0 auto clamp(1.5rem, 1rem + 1.6vw, 2.4rem);
  text-align: center;
}

.try-on-intro .eyebrow {
  font-size: var(--text-micro);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.85rem;
}

.try-on-intro h1 {
  font-family: var(--font-serif);
  font-size: var(--text-h2);
  font-weight: 500;
  line-height: 1.05;
  margin-bottom: 0.9rem;
}

.try-on-intro .lede {
  font-size: var(--text-lead);
  color: var(--ink-soft);
  line-height: 1.55;
}

/* ---------- Stage ---------- */
.try-on-stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1.25rem, 0.8rem + 1.6vw, 2.25rem);
}

.try-on-stage > * {
  min-width: 0;
}

@media (min-width: 1024px) {
  .try-on-stage {
    /* Stage gets ~58%, catalog gets ~42% — feels balanced at 1100 max-width. */
    grid-template-columns: minmax(0, 1.35fr) minmax(280px, 1fr);
    align-items: start;
    gap: clamp(1rem, 0.6rem + 1vw, 1.8rem);
  }
}

.stage-camera {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 4 / 3;
  background: linear-gradient(140deg, #2a2724 0%, #14110f 100%);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  /* pan-y, NOT none. The stage fills ~half the mobile viewport, so blocking all
     touch here trapped the whole page — you couldn't swipe past the stage to
     reach the catalog / Add-to-cart below. pan-y lets a vertical swipe over the
     stage scroll the page, while model orbit (the model-viewer keeps its own
     touch-action:none), the drag handle, and the two-finger scene pinch-zoom
     (JS preventDefault) all still work — those live on their own elements. */
  touch-action: pan-y;
}

@media (min-width: 1024px) {
  .stage-camera { aspect-ratio: 4 / 3; }
}

/* Zoom-layer groups the camera video + all placed model-viewers. Camera and
   item zoom are applied explicitly in JS so the overlays stay registered.
   Item-level drag handlers divide pointer deltas by sceneZoom so the drag
   feel stays consistent regardless of how far the user has zoomed in. */
.zoom-layer {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  will-change: transform;
}

.stage-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.stage-video.env-facing { transform: none; }
.stage-video.hidden { display: none; }

.placed-items {
  position: absolute;
  inset: 0;
  pointer-events: none; /* container is transparent to taps; items opt in */
}

.placed-item {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(170px, 52%, 260px);
  height: clamp(170px, 52%, 260px);
  transform-origin: center center;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  z-index: 2;
}
.placed-item.dragging { cursor: grabbing; }

.placed-item.active {
  z-index: 4; /* active piece floats above siblings while being adjusted */
}

.placed-item.active::after {
  /* Soft outline so the user knows which piece the plate controls drive. */
  content: '';
  position: absolute;
  inset: 6px;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(140, 106, 72, 0.18);
}

.placed-item model-viewer {
  display: block;
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  background: transparent;
  --poster-color: transparent;
  /* model-viewer fully owns every gesture inside its canvas — orbit (yaw +
     pitch), pinch-zoom, and tap. We no longer share the canvas with a
     drag-to-translate listener; that moved to .placed-item__handle. */
  touch-action: none;
  cursor: grab;
}
.placed-item.dragging model-viewer { cursor: grabbing; }

/* Still-image stand-in shown while a piece is frozen (its 3D model unloaded to
   save GPU memory). Sits above the now-empty model-viewer (z-index 3 vs 2) but
   below the drag handle; any light glow/pattern still render behind it. */
.placed-item__still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 3;
  pointer-events: none;
}
.placed-item__still[hidden] { display: none; }

/* Drag handle — pinned to the top-left corner of the active item. Hidden
   until the piece is selected so the unactive pieces stay visually clean. */
.placed-item__handle {
  position: absolute;
  top: -14px;
  left: -14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: 2px solid #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: grab;
  z-index: 5;
  touch-action: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  user-select: none;
}
.placed-item.active .placed-item__handle { display: flex; }
.placed-item.dragging .placed-item__handle { cursor: grabbing; }

/* ---------- Light glow (predefined "switched-on" effect) ----------
   For products carrying a `light` profile in catalog.json. A radial-gradient
   layer sits BEHIND the model-viewer (z-index 1 vs 2) and spills past the item
   box (negative inset) so the light bleeds into the surrounding room. We use
   mix-blend-mode: screen — it only ever brightens the pixels beneath it, which
   is exactly how a real lamp adds light to a scene. The effect is authored
   (predefined per product), not ray-traced: model-viewer can't light the flat
   camera <video>, so we composite the glow ourselves. CSS custom properties
   (--glow-*) are written per item from its light profile in try-on.js. */
.placed-item__glow {
  position: absolute;
  inset: -45%;
  z-index: 1;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: var(--glow-intensity, 0.7);
  background: radial-gradient(
    ellipse var(--glow-rx, 42%) var(--glow-ry, 40%) at 50% var(--glow-y, 40%),
    var(--glow-color, #ffd9a0) 0%,
    var(--glow-color, #ffd9a0) 16%,
    transparent 70%
  );
  transition: opacity var(--duration-normal, 300ms) var(--ease-out-expo, ease);
  will-change: opacity;
}
/* "Switched off" — fade the glow out (and the toggle drops model-viewer
   exposure back to neutral in JS, so the fixture reads as truly off). */
.placed-item__glow.is-off { opacity: 0; }

/* ---------- Projected pattern (e.g. the Kina's cast lattice) ----------
   For lights whose `light.pattern` is set: a warm radial-lattice texture,
   screen-blended over the room, spreading well beyond the fixture (it's the
   light thrown onto the ceiling/walls, not the lamp body). Sits behind the
   glow and the model. Like the glow, the effect is predefined — model-viewer
   cannot project the real lattice onto the camera feed, so we author it. */
.placed-item__pattern {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--pattern-scale, 2.6) * 100%);
  height: calc(var(--pattern-scale, 2.6) * 100%);
  transform: translate(-50%, -50%);
  background: var(--pattern-img) center / contain no-repeat;
  mix-blend-mode: screen;
  opacity: var(--pattern-opacity, 0.5);
  pointer-events: none;
  z-index: 0;
  transition: opacity var(--duration-normal, 300ms) var(--ease-out-expo, ease);
  will-change: opacity;
}
.placed-item__pattern.is-off { opacity: 0; }

/* The 💡 light-switch button only makes sense for light products; try-on.js
   adds .has-light to the plate controls when the active item carries a
   profile. Hidden otherwise so the control row stays clean for furniture. */
#plate-light { display: none; }
.plate-controls.has-light #plate-light { display: flex; }
.plate-btn--light.is-on {
  background: #ffd9a0;
  color: #5a3a16;
}
.plate-btn--light.is-on:hover { background: #ffce86; color: #5a3a16; }

.stage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: rgba(250, 248, 244, 0.78);
  font-family: var(--font-serif);
  font-size: clamp(1.05rem, 0.9rem + 0.6vw, 1.4rem);
  font-style: italic;
  z-index: 1;
}
.stage-empty.hidden { display: none; }

/* Scene zoom controls (vertical strip on the right side of the stage). */
.scene-zoom {
  position: absolute;
  right: clamp(0.5rem, 0.3rem + 0.6vw, 0.9rem);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 7;
}
.scene-zoom[hidden] { display: none; }

/* ---------- Permission gate ---------- */
.permission-gate {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  text-align: center;
  padding: 2rem;
  background: rgba(20, 17, 15, 0.86);
  color: rgba(250, 248, 244, 0.96);
  z-index: 5;
}
.permission-gate[hidden] { display: none; }

.permission-gate .eyebrow {
  font-size: var(--text-micro);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent-soft);
}

.permission-gate h2 {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 1.1rem + 1.2vw, 2rem);
  font-weight: 500;
  max-width: 24ch;
}

.permission-gate p {
  max-width: 38ch;
  color: rgba(250, 248, 244, 0.78);
}

.permission-gate .error {
  color: #ffb4a8;
  min-height: 1.2em;
  margin-top: 0.4rem;
  font-size: 0.92rem;
}

/* ---------- Plate controls ---------- */
.plate-controls {
  position: absolute;
  left: 50%;
  bottom: clamp(0.75rem, 0.4rem + 1vw, 1.5rem);
  transform: translateX(-50%);
  display: flex;
  gap: 0.4rem;
  padding: 0.4rem;
  /* No backdrop-filter here. This pill is always on screen while pieces are
     placed, and blurring its backdrop forces the browser to re-run a blur over
     the LIVE camera feed every single video frame — a major source of mobile
     jank. A more opaque solid fill reads the same at a fraction of the cost. */
  background: rgba(20, 17, 15, 0.82);
  border-radius: 999px;
  z-index: 6;
}
.plate-controls[hidden] { display: none; }

.plate-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(250, 248, 244, 0.92);
  /* Hardcoded ink — the button is always a light pill, so the icon must be
     a dark glyph regardless of the page theme. Using var(--ink) caused the
     icons to vanish in dark mode (light glyph on light pill). */
  color: #1B1A18;
  border: 0;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-out-expo),
              transform var(--duration-fast) var(--ease-out-expo);
}
.plate-btn:hover { background: var(--accent); color: #fff; }
.plate-btn:active { transform: scale(0.94); }
.plate-btn--reset {
  background: #8C6A48; /* walnut accent — same as light-mode --accent */
  color: #fff;
}
.plate-btn--danger {
  /* re-stating here so the danger variant doesn't get clobbered by the
     :hover rule above */
  background: rgba(160, 32, 32, 0.92);
  color: #fff;
}
.plate-btn--danger:hover { background: #c0392b; color: #fff; }

/* Destructive action — visually separated from the constructive controls.
   Darker red on dark backgrounds so it reads as "danger" without screaming. */
.plate-btn--danger {
  background: rgba(160, 32, 32, 0.92);
  color: #fff;
}
.plate-btn--danger:hover {
  background: #c0392b;
  color: #fff;
}

/* ---------- Stage actions (View in AR / Save) ---------- */
.stage-actions {
  position: absolute;
  top: clamp(0.6rem, 0.3rem + 1vw, 1.1rem);
  right: clamp(0.6rem, 0.3rem + 1vw, 1.1rem);
  display: flex;
  gap: 0.5rem;
  z-index: 6;
}
.stage-actions[hidden] { display: none; }

.stage-actions .hero-btn {
  font-size: 0.85rem;
  padding: 0.55rem 0.95rem;
}

/* ---------- Catalog ---------- */
.catalog-panel {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.catalog-tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: thin;
}
/* A `display:flex` rule beats the UA [hidden] { display:none }, so a single-
   category demo would still show its lone tab. Force it hidden. */
.catalog-tabs[hidden] { display: none; }

.catalog-tab {
  flex: 0 0 auto;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--paper-soft);
  color: var(--ink-soft);
  border: 1px solid transparent;
  font-size: 0.92rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out-expo),
              color var(--duration-fast) var(--ease-out-expo),
              border-color var(--duration-fast) var(--ease-out-expo);
}

.catalog-tab:hover { background: var(--accent-soft); color: var(--ink); }

.catalog-tab[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.catalog-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
  max-height: 60dvh;
  overflow-y: auto;
  padding: 0.25rem 0.15rem;
}

.catalog-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem;
  background: var(--paper-soft);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color var(--duration-fast) var(--ease-out-expo),
              box-shadow var(--duration-fast) var(--ease-out-expo),
              transform var(--duration-fast) var(--ease-out-expo);
}

.catalog-card[data-pending="1"] {
  opacity: 0.72;
}

.catalog-card:hover {
  border-color: var(--accent-soft);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.catalog-card[aria-selected="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-soft);
}

.catalog-card__thumb {
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  overflow: hidden;
  background: #222;
  position: relative;
}

.catalog-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.catalog-card__badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(20, 17, 15, 0.6);
  color: var(--paper);
}

.catalog-card__badge--pending {
  background: rgba(140, 106, 72, 0.85);
}

.catalog-card__title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.25;
}

.catalog-card__blurb {
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.catalog-card__actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.catalog-card__action {
  flex: 1 1 0;
  text-align: center;
  font-size: 0.78rem;
  font-family: var(--font-sans);
  padding: 0.45rem 0.55rem;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out-expo),
              color var(--duration-fast) var(--ease-out-expo),
              border-color var(--duration-fast) var(--ease-out-expo);
}

.catalog-card__action:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.catalog-card__action--cart {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.catalog-card__action--cart:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}

.catalog-note {
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.55;
  border-top: 1px solid var(--rule);
  padding-top: 0.9rem;
}

/* ---------- Save panel ---------- */
.save-panel {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 15, 0.55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
}
.save-panel[hidden] { display: none; }

@media (min-width: 700px) {
  .save-panel { align-items: center; }
}

.save-panel__sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--paper);
  border-radius: 10px;
  padding: clamp(1.25rem, 1rem + 1vw, 2rem);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  max-height: 92dvh;
  overflow-y: auto;
}

.save-panel__close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: transparent;
  border: 0;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
}

.save-panel h2 {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 1.2rem + 0.8vw, 1.8rem);
  font-weight: 500;
  margin-bottom: 0.6rem;
}

.save-panel p {
  color: var(--ink-soft);
  margin-bottom: 1rem;
}

.save-panel__rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--paper-soft);
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.save-panel__rows .row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.save-panel__rows .row strong {
  font-weight: 500;
  color: var(--ink);
}

.save-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.save-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.save-form input,
.save-form textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
}

.save-form input:focus,
.save-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.save-form__msg {
  font-size: 0.85rem;
  color: var(--accent);
  min-height: 1.2em;
}

/* ============================================================
   Mobile / small-screen refinements
   ============================================================
   Breakpoint set to <1024px (matches the desktop @min-width: 1024
   rule below — zero gap). Anything that isn't proven desktop gets
   the single-column phone layout. This avoids the "half-width
   dead zone" we kept hitting on Samsung S-series, foldables, and
   any device whose logical CSS width landed between 640–900px.
   ============================================================ */
@media (max-width: 1023px) {
  /* Force the document to the actual visual viewport — guards against any
     leaked horizontal-overflow source (cart drawer, negative-margin strips,
     transform stacking contexts) that would otherwise paint the page in a
     half-width column with empty gutters. */
  html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }
  .try-on-main {
    max-width: 100vw;
    width: 100%;
    box-sizing: border-box;
  }
  .try-on-header .site-header__inner {
    max-width: 100vw;
    width: 100%;
    box-sizing: border-box;
  }
  /* Force the save-panel to viewport space regardless of ancestor transforms.
     A transformed ancestor (the zoom-layer scale() on placed-items) creates
     a containing block for fixed-position descendants — even though the
     save-panel is a sibling, some browsers leak that scope. Using explicit
     top/left/width/height with viewport units sidesteps the issue. */
  .save-panel {
    /* inset: 0 first (resets longhands), then explicit top/left win. The
       earlier version had `inset: auto` LAST, which wiped the top/left we'd
       just set — leaving the panel at its in-flow position 1240px down the
       page (effectively invisible below the fold). */
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    padding: 0.6rem;
    align-items: flex-end;
    justify-content: center;
  }
  .save-panel__sheet {
    width: 100%;
    max-width: min(520px, 100%);
    margin-bottom: max(0.6rem, env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  /* Tighter outer padding; respect iOS safe areas. */
  .try-on-main {
    padding: 0.75rem max(0.75rem, env(safe-area-inset-left)) 1.8rem max(0.75rem, env(safe-area-inset-right));
  }

  /* Mobile header tweaks are inherited from the global .site-header rules
     in styles.css (mobile-nav-toggle visible, primary-nav hidden, etc.).
     Nothing to override here — alignment with the main site is the point. */

  /* CRITICAL: grid items default to min-width: auto, which lets their
     intrinsic content (the 7-tab catalog row) push the grid track wider
     than the viewport. This is what was rendering the catalog at 780px on
     a 555px screen. Forcing min-width: 0 lets the track shrink to viewport. */
  .try-on-stage > * { min-width: 0; }
  .catalog-panel    { min-width: 0; max-width: 100%; }
  .catalog-tabs,
  .catalog-strip    { max-width: 100%; box-sizing: border-box; }

  /* Make the catalog strip ALWAYS show a horizontal-swipe affordance, even
     when only 2 cards fit: a slim min-width so the second card peeks past
     the right edge. */
  .catalog-card { flex: 0 0 62%; max-width: 230px; }

  /* Dark-mode contrast for the cart drawer + save panel so they don't
     vanish on the dark stage background. */
  body.theme-dark .cart-drawer {
    box-shadow: -18px 0 36px rgba(0, 0, 0, 0.55);
    border-left: 1px solid var(--accent-soft);
  }
  body.theme-dark .save-panel__sheet {
    box-shadow: 0 -18px 36px rgba(0, 0, 0, 0.55);
    border: 1px solid var(--accent-soft);
  }

  /* Shorter intro so the stage is above the fold on phones. */
  .try-on-intro {
    margin-bottom: 1rem;
  }
  .try-on-intro h1 { font-size: clamp(1.5rem, 1.2rem + 2vw, 2rem); }
  .try-on-intro .lede {
    font-size: 0.9rem;
    line-height: 1.5;
    /* Trim to first sentence-ish for a quick read. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Stage uses a taller portrait ratio on phones (vs. 4:3 on tablet+).
     The previous `max-height` capped the height which back-capped the WIDTH
     via aspect-ratio — leaving the stage at ~412px on a 555px viewport with
     a visible right-side gap. We now force full container width and let the
     height follow the aspect-ratio so the stage fills the available space. */
  .stage-camera {
    aspect-ratio: 4 / 5;
    width: 100%;
    max-width: 100%;
    border-radius: 6px;
  }

  /* Placed items: tighter footprint so multiple pieces fit comfortably on
     a 360–414px-wide stage. */
  .placed-item {
    width: clamp(160px, 50vw, 240px);
    height: clamp(160px, 50vw, 240px);
  }

  /* Plate controls: bigger touch targets, fewer pixels of gap. */
  .plate-controls {
    bottom: max(0.7rem, env(safe-area-inset-bottom));
    padding: 0.45rem;
    gap: 0.3rem;
  }
  .plate-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  /* Scene zoom: tuck closer to the edge but stay above the plate. */
  .scene-zoom { right: 0.45rem; gap: 0.3rem; }
  .scene-zoom .plate-btn { width: 40px; height: 40px; }

  /* Stage-actions live in the top-right corner; on mobile we shrink the
     labels so they never overflow the stage. The AR icon does the heavy
     lifting; the Save button keeps a short label so the CTA is obvious. */
  .stage-actions {
    top: 0.55rem;
    right: 0.55rem;
    left: auto;
    gap: 0.4rem;
  }
  .stage-actions .hero-btn {
    font-size: 0.75rem;
    padding: 0.42rem 0.7rem;
    white-space: nowrap;
  }
  .stage-actions #view-in-ar { font-size: 0; padding: 0.4rem 0.55rem; }
  .stage-actions #view-in-ar::before {
    content: '◌  AR';
    font-size: 0.78rem;
    font-weight: 500;
  }

  /* Catalog flips from grid → horizontal scrolling strip. Stays directly
     under the stage so the customer never has to scroll down to find more
     pieces while they're placing. */
  .try-on-stage {
    gap: 0.75rem;
  }
  .catalog-panel {
    gap: 0.5rem;
  }
  .catalog-tabs {
    margin: 0 -0.9rem;            /* bleed to viewport edges so chips can scroll */
    padding: 0 0.9rem 0.25rem;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .catalog-strip {
    display: flex;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: visible;
    max-height: none;
    scroll-snap-type: x proximity;            /* "proximity" not "mandatory" — */
    /* mandatory was preventing the strip from scrolling smoothly when there  */
    /* were fewer than 2 cards visible at once (it tried to snap mid-drag).   */
    margin: 0 -0.9rem;
    padding: 0.25rem 0.9rem 0.75rem;
    -webkit-overflow-scrolling: touch;
    /* pan-x pan-y: horizontal swipe scrolls this product strip; vertical swipe
       propagates up to scroll the PAGE (the strip has no vertical overflow).
       pan-x alone trapped vertical swipes, so the page wouldn't scroll when the
       finger started over the products. */
    touch-action: pan-x pan-y;
    overscroll-behavior-x: contain;
    gap: 0.7rem;
    scrollbar-width: thin;
  }
  .catalog-strip::-webkit-scrollbar { height: 4px; }
  .catalog-strip::-webkit-scrollbar-thumb {
    background: var(--accent-soft);
    border-radius: 2px;
  }
  /* (Removed an edge-fade mask-image that was expensive to repaint on some
     Android browsers and contributed to "stuck"-feeling loads.) */
  .catalog-card {
    flex: 0 0 68%;                /* peek the next card so users know to swipe */
    max-width: 240px;
    scroll-snap-align: start;
    padding: 0.7rem;
  }
  .catalog-card__thumb {
    aspect-ratio: 4 / 3;          /* wider than tall on phones — saves vertical real-estate */
  }
  .catalog-card__title { font-size: 0.95rem; }
  .catalog-card__blurb {
    font-size: 0.76rem;
    /* Trim to 2 lines so cards stay the same height. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .catalog-card__action { font-size: 0.74rem; padding: 0.45rem 0.4rem; }

  .catalog-note { font-size: 0.74rem; }

  /* Permission gate — already centered, just tighten padding so the CTA
     stays visible under a thumb-reach zone. */
  .permission-gate {
    padding: 1.5rem 1.1rem;
    gap: 0.7rem;
  }
  .permission-gate h2 { font-size: 1.2rem; }
  .permission-gate p { font-size: 0.88rem; }

  /* Save panel — already a bottom-sheet at this width; add a thumb-reach
     drag affordance for clarity. */
  .save-panel__sheet {
    border-radius: 14px 14px 0 0;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }

  .try-on-body .cart-drawer {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
  }

  .try-on-body .cart-drawer__head,
  .try-on-body .cart-drawer__body,
  .try-on-body .cart-drawer__foot {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .try-on-body .cart-line {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 0.8rem;
  }

  .try-on-body .cart-line__photo,
  .try-on-body .cart-line--gift .cart-line__icon {
    width: 64px;
    height: 82px;
  }

  .try-on-body .cart-line__row {
    align-items: flex-start;
    gap: 0.55rem;
    flex-direction: column;
  }

  .try-on-body .toast {
    width: calc(100vw - 2rem);
    max-width: 420px;
    bottom: max(1rem, env(safe-area-inset-bottom));
    text-align: center;
  }
}

/* Very narrow phones (≤ 360px — iPhone SE etc.) — drop a step further. */
@media (max-width: 360px) {
  .catalog-card { flex-basis: 78%; }
  .plate-btn { width: 40px; height: 40px; }
  .stage-actions .hero-btn { font-size: 0.72rem; padding: 0.4rem 0.55rem; }
}

/* ---------- Disabled state (admin toggle off) ---------- */
.try-on-disabled {
  max-width: 56ch;
  margin: clamp(2rem, 1.4rem + 2vw, 4rem) auto;
  padding: clamp(1.5rem, 1rem + 1.2vw, 2.5rem);
  text-align: center;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.try-on-disabled[hidden] { display: none; }

.try-on-disabled h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem);
  font-weight: 500;
  margin-bottom: 0.8rem;
}

.try-on-disabled p {
  color: var(--ink-soft);
  margin-bottom: 1rem;
}

.try-on-disabled a {
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
}
.try-on-disabled .hero-btn { border-bottom: 0; }

/* ---------- Footer tweaks ---------- */
.try-on-footer {
  margin-top: clamp(3rem, 2rem + 4vw, 5rem);
}

.powered-by-line {
  border-top: 1px solid var(--rule);
  padding: 1rem var(--gutter);
  text-align: center;
}
.powered-by-line .powered-by {
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}
.powered-by-line .powered-by a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

/* ============================================================
   Fabric picker (standalone demo — the recolor feature)
   ============================================================ */
.fabric-picker {
  border-top: 1px solid var(--rule);
  padding-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.fabric-picker[hidden] { display: none; }

.fabric-picker__label {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}
.fabric-picker__label span {
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}

.fabric-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* Each swatch is a circular chip filled with its fabric colour (--swatch is set
   inline from catalog.json). The active chip gets a ring drawn OUTSIDE the chip
   (box-shadow) so the colour stays true and selection reads clearly on either
   theme. */
.fabric-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  background: var(--swatch, #888);
  cursor: pointer;
  padding: 0;
  box-shadow: 0 0 0 1px var(--rule);
  transition: transform var(--duration-fast, 150ms) var(--ease-out-expo, ease),
              box-shadow var(--duration-fast, 150ms) var(--ease-out-expo, ease);
}
.fabric-swatch:hover { transform: scale(1.08); }
.fabric-swatch.is-active {
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px rgba(140, 106, 72, 0.25);
}
.fabric-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Catalog card: placeholder thumbnail (authored model, no source photo) + the
   "tap to place" affordance. */
.catalog-card__thumb--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, #2a2724 0%, #14110f 100%);
  color: rgba(250, 248, 244, 0.55);
}
.catalog-card__thumb--placeholder svg {
  width: 56%;
  height: auto;
}

.catalog-card__hint {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 0.15rem;
}
