/* Product-story motion layer. The production editor is intentionally separate. */
.demo-stage {
  --motion-ease: cubic-bezier(.22,1,.36,1);
  --motion-green: var(--accent);
  --object-x: 22%;
  --object-y: 29%;
  --object-scale: 1;
  min-height: 510px;
  max-height: 710px;
}
.demo-stage .scene-frame { margin-top: -28px; }
.demo-stage .scene-layer {
  transition: transform 1.15s var(--motion-ease), opacity .65s, background .8s, box-shadow .8s;
}
.demo-stage .scene-background,
.demo-stage:is([data-phase="4"],[data-phase="5"]) .scene-background {
  background: linear-gradient(125deg,#ebd0ac,#eedec6 45%,#cbb795);
}
.demo-stage .scene-product { pointer-events: none; }
.demo-stage .product-object {
  position: absolute;
  width: calc(59% * var(--object-scale));
  height: calc(66% * var(--object-scale));
  left: var(--object-x,22%);
  top: var(--object-y,29%);
  transform: none;
  transform-origin: center;
  transition: none;
}
.demo-stage .product-object img,
.demo-stage:is([data-phase="3"],[data-phase="4"],[data-phase="5"]) .product-object img {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: rotate(-7deg);
  transition: opacity 1.1s, filter 1.1s;
  filter: drop-shadow(14px 15px 10px #7463402b);
  user-select: none;
  -webkit-user-drag: none;
}
.demo-stage .product-edited { opacity: 0; }
.demo-stage .selection {
  inset: 0;
  width: 100%;
  height: 100%;
  border: 1px solid var(--motion-green);
  opacity: 0;
  visibility: hidden;
  transition: opacity .4s, visibility .4s;
  pointer-events: none;
}
.demo-stage .selection small {
  top: auto;
  bottom: calc(100% + 9px);
  font-size: 9px;
  background: var(--motion-green);
  border-radius: 2px;
}
.resize-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  padding: 0;
  background: var(--accent);
  border: 1px solid var(--motion-green);
  border-radius: 1px;
  touch-action: none;
}
.resize-handle::after { content: ""; position: absolute; inset: -8px; }
.resize-handle[data-corner="nw"] { top: -5px; left: -5px; cursor: nwse-resize; }
.resize-handle[data-corner="ne"] { top: -5px; right: -5px; cursor: nesw-resize; }
.resize-handle[data-corner="sw"] { bottom: -5px; left: -5px; cursor: nesw-resize; }
.resize-handle[data-corner="se"] { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* A real sequence: type a brief, refine it, then send it to generation. */
.demo-stage .idea-bubble {
  width: min(365px, 72%);
  max-width: 365px;
  top: 48%;
  left: 1%;
  padding: 24px;
  border-radius: 13px;
  border-color: var(--line);
  background: var(--surface);
  box-shadow: 0 24px 65px -20px #263b3326;
  transform: translateY(-50%);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s, transform .8s var(--motion-ease), visibility .5s;
}
.demo-stage[data-phase="0"] .idea-bubble {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%);
}
.demo-stage:not([data-phase="0"]) .idea-bubble { transform: translateY(calc(-50% - 20px)); }
.idea-bubble > .caption-row {
  padding: 0;
  border: 0;
  display: flex;
  gap: 7px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .04em;
}
.status-dot { display: inline-block; flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.idea-bubble .idea-input {
  min-height: 68px;
  margin: 18px 0 20px;
  font-size: 21px;
  line-height: 1.6;
  letter-spacing: -.035em;
  color: var(--ink);
}
.demo-stage[data-phase="0"][data-state="typing"] #ideaText::after,
.demo-stage[data-phase="0"][data-state="refining"] #refinedText::after,
.demo-stage[data-phase="4"][data-state="edit-input"] #editText::after {
  content: "";
  display: inline-block;
  vertical-align: -.1em;
  width: 1px;
  height: 1em;
  background: var(--accent);
  margin-left: 3px;
  animation: storyCaret .85s steps(1) infinite;
}
.idea-bubble button,
.edit-bubble button {
  border: 0;
  padding: 0;
  background: transparent;
  font-size: 11px;
}
.idea-bubble #refineDemoButton {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding-top: 15px;
  line-height: 20px;
  color: var(--accent);
}
.idea-bubble #refineDemoButton i:last-child { margin-left: auto; }
.demo-stage[data-state="refine-click"] #refineDemoButton { color: var(--ink); transform: translateY(1px); }
.idea-bubble > .refined-output {
  display: block;
  margin-top: 18px;
  padding-top: 17px;
  border-top: 1px solid var(--line);
  max-height: 0;
  margin-bottom: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: max-height .7s var(--motion-ease), opacity .5s, margin .5s, padding .5s;
}
.idea-bubble .refined-output small { display: block; font-size: 10px; color: var(--muted); letter-spacing: .08em; }
.idea-bubble .refined-output p {
  min-height: 130px;
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.85;
  letter-spacing: 0;
  color: var(--muted);
}
.idea-bubble #generateDemoButton {
  width: 100%;
  height: 36px;
  margin-top: 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 13px;
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-ink);
  opacity: 0;
  visibility: hidden;
  transition: opacity .5s, background .2s;
}
.demo-stage[data-phase="0"]:is([data-state="refining"],[data-state="refined"],[data-state="generate-click"],[data-state="submitted"]) .refined-output {
  max-height: 310px;
  opacity: 1;
  visibility: visible;
}
.demo-stage[data-phase="0"]:is([data-state="typing"],[data-state="refine-click"]) .refined-output { padding: 0; margin-top: 0; border: 0; }
.demo-stage[data-phase="0"]:is([data-state="refined"],[data-state="generate-click"],[data-state="submitted"]) #generateDemoButton { opacity: 1; visibility: visible; }
.demo-stage[data-state="generate-click"] #generateDemoButton { background: var(--accent-hover); }
.demo-stage[data-phase="0"] .scene-frame { transform: translate(94px,5px) scale(.78) rotate(8deg); }
.demo-stage[data-phase="0"] .product-object { width: 70%; height: 80%; top: 10%; left: 15%; transform: none; }
.demo-stage[data-phase="0"] .product-object img { inset: 0; width: 100%; height: 100%; transform: none; }

