/*
 * Sablemoor Cold Brew — a one-page project in live 3D (tickets/SC-09.md).
 *
 * Layers of the pinned stage, back to front:
 *   .field   z0  a field of coffee: only for a page without WebGL or script
 *   #gl      z1  everything that is lit: the bar (a wall with a shelf, a counter of wet
 *                stone, the light of a window), the bottles, the ice, the glass. One
 *                opaque canvas — glass refracts only what is drawn in its scene
 *   .bar …   z2  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 — the back label of the bottle.
 */

:root {
  --sb-dark: #1b120c;
  --sb-caramel: #c98a4b;
  --sb-cream: #f3e9dc;
  --sb-oat: #b98a5e;
  --sb-vanilla: #e7d3b1;

  --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 brand's own pair: the face of the label for every large word, a quiet grotesque
     for the small type. The studio's faces stay in the studio's corner alone. */
  --face-display: "Gloock", Georgia, "Times New Roman", serif;
  --face-text: "Instrument 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(--sb-dark);
  scrollbar-color: var(--sb-caramel) var(--sb-dark);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--sb-cream);
  font-family: var(--face-text);
  font-size: 16px;
  line-height: 1.35;
  /* Gloock has one weight: a bolder one is never faked. */
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
}

::selection {
  background-color: var(--sb-caramel);
  color: var(--sb-dark);
}

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;
  background-color: var(--sb-dark);
}

/* ——— z0: the field of a page without WebGL ——— */

.field {
  position: absolute;
  inset: 0;
  background-color: var(--sb-dark);
  background-image: radial-gradient(120% 88% at 50% 44%, #2e1e13 0%, #1b120c 48%, #110a06 100%);
}

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

/* ——— z1: the scene ——— */

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

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

/* ——— Tones of the interface: coffee on a light wall, cream on a dark one and on the counter ——— */

[data-ui] {
  --ui: var(--sb-dark);
  --ui-dim: rgb(27 18 12 / 0.94);
  --ui-line: rgb(27 18 12 / 0.45);
  --ui-moon: var(--sb-cream);
  color: var(--ui);
  transition: color 420ms var(--ease-camera);
}

[data-ui][data-tone="dark"] {
  --ui: var(--sb-cream);
  --ui-dim: rgb(243 233 220 / 0.74);
  --ui-line: rgb(243 233 220 / 0.36);
  --ui-moon: var(--sb-caramel);
}

/* ——— z2: 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: 500;
  line-height: 1;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-text {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
}

/* The name as on the label. */
.brand-name {
  font-family: var(--face-display);
  font-size: 23px;
  font-weight: 400;
  letter-spacing: -0.01em;
}

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

.brand-moon {
  fill: var(--ui-moon);
  transition: fill 420ms var(--ease-camera);
}

.bar-note {
  color: var(--ui-dim);
  transition: color 420ms var(--ease-camera);
}

/* 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(38px, 4.5vw, 74px);
  font-weight: 400;
  letter-spacing: -0.012em;
  line-height: 1;
}

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

/* 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 320ms 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 pointer of the three drinks. */
/* It stands over the hint, on the dark of the counter. */
.index {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--gutter) + 58px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  transition:
    opacity 420ms var(--ease-camera),
    visibility 0s linear 0s,
    color 420ms var(--ease-camera);
}

.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;
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  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;
}

.count-dash {
  color: var(--ui-dim);
}

.ticks {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  list-style: none;
}

.ticks button {
  position: relative;
  display: block;
  width: 44px;
  height: 18px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
}

.ticks button::after {
  content: "";
  position: absolute;
  right: 0;
  top: 8px;
  width: 16px;
  height: 2px;
  background-color: currentColor;
  opacity: 0.45;
  transition:
    width 500ms var(--ease-text),
    opacity 300ms linear;
}

.ticks button:hover::after,
.ticks button:focus-visible::after {
  opacity: 0.85;
}

.ticks button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.stage[data-state="0"] .ticks li:nth-child(1) button::after,
.stage[data-state="1"] .ticks li:nth-child(1) button::after,
.stage[data-state="2"] .ticks li:nth-child(2) button::after,
.stage[data-state="3"] .ticks li:nth-child(3) button::after {
  width: 40px;
  opacity: 1;
}

