/*
 * Order story. Mobile-first (REQ-22): the base rules describe the 390px stack — stage on
 * top, steps underneath — and the min-width queries at the foot build the two-column
 * desktop layout where the steps drive a sticky stage on the right.
 */
.cp-story__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--cp-space-lg);
  align-items: start;
}

.cp-story__stage {
  position: sticky;
  top: calc(var(--cp-header-height) + var(--cp-space-xs));
  z-index: 5;
  grid-column: 1;
  grid-row: 1;
}

.cp-story__steps {
  grid-column: 1;
  grid-row: 2;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cp-story__step {
  position: relative;
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  align-content: start;
  column-gap: var(--cp-space-sm);
  min-height: 42vh;
  opacity: 0.32;
  transition: opacity 300ms var(--cp-ease);
}

.cp-story__step:first-child {
  align-content: start;
  min-height: 50vh;
}

.cp-story__step:last-child {
  min-height: 52vh;
}

.cp-story__step[data-active='true'] {
  opacity: 1;
}

.cp-story__marker {
  display: grid;
  grid-row: span 2;
  place-items: center;
  align-self: start;
  width: 2.5rem;
  height: 2.5rem;
  border: var(--cp-frame) solid var(--cp-ink);
  background: var(--cp-sheet);
  font-family: var(--cp-font-display);
  font-size: var(--cp-text-lg);
  line-height: 1;
  transition: background-color 300ms var(--cp-ease);
}

.cp-story__step[data-active='true'] .cp-story__marker {
  background: var(--cp-amber);
}

.cp-story__name {
  font-size: var(--cp-text-lg);
  font-weight: 600;
  line-height: 1.2;
}

.cp-story__step p {
  max-width: 28rem;
  margin-top: var(--cp-space-xs);
  color: var(--cp-graphite);
}

/* Stage frame */
.cp-stage {
  border: var(--cp-frame) solid var(--cp-ink);
  background: var(--cp-sheet);
  box-shadow: 6px 6px 0 var(--cp-ink);
}

.cp-stage__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cp-space-sm);
  padding: var(--cp-space-sm) var(--cp-space-sm) 0;
}

.cp-stage__order {
  font-size: var(--cp-text-sm);
  font-weight: 600;
}

.cp-stage__status {
  padding: 0.3125rem 0.625rem;
  background: var(--cp-amber-soft);
  font-size: var(--cp-text-xs);
  font-weight: 600;
}

.cp-stage__progress {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.25rem;
  margin: var(--cp-space-sm) 0 0;
  padding: 0 var(--cp-space-sm) var(--cp-space-sm);
  border-bottom: 1px solid var(--cp-line);
  list-style: none;
}

.cp-stage__progress li {
  height: 4px;
  background: var(--cp-line);
  transition: background-color 300ms var(--cp-ease);
}

.cp-stage__progress li[data-state='done'] {
  background: var(--cp-ink);
}

.cp-stage__progress li[data-state='current'] {
  background: var(--cp-amber);
}

.cp-stage__scenes {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
}

.cp-scene {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--cp-space-sm);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity 360ms var(--cp-ease), transform 480ms var(--cp-ease), visibility 360ms;
}

.cp-scene[data-active='true'] {
  opacity: 1;
  visibility: visible;
  transform: none;
}

/* Scene 1: chat */
.cp-chat {
  display: grid;
  gap: var(--cp-space-xs);
  width: min(100%, 22rem);
}

.cp-chat__bubble {
  max-width: 85%;
  margin: 0;
  padding: 0.625rem 0.875rem;
  font-size: var(--cp-text-xs);
  line-height: 1.4;
}

.cp-chat__bubble--in {
  justify-self: start;
  border-radius: var(--cp-radius-bubble) var(--cp-radius-bubble) var(--cp-radius-bubble) 4px;
  background: var(--cp-page);
}

.cp-chat__bubble--out {
  justify-self: end;
  border-radius: var(--cp-radius-bubble) var(--cp-radius-bubble) 4px var(--cp-radius-bubble);
  background: var(--cp-amber-soft);
}

