/* ==========================================================================
   UP BEFORE THE ROOSTER — web pitch
   A 15-slide scrolling deck. Each slide pins to the viewport while the next
   one rises and dissolves over it; slides made of discrete panels have those
   panels flown in one at a time off a painted-out plate.

   Sections below run in the order the page is built:
     1. fonts + tokens      5. the caption + rail
     2. reset + ground      6. the outro
     3. the deck            7. the viewer
     4. the chrome          8. mobile + reduced motion
   ========================================================================== */

/* --- 1. fonts + tokens --------------------------------------------------- */

/* Agrandir (the deck's face) has no web licence, so the chrome is set in
   Archivo at its widest, heaviest setting — the same stand-in the printed
   bible's web edition uses. The slides themselves carry their own type. */
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url(fonts/archivo-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url(fonts/archivo-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --orange: #dd4500;
  --orange-lift: #ff5c12;
  --ink: #0b0a09;
  --ink-2: #141210;
  --paper: #e7e7e9;
  --hair: rgba(231, 231, 233, .16);

  --ui: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --tight: -0.03em;

  /* one scene = one slide's scroll runway */
  --scene: 165svh;
  --pad: clamp(18px, 3.4vw, 46px);

  /* the margin the slide floats in, which is also where the chrome lives */
  --gut: clamp(46px, 6.2vh, 78px);

  /* flipped per slide by the engine, so the chrome always has contrast */
  --chrome: #ffffff;
  --chrome-soft: rgba(255, 255, 255, .5);
  --chrome-faint: rgba(255, 255, 255, .28);

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);
}

body.on-light {
  --chrome: #14110f;
  --chrome-soft: rgba(20, 17, 15, .52);
  --chrome-faint: rgba(20, 17, 15, .3);
}

/* --- 2. reset + ground --------------------------------------------------- */

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

html { background: var(--ink); }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--ui);
  font-stretch: 112%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* film grain, laid over everything but the cursor */
#grain {
  position: fixed;
  inset: -60px;
  z-index: 90;
  pointer-events: none;
  opacity: .055;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 900ms steps(4) infinite;
}
@keyframes grain {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-14px, 9px); }
  50%  { transform: translate(11px, -12px); }
  75%  { transform: translate(-8px, -6px); }
  100% { transform: translate(0, 0); }
}

/* --- 3. the deck --------------------------------------------------------- */

#deck { position: relative; z-index: 0; }

/* The scene is only a runway — it has no visible surface of its own. */
.scene { position: relative; }

.stage {
  display: grid;
  place-items: center;
  background: var(--bg, var(--ink));
}

.frame {
  position: relative;
  margin: 0;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg, var(--ink)) center / cover no-repeat;
  transform-origin: 50% 50%;
}

.frame > .flat,
.frame .plate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Layer stack: hidden until every piece has decoded, so a slow connection
   never shows a plate with holes in it. */
.frame .layers { position: absolute; inset: 0; opacity: 0; }
.frame.layered .layers { opacity: 1; }
.frame.layered > .flat { opacity: 0; }

.frame .lyr {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  object-fit: cover;
  will-change: transform, opacity;
}

/* the outgoing slide sinks behind a scrim as the next one arrives */
.frame .dim {
  position: absolute;
  inset: 0;
  background: #050403;
  opacity: 0;
  pointer-events: none;
}

/* --- pinned mode (JS on, motion allowed) --- */
html.cine .scene { height: var(--scene); }
html.cine .stage {
  position: fixed;
  inset: 0;
  height: 100%;
  z-index: var(--i);
  will-change: transform, opacity;
  contain: strict;
}
html.cine .frame {
  width: min(calc(100vw - var(--gut) * 2), calc((100dvh - var(--gut) * 2) * 16 / 9));
  border-radius: 3px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .30), 0 2px 10px rgba(0, 0, 0, .18);
  cursor: zoom-in;
}
html.cine #deck { pointer-events: none; }
html.cine .frame { pointer-events: auto; }

