/* UI/UX: single-page shell, sticky period nav, hero and scroll-driven text effects. Mobile first.
   Everything animated lives inside prefers-reduced-motion: no-preference; without it, or in a browser
   with no scroll-driven animation, every element is plain, visible text. */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: var(--header-h, 6rem); }
body { margin: 0; overflow-wrap: break-word; overflow-x: clip; }

.skip-link { position: absolute; left: -999px; top: 0; z-index: 20; padding: var(--space-1) var(--space-2); background: var(--color-bg); color: var(--color-link); }
.skip-link:focus { left: var(--space-1); top: var(--space-1); }

/* Content column: bands run edge to edge, text stays within 60rem. */
.site-header, .site-footer, .era, .hero { padding-inline: max(var(--space-2), calc((100% - 60rem) / 2)); }

/* Sticky header: site name, period strip and a progress line, compact enough for a phone. */
.site-header { --header-h: 5.75rem; position: sticky; top: 0; z-index: 10; background: var(--color-header-bg); color: var(--color-header-text); border-bottom: 1px solid var(--color-border); }
.site-header a { color: inherit; }
.site-header a:hover { color: var(--color-accent-strong); }
.site-header a:focus-visible { outline: 3px solid var(--color-focus); outline-offset: -3px; }
.site-title { margin: 0; padding-top: 0.4rem; font-family: var(--font-heading); font-size: 1.05rem; font-weight: bold; line-height: 1.4; }
.site-title a { text-decoration: none; }
.site-title a:hover { text-decoration: underline; }

.period-nav { margin-inline: calc(-1 * max(var(--space-2), calc((100vw - 60rem) / 2))); padding-inline: max(var(--space-2), calc((100vw - 60rem) / 2)); }
.period-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 0.25rem; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: thin; }
.period-nav li { flex: none; scroll-snap-align: center; }
.period-nav a { display: block; padding: 0.7rem 0.6rem; min-height: 2.75rem; font-size: var(--text-sm); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; }
.period-nav a[aria-current="location"] { border-bottom-color: var(--color-accent-strong); font-weight: bold; }

.progress { height: var(--progress-height, 4px); margin-inline: calc(-1 * max(var(--space-2), calc((100vw - 60rem) / 2))); background: var(--color-border); }
.progress::before { content: ""; display: block; height: 100%; background: var(--progress-color, var(--color-accent)); transform-origin: 0 50%; transform: scaleX(var(--p, 0)); }

/* Hero: a full-screen opening. */
.hero { min-height: calc(100vh - var(--header-h, 5.75rem)); min-height: calc(100svh - var(--header-h, 5.75rem)); display: flex; flex-direction: column; justify-content: center; padding-block: var(--space-4); background: var(--gradient-hero); color: var(--color-hero-text); overflow: clip; }
.hero h1 { margin: 0 0 var(--space-3); font-size: var(--text-display); line-height: var(--leading-heading); letter-spacing: var(--tracking-display); }
.hero .w { display: inline-block; white-space: nowrap; }
.hero .ch { display: inline-block; }
.hero-lead { font-size: var(--text-xl); max-width: 36ch; margin: 0 0 var(--space-2); }
.hero-note { color: var(--color-muted); max-width: var(--measure); margin: 0 0 var(--space-2); }
.hero ol, .hero ul { max-width: var(--measure); }
.story-index { padding: 3px; margin: -3px; }

/* Eras: one band per period. */
.era { padding-block: var(--space-5); border-top: var(--rule); position: relative; overflow: clip; }
.era:nth-of-type(odd) { background: var(--color-surface); }
.era-label { margin: 0 0 var(--space-2); font-family: var(--font-heading); font-size: clamp(2.5rem, 11vw, 7rem); line-height: 0.95; letter-spacing: var(--tracking-display); color: var(--color-accent); }
.era h2 { font-size: var(--text-era); line-height: var(--leading-heading); margin: 0 0 var(--space-3); }
.era h2 .mask { display: block; overflow: clip; padding-bottom: 0.15em; }
.era h2 .slide { display: block; }
.era p, .era li { max-width: var(--measure); }
.era :target { scroll-margin-top: var(--header-h, 5.75rem); }