.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: 500;
  line-height: 1;
  transition:
    opacity 420ms var(--ease-camera),
    color 420ms var(--ease-camera);
}

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

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

/* ——— Act 2: one bottle 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;
  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;
  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.55;
  transition: opacity 240ms linear 620ms;
}

.callout {
  position: absolute;
  left: var(--gutter);
  white-space: nowrap;
}

/* The first line stands under the shelf of the bar. */
.callout[data-n="0"] {
  top: 29%;
}

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

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

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

.callout-word {
  width: -webkit-fit-content;
  width: fit-content;
  font-family: var(--face-display);
  font-size: clamp(28px, 3.1vw, 52px);
  font-weight: 400;
  letter-spacing: -0.012em;
  line-height: 1.04;
}

/* ——— Act 3: the phrase, for a reader that does not see the canvas ——— */

.slow {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

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

.final-title {
  font-family: var(--face-display);
  font-size: clamp(3.25rem, 6.2vw, 6.75rem);
  font-weight: 400;
  letter-spacing: -0.018em;
  line-height: 0.96;
}

/* The button: a capsule with its arrow in a round — coffee on the field, caramel in the round. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  height: 56px;
  margin-top: clamp(24px, 4vh, 44px);
  padding: 6px 6px 6px 24px;
  border-radius: 999px;
  background-color: var(--sb-dark);
  color: var(--sb-cream);
  font-size: 15px;
  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: #2e1e13;
}

.pill:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

/* Over the dark stone of the counter the capsule is the light one. */
.final[data-tone="dark"] .pill {
  background-color: var(--sb-cream);
  color: var(--sb-dark);
}

.final[data-tone="dark"] .pill:hover {
  background-color: #fff8ee;
}

.pill-round {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--sb-caramel);
  color: var(--sb-dark);
  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 back label of the bottle ———
 *
 * The wall of the bar goes on under the stage, the light of the blinds still across it.
 * No grid of a name on the left and a list on the right, as on the other pages of the set.
 * On it, what a bottle carries on its back: a narrow column set to the middle — the mark,
 * the name in the label's own face, the three drinks between hairlines, a line of small
 * type, the size. The studio's lime corner is the only thing here that is not the brand's.
 */

.foot {
  position: relative;
  display: grid;
  justify-items: center;
  padding: clamp(48px, 8vh, 76px) var(--gutter) clamp(88px, 12vh, 108px);
  overflow: hidden;
  isolation: isolate;
  background-color: #21160f;
  color: var(--sb-cream);
}

/* The window's light on the wall: slanted bands, lost towards the edges. */
.foot::before {
  content: "";
  position: absolute;
  inset: -20% -10%;
  z-index: -1;
  background-image: repeating-linear-gradient(
    194deg,
    rgb(116 73 42 / 0.42) 0 38px,
    rgb(116 73 42 / 0.3) 38px 42px,
    transparent 46px 70px,
    rgb(116 73 42 / 0.3) 74px 76px
  );
  -webkit-mask-image: radial-gradient(58% 70% at 50% 46%, #000 30%, transparent 100%);
  mask-image: radial-gradient(58% 70% at 50% 46%, #000 30%, transparent 100%);
}

.back {
  display: grid;
  justify-items: center;
  width: min(100%, 320px);
  text-align: center;
}

.back-mark {
  width: 40px;
  height: 40px;
}

/* The name as it is printed on the label. */
.back-name {
  margin-top: 16px;
  font-family: var(--face-display);
  font-size: clamp(2.5rem, 4.4vw, 3.25rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1;
}

.back-kind {
  margin-top: 10px;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
}

.back-list {
  width: 100%;
  margin-top: 26px;
  list-style: none;
  border-top: 1px solid rgb(243 233 220 / 0.42);
}

.back-list li {
  padding: 13px 0 12px;
  border-bottom: 1px solid rgb(243 233 220 / 0.42);
  font-family: var(--face-display);
  font-size: 23px;
  font-weight: 400;
  letter-spacing: -0.005em;
  line-height: 1.2;
}

.back-text {
  max-width: 30ch;
  text-wrap: balance;
  margin-top: 20px;
  color: rgb(243 233 220 / 0.82);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}

/* The size, as a label states it: by itself, at the foot. */
.back-size {
  margin-top: 16px;
  font-family: var(--face-display);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.005em;
  line-height: 1;
}

/* 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(--sb-cream);
  outline-offset: 3px;
}

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

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

/* ——— A tall screen ——— */

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

  .bar {
    font-size: 14px;
  }

  .brand-name {
    font-size: 21px;
  }

  .bar-note {
    display: none;
  }

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

  .title {
    font-size: 38px;
  }

  .notes {
    margin-top: 10px;
    font-size: 14px;
  }

  .index {
    top: var(--gutter);
    bottom: auto;
    gap: 14px;
  }

  .count {
    height: 26px;
    font-size: 14px;
  }

  .ticks button {
    width: 44px;
    height: 20px;
  }

  .hint {
    bottom: calc(var(--gutter) + 6px + env(safe-area-inset-bottom, 0px));
  }

  .hint span {
    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) + 6px + env(safe-area-inset-bottom, 0px));
    width: auto;
    text-align: left;
  }

  .callout-word,
  .callout[data-n="1"] .callout-word {
    margin-left: 0;
    font-size: clamp(25px, 8vw, 34px);
  }

  /* The line and the button stand on the wall, over the three on the counter. */
  .final-body {
    top: calc(var(--gutter) + 62px);
    width: auto;
    transform: none;
  }

  .final-title {
    font-size: clamp(2.9rem, 14.4vw, 3.9rem);
  }

  .pill {
    height: 52px;
    margin-top: 20px;
  }

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

  .foot {
    padding-top: 44px;
    padding-bottom: 96px;
  }
}

/*
 * ——— 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 picture of the scene and
 * the words of that act — 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;
  background-color: var(--sb-dark);
}

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

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

.rm #gl,
.rm [data-ui],
.rm .line > span,
.rm .roll,
.rm .leader path,
.rm .leader circle,
.rm .pill {
  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.55;
}

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

@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: 10px;
    padding: 0 var(--gutter) calc(var(--gutter) + 6px);
  }

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

  .rm .callout-word {
    font-size: 27px;
  }

  .rm .leaders {
    display: none;
  }
}

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

  .stage {
    position: relative;
  }

  #gl,
  [data-ui],
  .line > span,
  .roll {
    transition: none;
  }
}

/*
 * ——— Without the script ———
 *
 * One tall field of coffee, every word of the page in a column. The root carries the
 * class no-js in the markup; the script takes it off as it starts.
 */

.no-js .scene {
  height: auto;
}

.no-js .stage {
  position: relative;
  height: auto;
  min-height: 100vh;
  padding: clamp(96px, 16vh, 150px) var(--gutter) 56px;
}

.no-js .captions,
.no-js .detail,
.no-js .final {
  position: relative;
  inset: auto;
  display: block;
  width: auto;
  margin: 0 0 44px;
}

.no-js .final-body {
  position: static;
  width: auto;
  transform: none;
}

.no-js .caption,
.no-js .callout[data-n] {
  position: static;
  width: auto;
  margin-bottom: 24px;
  text-align: left;
}

.no-js .callout[data-n] .callout-word {
  margin-left: 0;
}

.no-js .line > span {
  transform: none;
}

.no-js .pill {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  background-color: var(--sb-cream);
  color: var(--sb-dark);
}

/* The phrase of act 3, which the script paints on the wall. */
.no-js .slow {
  position: relative;
  width: auto;
  height: auto;
  margin: 0 0 44px;
  overflow: visible;
  clip-path: none;
  white-space: normal;
  color: var(--sb-caramel);
  font-family: var(--face-display);
  font-size: clamp(3.6rem, 17vw, 7.5rem);
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 0.9;
}

.no-js .index,
.no-js .hint,
.no-js .leaders,
.no-js #gl {
  display: none;
}

/* ——— No WebGL: the field 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: 11px/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;
}
