:root {
  --ink: #0b0b0d;
  --paper: #f4eee4;
  --paper-dim: rgba(244, 238, 228, 0.84);
  --paper-faint: rgba(244, 238, 228, 0.52);
  --gold: #e8bd77;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --gutter: clamp(1.25rem, 4vw, 4.5rem);
  --scene-h: 165vh;
  --panel-h: 100vh;
  --edge-l: max(var(--gutter), env(safe-area-inset-left));
  --edge-r: max(var(--gutter), env(safe-area-inset-right));
}

/* Small-viewport units hold still while a phone's URL bar slides in and out,
   which vh does not. */
@supports (height: 1svh) {
  :root {
    --scene-h: 165svh;
    --panel-h: 100svh;
  }
}

* { box-sizing: border-box; }

/* Vertical only. `clip` blocks sideways scrolling without turning the element
   into a scroll container the way `hidden` does; `hidden` stays as the fallback
   for older Safari. touch-action keeps pinch-zoom available for accessibility
   while refusing horizontal pans. */
html {
  scroll-behavior: smooth;
  overflow-x: hidden;
  overflow-x: clip;
}

body {
  margin: 0;
  max-width: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-x: clip;
  touch-action: pan-y pinch-zoom;
  overscroll-behavior-x: none;
}

/* ------------------------------------------------------------- the stage - */

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  opacity: 0;
  transition: opacity 1.6s ease 0.15s;
}

body.is-ready #stage { opacity: 1; }

/* A little real film grain over everything, so the WebGL layer and the type
   sit in the same material rather than looking pasted together. It used to
   step to a new offset three times a second, which on a still canvas read as
   crawling video noise; holding it still makes it read as the tooth of paper. */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* One shared wash behind the type, fixed to the viewport and faded in by the
   scroll code. A single element rather than a pseudo-element per panel, which
   is what used to reach past the viewport edge and invite sideways scrolling. */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(
    to right,
    rgba(7, 7, 9, 0.86) 0%,
    rgba(7, 7, 9, 0.74) 28%,
    rgba(7, 7, 9, 0.4) 50%,
    rgba(7, 7, 9, 0) 72%
  );
}

/* ----------------------------------------------------------------- chrome - */

.masthead {
  position: fixed;
  top: max(var(--gutter), env(safe-area-inset-top));
  left: var(--edge-l);
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  font-family: var(--sans);
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--paper-faint);
  pointer-events: none;
  /* The corners sit over whatever the canvas is doing, which is often a bright
     sky, so the chrome carries its own shadow rather than a scrim. */
  text-shadow: 0 1px 3px rgba(6, 6, 8, 0.85), 0 0 16px rgba(6, 6, 8, 0.7);
}

.masthead__name { color: var(--paper-dim); }

.rail li { text-shadow: 0 1px 3px rgba(6, 6, 8, 0.85), 0 0 14px rgba(6, 6, 8, 0.65); }

.rail {
  position: fixed;
  top: 50%;
  right: clamp(0.9rem, 2.2vw, 2.4rem);
  transform: translateY(-50%);
  z-index: 4;
  pointer-events: none;
  font-family: var(--sans);
}

.rail__now { display: none; }

.rail ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  align-items: flex-end;
}

.rail li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  color: rgba(239, 231, 218, 0.2);
  transition: color 0.5s ease;
}

.rail .year {
  order: -1;
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.rail .tick {
  width: 14px;
  height: 1px;
  background: currentColor;
  transition: width 0.5s ease, background 0.5s ease;
}

.rail li.is-past { color: rgba(239, 231, 218, 0.32); }

.rail li.is-active { color: var(--gold); }
.rail li.is-active .tick { width: 30px; }
.rail li.is-active .year { opacity: 1; transform: translateX(0); }

/* ---------------------------------------------------------------- panels - */

#scroller {
  position: relative;
  z-index: 3;
}

.panel {
  position: relative;
  display: flex;
  align-items: center;
  padding-left: var(--edge-l);
  padding-right: var(--edge-r);
}

.panel--prologue { min-height: var(--panel-h); }

.panel--epilogue {
  min-height: var(--panel-h);
  padding-top: 14vh;
  padding-bottom: max(14vh, env(safe-area-inset-bottom));
}

.panel--scene { height: var(--scene-h); }

/* The prologue and epilogue centre; the scene plates sit in the left column
   with the painting held in the right two thirds by the shader. */
.prologue {
  max-width: 34rem;
  margin: 0 auto;
  text-align: center;
}

.plate {
  position: sticky;
  top: 50%;
  width: min(30rem, 34vw);
  transform: translate3d(0, 26px, 0);
  will-change: opacity, transform;
  text-shadow: 0 1px 14px rgba(6, 6, 8, 0.55);
}

.plate > * { margin: 0; }

.prologue { text-shadow: 0 1px 18px rgba(6, 6, 8, 0.6); }

/* ------------------------------------------------------------------ type - */

.eyebrow {
  font-family: var(--sans);
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 1.4em !important;
}

