/*
 * The scroll story. hero.js writes the eased act progress --a1…--a4 (0…1) on .hero;
 * every moving part derives its state from them. Without animation all acts stay at 1
 * (end state) and the section is not pinned.
 */

.hero {
  --a1: 1;
  --a2: 1;
  --a3: 1;
  --a4: 1;
  position: relative;
  overflow-x: clip;
}

.anim .hero {
  --a1: 0;
  --a2: 0;
  --a3: 0;
  --a4: 0;
  height: 520vh;
}

.pin {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: center;
  gap: clamp(16px, 3vw, 48px);
  width: min(1320px, 100% - 2 * var(--gutter));
  margin-inline: auto;
  padding-top: calc(var(--header) + 32px);
  padding-bottom: 48px;
}

.anim .pin {
  position: sticky;
  top: 0;
  height: 100svh;
  padding-bottom: 24px;
}

/* Beats */

.beats {
  display: grid;
  gap: 40px;
}

.anim .beats {
  display: block;
  position: relative;
  height: 100%;
}

.anim .beat {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity 0.45s ease,
    transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
  pointer-events: none;
}

.anim .beat.is-active {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.beat h2 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.beat p {
  font-size: clamp(1.05rem, 1.5vw, 1.25rem);
  color: var(--muted);
  max-width: 32ch;
}

.hint {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--accent) !important;
  font-size: 1rem !important;
}

.hint::after {
  content: "";
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-3px);
  animation: nudge 1.8s ease-in-out infinite;
}

@keyframes nudge {
  50% {
    translate: 0 5px;
  }
}

.progress {
  display: none;
}

.anim .progress {
  display: flex;
  gap: 8px;
  position: absolute;
  bottom: 12%;
  left: 0;
}

