/*
 * Zestmere Sparkling Water — a one-page project in live 3D (tickets/SC-11.md).
 *
 * Layers of the pinned stage, back to front:
 *   .field     z0  the place before the script: sky over water, and the word
 *   #gl        z2  the place itself — a lake under an open sky, the word standing in
 *                  it — and the cans, the fruit, the water thrown up: one canvas
 *   .bar …     z4  the interface, which stands still: the captions of act 1, the callouts
 *                  of act 2, the line and the button of act 4
 * After the stage, in the flow of the page: .foot.
 *
 * A light page: every hour of the lake is a light one and the interface is one ink on all of them.
 */

:root {
  --zm-sky: #eaf6ff;
  --zm-pink: #ff5a7a;
  --zm-lemon: #ffd23f;
  --zm-mint: #7bd389;
  --zm-ink: #0b2545;
  --zm-white: #ffffff;

  --ease-camera: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-text: cubic-bezier(0.16, 1, 0.3, 1);
  --gutter: clamp(16px, 2.6vw, 40px);

  /*
   * The project's own pair. Shrikhand — the face on the can — sets every large word:
   * it has one weight, and is never set under 20px. DM Sans sets everything small.
   * The studio's faces are used in one place only: the studio's corner of the footer.
   */
  --face-display: "Shrikhand", Georgia, "Times New Roman", serif;
  --face-text: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --face-studio: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--zm-sky);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--zm-ink);
  font-family: var(--face-text);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
}

p,
h1,
h2,
h3,
ol,
ul {
  margin: 0;
  padding: 0;
}

/* ——— The pinned scene ——— */

/* 6.3 screens of scroll for the four acts, and the screen the stage itself takes. */
.scene {
  position: relative;
  height: 730vh;
}

.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  isolation: isolate;
}

/*
 * ——— z0: the place, before the script and without it ———
 *
 * Live, the lake is drawn in the canvas. Here it is two washes: the sky paling to the
 * horizon, the water deepening from it — and the word standing where they meet.
 */

.field {
  position: absolute;
  inset: 0;
  background-color: var(--zm-sky);
  background-image: linear-gradient(
    to bottom,
    #a9d9fa 0%,
    #eaf6ff 50%,
    #c4e4f8 50.2%,
    #7cc5ee 100%
  );
}

.is-live .field {
  visibility: hidden;
}

/* ——— z1: the monument word ——— */

.word {
  position: absolute;
  left: 0;
  right: 0;
  top: 46%;
  transform: translate3d(0, -50%, 0);
  color: var(--zm-pink);
  font-family: var(--face-display);
  font-size: var(--word-size, 17vw);
  font-weight: 400;
  font-synthesis: none;
  line-height: 0.8;
  text-align: center;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

/* The phrase of act 3 is in the picture; this is the same phrase for a reader that does not see it. */
.said {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ——— z2: the cans ——— */

#gl {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 700ms var(--ease-camera);
}

#gl.is-ready {
  opacity: 1;
}

/* ——— Tones of the interface: one ink; on pink it is never thinned ——— */

[data-ui] {
  --ui: var(--zm-ink);
  --ui-dim: rgb(11 37 69 / 0.82);
  --ui-line: rgb(11 37 69 / 0.42);
  color: var(--ui);
}

[data-ui][data-tone="pink"] {
  --ui-dim: var(--zm-ink);
  --ui-line: rgb(11 37 69 / 0.6);
}

/* ——— z4: the interface ——— */

.bar {
  position: absolute;
  top: var(--gutter);
  left: var(--gutter);
  right: var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--face-display);
  font-size: 22px;
  font-weight: 400;
  font-synthesis: none;
}

.brand-mark {
  flex: none;
  width: 28px;
  height: 28px;
}

.brand-cut {
  fill: none;
  stroke: var(--zm-white);
  stroke-width: 3.4;
  stroke-linecap: round;
}

.bar-note {
  color: var(--ui-dim);
}