/* --- flat mode (no JS, or reduced motion): a plain vertical gallery --- */
html:not(.cine) #deck { padding: 96px var(--pad) 40px; display: grid; gap: clamp(20px, 4vw, 56px); }
html:not(.cine) .frame { border-radius: 2px; }
html:not(.cine) #rail, html:not(.cine) #hint, html:not(.cine) #caption { display: none; }
html:not(.cine) #loader { display: none; }

/* --- 4. the chrome ------------------------------------------------------- */

#chrome {
  position: fixed;
  z-index: 60;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 calc(var(--gut) + 2px);
  height: var(--gut);
  pointer-events: none;
  color: var(--chrome);
  transition: color .45s var(--ease-io);
}
#chrome .mark {
  display: flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
#chrome .mark img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  /* a hairline so the white roundel still has an edge on the cream slides */
  box-shadow: 0 0 0 1px var(--chrome-faint);
  transition: box-shadow .45s var(--ease-io);
}
#chrome .count {
  margin: 0;
  display: flex;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  font-variant-numeric: tabular-nums;
}
#chrome .count i,
#chrome .count span { font-style: normal; color: var(--chrome-soft); }

/* scroll hint, slide one only */
#hint {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: 0;
  height: var(--gut);
  display: grid;
  place-items: center;
  transform: translateX(-50%);
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--chrome-faint);
  transition: opacity .5s var(--ease-io), color .45s var(--ease-io);
}
#hint span { display: inline-block; animation: bob 2.4s var(--ease-io) infinite; }
#hint.gone { opacity: 0; }
@keyframes chev {
  0%, 100% { transform: translateY(0) rotate(45deg); opacity: .5; }
  50%      { transform: translateY(4px) rotate(45deg); opacity: 1; }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: .55; }
  50%      { transform: translateY(6px); opacity: 1; }
}

/* --- 5. the caption + rail ----------------------------------------------- */

#caption {
  position: fixed;
  z-index: 60;
  left: calc(var(--gut) + 2px);
  bottom: 0;
  height: var(--gut);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 46vw;
  pointer-events: none;
  color: var(--chrome);
  transition: color .45s var(--ease-io), opacity .5s var(--ease-io);
}
#caption .cap-kicker {
  margin: 0;
  padding-right: 12px;
  border-right: 1px solid var(--chrome-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--chrome-soft);
  white-space: nowrap;
}
#caption .cap-num { display: none; }
#caption .cap-title {
  margin: 0;
  font-size: clamp(15px, 1.5vw, 21px);
  font-weight: 800;
  font-stretch: 118%;
  letter-spacing: var(--tight);
}
/* each change swaps the text and replays this */
#caption.swap .cap-kicker,
#caption.swap .cap-title { animation: capIn .62s var(--ease-out) backwards; }
#caption.swap .cap-title { animation-delay: .05s; }
@keyframes capIn {
  from { opacity: 0; transform: translateY(14px); clip-path: inset(0 0 100% 0); }
  to   { opacity: 1; transform: none; clip-path: inset(0 0 -20% 0); }
}

body.at-end #caption,
body.at-end #rail,
body.at-end #hint,
body.at-end #tap-note {
  opacity: 0;
  pointer-events: none;
}

#rail {
  position: fixed;
  z-index: 60;
  right: calc(var(--gut) * .34);
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  gap: 9px;
  color: var(--chrome);
  transition: color .45s var(--ease-io), opacity .5s var(--ease-io);
}
#rail button {
  position: relative;
  display: block;
  width: 26px;
  height: 10px;
  padding: 0;
}
#rail button::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 12px;
  height: 1.5px;
  background: currentColor;
  opacity: .3;
  transition: width .4s var(--ease-out), opacity .4s var(--ease-out);
}
#rail button:hover::after { width: 20px; opacity: .7; }
#rail button[aria-current='true']::after { width: 26px; opacity: 1; }
#rail button span {
  position: absolute;
  right: 34px;
  top: 50%;
  transform: translate(6px, -50%);
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: currentColor;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s var(--ease-out), transform .35s var(--ease-out);
}
#rail button:hover span { opacity: .85; transform: translate(0, -50%); }

