/* ══════════════════════════════════════════════════════════════════════════
   THE STORY PAGE

   One page where the background does the telling. The lot behind the words
   starts as rubble and is cleared, poured, framed and finished as you read
   — the same shape the account itself has.

   Two systems share this screen and must not fight over it:

     the sun   owns LIGHT    — sky colour, stars, haze, and whether the
                               windows are lit. Already computed by sky.js
                               from Flagstaff's real solar position; nothing
                               here recalculates any of it.
     the scroll owns STRUCTURE — what is standing on the lot.

   So the same read at 2pm and at 2am is the same build under a different
   sky, which is what the page is about.

   The words always sit on a solid card. The background can be any colour
   the sun makes it, from pale haze at noon to deep blue at midnight, and
   text laid straight onto that would pass contrast at one hour and fail at
   another. The card settles it once.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── the sky, as the page's own background ──────────────────────────────── */
/* The sky is painted on a fixed layer of its own rather than on this
   element. As an in-flow background it paints above anything at a negative
   z-index, which would have hidden the entire engraving behind it -- the
   page would have looked exactly as empty as it did before. Sky at -2,
   engraving at -1, words on top. */
.story-page{
  position:relative;
  min-height:100vh;
  background:none;
}
.story-page::before{
  content:"";position:fixed;inset:0;z-index:-2;pointer-events:none;
  background:linear-gradient(to bottom,
    var(--sky-top) 0%, var(--sky-mid) 46%, var(--sky-low) 100%);
  transition:background 2.4s linear;
}

/* The background is the engraving now, and it lives in empire.css -- the
   same one the home page runs. What used to be here was a photo-tile stage
   with no stylesheet written for it, which is why this page had nothing
   behind it at all. */

/* ── the column of words ────────────────────────────────────────────────── */
.story-flow{
  position:relative;z-index:1;
  max-width:720px;margin:0 auto;
  padding:clamp(28px,7vh,72px) var(--pad) clamp(40px,8vh,90px);
}

/* The opening is deliberately not rubble. You land on a sentence, with the
   wreckage already on the horizon behind it -- noticed, not announced. */
/* A full screen of it before the first card. This is the one everybody
   sees, and it should be the empire, not a headline on an empty sky. */
.story-open{
  position:relative;
  min-height:88vh;
  display:flex;flex-direction:column;justify-content:center;
  padding:clamp(40px,10vh,110px) 0 clamp(30px,6vh,60px);
  text-align:left;
}

/* A scrim, and the text is light on it at every hour.

   This used to pick its ink by sampling the sky at the text's height, which
   worked while the background WAS the sky. It is a tower now, with lit
   windows in it, and the sampler cannot see that -- so at night it read a
   dark sky, chose dark ink, and laid the headline straight over a grid of
   glowing windows. Nothing legible survives that.

   Against a busy background the answer is not a cleverer ink. It is to put
   something between the words and the background, and the gradient keeps
   the tower visible around and above the text rather than boxing it. */
.story-open::before,
.story-close::before{
  content:"";position:absolute;z-index:-1;
  inset:-6vh calc(var(--pad) * -1);
  background:radial-gradient(120% 86% at 30% 50%,
    rgba(6,10,16,.84) 0%, rgba(6,10,16,.72) 42%,
    rgba(6,10,16,.38) 72%, rgba(6,10,16,0) 100%);
}
.story-close::before{
  /* Held high and tight. The rubble is at the foot of this screen and the
     scrim was covering it, which left the last thing on the page -- the
     ground he started from -- as an empty dark field. */
  /* No sideways bleed here: unlike the opening, this block is already as
     wide as the window, so a negative inset goes off the edge of it. */
  inset:-4vh 0 42%;
  background:radial-gradient(100% 72% at 50% 34%,
    rgba(6,10,16,.84) 0%, rgba(6,10,16,.66) 46%,
    rgba(6,10,16,.26) 76%, rgba(6,10,16,0) 100%);
}
.story-open .eyebrow{
  display:block;margin-bottom:18px;
  /* It inherits a dark grey from the site's own .eyebrow, which is right on
     paper and wrong here: this one sits on the dark scrim and measured
     1.15:1. Light, like everything else on that scrim. */
  color:#D6DFD4;
  text-shadow:0 2px 12px rgba(4,8,12,.8);
}
.story-open h1{
  font-family:"Fraunces",serif;font-weight:600;
  font-size:clamp(1.9rem,5.4vw,3.1rem);line-height:1.04;letter-spacing:-.022em;
  color:#F6F4EE;max-width:17ch;
  text-shadow:0 2px 18px rgba(4,8,12,.8);
}
/* The accent green only reads on a light sky; on a dark one it goes muddy,
   so the emphasis carries on the italic alone there. */