/* Image reveal remains visibly paced even when entering the stage directly. */
.demo-stage[data-phase="1"][data-state="generating"] .scene-frame {
  animation: storyImageReveal 2.2s var(--motion-ease) both;
}
.demo-stage[data-phase="1"][data-state="generating"] .scene-frame::after {
  content: "";
  position: absolute;
  pointer-events: none;
  inset: -2px;
  background: linear-gradient(180deg,transparent 20%,#fffdf982 50%,transparent 80%);
  background-size: 100% 100%;
  animation: storyScan 2.2s var(--motion-ease) both;
}
.demo-stage .scene-dimension {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  top: calc(100% + 20px);
  width: max-content;
  max-width: 150%;
  left: 50%;
  right: auto;
  transform: translateX(-50%) translateY(8px);
  font-size: 10px;
  padding: 9px 13px;
  color: var(--muted);
  border: 0;
  border-radius: 6px;
  background: var(--surface);
  opacity: 0;
  visibility: hidden;
  box-shadow: none;
  transition: opacity .6s, transform .6s var(--motion-ease), visibility .6s;
}
.dimension-original { color: var(--secondary); }
.dimension-result { font-weight: 500; color: var(--accent); }
.dimension-check { display: inline-flex; align-items: center; gap: 4px; }
.dimension-check .lb-icon { width: 12px; height: 12px; }
.demo-stage[data-phase="1"][data-state="size"] .scene-dimension {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
.demo-stage[data-phase="1"][data-state="size"] .dimension-check { animation: storyBadgeIn .65s var(--motion-ease) both; }

/* First fan the layers apart, then settle them into four distinct canvases. */
.demo-stage[data-phase="2"][data-state="stack"] .scene-frame { transform: translateX(-8px); }
.demo-stage[data-phase="2"][data-state="stack"] .scene-layer { transform: none; outline: none; }
.demo-stage[data-phase="2"][data-state="stack"] :is(.scene-copy,.scene-product,.scene-footer) { background: transparent; }
.demo-stage[data-phase="2"] .layer-labels { opacity: 0; visibility: hidden; }
.demo-stage[data-phase="2"][data-state="exploded"] .layer-labels { opacity: 1; visibility: visible; }
.scene-layer::after {
  content: attr(data-layer-label);
  position: absolute;
  top: calc(100% + 11px);
  left: 0;
  right: 0;
  text-align: center;
  font: 400 20px/1.3 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  letter-spacing: .05em;
  color: var(--muted);
  opacity: 0;
  transition: opacity .5s;
  pointer-events: none;
}
.demo-stage[data-phase="2"][data-state="grid"] .scene-frame { transform: translateX(-8px) translateY(-8px); }
.demo-stage[data-phase="2"][data-state="grid"] .scene-layer {
  outline: 1px solid #274c4624;
  box-shadow: 0 14px 28px -15px #263b3324;
}
.demo-stage[data-phase="2"][data-state="grid"] :is(.scene-copy,.scene-product,.scene-footer) {
  background-color: #202429;
  background-image: linear-gradient(45deg,#ffffff08 25%,transparent 25%),linear-gradient(-45deg,#ffffff08 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#ffffff08 75%),linear-gradient(-45deg,transparent 75%,#ffffff08 75%);
  background-size: 26px 26px;
  background-position: 0 0,0 13px,13px -13px,-13px 0;
}
.demo-stage[data-phase="2"][data-state="grid"] .scene-copy { transform: translate(-28%,-29%) scale(.48); }
.demo-stage[data-phase="2"][data-state="grid"] .scene-product { transform: translate(28%,-29%) scale(.48); }
.demo-stage[data-phase="2"][data-state="grid"] .scene-footer { transform: translate(-28%,29%) scale(.48); }
.demo-stage[data-phase="2"][data-state="grid"] .scene-background { transform: translate(28%,29%) scale(.48); }
.demo-stage[data-phase="2"][data-state="grid"] .scene-graphics { opacity: 0; }
.demo-stage[data-phase="2"][data-state="grid"] .scene-layer::after { opacity: 1; }

/* Selection bounds follow the item, including the actual draggable demo. */
.demo-stage[data-phase="3"] .scene-product,
.demo-stage[data-phase="4"] .scene-product { z-index: 3; }
.demo-stage[data-phase="3"] .selection,
.demo-stage[data-phase="4"] .selection { visibility: visible; opacity: 1; }
.demo-stage:is([data-phase="3"],[data-phase="4"])[data-state="select"]:not(.selection-active) .selection { visibility: hidden; opacity: 0; }
.demo-stage[data-phase="3"] .product-object,
.demo-stage[data-phase="4"] .product-object { pointer-events: auto; }
.demo-stage[data-phase="3"][data-state="interactive"] .product-object {
  transition: none;
  cursor: grab;
  touch-action: none;
}
.demo-stage[data-phase="3"][data-state="interactive"] .product-object:active { cursor: grabbing; }
.demo-stage.is-manipulating .product-object { transition: none !important; }
.demo-stage[data-phase="3"][data-state="interactive"] .selection { pointer-events: auto; }
.demo-stage[data-phase="3"][data-state="interactive"] .resize-handle { pointer-events: auto; }
.demo-stage .product-object img { pointer-events: none; }

/* A material change demonstrates AI editing, rather than another resize. */
.demo-stage .edit-bubble {
  display: block;
  padding: 17px 19px;
  left: 0;
  right: auto;
  width: min(370px,88%);
  bottom: 10%;
  border-radius: 10px;
  box-shadow: 0 15px 40px -20px #263b3326;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(15px);
  transition: opacity .5s, transform .7s var(--motion-ease), visibility .5s;
}
.edit-bubble > small { display: block; font-size: 10px; color: var(--muted); letter-spacing: .04em; }
.edit-bubble > p { min-height: 43px; font-size: 13px; line-height: 1.8; color: var(--ink); margin: 9px 0 14px; }
.edit-bubble #editDemoButton {
  min-height: 31px;
  padding: 0 12px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.edit-status { color: var(--muted); font-size: 10px; margin-left: 9px; }
.demo-stage[data-phase="4"] .edit-bubble { opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(15px); }
.demo-stage[data-phase="4"]:is([data-state="edit-input"],[data-state="editing"]) .edit-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}
.demo-stage[data-phase="4"][data-state="editing"] .product-object {
  animation: storyProductWorking 1.8s ease-in-out infinite;
}
.demo-stage[data-phase="4"][data-state="edit-result"] .product-original,
.demo-stage[data-phase="5"] .product-original { opacity: 0; }
.demo-stage[data-phase="4"][data-state="edit-result"] .product-edited,
.demo-stage[data-phase="5"] .product-edited { opacity: 1; }
.demo-stage[data-phase="4"][data-state="edit-result"][data-compare="before"] .product-original { opacity: 1; }
.demo-stage[data-phase="4"][data-state="edit-result"][data-compare="before"] .product-edited { opacity: 0; }
.demo-stage .edit-comparison {
  position: absolute;
  z-index: 7;
  top: calc(50% + 226px);
  left: 50%;
  transform: translateX(calc(-50% - 8px)) translateY(10px);
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .5s, transform .6s var(--motion-ease), visibility .5s;
}
.edit-comparison button { min-height: 29px; padding: 0 14px; border: 0; border-radius: 4px; background: none; font-size: 11px; color: var(--muted); white-space: nowrap; }
.edit-comparison button[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); }
.demo-stage[data-phase="4"][data-state="edit-result"] .edit-comparison { opacity: 1; visibility: visible; pointer-events: auto; transform: translateX(calc(-50% - 8px)) translateY(0); }
.demo-stage[data-phase="4"][data-state="edit-result"] .scene-dimension { opacity: 0; visibility: hidden; }
.demo-stage .export-bubble { visibility: hidden; pointer-events: none; }
.demo-stage[data-phase="5"] .export-bubble { visibility: visible; }

/* The instructional pointer is a separate overlay, never the user's cursor. */
.stage-cursor {
  position: absolute;
  z-index: 15;
  left: var(--cursor-x,0px);
  top: var(--cursor-y,0px);
  width: 25px;
  height: 29px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  filter: drop-shadow(0 2px 3px #263b3326);
  transition: left .8s var(--motion-ease),top .8s var(--motion-ease),opacity .2s,visibility .2s;
}
.stage-cursor svg { width: 100%; height: 100%; }
.stage-cursor.is-visible { visibility: visible; opacity: 1; }
.stage-cursor::before {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  left: -13px;
  top: -13px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  transform: scale(.4);
}
.stage-cursor.is-clicking::before { animation: storyClick .65s ease-out both; }
.stage-cursor.is-clicking svg { transform: scale(.86); transform-origin: 0 0; }
.stage-cursor.is-dragging svg { transform: scale(.92); }
.stage-cursor.is-dragging { transition: opacity .2s, visibility .2s; }
.scene-status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 42px;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: .03em;
  pointer-events: none;
}
.demo-stage[data-paused="true"] *, .demo-stage[data-paused="true"] *::before, .demo-stage[data-paused="true"] *::after { animation-play-state: paused !important; }

@keyframes storyCaret { 0%,45% { opacity: 1; } 46%,100% { opacity: 0; } }
@keyframes storyImageReveal {
  0% { opacity: .12; filter: blur(22px) saturate(.2); clip-path: inset(0 0 80%); }
  35% { opacity: .65; filter: blur(12px) saturate(.5); clip-path: inset(0 0 43%); }
  100% { opacity: 1; filter: blur(0) saturate(1); clip-path: inset(0 0 -1px); }
}
@keyframes storyScan { 0% { transform: translateY(-80%); opacity: 0; } 20% { opacity: .8; } 100% { transform: translateY(85%); opacity: 0; } }
@keyframes storyBadgeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes storyClick { 0% { opacity: .8; transform: scale(.4); } 100% { opacity: 0; transform: scale(1.2); } }
@keyframes storyProductWorking { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.14); } }

