/* ==========================================================================
   Mum's Birthday Card — Direction C · Atelier
   Tokens come straight from DESIGN.md §1. One easing curve, one shadow,
   no gradients, no rounded cards, no bounce.
   ========================================================================== */

:root {
  /* colour — roles, not decoration */
  --bg:      #E9E3DB;   /* putty  — page background, never white          */
  --surface: #D4CBC0;   /* greige — mats, caption plates, game sky        */
  --line:    #B7AA9B;   /* taupe  — hairlines, numerals, game ground      */
  --muted:   #6B5C50;   /* mocha  — labels, dates, captions               */
  --ink:     #3B3129;   /* cocoa  — primary type, line art, dark frame    */
  --accent:  #9E6F44;   /* clay   — one word per couplet, large type only */

  /* type */
  --sans:  "Outfit", "Helvetica Neue", Arial, sans-serif;
  --serif: "Cormorant Garamond", Garamond, Georgia, serif;

  /* spacing scale: 4 · 8 · 16 · 24 · 40 · 64 · 96 */
  --s1: 4px;  --s2: 8px;  --s3: 16px; --s4: 24px;
  --s5: 40px; --s6: 64px; --s7: 96px;
  --gutter: var(--s4);
  --section-pad: var(--s7);

  /* shape */
  --arch: 999px 999px 0 0;
  --shadow-soft: 0 40px 60px -40px rgba(59, 49, 41, 0.35);

  /* motion */
  --ease:  cubic-bezier(0.16, 1, 0.3, 1);
  --fast:  400ms;
  --base:  900ms;
  --slow:  1400ms;
  --drift: 9s;
}

@media (min-width: 900px) {
  :root { --gutter: var(--s6); --section-pad: 160px; }
}

/* --------------------------------------------------------------- reset -- */

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

html {
  -webkit-text-size-adjust: 100%;
  /* scrolling yes, pinching no: the layout has fixed bounds and zooming out
     puts the page in a frame it was never drawn for */
  touch-action: pan-x pan-y;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 300;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

img, video, canvas, svg { display: block; max-width: 100%; }
img { height: auto; }
figure { margin: 0; }
p, h1 { margin: 0; }
button { font: inherit; color: inherit; }

::selection { background: var(--line); color: var(--ink); }

:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }

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

/* Lenis (desktop smooth scroll) */
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }

/* ---------------------------------------------------------------- grain -- */

.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 90;
  opacity: 0.06;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* Pre-animation state. The page is rendered from content.js, so it needs JS
   either way; hiding these before the intro keeps the first paint quiet. */
.js .title,
.js .title__sig,
.js .title__meta { opacity: 0; }
.js .hero { clip-path: inset(0 calc(50% - 10px) 0 calc(50% - 10px)); }

/* ------------------------------------------------------------ typography -- */

.title {
  font-family: var(--sans);
  font-weight: 200;
  font-size: clamp(48px, 8vw, 112px);
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-transform: lowercase;
  text-align: center;
  text-wrap: balance;
  will-change: transform, filter, opacity;
}

.title__name {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.15em;
  letter-spacing: 0;
  text-transform: none;
}

.label {
  font-family: var(--sans);
  font-weight: 400;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

@media (min-width: 900px) { .label { font-size: 11px; } }

.caption {
  font-family: var(--sans);
  font-weight: 300;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

.couplet {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(24px, 3vw, 40px);
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--ink);
  max-width: min(100%, 32ch);
}

.couplet__line { display: block; text-wrap: balance; }
.couplet__line + .couplet__line { margin-top: 0.25em; }

.couplet .w--accent { color: var(--accent); }

/* 02 only: the words start taupe and are coloured in one at a time, with the
   clay word landing last */
.section--stack .couplet .w { color: var(--line); }

/* ------------------------------------------------------------- sections -- */

.section {
  position: relative;
  padding-inline: var(--gutter);
}

.pin {
  min-height: 100vh;             /* iOS before 15.4 has no svh */
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--s5);
  padding-block: var(--s7);
}

/* =========================================================== 01 · title == */

.section--title {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s5);
  padding-block: var(--s7);
  text-align: center;
}

.arch {
  border-radius: var(--arch);
  overflow: hidden;
  background: var(--surface);
}

.hero {
  width: min(70vw, 300px);
  aspect-ratio: 3 / 4;
}

@media (min-width: 900px) { .hero { width: min(30vw, 380px); } }

.hero__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: 50% 55%;
  will-change: transform, filter;
}

/* label size and tracking, but DESIGN.md §1 fixes this line as lowercase */
.title__sig {
  margin-top: calc(var(--s5) * -0.6);
  text-transform: none;
}

.mark {
  position: fixed;
  top: max(var(--s4), env(safe-area-inset-top));
  left: var(--gutter);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}

/* the corner label would vanish against the dark frame in 05 */
.mark--light { color: var(--bg); mix-blend-mode: normal; }

.cue {
  position: absolute;
  left: 50%;
  bottom: var(--s5);
  width: 1px;
  height: 0;
  background: var(--ink);
  transform: translateX(-50%);
}