.story-open h1 em{font-style:italic;font-weight:400;color:#8FD49A}
.story-open .lede{
  margin-top:20px;max-width:46ch;font-size:clamp(1rem,1.6vw,1.12rem);
  color:#DFE3DC;
  text-shadow:0 2px 14px rgba(4,8,12,.75);
}

/* a chapter */
.beat{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--r-card);
  padding:clamp(24px,4.4vw,44px);
  /* A long gap on purpose. The collapse happens BETWEEN the chapters --
     if the cards run one into the next there is nowhere to watch it from,
     and on a phone the cards are full width so the gaps are the only
     window onto the background at all. */
  margin:clamp(60px,34vh,300px) 0;
  box-shadow:0 18px 50px -28px rgba(20,28,22,.45);
}
.beat-mark{
  display:flex;align-items:baseline;gap:14px;
  margin-bottom:16px;
  border-bottom:1px solid var(--line);padding-bottom:14px;
}
.beat-mark .yr{
  font-family:"JetBrains Mono",monospace;font-size:.72rem;font-weight:600;
  letter-spacing:.14em;text-transform:uppercase;color:var(--c1-deep);
  white-space:nowrap;
}
.beat-mark h2{
  font-family:"Fraunces",serif;font-weight:600;
  font-size:clamp(1.25rem,2.6vw,1.6rem);line-height:1.12;letter-spacing:-.016em;
  color:var(--bone);
}
.beat p{margin-top:14px;color:var(--bone)}
.beat p.muted{color:var(--muted)}
.beat p:first-of-type{margin-top:0}

/* the one pulled line, used once */
.beat .said{
  margin-top:26px;padding-top:22px;border-top:1px solid var(--line);
  font-family:"Fraunces",serif;font-size:clamp(1.08rem,2.2vw,1.35rem);
  line-height:1.3;color:var(--bone);
}
.beat .said span{display:block;margin-top:8px;color:var(--muted);font-size:.84em}

/* a photograph inside a chapter */
.beat figure{margin-top:22px}
.beat figure img{
  width:100%;height:auto;display:block;
  border-radius:var(--r-small);border:1px solid var(--line);
}
.beat figcaption{
  margin-top:10px;font-family:"JetBrains Mono",monospace;
  font-size:.7rem;letter-spacing:.06em;color:var(--muted-2);
}

/* The close: no card, so the last thing read is standing on the lot.

   It is deliberately tall. The lot is fixed to the foot of the window and
   the footer is opaque and sits on top of it, so without a stretch of open
   page here the finished buildings spend their entire existence behind the
   footer -- the one thing the whole page has been building towards, never
   actually seen. This is the room it gets to be seen in. */
.story-close{
  position:relative;z-index:1;
  text-align:center;
  min-height:92vh;
  display:flex;flex-direction:column;justify-content:flex-start;
  padding:clamp(60px,14vh,150px) var(--pad) clamp(230px,36vh,400px);
}
.story-close p{
  font-family:"Fraunces",serif;
  font-size:clamp(1.15rem,2.8vw,1.6rem);line-height:1.25;
  color:#F6F4EE;
  max-width:24ch;margin:0 auto 26px;
  text-shadow:0 2px 16px rgba(4,8,12,.78);
}

/* The two buttons at the end stand on the sky with nothing behind them, so
   both are given a solid fill rather than the site's ghost outline. An
   outlined button with --bone text is legible at noon and invisible at
   midnight, and these are the last thing on the page -- the point at which
   someone decides to get in touch. They cannot be the thing that is hard
   to see. */
.story-close .ends{
  display:flex;flex-wrap:wrap;gap:12px;justify-content:center;
  padding-bottom:clamp(30px,7vh,70px);
}
.story-close .ends a{
  display:inline-flex;align-items:center;gap:8px;
  min-height:46px;padding:12px 22px;border-radius:var(--r-small);
  font-weight:600;font-size:.95rem;text-decoration:none;
  border:1px solid transparent;
  transition:transform .3s var(--ease), background .3s var(--ease);
}
.story-close .ends .go{background:var(--c1-deep);color:#fff}
.story-close .ends .go:hover{transform:translateY(-2px);background:var(--green)}
.story-close .ends .alt{
  background:var(--surface);color:var(--bone);border-color:var(--line);
}
.story-close .ends .alt:hover{transform:translateY(-2px);border-color:var(--c1-deep);color:var(--c1-deep)}

/* The footer is the one piece of the page that must sit ON the lot rather
   than behind it. Without its own background the fixed lot showed straight
   through the address and the social links, because a positioned fixed
   element paints over static content however late that content comes. */
.story-page ~ footer{
  position:relative;z-index:2;
  background:var(--ink);
}

/* ── small screens ──────────────────────────────────────────────────────── */
@media (max-width:640px){
  /* background-attachment:fixed is expensive and unreliable on mobile --
     iOS has never handled it properly -- so the sky scrolls with the page
     there and only the lot stays pinned. */
  .story-close{min-height:78vh;padding-bottom:clamp(190px,30vh,280px)}
}

/* ── reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion:reduce){
  /* Nothing collapses. The chapters keep their boxes start to finish, and
     nobody has to scroll through a demolition to read a man's account of
     his life. */
  .beat{--c:0!important;--s:0!important;clip-path:none!important;transition:none}
  .beat::before{display:none}
}