@media (max-width: 1050px) and (min-width: 651px) {
  .demo-stage { min-height: 490px; }
  .demo-stage .idea-bubble { width: 86%; left: -2%; padding: 20px; }
  .idea-bubble .idea-input { font-size: 18px; min-height: 60px; margin: 14px 0 16px; }
  .idea-bubble .refined-output p { font-size: 12px; line-height: 1.8; }
  .demo-stage .scene-frame { width: min(70%,300px); }
  .demo-stage .scene-dimension { padding: 8px 10px; font-size: 9px; max-width: 145%; gap: 5px; }
  .demo-stage .edit-comparison { top: auto; bottom: 67px; }
  .scene-status { bottom: 34px; font-size: 9px; }
  .edit-status { display: block; margin: 9px 0 0; }
}
@media (max-width: 650px) {
  .story-sticky { height: calc(100svh - 36px); min-height: 0; padding: 21px 6% 14px; }
  .story-content { padding-top: 15px; }
  .demo-stage { height: clamp(330px,calc(100svh - 340px),450px); min-height: 0; max-height: 450px; }
  .demo-stage .scene-frame { width: min(232px,calc(65svh - 265px)); margin-top: -62px; }
  .demo-stage .idea-bubble { width: min(310px,95%); max-width: none; top: 46%; left: 0; padding: 18px 20px; border-radius: 10px; }
  .idea-bubble .idea-input { min-height: 54px; margin: 13px 0 13px; font-size: 18px; line-height: 1.5; }
  .idea-bubble .caption-row { font-size: 9px; }
  .idea-bubble #refineDemoButton { padding-top: 10px; font-size: 10px; }
  .idea-bubble > .refined-output { margin-top: 13px; padding-top: 12px; }
  .idea-bubble .refined-output p { min-height: 86px; font-size: 11px; line-height: 1.8; margin-top: 7px; }
  .idea-bubble #generateDemoButton { height: 32px; margin-top: 12px; font-size: 10px; }
  .demo-stage[data-phase="0"] .scene-frame { transform: translate(62px,-30px) scale(.85) rotate(8deg); }
  .demo-stage[data-phase="2"][data-state="grid"] .scene-frame { width: 268px; transform: translateX(0) translateY(-9px); }
  .demo-stage[data-phase="2"][data-state="exploded"] .scene-frame { transform: translateX(-24px) scale(.79) rotateX(15deg) rotateY(-17deg) rotateZ(-7deg); }
  .demo-stage .scene-dimension { top: calc(100% + 15px); font-size: 9px; padding: 7px 9px; gap: 5px; max-width: 140%; }
  .demo-stage .edit-bubble { bottom: 65px; width: 96%; left: 2%; padding: 14px 15px; }
  .edit-bubble > p { min-height: 36px; font-size: 12px; line-height: 1.7; margin: 7px 0 10px; }
  .edit-bubble > small { font-size: 9px; }
  .edit-status { font-size: 9px; }
  .demo-stage .edit-comparison { top: auto; bottom: 59px; transform: translateX(-50%) translateY(10px); }
  .demo-stage[data-phase="4"][data-state="edit-result"] .edit-comparison { transform: translateX(-50%); }
  .edit-comparison button { min-height: 26px; padding: 0 13px; font-size: 10px; }
  .demo-stage .export-bubble { bottom: 64px; left: 4%; right: 1%; padding: 14px; }
  .selection small { font-size: 8px; }
  .scene-status { bottom: 34px; font-size: 9px; }
  .story-copy { padding: 20px 0 10px; }
  .story-copy h2 { font-size: 29px; }
  .story-copy > p:not(.step-detail) { margin: 10px 0 8px; }
  .story-tabs button { font-size: 9px; }
}
@media (min-width: 651px) and (max-height: 760px) {
  .demo-stage .scene-frame { width: min(67%,286px); margin-top: -30px; }
  .demo-stage .edit-comparison { top: auto; bottom: 70px; }
}
@media (max-width: 370px) {
  .demo-stage .idea-bubble { padding: 16px; width: 98%; }
  .idea-bubble .idea-input { font-size: 17px; }
  .demo-stage .scene-dimension { gap: 4px; font-size: 8px; }
  .story-copy h2 { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .stage-cursor { display: none; }
  .demo-stage *, .demo-stage *::before, .demo-stage *::after { animation: none !important; transition: none !important; }
  .demo-stage[data-phase="1"] .scene-frame { clip-path: none; filter: none; opacity: 1; }
}

/* Keep the step navigation close to the story on taller displays. */
@media (min-width: 651px) and (min-height: 850px) {
  .story-sticky { height: calc(100svh - 80px); max-height: 1020px; }
}

.demo-stage[data-phase="2"][data-state="grid"] :is(.scene-copy,.scene-footer) { color: #eff1f2; }