/* --- the opening curtain ------------------------------------------------- */

#loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--ink);
  transition: opacity .7s var(--ease-io), visibility .7s;
}
#loader.done { opacity: 0; visibility: hidden; }
.loader-in { display: grid; justify-items: center; gap: 18px; }
.loader-in img { width: 54px; height: 54px; animation: pulse 2.6s var(--ease-io) infinite; }
@keyframes pulse { 0%, 100% { opacity: .5; transform: scale(.97); } 50% { opacity: 1; transform: scale(1); } }
.loader-line {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .32em;
  text-transform: uppercase;
  opacity: .55;
}
.loader-bar { width: 140px; height: 1.5px; background: rgba(231, 231, 233, .16); overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; background: var(--orange-lift); transition: width .35s var(--ease-out); }

/* --- 6. the outro -------------------------------------------------------- */

#outro {
  position: relative;
  z-index: 40;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 14px;
  min-height: 88svh;
  padding: 12svh var(--pad);
  text-align: center;
  background: var(--ink);
  border-top: 1px solid var(--hair);
}
.outro-kicker {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--orange-lift);
}
.outro-title {
  margin: 0;
  font-size: clamp(30px, 6.4vw, 82px);
  font-weight: 900;
  font-stretch: 125%;
  line-height: .94;
  letter-spacing: var(--tight);
  text-transform: uppercase;
}
.outro-note {
  margin: 2px 0 0;
  max-width: 34ch;
  font-size: clamp(13px, 1.5vw, 17px);
  font-weight: 500;
  line-height: 1.45;
  color: rgba(231, 231, 233, .58);
}
.outro-meta {
  margin: 14px 0 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
}
.outro-meta a { border-bottom: 1px solid rgba(231, 231, 233, .28); padding-bottom: 2px; transition: color .3s, border-color .3s; }
.outro-meta a:hover { color: var(--orange-lift); border-color: var(--orange-lift); }
.outro-meta span { opacity: .3; }
.outro-sig { margin: 6px 0 0; font-size: 10px; letter-spacing: .22em; text-transform: uppercase; opacity: .38; }

/* --- 7. the viewer ------------------------------------------------------- */

#viewer {
  /* height of the bottom bar, so the slide can be sized against the rest */
  --vbar: calc(69px + env(safe-area-inset-bottom));
  position: fixed;
  inset: 0;
  z-index: 150;
  background: #050403;
  display: grid;
  grid-template-rows: 1fr auto;
  opacity: 0;
  transition: opacity .4s var(--ease-io);
  touch-action: none;
}
#viewer[hidden] { display: none; }
#viewer.open { opacity: 1; }

.v-stage {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  cursor: grab;
}
.v-stage.dragging { cursor: grabbing; }
/* Sized outright rather than by max-width/max-height: the pan/zoom maths
   needs the layout box to be the slide's true 16:9 rectangle. */
#v-img {
  width: min(100vw, calc((100dvh - var(--vbar)) * 16 / 9));
  height: auto;
  transform-origin: 50% 50%;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

/* Turned on its side, a 16:9 slide fills a portrait phone instead of
   sitting in a 210px band — which is the difference between reading the
   8pt body copy and squinting at it. */
.v-stage.rot #v-img {
  width: min(calc(100dvh - var(--vbar) - 16px), calc(100vw * 16 / 9));
}