/* ── the green goes light after dark ─────────────────────────────────────
   The site already knows this: at dusk and night --c1-deep becomes a pale
   green, and styles.css flips .btn-primary, .nav-call and the pills to dark
   text so they stay readable on it. My close button was not on that list,
   so it kept white text on a pale green and measured 2.31:1 at dusk against
   a required 4.5 -- on the one button the whole page is asking you to press.
   Same convention, same fix. */
:root[data-sky="dusk"]  .story-close .ends .go,
:root[data-sky="night"] .story-close .ends .go{ color:#0C1016 }

/* The lot's artwork is sliced to fill the width, which means it is wider
   than its box by design. Clip it, or that overhang counts as page width
   and a phone gets a sideways scroll on a story about going straight. */
.lot-wrap{ overflow:hidden }


/* ══════════════════════════════════════════════════════════════════════════
   THE CHAPTERS COME APART

   Reading down this page runs backwards through his life, so the page should
   be in worse shape the further down you get. The first chapter keeps its
   box. The last one has none at all: the words stand on the sky on their
   own, which is the whole point of the page said in layout rather than in a
   sentence.

   The hard part is that a card and a bare sky want OPPOSITE ink. Dark text
   needs the light panel; take the panel away and the same text has to turn
   light and find something to sit on. Crossfading between the two states
   linearly puts the words through a grey middle where ink and background
   meet, which is unreadable at exactly the halfway point.

   So the two things are driven separately:

     --c  the erosion. 0 to 1, slow, over the full scroll. This is the part
          you watch happen: corners first, then the edges, then the box.
     --s  the swap. 0 or 1, quick, and never resting in between. Panel and
          dark ink, or scrim and light ink. There is no halfway state to be
          caught in, because no chapter stops there.
   ══════════════════════════════════════════════════════════════════════════ */

/* inherits:true, and it matters. A pseudo-element counts as a child for
   inheritance, so with inherits:false the scrim on .beat::before and the
   cracks on .rung::after both read --s as its initial 0 and quietly did
   nothing at all -- the chapters lost their boxes and got no scrim to
   stand on, which is dark text on a pale sky. */
@property --s{ syntax:'<number>'; inherits:true; initial-value:0; }

.beat{
  position:relative;
  --c:0; --s:0;
  transition:--c 1.2s cubic-bezier(.33,0,.68,.35),
             --s .45s linear .3s,
             background-color .5s linear .3s,
             border-color .9s linear,
             box-shadow .9s linear;

  /* The panel thins steadily on --c and then, at the swap, is not there at
     all. Without the first part the box went from solid to absent between
     one chapter and the next, which is a cut, not a collapse. */
  background-color:color-mix(in srgb, var(--surface),
    transparent calc(min(1, var(--s) + var(--c) * .5) * 100%));
  border-color:color-mix(in srgb, var(--line), transparent calc(var(--c) * 30%));
  box-shadow:0 18px 50px -28px rgba(20,28,22,calc(.45 * (1 - var(--s))));

  /* and the ink turns over with it */
  --ink:color-mix(in srgb, var(--bone), #F7F5EF calc(var(--s) * 100%));
  --ink-2:color-mix(in srgb, var(--muted), #D6DBD4 calc(var(--s) * 100%));
  --ink-3:color-mix(in srgb, var(--c1-deep), #93D79E calc(var(--s) * 100%));
}

/* What the panel is replaced by. The sky behind this page runs from pale
   blue at noon to deep blue at midnight, so bare light text would be
   unreadable for half the day. The scrim is the same device the opening and
   closing blocks already use, and it holds at every hour. */
.beat::before{
  content:"";position:absolute;z-index:-1;
  /* Held inside the border box on purpose. The clip-path that eats this
     chapter's corners clips its children too, so a scrim bled outside the
     box would simply be cut off square -- the soft edge has to be in the
     gradient, not in the geometry. It picks up the chipped outline for
     free, which is what a pool of shadow under a broken thing should do. */
  inset:0;
  opacity:var(--s);
  transition:opacity .45s linear .3s;
  background:radial-gradient(104% 92% at 44% 48%,
    rgba(6,10,16,.93) 0%, rgba(6,10,16,.88) 48%,
    rgba(6,10,16,.58) 76%, rgba(6,10,16,0) 100%);
}

.beat p,
.beat-mark h2,
.beat .said{ color:var(--ink);
  text-shadow:0 2px 14px rgba(4,8,12,calc(var(--s) * .85)); }
.beat p.muted,
.beat .said span,
.beat figcaption{ color:var(--ink-2);
  text-shadow:0 2px 14px rgba(4,8,12,calc(var(--s) * .85)); }
.beat .yr{ color:var(--ink-3) }

/* the rules inside the card go with the card */
.beat-mark,
.beat .said{ border-color:color-mix(in srgb, var(--line), transparent calc(var(--s) * 72%)); }
.beat figure img{ border-color:color-mix(in srgb, var(--line), transparent calc(var(--s) * 60%)); }