/* The captions share one cell; one is shown at a time. */
.captions {
  position: absolute;
  left: var(--gutter);
  bottom: calc(var(--gutter) + 4px);
  display: grid;
  width: min(34vw, 520px);
}

.caption {
  grid-area: 1 / 1;
  align-self: end;
}

.title {
  font-family: var(--face-display);
  font-size: clamp(30px, 3.3vw, 54px);
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.04;
}

.notes {
  margin-top: 14px;
  color: var(--ui-dim);
  font-size: clamp(15px, 1.2vw, 18px);
  font-weight: 500;
  line-height: 1.35;
}

/* A line comes up from under a mask and leaves the way it came. */
.line {
  display: block;
  overflow: hidden;
  padding-bottom: 0.14em;
  margin-bottom: -0.14em;
}

.line > span {
  display: block;
  transform: translate3d(0, 118%, 0);
  transition: transform 300ms var(--ease-camera);
}

.caption.is-on .line > span,
.callout.is-on .line > span,
.final.is-on .line > span {
  transform: none;
  transition: transform 700ms var(--ease-text) calc(var(--i, 0) * 70ms + 160ms);
}

/* The three flavours: a swatch each. The one in front is ringed. */
.index {
  position: absolute;
  right: var(--gutter);
  top: 70%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  transform: translateY(-50%);
  transition:
    opacity 420ms var(--ease-camera),
    visibility 0s linear 0s;
}

.stage:not([data-act="0"]) .index {
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 420ms var(--ease-camera),
    visibility 0s linear 420ms;
}

.count {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.count-now {
  display: block;
  height: 1em;
  overflow: hidden;
}

.roll {
  display: flex;
  flex-direction: column;
  transform: translate3d(0, calc(var(--n, 0) * -1em), 0);
  transition: transform 700ms var(--ease-text);
}

.roll > span {
  display: block;
  height: 1em;
}

.swatches {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  list-style: none;
}

.swatches button {
  position: relative;
  display: block;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

[data-flavour="grapefruit"] {
  --c: var(--zm-pink);
}

[data-flavour="lemon"] {
  --c: var(--zm-lemon);
}

[data-flavour="lime"] {
  --c: var(--zm-mint);
}

.swatches button::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px solid var(--zm-ink);
  border-radius: 50%;
  background-color: var(--c);
  transition: transform 500ms var(--ease-text);
}

.swatches button::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px solid var(--zm-ink);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.7);
  transition:
    opacity 300ms linear,
    transform 500ms var(--ease-text);
}

.swatches button:hover::before,
.swatches button:focus-visible::before {
  transform: scale(1.18);
}

.swatches button:focus-visible {
  outline: 2px solid var(--zm-ink);
  outline-offset: 2px;
}

.stage[data-state="1"] .swatches li:nth-child(1) button::after,
.stage[data-state="2"] .swatches li:nth-child(2) button::after,
.stage[data-state="3"] .swatches li:nth-child(3) button::after {
  opacity: 1;
  transform: none;
}

.hint {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--gutter) + 4px);
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ui-dim);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  transition: opacity 420ms var(--ease-camera);
}

.hint i {
  display: block;
  width: 1px;
  height: 34px;
  background-color: currentColor;
}

.stage.is-moving .hint {
  opacity: 0;
}

/* ——— Act 2: one can in detail ——— */