.v-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 14px var(--pad) calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hair);
}
.v-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--hair);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  transition: background .3s, border-color .3s;
}
.v-btn:hover { background: var(--orange); border-color: var(--orange); }
.v-label {
  margin: 0;
  min-width: 42vw;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.v-label b { color: var(--orange-lift); font-variant-numeric: tabular-nums; }
.v-close,
.v-rot {
  position: absolute;
  top: calc(var(--pad) * .6);
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 16px;
  border-radius: 50%;
  transition: background .3s;
}
.v-close { right: calc(var(--pad) * .6); }
.v-rot { left: calc(var(--pad) * .6); font-size: 19px; }
.v-close:hover,
.v-rot:hover { background: rgba(231, 231, 233, .1); }
.v-stage.rot ~ .v-rot { color: var(--orange-lift); }
.v-hint {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  margin: 0;
  font-size: 10px;
  letter-spacing: .22em;
  text-transform: uppercase;
  opacity: .4;
  pointer-events: none;
  transition: opacity .4s;
}
#viewer.touched .v-hint { opacity: 0; }

/* --- 8. mobile ----------------------------------------------------------- */

/* The phone layout keeps the same pinned cross-dissolve, but the 16:9 frame
   sits full-width on a constant dark ground with its caption above and a
   tap-to-enlarge affordance below — a deliberate viewer, not a letterbox.
   --card is half the frame's height, which is what the two of them hang off. */

@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  :root {
    --scene: 138svh;
    --card: calc(min(94vw, calc((100dvh - 190px) * 16 / 9)) * 0.281);
  }

  html.cine .stage { background: var(--ink); }

  /* A soft halo in the slide's own ground colour, so the dark surround
     around a 16:9 card on a tall screen still belongs to the slide. */
  html.cine .stage::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg, var(--ink));
    opacity: .17;
    -webkit-mask-image: radial-gradient(64% 30% at 50% 50%, #000 0%, transparent 74%);
    mask-image: radial-gradient(64% 30% at 50% 50%, #000 0%, transparent 74%);
    pointer-events: none;
  }
  html.cine .frame {
    width: min(94vw, calc((100dvh - 190px) * 16 / 9));
    border-radius: 3px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
    cursor: pointer;
  }

  body, body.on-light {
    --chrome: #ffffff;
    --chrome-soft: rgba(255, 255, 255, .5);
    --chrome-faint: rgba(255, 255, 255, .28);
  }
  #rail { display: none; }
  #chrome {
    height: 54px;
    padding: 0 var(--pad);
    padding-top: env(safe-area-inset-top);
  }
  #chrome .mark span { display: none; }

  #caption {
    left: 0;
    right: 0;
    bottom: auto;
    height: auto;
    top: calc(50dvh - var(--card) - 138px);
    display: block;
    max-width: none;
    padding: 0 var(--pad);
    text-align: center;
  }
  #caption .cap-num {
    display: block;
    margin: 0 0 2px;
    font-size: 52px;
    font-weight: 900;
    font-stretch: 125%;
    line-height: .9;
    letter-spacing: -.05em;
    color: rgba(255, 255, 255, .085);
  }
  #caption .cap-kicker {
    margin: 0 0 5px;
    padding: 0;
    border: 0;
  }
  #caption .cap-title { font-size: 17px; }

  /* Not a label any more — pressing it advances one slide. Padded out to a
     proper thumb target rather than the 10px cap-height of the text. */
  #tap-note {
    position: fixed;
    z-index: 60;
    left: 50%;
    transform: translateX(-50%);
    top: calc(50dvh + var(--card) + 20px);
    margin: 0;
    padding: 12px 20px 10px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .26em;
    text-transform: uppercase;
    /* left:50% halves the shrink-to-fit width, which wraps the label */
    white-space: nowrap;
    color: var(--chrome-faint);
    -webkit-tap-highlight-color: transparent;
    transition: opacity .5s var(--ease-io), color .3s var(--ease-io);
  }
  #tap-note:active { color: var(--chrome-soft); }
  #tap-note::after {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    margin: 8px auto 0;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    animation: chev 2.4s var(--ease-io) infinite;
  }

  /* the bottom scroll hint would just say the same thing twice */
  #hint { display: none; }

  #hint {
    height: auto;
    bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  }
  .v-label { min-width: 0; }
  .v-hint { bottom: 78px; }
}

@media (min-width: 901px) { #tap-note { display: none; } }
html:not(.cine) #tap-note { display: none; }

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

@media (prefers-reduced-motion: reduce) {
  #grain { animation: none; }
  #hint span { animation: none; }
  #tap-note::after { animation: none; }
  .loader-in img { animation: none; }
  #caption.swap .cap-kicker,
  #caption.swap .cap-title { animation: none; }
}