/* =========================================================== 02 · stack == */

.section--stack .pin { align-items: center; text-align: center; }

.stack {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s4);
}

.stack__pile {
  position: relative;
  width: 100%;
  height: min(46svh, 400px);
  touch-action: pan-y;
}

.print {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(56vw, 240px);
  padding: var(--s2);              /* 8px greige mat */
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  will-change: transform;
}

@media (min-width: 900px) { .print { width: 290px; } }

.print__img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--line);
}

.stack__caption { opacity: 0; min-height: 1.55em; }

/* each print carries its caption, shown only where the pile is a column */
.print__caption { display: none; }

.stack__pile--static {
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s5);
}

.stack__pile--static .print { position: static; box-shadow: none; }
.stack__pile--static .print:first-child { box-shadow: var(--shadow-soft); }
.stack__pile--static .print__caption { display: block; margin-top: var(--s2); }

/* ============================================================ 03 · reel == */

.section--reel .pin { gap: var(--s6); }

.couplet--reel { text-align: left; }
.couplet--reel .couplet__line { will-change: transform, filter, opacity; }

.reel { width: 100%; }

/* touch and reduced motion get a native swipe strip instead of a pinned one */
.reel--native {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
}

.reel--native::-webkit-scrollbar { display: none; }
.reel--pinned { overflow: hidden; }

.reel__track {
  display: flex;
  gap: var(--s3);
  width: max-content;
  will-change: transform;
}

.clip {
  flex: 0 0 auto;
  width: min(62vw, 240px);
  scroll-snap-align: center;
}

@media (min-width: 900px) { .clip { width: 260px; } }

.clip__frame {
  position: relative;
  aspect-ratio: 9 / 16;
  background: var(--surface);
  opacity: 0.5;
  transition: opacity var(--fast) var(--ease);
}

.clip__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

/* a cocoa hairline at 6px offset means this one is playing */
.clip__frame::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1px solid var(--ink);
  opacity: 0;
  transition: opacity var(--fast) var(--ease);
  pointer-events: none;
}

.clip--playing .clip__frame { opacity: 1; }
.clip--playing .clip__frame::after { opacity: 1; }

/* an invisible control over a clip: the keyboard route to "tap for sound" */
.sound-toggle {
  position: absolute;
  inset: 0;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
}

.clip__caption {
  display: block;
  margin-top: var(--s3);
  color: var(--muted);
}

.clip--sound .clip__caption::after {
  content: " · sound on";
  color: var(--ink);
}

/* =========================================================== 04 · burst == */

.section--burst .pin {
  position: relative;
  align-items: center;
}

/* a phone has to fit a couplet and eight cells in one pinned viewport, so
   this section gets tighter padding than the rest */
@media (max-width: 899px) {
  .section--burst .pin {
    gap: var(--s4);
    padding-block: var(--s5);
  }
}

.couplet--burst {
  text-align: center;
  letter-spacing: 0.08em;
}

/* the grid the photos fly out to; they start stacked on its centre. Kept
   narrow on a phone so eight square cells and a couplet fit one pinned
   viewport without spilling past the edges. */
.burst {
  position: relative;
  width: 100%;
  /* two columns of four squares is 2x the width tall, so on a short phone the
     width has to come off the height: what is left after the padding and the
     couplet, halved */
  max-width: min(280px, calc((100svh - 260px) / 2));
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s2);
}

@media (min-width: 900px) {
  .burst {
    max-width: 900px;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--s3);
  }
}

.burst__img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface);
  will-change: transform, opacity;
}

/* ========================================================== 05 · window == */

/* the one section that runs to the edges: the dark frame has to cover the
   whole viewport, not just the column inside the gutters */
.section--window { padding-inline: 0; }

.section--window .pin {
  position: relative;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: 64px var(--gutter) var(--s4);   /* the top clears the fixed corner label */
  overflow: hidden;
}

.window__dark {
  position: absolute;
  inset: 0;
  background: var(--ink);
  opacity: 0;
}

/* The clip keeps its own 9:16. Full bleed cropped a vertical video down to
   a band across the middle on a laptop, and covered it with the couplet. */
.window__stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.window__media {
  position: relative;
  height: 100%;
  aspect-ratio: 9 / 16;
  max-width: 100%;
  will-change: clip-path;
}

.window__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--ink);
  cursor: pointer;
}

.couplet--window {
  position: relative;
  flex: none;
  text-align: center;
  color: var(--bg);
}

/* a ghost button in putty, since it sits on the dark frame */
.window__sound {
  position: relative;
  flex: none;
  min-height: 44px;
  padding-inline: var(--s4);
  color: var(--bg);
  background: transparent;
  border: 1px solid rgba(233, 227, 219, 0.45);
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}

.window__sound:hover,
.window--sound .window__sound {
  color: var(--ink);
  background: var(--bg);
  border-color: var(--bg);
}

.couplet--window .couplet__line { will-change: transform, filter, opacity; }

/* ========================================================= 06 · columns == */

.section--columns {
  padding-block: var(--section-pad);
  overflow: hidden;              /* the parallax runs past the section edges */
}