.progress span {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.progress span::after {
  content: "";
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(var(--p, 0));
}

.progress span:nth-child(1)::after { --p: var(--a1); }
.progress span:nth-child(2)::after { --p: var(--a2); }
.progress span:nth-child(3)::after { --p: var(--a3); }
.progress span:nth-child(4)::after { --p: var(--a4); }

/* Stage: a fixed 960×720 design box, scaled to fit (--s set by hero.js). */

.stage {
  position: relative;
  height: min(72vh, 640px);
  min-height: 320px;
}

.anim .stage {
  height: 100%;
  max-height: 720px;
}

.scene {
  --s: 0.6;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 960px;
  height: 720px;
  transform: translate(-50%, -50%) scale(var(--s));
  font-family: var(--sans);
  color: var(--text);
}

.scene * {
  position: absolute;
}

.scene svg {
  overflow: visible;
}

/* Kitchen backdrop */

.kitchen {
  inset: 0;
  opacity: calc(1 - clamp(0, var(--a3) * 3, 1));
  transform: translateY(calc(var(--a3) * -40px));
}

.wall {
  inset: 0 0 60px;
  border-radius: 36px;
  background:
    linear-gradient(115deg, rgb(255 244 214 / 0.9) 0 18%, transparent 42%),
    #f1e9d8;
  overflow: hidden;
}

.wall::after {
  content: "";
  position: absolute;
  left: 4%;
  top: 6%;
  width: 26%;
  height: 58%;
  background:
    linear-gradient(90deg, transparent 47%, rgb(241 233 216 / 0.8) 47% 53%, transparent 53%),
    linear-gradient(0deg, transparent 47%, rgb(241 233 216 / 0.8) 47% 53%, transparent 53%),
    rgb(255 248 228 / 0.75);
  transform: skewX(-14deg);
  filter: blur(6px);
}

.tiles {
  left: 0;
  right: 0;
  top: 430px;
  height: 136px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='68'%3E%3Crect width='128' height='68' fill='%23f7f1e4'/%3E%3Cpath d='M0 1H128M0 35H128M1 0V35M65 0V35M33 35V68M97 35V68' stroke='%23e4dac4' stroke-width='2'/%3E%3C/svg%3E");
}

.worktop {
  left: -20px;
  right: -20px;
  top: 562px;
  height: 30px;
  border-radius: 6px;
  background: linear-gradient(#e2bc85, #d2a466);
  box-shadow: 0 16px 0 #b98a52, 0 30px 40px -10px rgb(80 50 20 / 0.35);
}

.basil {
  left: 36px;
  top: 440px;
  width: 110px;
  height: 124px;
}

.board {
  left: 790px;
  top: 452px;
  width: 92px;
  height: 112px;
}

/* Cabinet */

.cabinet {
  left: 120px;
  top: 40px;
  width: 460px;
  height: 382px;
  border-radius: 10px;
  background: #8fae8b;
  box-shadow: 0 24px 40px -20px rgb(40 60 40 / 0.45);
}

.cabinet::before {
  content: "";
  position: absolute;
  left: -12px;
  right: -12px;
  top: -14px;
  height: 22px;
  border-radius: 6px;
  background: #7e9c7a;
}

.interior {
  left: 18px;
  right: 18px;
  top: 30px;
  bottom: 16px;
  border-radius: 6px;
  background: linear-gradient(#efe0c3, #f6ead3);
  box-shadow: inset 0 10px 18px -8px rgb(90 60 20 / 0.35);
  overflow: hidden;
}

.interior::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgb(255 236 180 / 0.9), transparent 70%);
  opacity: var(--a1);
}

.shelf {
  left: 0;
  right: 0;
  height: 10px;
  background: #c69a62;
  box-shadow: 0 6px 8px -4px rgb(90 60 20 / 0.4);
}

.shelf-1 {
  top: 158px;
}

.shelf-2 {
  bottom: 0;
}

.doors {
  inset: 0;
  opacity: calc(1 - clamp(0, var(--a3) * 3, 1));
  transform: translateY(calc(var(--a3) * -40px));
  pointer-events: none;
}

.door {
  top: 70px;
  width: 212px;
  height: 336px;
  border-radius: 6px;
  background: #9db79a;
  box-shadow: inset 0 0 0 2px #88a585;
}

.door::before {
  content: "";
  position: absolute;
  inset: 22px;
  border-radius: 4px;
  box-shadow:
    inset 0 0 0 3px #88a585,
    inset 0 0 0 5px #b2c8ae;
}

.door::after {
  content: "";
  position: absolute;
  top: 190px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f0cf8a, #b8893b 60%, #8a6428);
  box-shadow: 0 3px 4px rgb(60 40 10 / 0.35);
}

.door-left {
  left: 138px;
  transform-origin: left center;
  transform: perspective(1800px) rotateY(calc(var(--a1) * -104deg));
}

.door-left::after {
  right: 14px;
}

.door-right {
  left: 350px;
  transform-origin: right center;
  transform: perspective(1800px) rotateY(calc(var(--a1) * 104deg));
}

.door-right::after {
  left: 14px;
}

/* Offer cards (act 2) */

.offer {
  --s2: clamp(0, (var(--a2) - var(--k) * 0.15) / 0.7, 1);
  left: 640px;
  width: 262px;
  height: 112px;
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 18px 34px -18px rgb(30 42 34 / 0.45);
  border: 1px solid var(--border);
  transform: translateX(calc((1 - var(--s2)) * 440px));
  opacity: calc(1 - clamp(0, var(--a3) * 3, 1));
}

.offer b,
.offer i,
.offer s,
.offer em {
  left: 108px;
  white-space: nowrap;
}

.offer b {
  top: 16px;
  font-size: 22px;
}

.offer i {
  top: 46px;
  font-style: normal;
  color: var(--muted);
  font-size: 16px;
}

.offer s {
  left: auto;
  right: 18px;
  top: 72px;
  color: var(--muted);
  font-size: 15px;
}

.offer em {
  top: 70px;
  font-style: normal;
  font-weight: 700;
  font-size: 22px;
}

.offer mark {
  right: 14px;
  top: 14px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f6e1d6;
  color: var(--savings);
  font-weight: 700;
  font-size: 15px;
}

/* Ingredient tokens: sit in the cabinet or on an offer card, then fly to a day (act 3). */

.token {
  --sx: 0px;
  --k: 0;
  --s2: clamp(0, (var(--a2) - var(--k) * 0.15) / 0.7, 1);
  --t: clamp(0, (var(--a3) - var(--d)) / 0.45, 1);
  --pop: clamp(0, (var(--a3) - 0.82) / 0.18, 1);
  left: var(--x0);
  top: var(--y0);
  width: var(--w);
  height: var(--w);
  transform: translate(
      calc((var(--x1) - var(--x0)) * var(--t) + var(--sx) * (1 - var(--s2))),
      calc((var(--y1) - var(--y0)) * var(--t) - 4 * var(--t) * (1 - var(--t)) * 150px)
    )
    scale(calc(1 - 0.4 * var(--t)))
    rotate(calc(var(--t) * var(--r, 0deg)));
  opacity: calc(1 - var(--pop));
  filter: drop-shadow(0 6px 6px rgb(60 40 10 / 0.25));
}

.token svg {
  position: static;
  width: 100%;
  height: 100%;
}

/* Week plan (act 3) */

.day {
  --in: clamp(0, (var(--a3) - 0.2) * 4 - var(--i) * 0.15, 1);
  --pop: clamp(0, (var(--a3) - 0.8) / 0.2, 1);
  left: calc(36px + var(--i) * 180px);
  top: 250px;
  width: 168px;
  height: 290px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 20px 36px -22px rgb(30 42 34 / 0.5);
  opacity: calc(var(--in) * (1 - var(--a4) * 0.8));
  transform: translateY(calc((1 - var(--in)) * 50px - var(--a4) * 170px)) scale(calc(1 - var(--a4) * 0.2));
}

.day b {
  top: 16px;
  left: 18px;
  font-family: var(--serif);
  font-size: 24px;
}

.day span {
  left: 16px;
  right: 16px;
  bottom: 18px;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 600;
  opacity: var(--pop);
}

.dish {
  left: 14px;
  top: 76px;
  width: 140px;
  height: 140px;
  opacity: var(--pop);
  transform: scale(calc(0.5 + var(--pop) * 0.5));
}

.dish svg {
  position: static;
  width: 100%;
  height: 100%;
}

/* Shopping list (act 4) */

.list {
  --in: clamp(0, var(--a4) * 2, 1);
  left: 230px;
  top: 120px;
  width: 500px;
  height: 560px;
  border-radius: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 40px 70px -30px rgb(30 42 34 / 0.55);
  opacity: var(--in);
  transform: translateY(calc((1 - var(--in)) * 420px));
}

.list h3 {
  left: 32px;
  top: 28px;
  margin: 0;
  font-size: 36px;
}

.list .example {
  right: 28px;
  top: 36px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

.list .sum {
  left: 32px;
  top: 88px;
  font-size: 24px;
  font-weight: 700;
  white-space: nowrap;
}

.list .sum * {
  position: static;
}

.list .sum em {
  font-style: normal;
  color: var(--savings);
  margin-left: 14px;
}

.list .pantry {
  left: 32px;
  right: 32px;
  top: 136px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
}

.row {
  --c: clamp(0, (var(--a4) - 0.45 - var(--i) * 0.09) / 0.09, 1);
  left: 32px;
  right: 32px;
  top: calc(214px + var(--i) * 66px);
  height: 66px;
  border-top: 1px solid var(--border);
}

.row .box {
  left: 0;
  top: 20px;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 2px solid #9aa295;
}

.row .box::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 7px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
      center / 18px no-repeat,
    var(--accent);
  opacity: var(--c);
  transform: scale(calc(0.4 + var(--c) * 0.6));
}

.row b {
  left: 46px;
  top: 8px;
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
}

.row i {
  left: 46px;
  top: 36px;
  font-style: normal;
  font-size: 15px;
  color: var(--muted);
  white-space: nowrap;
}

.row i mark {
  position: static;
  background: none;
  color: var(--savings);
  font-weight: 700;
  margin-left: 6px;
}

.row em {
  right: 0;
  top: 10px;
  font-style: normal;
  font-weight: 700;
  font-size: 20px;
}

.row s {
  right: 0;
  top: 38px;
  color: var(--muted);
  font-size: 15px;
}

/* Mobile: text above the stage. */

@media (max-width: 860px) {
  .pin {
    grid-template-columns: 1fr;
    align-content: start;
    gap: 8px;
  }

  .anim .pin {
    grid-template-rows: minmax(0, 38%) minmax(0, 1fr);
    padding-top: calc(var(--header) + 12px);
  }

  .beat h2 {
    font-size: clamp(1.7rem, 7vw, 2.4rem);
  }

  .anim .beat h1 {
    font-size: clamp(2rem, 9vw, 2.8rem);
  }

  .anim .beat .lead,
  .anim .beat p {
    font-size: 1rem;
    margin-bottom: 0.6em;
  }

  .anim .beat {
    justify-content: flex-end;
  }

  .anim .progress {
    display: none;
  }
}

/* Without animation: all beats as a list, the finished scene stays beside them. */

html:not(.anim) .hint {
  display: none;
}

html:not(.anim) .pin {
  align-items: start;
}

html:not(.anim) .stage {
  position: sticky;
  top: calc(var(--header) + 32px);
}