h1 {
  font-size: clamp(2.8rem, 7.5vw, 5.4rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 0 0 0.5em !important;
}

h2 {
  font-size: clamp(1.5rem, 2.5vw, 2.1rem);
  font-weight: 400;
  line-height: 1.16;
  letter-spacing: -0.015em;
  margin-bottom: 0.7em !important;
}

.standfirst {
  font-size: clamp(1rem, 1.35vw, 1.15rem);
  line-height: 1.66;
  color: var(--paper-dim);
}

.body {
  font-size: clamp(0.98rem, 1.15vw, 1.08rem);
  line-height: 1.72;
  color: var(--paper-dim);
}

.body em { color: var(--paper); font-style: italic; }

.label {
  margin-top: 2.2em !important;
  padding-top: 1.1em;
  border-top: 1px solid rgba(239, 231, 218, 0.14);
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}

.label__title {
  font-size: 1.02rem;
  font-style: italic;
  color: var(--paper);
}

.label__meta {
  font-family: var(--sans);
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--paper-faint);
}

.hint {
  margin-top: 3.5em !important;
  font-family: var(--sans);
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--paper-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}

.hint__rule {
  width: 1px;
  height: 3.4rem;
  background: linear-gradient(to bottom, transparent, var(--gold));
  animation: reach 2.8s ease-in-out infinite;
  transform-origin: top;
}

@keyframes reach {
  0%, 100% { transform: scaleY(0.45); opacity: 0.4; }
  50%      { transform: scaleY(1);    opacity: 1; }
}

.coda {
  margin-top: 2.4em !important;
  font-size: 0.94rem;
  line-height: 1.7;
  color: var(--paper-faint);
  font-style: italic;
}

.disclosure {
  margin-top: 2.2em !important;
  padding: 1.3em 1.5em;
  border: 1px solid rgba(232, 189, 119, 0.24);
  font-size: 0.88rem;
  line-height: 1.7;
  text-align: left;
  color: var(--paper-faint);
}

.credit {
  margin-top: 2.4em !important;
  font-family: var(--sans);
  font-size: 0.64rem;
  line-height: 1.85;
  letter-spacing: 0.04em;
  color: rgba(239, 231, 218, 0.24);
}

/* -------------------------------------------------------------- fallback - */

.fallback {
  display: none;
  position: relative;
  z-index: 5;
  max-width: 32rem;
  margin: 0 auto;
  padding: 22vh var(--gutter);
  text-align: center;
}

.fallback p { color: var(--paper-dim); line-height: 1.7; }

body.no-webgl .fallback--gl { display: block; }
body.no-webgl #scroller,
body.no-webgl .rail { display: none; }

noscript .fallback { display: block; }

/* ------------------------------------------------------------ responsive - */

@media (max-width: 899px), (max-aspect-ratio: 21/20) {
  :root { --scene-h: 132vh; }
  @supports (height: 1svh) { :root { --scene-h: 132svh; } }

  .panel--scene {
    align-items: flex-end;
    padding-bottom: max(9vh, calc(env(safe-area-inset-bottom) + 2.5rem));
  }

  .plate {
    position: sticky;
    top: auto;
    bottom: max(7vh, calc(env(safe-area-inset-bottom) + 1.5rem));
    width: 100%;
    max-width: 34rem;
    margin: 0 auto;
  }

  /* The type sits under the canvas here, so the wash rises from the bottom. */
  .scrim {
    background: linear-gradient(
      to top,
      rgba(7, 7, 9, 0.93) 0%,
      rgba(7, 7, 9, 0.87) 24%,
      rgba(7, 7, 9, 0.5) 52%,
      rgba(7, 7, 9, 0) 78%
    );
  }

  .rail { display: none; }

  .masthead {
    flex-direction: row;
    align-items: baseline;
    gap: 0.9em;
    font-size: 0.6rem;
  }

  /* Nudge the reading sizes up: the desktop clamps bottom out too small once
     the vw term stops contributing anything on a narrow screen. */
  h1 { font-size: clamp(2.5rem, 12vw, 3.9rem); }
  h2 { font-size: clamp(1.5rem, 6.2vw, 2.05rem); }

  .body { font-size: 1.04rem; line-height: 1.66; }
  .standfirst { font-size: 1.06rem; line-height: 1.62; }
  .eyebrow { font-size: 0.66rem; letter-spacing: 0.22em; margin-bottom: 1.1em !important; }

  .label { margin-top: 1.7em !important; padding-top: 0.95em; }
  .label__title { font-size: 1.06rem; }
  .label__meta { font-size: 0.7rem; letter-spacing: 0.1em; }

  .coda { font-size: 0.98rem; }
  .disclosure { font-size: 0.92rem; padding: 1.1em 1.2em; }
  .credit { font-size: 0.68rem; }
  .hint { margin-top: 2.6em !important; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .hint__rule { animation: none; transform: scaleY(1); }
  #stage { transition: none; }
}