.couplet--columns {
  margin-left: auto;
  margin-bottom: var(--s7);
  text-align: right;
}

.couplet--columns .couplet__line { will-change: transform, opacity; }

.columns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s3);
  align-items: start;
}

@media (min-width: 900px) {
  .columns { grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
}

.column {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  will-change: transform;
}

/* on a phone the three columns are dealt back into two, so no photo is
   hidden — the items are redistributed, not dropped */

.column__img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--surface);
}

.column__img:nth-child(even) { aspect-ratio: 3 / 4; }

/* tonal plates carrying a line of caption, same family as the mats in 02 */
.column__card {
  color: var(--ink);
  background: var(--surface);
  padding: var(--s4);
  display: flex;
  align-items: center;
  min-height: 140px;
}

/* ============================================================ 07 · game == */

.section--game .pin { align-items: center; }

.couplet--game { text-align: center; }

.game {
  position: relative;
  width: 100%;
  max-width: 880px;
  touch-action: manipulation;
}

.game__canvas {
  width: 100%;
  height: 260px;
  background: var(--surface);
  cursor: pointer;
}

.game__canvas:focus-visible { outline-color: var(--line); }

/* night mode turns the sky cocoa; the HUD would vanish in mocha */
.game--night .label,
.game--night .score { color: var(--bg); }
.game--night .game__canvas:focus-visible { outline-color: var(--bg); }

.game__hud {
  position: absolute;
  top: var(--s3);
  z-index: 2;
  margin: 0;
}

.game__hud--left  { left: var(--s3); color: var(--ink); }

.game__hud--right {
  right: var(--s3);
  text-align: right;
  display: grid;
  gap: var(--s2);
  justify-items: end;
}

.score {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
}

.game__best { color: var(--ink); }
.game__mor, .game__flash { opacity: 0; }
.game__mor { color: var(--ink); }
.game__flash { max-width: 22ch; text-align: right; line-height: 1.5; }

.game__toast,
.game__place {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  opacity: 0;
  white-space: nowrap;
}

.game__toast { top: 26%; }

.game__place {
  top: 38%;
  font-size: 13px;
  letter-spacing: 0.4em;
  color: var(--ink);
}

.game__panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  padding: var(--s4);
  text-align: center;
  pointer-events: none;      /* a tap anywhere still reaches the canvas */
}

.game__panel .btn { pointer-events: auto; }
.game__panel--veil { background: rgba(233, 227, 219, 0.88); }

/* the intro has no veil, so it sits above her head rather than across it */
.game__panel--top { justify-content: flex-start; padding-top: var(--s6); }

/* the finish sits under the field: a 342px canvas has no room for copy over
   the shopfront, and the point of that scene is to be looked at */
.game__panel--below {
  inset: 100% 0 auto 0;
  padding: var(--s4) 0 0;
}

.game__panel[hidden] { display: none; }

.game__actions {
  display: flex;
  gap: var(--s3);
}

.game__copy {
  font-family: var(--sans);
  font-weight: 300;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  max-width: 28ch;
}

.btn {
  min-height: 44px;
  padding-inline: var(--s4);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}

.btn[hidden] { display: none; }
.btn--solid { background: var(--ink); color: var(--bg); }
.btn:hover  { background: var(--ink); color: var(--bg); }
.btn--solid:hover { background: transparent; color: var(--ink); }

.game__skip {
  position: absolute;
  right: 0;
  bottom: calc(var(--s5) * -1);
  padding: var(--s2) 0;
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.game__skip[hidden] { display: none; }

/* =========================================================== 08 · close == */

.section--close {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s6);
  padding-block: var(--section-pad);
  text-align: center;
}

.couplet--close { }

/* the print that turns over */
.turn {
  width: min(62vw, 260px);
  perspective: 1400px;
}

@media (min-width: 900px) { .turn { width: 300px; } }

.turn__inner {
  position: relative;
  transform-style: preserve-3d;
  will-change: transform;
}

.turn__face {
  padding: var(--s2);                /* the same 8px greige mat as 02 */
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  backface-visibility: hidden;
}

.turn__face--back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
}

.turn__img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--line);
}

.turn__hand {
  width: 52%;
  height: auto;
  opacity: 0.85;
}

.turn--photo .turn__face--back {
  justify-content: flex-start;
  gap: var(--s2);
  padding-bottom: var(--s3);
}

.turn--photo .turn__hand {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  object-fit: cover;
  opacity: 1;
}

/* hand-written, so it borrows the italic serif rather than the caps label */
.turn__sign {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  color: var(--ink);
}

.turn--flat .turn__inner { transform: none !important; transform-style: flat; }
.turn--flat .turn__face { backface-visibility: visible; }
.turn--flat .turn__face--back { transform: none; }

.close__rule {
  width: 40px;
  height: 1px;
  background: var(--line);
}

.close__top {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: var(--s1);
  transition: border-color var(--fast) var(--ease);
}

.close__top:hover { border-bottom-color: var(--line); }

/* ------------------------------------------------- reduced motion --------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.4s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.4s !important;
  }
  .hero__img { transform: none !important; filter: none !important; }
}