.cp-chat__photo {
  display: grid;
  gap: 0.375rem;
  padding: 0.375rem;
}

.cp-chat__photo canvas {
  width: 9rem;
  height: 6rem;
  border-radius: 0;
}

.cp-chat__photo figcaption {
  padding-inline: 0.25rem;
  color: var(--cp-graphite);
  font-size: var(--cp-text-xs);
}

.cp-scene[data-active='true'] .cp-chat__bubble {
  animation: cp-bubble 420ms var(--cp-ease) both;
}

.cp-scene[data-active='true'] .cp-chat__bubble:nth-child(2) {
  animation-delay: 450ms;
}

.cp-scene[data-active='true'] .cp-chat__bubble:nth-child(3) {
  animation-delay: 1200ms;
}

@keyframes cp-bubble {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}

/* Scene 2: blueprint */
.cp-scene--blueprint {
  background-image:
    linear-gradient(color-mix(in srgb, var(--cp-ink) 5%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--cp-ink) 5%, transparent) 1px, transparent 1px);
  background-size: 20px 20px;
}

.cp-blueprint {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.cp-blueprint__shape {
  fill: none;
  stroke: var(--cp-ink);
  stroke-width: 0.6;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.cp-blueprint__dimension {
  fill: none;
  stroke: var(--cp-amber);
  stroke-width: 0.5;
}

.cp-blueprint__label {
  fill: var(--cp-ink);
  font-family: var(--cp-font-body);
  font-size: 4px;
  font-weight: 600;
}

.cp-scene[data-active='true'] .cp-blueprint__shape {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1400ms var(--cp-ease);
  transition-delay: calc(var(--order, 0) * 60ms);
}

/* Scene 3: the shop illustrates and picks the colours */
.cp-palette {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  align-items: center;
  gap: var(--cp-space-sm);
  width: min(100%, 27rem);
  padding: var(--cp-space-sm);
  border: 2px solid var(--cp-line);
  background: var(--cp-sheet);
  transition: border-color 300ms var(--cp-ease);
}

.cp-palette img {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  background: var(--cp-slot);
  object-fit: contain;
}

.cp-palette__name {
  font-weight: 600;
}

.cp-palette__meta {
  color: var(--cp-graphite);
  font-size: var(--cp-text-sm);
}

.cp-palette__tag {
  margin-top: var(--cp-space-2xs);
  font-size: var(--cp-text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cp-graphite);
  transition: color 300ms var(--cp-ease);
}

.cp-palette__swatches {
  display: flex;
  gap: var(--cp-space-2xs);
  margin-top: var(--cp-space-sm);
  padding: 0;
  list-style: none;
}

.cp-palette__swatches li {
  width: 1.75rem;
  height: 1.75rem;
  border: 2px solid var(--cp-line);
  background: var(--swatch);
  opacity: 0.35;
  transform: translateY(0.25rem);
  transition: opacity 300ms var(--cp-ease), transform 300ms var(--cp-ease), border-color 300ms var(--cp-ease);
}

.cp-palette__swatches li:nth-child(2) { transition-delay: 90ms; }
.cp-palette__swatches li:nth-child(3) { transition-delay: 180ms; }
.cp-palette__swatches li:nth-child(4) { transition-delay: 270ms; }

.cp-palette[data-chosen='true'] {
  border-color: var(--cp-amber);
}

.cp-palette[data-chosen='true'] .cp-palette__tag {
  color: var(--cp-ink);
}

.cp-palette[data-chosen='true'] .cp-palette__swatches li {
  opacity: 1;
  transform: translateY(0);
  border-color: var(--cp-ink);
}

@media (prefers-reduced-motion: reduce) {
  .cp-palette__swatches li {
    transition: none;
  }
}

/* Scene 4: print */
/*
 * The print and delivery scenes fill the stage edge to edge — but only once there is room.
 * At 390px they keep the same inset as every other scene, so their `padding: 0` lives in
 * the 601px query at the foot of this file rather than here. That is the pre-inversion
 * behaviour: the old `max-width: 600px` rule sat after these two and beat them by source
 * order, which is precisely the kind of accident this refactor is meant to make visible.
 */

.cp-scene__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Scene 5: delivery */
.cp-scene--delivery {
  background: var(--cp-stage-wash);
}

.cp-route {
  width: 100%;
  height: 100%;
}

.cp-route__streets path {
  fill: none;
  stroke: var(--cp-stage-rule);
  stroke-width: 14;
}

.cp-route__streets .cp-route__avenue {
  stroke-width: 22;
}

.cp-route__path {
  fill: none;
  stroke: var(--cp-amber);
  stroke-width: 5;
  stroke-dasharray: 10 7;
  stroke-linecap: square;
}

.cp-route__start {
  fill: var(--cp-ink);
}

.cp-route__pin circle {
  fill: var(--cp-ink);
}

.cp-route__pin .cp-route__pin-dot {
  fill: var(--cp-amber);
}

.cp-route__rider circle {
  fill: var(--cp-amber);
  stroke: var(--cp-ink);
  stroke-width: 3;
}

.cp-route__card {
  position: absolute;
  left: var(--cp-space-md);
  bottom: var(--cp-space-md);
  padding: var(--cp-space-xs) var(--cp-space-sm);
  border: 2px solid var(--cp-ink);
  background: var(--cp-sheet);
  font-size: var(--cp-text-xs);
  color: var(--cp-graphite);
}

.cp-route__title {
  color: var(--cp-ink);
  font-size: var(--cp-text-sm);
  font-weight: 600;
}

/* ------------------------------------------------------------------ *
 * Wider screens. 601px and 1081px are the exact complements of the
 * 600px / 1080px max-width queries these replace.
 *
 * `.cp-story__step:first-child` and `:last-child` are two-class selectors and outrank
 * the single-class `.cp-story__step` rules below whatever their order, so the first and
 * last steps keep their own heights at every width. That is the existing behaviour, not
 * a new one — it is spelled out here because it is easy to "tidy" away.
 * ------------------------------------------------------------------ */
@media (min-width: 601px) {
  .cp-stage__bar,
  .cp-stage__progress {
    padding-inline: var(--cp-space-md);
  }

  .cp-scene {
    padding: var(--cp-space-lg);
  }

  /* Must stay after `.cp-scene` above: same specificity, so source order decides. */
  .cp-scene--print,
  .cp-scene--delivery {
    padding: 0;
  }

  .cp-chat__photo canvas {
    width: 13rem;
    height: 9rem;
  }

  .cp-chat__bubble {
    font-size: var(--cp-text-sm);
  }

  .cp-palette {
    grid-template-columns: 9.5rem minmax(0, 1fr);
    gap: var(--cp-space-md);
  }

  .cp-story__name {
    font-size: var(--cp-text-xl);
  }

  .cp-story__step {
    grid-template-columns: 3rem minmax(0, 1fr);
    column-gap: var(--cp-space-md);
    min-height: 50vh;
  }

  .cp-story__marker {
    width: 3rem;
    height: 3rem;
    font-size: var(--cp-text-xl);
  }
}

@media (min-width: 1081px) {
  .cp-story__layout {
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    gap: var(--cp-space-xl);
  }

  .cp-story__stage {
    top: calc(var(--cp-header-height) + var(--cp-space-lg));
    z-index: auto;
    grid-column: 2;
  }

  .cp-story__steps {
    grid-row: 1;
  }

  .cp-stage {
    box-shadow: 10px 10px 0 var(--cp-ink);
  }

  .cp-stage__scenes {
    aspect-ratio: 4 / 2.75;
  }

  .cp-story__step {
    align-content: center;
    min-height: 44vh;
  }

  .cp-story__step:first-child {
    align-content: start;
    min-height: 34vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cp-scene[data-active='true'] .cp-chat__bubble {
    animation: none;
  }

  .cp-blueprint__shape {
    stroke-dashoffset: 0;
  }
}