.detail,
.final {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.leader path {
  fill: none;
  stroke: var(--ui);
  stroke-width: 1.5;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 300ms var(--ease-camera);
}

.leader .dot {
  fill: var(--ui);
  opacity: 0;
  transition: opacity 200ms linear;
}

.leader .ring {
  fill: none;
  stroke: var(--ui);
  stroke-width: 1.5;
  opacity: 0;
  transition: opacity 200ms linear;
}

.leader.is-on path {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 700ms var(--ease-text) 140ms;
}

.leader.is-on .dot {
  opacity: 1;
  transition: opacity 240ms linear 520ms;
}

.leader.is-on .ring {
  opacity: 0.6;
  transition: opacity 240ms linear 620ms;
}

.callout {
  position: absolute;
  left: var(--gutter);
  width: min(26vw, 400px);
}

.callout[data-n="0"] {
  top: 21%;
}

.callout[data-n="1"] {
  left: auto;
  right: var(--gutter);
  top: 40%;
  text-align: right;
}

.callout[data-n="1"] .callout-word {
  margin-left: auto;
}

.callout[data-n="2"] {
  top: 66%;
}

.callout-word {
  width: -webkit-fit-content;
  width: fit-content;
  font-family: var(--face-display);
  font-size: clamp(38px, 5vw, 84px);
  font-weight: 400;
  font-synthesis: none;
  line-height: 0.98;
}

/* ——— Act 4: the three together ——— */

.final-body {
  position: absolute;
  left: var(--gutter);
  top: 50%;
  width: min(50vw, 760px);
  transform: translate3d(0, -50%, 0);
}

.final-title {
  font-family: var(--face-display);
  font-size: clamp(2.75rem, 6vw, 6.5rem);
  font-weight: 400;
  font-synthesis: none;
  line-height: 0.98;
}

/* The button: a capsule with its arrow in a round — ink on the field, the pink of the brand. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  height: 60px;
  margin-top: clamp(24px, 4.4vh, 48px);
  padding: 6px 6px 6px 28px;
  border-radius: 999px;
  background-color: var(--zm-ink);
  color: var(--zm-white);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity 240ms linear,
    transform 320ms var(--ease-camera),
    background-color 180ms linear;
}

.final.is-on .pill {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  transition:
    opacity 420ms linear 440ms,
    transform 700ms var(--ease-text) 440ms,
    background-color 180ms linear;
}

.pill:hover {
  background-color: #061a33;
}

.pill:focus-visible {
  outline: 2px solid var(--zm-ink);
  outline-offset: 3px;
}

.pill-round {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--zm-pink);
  color: var(--zm-ink);
  transition: transform 180ms var(--ease-camera);
}

.pill-round svg,
.studio svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 180ms var(--ease-camera);
}

.pill:hover .pill-round,
.pill:focus-visible .pill-round {
  transform: scale(1.06);
}

.pill:hover .pill-round svg,
.pill:focus-visible .pill-round svg {
  transform: rotate(45deg);
}

/*
 * ——— The footer: the lake goes on ———
 *
 * Not a sheet with a name and a list: the water of the lake's last hour, lemon light on
 * it. The three flavours float on it as three wheels of fruit, their names under them;
 * the name of the brand stands in the water to its middle and is mirrored under itself.
 */

.foot {
  position: relative;
  padding-top: clamp(30px, 4.6vh, 44px);
  background-color: var(--zm-lemon);
  background-image:
    radial-gradient(60% 70% at 28% 36%, rgb(255 255 255 / 0.34), rgb(255 255 255 / 0) 70%),
    linear-gradient(to bottom, #ffd84c 0%, #ffcf37 55%, #f8c11f 100%);
  color: var(--zm-ink);
}

/* No edge where the picture of the lake ends and this water begins: one runs into the other. */
.foot::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 28px;
  background-image: linear-gradient(to bottom, rgb(255 216 76 / 0), #ffd84c);
  pointer-events: none;
}

/* The ripples: long thin streaks of light, made by a filter. */
.foot-water {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.38;
  pointer-events: none;
}

.foot-fruit {
  position: relative;
  display: flex;
  justify-content: center;
  gap: clamp(12px, 5vw, 90px);
  padding: 0 var(--gutter);
  list-style: none;
}

.foot-fruit li {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: clamp(96px, 20vw, 290px);
  text-align: center;
}

/* A wheel lies on the water: its shadow is under it and does not turn with it. */
.afloat {
  display: block;
  width: clamp(88px, 10.4vw, 150px);
  filter: drop-shadow(0 12px 9px rgb(150 96 0 / 0.3));
}

/* The fruit is a photograph, cut out. Its very edge — the fringe of the cut-out — is left outside the round. */
.wheel {
  display: block;
  width: 100%;
  height: auto;
  clip-path: circle(48.4%);
  filter: saturate(1.16);
  animation: zm-turn 64s linear infinite;
}

.wheel[data-flavour="lime"] {
  clip-path: circle(47.4%);
}

.foot-fruit li:nth-child(2) .wheel {
  animation-duration: 80s;
  animation-direction: reverse;
}

@keyframes zm-turn {
  to {
    transform: rotate(1turn);
  }
}

.foot-fruit b {
  margin-top: clamp(12px, 1.6vw, 20px);
  font-family: var(--face-display);
  font-size: clamp(20px, 1.9vw, 28px);
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.12;
}

.foot-fruit span {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
}

.foot-line {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 6px 18px;
  margin: clamp(20px, 3vh, 28px) var(--gutter) 0;
  text-align: center;
}

.foot-line b {
  font-family: var(--face-display);
  font-size: 22px;
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.2;
}

.foot-line span {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.35;
}

/* The name: the brand's own face, as on the can. */
.foot-word {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  margin-top: clamp(4px, 1vh, 10px);
}

.foot-letters {
  fill: var(--zm-pink);
  font-family: "Shrikhand", Georgia, "Times New Roman", serif;
  font-size: 264px;
  font-weight: 400;
}

.foot-waterline {
  fill: none;
  stroke: var(--zm-white);
  stroke-width: 2.5;
  stroke-opacity: 0.75;
  stroke-dasharray: 220 26 90 18 320 30 60 22;
}

/* The studio signs in its own colours, not the brand's: volt and ink, in the corner. */
.studio {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px var(--gutter) 18px 26px;
  border-top-left-radius: 28px;
  background-color: #d6fa50;
  color: #0a0a0a;
  font-family: var(--face-studio);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
  transition: background-color 180ms linear;
}

.studio:hover,
.studio:focus-visible {
  background-color: #b8dc2c;
}

.studio:focus-visible {
  outline: 2px solid var(--zm-ink);
  outline-offset: 3px;
}

.studio svg {
  width: 16px;
  height: 16px;
}

.studio:hover svg,
.studio:focus-visible svg {
  transform: rotate(45deg);
}

/* ——— A tall screen: the word in two halves, over the can and under it ——— */

@media (max-aspect-ratio: 4 / 5) {
  .scene {
    height: 710vh;
    height: 710svh;
  }

  /* The word in two halves: one in the sky, one on the water. */
  .word {
    top: 12%;
    bottom: 25%;
    left: 5%;
    right: 5%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transform: none;
    font-size: var(--word-size, 19vw);
  }

  .word span:first-child {
    text-align: left;
  }

  .word span:last-child {
    text-align: right;
  }

  .brand {
    font-size: 20px;
  }

  .bar-note {
    display: none;
  }

  .captions {
    width: min(78vw, 320px);
    bottom: calc(var(--gutter) + 6px + env(safe-area-inset-bottom, 0px));
  }

  .title {
    font-size: 30px;
  }

  .notes {
    margin-top: 8px;
    font-size: 15px;
  }

  /* The swatches lie in a row at the foot, on the right. */
  .index {
    top: auto;
    bottom: calc(var(--gutter) - 4px + env(safe-area-inset-bottom, 0px));
    right: calc(var(--gutter) - 10px);
    transform: none;
    gap: 0;
  }

  .count {
    display: none;
  }

  .swatches {
    flex-direction: row;
    align-items: center;
  }

  .swatches button {
    width: 34px;
  }

  .swatches button::before {
    inset: 12px 7px;
  }

  .swatches button::after {
    inset: 7px 2px;
  }

  .hint {
    display: none;
  }

  /* The callouts share the foot of the screen; the newest one is shown. */
  .callout[data-n="0"],
  .callout[data-n="1"],
  .callout[data-n="2"] {
    left: var(--gutter);
    right: var(--gutter);
    top: auto;
    bottom: calc(var(--gutter) + 8px + env(safe-area-inset-bottom, 0px));
    width: auto;
    text-align: left;
  }

  .callout-word,
  .callout[data-n="1"] .callout-word {
    margin-left: 0;
    font-size: 48px;
  }

  .final-body {
    top: auto;
    bottom: calc(var(--gutter) + 10px + env(safe-area-inset-bottom, 0px));
    width: auto;
    transform: none;
  }

  .final-title {
    font-size: clamp(2.5rem, 12.6vw, 3.6rem);
  }

  .pill {
    height: 54px;
    margin-top: 20px;
    padding-left: 24px;
  }

  .pill-round {
    width: 42px;
    height: 42px;
  }

  /* The corner of the studio stands under the name, on the water. */
  .foot {
    padding-bottom: 64px;
  }

  .foot-fruit {
    gap: 10px;
    justify-content: space-between;
  }

  /* A name may take two lines; the line under the names stays level. */
  .foot-fruit b {
    display: flex;
    align-items: center;
    min-height: 2.24em;
  }

  .foot-line {
    flex-direction: column;
    align-items: center;
  }
}

/*
 * ——— Reduced motion (or ?still): the acts become plain sections ———
 *
 * No pinned stage and no long scroll: the script draws one frame of each act
 * and sets it in a section of its own (.still) — the field, the picture of
 * the cans, the words — one under another.
 */

.rm .scene {
  height: auto;
}

.rm .stage {
  position: relative;
}

.rm .stage[hidden] {
  display: none;
}

.still {
  position: relative;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  isolation: isolate;
}

.still-shot {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.rm .hint,
.rm .index {
  display: none;
}

.rm #gl,
.rm .line > span,
.rm .roll,
.rm .leader path,
.rm .leader circle,
.rm .pill,
.rm .index {
  transition: none !important;
}

.rm .line > span {
  transform: none;
}

.rm .caption:not(.is-on) {
  display: none;
}

.rm .leader path {
  stroke-dashoffset: 0;
}

.rm .leader .dot {
  opacity: 1;
}

.rm .leader .ring {
  opacity: 0.6;
}

.rm .pill {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.rm .wheel {
  animation: none;
}

@media (max-aspect-ratio: 4 / 5) {
  /* On a phone the three callouts stand in a column at the foot, without their lines. */
  .rm .detail {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
    padding: 0 var(--gutter) calc(var(--gutter) + 6px);
  }

  .rm .callout,
  .rm .callout[data-n="1"] {
    position: static;
  }

  .rm .callout-word,
  .rm .callout[data-n="1"] .callout-word {
    font-size: 30px;
  }

  .rm .callout-word .line {
    display: inline-block;
    vertical-align: top;
  }

  .rm .leaders {
    display: none;
  }
}

/* Before the script has run, or without it. */
@media (prefers-reduced-motion: reduce) {
  .scene {
    height: auto;
  }

  .stage {
    position: relative;
  }

  #gl,
  .line > span,
  .roll {
    transition: none;
  }

  .wheel {
    animation: none;
  }
}

/* ——— No WebGL: the field, the word and the words stay ——— */

.no-gl #gl {
  display: none;
}

/* ——— Checks ——— */

.hud {
  position: fixed;
  left: 8px;
  top: 64px;
  z-index: 20;
  margin: 0;
  padding: 8px 10px;
  border-radius: 4px;
  background: rgb(0 0 0 / 0.82);
  color: #b6ff7a;
  font: 12px/1.45 ui-monospace, Menlo, monospace;
  white-space: pre;
  pointer-events: none;
}

.labels {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  gap: 8px;
  padding: 8px;
  overflow: auto;
  background: #222;
}

.labels canvas {
  display: block;
  width: 100%;
  height: auto;
}

.labels .fruit {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