.site-footer { margin-top: 0; }

@media (min-width: 48rem) {
  .site-header { --header-h: 3.75rem; display: flex; align-items: center; flex-wrap: wrap; gap: 0 var(--space-3); }
  .site-title { padding-top: 0; white-space: nowrap; }
  .period-nav { flex: 1 1 0; min-width: 0; margin-inline: 0; padding-inline: 0; }
  .progress { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; }
  .period-nav a { padding-block: 0.9rem; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }

  /* Hero title: each letter drops in with a stagger, then a light sweep runs through the text. */
  @keyframes letter-in {
    from { opacity: 0; transform: translateY(var(--reveal-distance-lg)) scale(var(--reveal-scale-from)) rotate(8deg); filter: blur(var(--reveal-blur-from)); }
  }
  /* The sweep ends at 0%, where the gradient still covers the letter in the plain text colour. */
  @keyframes sweep { from { background-position: 100% 0; } to { background-position: 0% 0; } }
  @keyframes line-in {
    from { opacity: 0; clip-path: var(--reveal-mask-from); transform: translateY(var(--reveal-distance)); }
    to { opacity: 1; clip-path: var(--reveal-mask-to); transform: none; }
  }
  .hero .ch {
    animation: letter-in var(--duration-reveal) var(--ease-back) both;
    animation-delay: calc(var(--stagger) * var(--i, 0));
  }
  @supports (background-clip: text) or (-webkit-background-clip: text) {
    .hero .ch {
      background: var(--gradient-sweep) 100% 0 / var(--sweep-size) 100% no-repeat;
      -webkit-background-clip: text; background-clip: text;
      -webkit-text-fill-color: transparent;
      animation: letter-in var(--duration-reveal) var(--ease-back) both,
                 sweep var(--duration-sweep) linear 3 both;
      animation-delay: calc(var(--stagger) * var(--i, 0)), calc(var(--duration-reveal) + var(--stagger) * var(--i, 0));
    }
  }
  .hero-lead, .hero-note { animation: line-in var(--duration-slow) var(--ease-expo) backwards; animation-delay: calc(var(--duration-reveal) + var(--stagger-line)); }
  .hero-note { animation-delay: calc(var(--duration-reveal) + var(--stagger-line) * 2); }
  .hero ol, .hero ul { animation: line-in var(--duration-slow) var(--ease-expo) backwards; animation-delay: calc(var(--duration-reveal) + var(--stagger-line) * 3); }

  @supports (animation-timeline: view()) {
    /* Progress line grows with the page. */
    @keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
    .progress::before { transform: none; transform-origin: 0 50%; animation: grow linear both; animation-timeline: scroll(root block); }

    /* Hero title drifts up and dims as you leave it. */
    @keyframes hero-exit { to { transform: translateY(calc(-1 * var(--parallax-shift))) scale(0.92); opacity: 0.35; } }
    .hero h1 { animation: hero-exit linear both; animation-timeline: view(); animation-range: exit 0% exit 100%; transform-origin: 0 50%; }

    /* Era date: grows in from the side, then slides on past. */
    @keyframes era-date {
      0%   { opacity: 0.1; transform: translateX(var(--era-shift)) scale(var(--era-scale-from)); }
      35%  { opacity: 1; transform: none; }
      65%  { opacity: 1; transform: none; }
      100% { opacity: 0.25; transform: translateX(calc(-0.5 * var(--era-shift))) scale(1.04); }
    }
    .era-label { animation: era-date linear both; animation-timeline: view(); animation-range: cover 0% cover 100%; transform-origin: 0 100%; }

    /* Era heading slides up out of a mask like a line being drawn; body text rises in. */
    @keyframes slide-up { from { transform: translateY(110%) skewY(4deg); } to { transform: none; } }
    @keyframes rise {
      from { opacity: 0; transform: translateY(var(--reveal-distance)); }
      to { opacity: 1; transform: none; }
    }
    .era h2 .slide { animation: slide-up linear both; animation-timeline: view(); animation-range: entry 5% entry 55%; }
    .era h3, .era p:not(.era-label), .era li { animation: rise linear both; animation-timeline: view(); animation-range: entry 0% entry 45%; }
  }
}
