/* ============================================================
   story.css: the layout of story.html, my story in five chapters.

   It loads after style.css and page.css and reuses them: the fonts,
   buttons, theme switch, top bar and footer all come from there.
   This file adds the warm studio colours of the photos (in both
   themes, under the same token names), the retained chapter photos,
   text-led interlude, word band and Then & now slider.
   The word band's movement itself is shared, in style.css.

   Layout rule: one selector and one declaration per line. After
   editing I run python3 tools/format_css.py.
   ============================================================ */

/* Warm studio colours, dark (my default). Same token names as style.css, so the top bar and footer follow them. */
body.story {
  --bg: #1f1a16;
  --surface: #2a231d;
  --surface-2: #332a22;
  --border: rgba(241,233,223,.12);
  --border-strong: rgba(241,233,223,.22);
  --text: #f1e9df;
  --muted: #c9bcad;
  --dim: #ab9c8c;
  --glow: rgba(241,233,223,.05);
  --story-photo-shadow: 0 18px 44px rgba(0,0,0,.4);
}

/* Light theme: the lighter backdrop from the studio photos. */
:root[data-theme="light"] body.story {
  --bg: #e6dccf;
  --surface: #efe7dc;
  --surface-2: #ddd1c2;
  --border: rgba(33,26,20,.14);
  --border-strong: rgba(33,26,20,.26);
  --text: #211a14;
  --muted: #4b3f33;
  --dim: #5c4e41;
  --glow: rgba(255,255,255,.35);
  --story-photo-shadow: 0 16px 40px rgba(33,26,20,.16);
}

/* Shared width of every block on the page. */
.story-wrap {
  width: min(1120px, calc(100% - 32px));
  margin-left: auto;
  margin-right: auto;
}

/* The top bar and footer come from page.css at 880 px; here they line up with the story's wider column. */
.story .page-bar,
.story .page-footer {
  width: min(1120px, calc(100% - 32px));
}

.story-eyebrow {
  margin-bottom: 0;
  color: var(--dim);
  font: 500 12px/1.5 var(--font-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
}

.story img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.story figure {
  margin: 0;
  min-width: 0;
}

.story figcaption {
  margin-top: 8px;
  color: var(--dim);
  font: 12.5px/1.5 var(--font-mono);
}

/* ---------- Hero: the motto and the suit portrait ---------- */
.story-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
  gap: clamp(24px, 5vw, 64px);
  align-items: end;
  padding-top: clamp(32px, 6vw, 72px);
}

.story-hero h1 {
  margin: 14px 0 0;
  font-size: clamp(52px, 9vw, 116px);
  line-height: .98;
  letter-spacing: -.05em;
  text-wrap: balance;
}

.story-accent {
  color: var(--brand);
}

.story-lede {
  max-width: 36ch;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: clamp(18px, 2vw, 21px);
  line-height: 1.6;
}

.story-lede strong {
  color: var(--text);
  font-weight: 500;
}

.story-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}

.story-toc a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  font: 500 13px var(--font-mono);
}

.story-toc a:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.story-toc span {
  color: var(--dim);
}

.story-hero-photo img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: 50% 20%;
  box-shadow: var(--story-photo-shadow);
}

/* ---------- Chapters: retained lead photos and text-only chapters ---------- */
.chapter {
  display: grid;
  gap: clamp(28px, 4vw, 48px);
  padding: clamp(56px, 9vw, 112px) 0;
  border-top: 1px solid var(--border);
}

.chapter:first-of-type {
  margin-top: clamp(48px, 7vw, 88px);
}

/* A retained lead photo stays in view while its chapter text scrolls. */
.chapter-body {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: clamp(20px, 4vw, 48px);
  align-items: start;
}

.chapter-media {
  grid-column: 1 / span 5;
  position: sticky;
  top: 24px;
}

.chapter-text {
  grid-column: 6 / span 7;
  display: grid;
  gap: 20px;
  min-width: 0;
}

/* Chapters without lead photography use a readable editorial text column. */
.chapter-body--text-only {
  grid-template-columns: minmax(0, 1fr);
}

.chapter-body--text-only .chapter-text {
  grid-column: 1 / -1;
  max-width: 78ch;
}

/* Chapter 5's second campus photograph supports, rather than competes with, the lead image. */
.chapter-support {
  display: flex;
  justify-content: flex-end;
  margin-top: clamp(20px, 3vw, 32px);
}

.chapter-support figure {
  width: min(360px, 100%);
}

.chapter-support img {
  width: 100%;
  aspect-ratio: 780 / 925;
  object-fit: cover;
  box-shadow: var(--story-photo-shadow);
}

.chapter.flip .chapter-media {
  grid-column: 8 / span 5;
  grid-row: 1;
}

.chapter.flip .chapter-text {
  grid-column: 1 / span 7;
  grid-row: 1;
}

/* The text-only modifier takes precedence over the alternating photo layout. */
.chapter.flip .chapter-body--text-only .chapter-text {
  grid-column: 1 / -1;
  grid-row: auto;
}

.chapter-media img {
  width: 100%;
  box-shadow: var(--story-photo-shadow);
}

/* The chapter number: outlined in blue where the browser can, solid blue otherwise. */
.chapter-num {
  color: var(--brand);
  font: 800 clamp(64px, 10vw, 112px)/.8 var(--font-display);
  letter-spacing: -.04em;
}

@supports (-webkit-text-stroke: 1px black) {
  .chapter-num {
    color: transparent;
    -webkit-text-stroke: 1.5px var(--brand);
  }
}

.chapter h2 {
  font-size: clamp(32px, 4.4vw, 52px);
  line-height: 1.04;
  letter-spacing: -.035em;
  text-wrap: balance;
}

/* Story paragraphs; the small label above each chapter title keeps its own size. */
.chapter-text p:not(.story-eyebrow) {
  max-width: 62ch;
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.7;
}

/* The first paragraph of each chapter opens with a large blue letter. */
.chapter .first::first-letter {
  float: left;
  margin: .08em .1em 0 0;
  color: var(--brand);
  font: 800 3.4em/.85 var(--font-display);
}

.pull {
  display: grid;
  gap: 8px;
  max-width: 30ch;
  margin: 4px 0;
  padding-left: 18px;
  border-left: 3px solid var(--brand);
  color: var(--text);
  font: 600 clamp(22px, 2.4vw, 27px)/1.3 var(--font-display);
  letter-spacing: -.02em;
}

.pull small {
  color: var(--dim);
  font: 13px/1.55 var(--font-mono);
  letter-spacing: 0;
}

/* ---------- Interlude: the blue thread (text-led) ---------- */
.thread,
.compare-section,
.story-next {
  display: grid;
  gap: 24px;
  padding: clamp(56px, 9vw, 112px) 0;
  border-top: 1px solid var(--border);
}

.thread h2,
.compare-section h2,
.story-next h2 {
  font-size: clamp(32px, 5vw, 56px);
  letter-spacing: -.035em;
  text-wrap: balance;
}

.thread-intro {
  max-width: 58ch;
  margin-bottom: 0;
  font-size: 18px;
}

/* ---------- The words that carried me (a ticker, see style.css) ---------- */

/* On the story the band is a display line: big words in the page's own colour, blue dots between them. */

/* Deep navy, the colour of the school sweater and the suit, with the story's warm cream words and light-blue dots.
   The same in both themes. */
.ticker-story {
  margin-top: 0;
  margin-bottom: clamp(24px, 4vw, 40px);
  padding: clamp(18px, 3vw, 26px) 16px clamp(18px, 3vw, 26px) 4px;
  border-radius: 4px;
  background: #1c2a56;
}

.ticker-story .ticker-item {
  color: #f1e9df;
  font: 800 clamp(24px, 3.4vw, 38px)/1.2 var(--font-display);
  letter-spacing: -.02em;
  text-transform: none;
}

.ticker-story .ticker-item::after {
  margin: 0 26px;
  color: #8ea8ff;
}

/* ---------- Then & now ---------- */

/* Without JavaScript: the two photos side by side, each with its caption. */
.compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 640px;
  justify-self: center;
}

.compare img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

/* "Now" comes first in the HTML so the slider can stack "Then" on top of it; side by side, "Then" goes first. */
.compare-then {
  order: -1;
}

/* With story.js: the photos stack and the range input wipes between them. */
.compare.is-slider {
  display: block;
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: var(--story-photo-shadow);
}

.compare.is-slider figure {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.compare.is-slider img {
  height: 100%;
  border-radius: 0;
}

.compare.is-slider .compare-then {
  z-index: 1;
  clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0);
}

.compare.is-slider figcaption {
  position: absolute;
  top: 12px;
  margin: 0;
  padding: 5px 9px;
  background: var(--bg);
  color: var(--text);
  font: 500 12px var(--font-mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.compare.is-slider .compare-then figcaption {
  left: 12px;
}

.compare.is-slider .compare-now figcaption {
  right: 12px;
}

.compare.is-slider::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos, 50%);
  z-index: 2;
  width: 2px;
  background: var(--brand);
  pointer-events: none;
}

.compare input {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 3;
  width: calc(100% - 24px);
  min-height: 24px;
  margin: 0;
  accent-color: var(--brand);
}

/* ---------- Keep reading ---------- */
.story-next p {
  max-width: 58ch;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 18px;
}

.story-next-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- Tablets and phones: everything in one column ---------- */
@media (max-width: 860px) {
  .story-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .story-hero-photo {
    max-width: 420px;
  }

  .chapter-media,
  .chapter-text,
  .chapter.flip .chapter-media,
  .chapter.flip .chapter-text {
    grid-column: 1 / -1;
    grid-row: auto;
    position: static;
  }

  .chapter-media {
    max-width: 520px;
  }

  .chapter-body--text-only .chapter-text {
    max-width: 100%;
  }

  .chapter-support {
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  .chapter-text p:not(.story-eyebrow),
  .thread-intro,
  .story-next p {
    font-size: 17px;
  }

}

/* Print: the story in black on white, photos kept, no slider. */
@media print {
  .story-toc,
  .story-next-actions,
  .compare input {
    display: none !important;
  }

  .chapter-media {
    position: static;
  }
}
