/*
 * site.css: the shared shell for every page in Deep Time.
 *
 * Responsibility: layout, typography, and all structural components that repeat
 * across the 16 era pages and the index (deep-time rail, hero, scene frame,
 * vitals grid, death timeline, survival list, uncertainty note, pager).
 *
 * It deliberately contains NO era-specific colour. Every colour is read from a
 * custom property (--bg, --ink, --accent, --sky-*, ...) whose value is set by
 * eras.css based on the `data-era` attribute on <body>. That split is what lets
 * one stylesheet carry sixteen different moods without sixteen copies of the layout.
 *
 * Read alongside: assets/eras.css (the themes), assets/nav.js (injects the rail
 * and pager markup this file styles), eras/*.html (the markup contract).
 *
 * Constraint: no build step and no framework. Fonts are self-hosted under
 * assets/fonts/, so the site makes no third-party request and renders identically
 * offline.
 */

@import url('fonts.css');

/* ---- reset ---- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; }

/* ---- defaults; eras.css overrides the colour half of this ---- */
:root {
  --bg:        #08090a;
  --bg-raise:  #101214;
  --ink:       #e7e3d8;
  --ink-dim:   #8e8b83;
  --ink-faint: #55534e;
  --rule:      #22252a;
  --accent:    #d8552f;
  --accent-2:  #e8b04b;

  --sky-1: #101214;
  --sky-2: #1a1d21;
  --sky-3: #24282d;

  --display: 'Big Shoulders Display', 'Haettenschweiler', 'Arial Narrow', sans-serif;
  --body:    'Newsreader', Georgia, 'Times New Roman', serif;
  --mono:    'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --rail-w: 76px;
  --pad: clamp(1.25rem, 4vw, 4rem);
  --measure: 62ch;
}

/* ---- page ---- */
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: clamp(1.02rem, 0.55vw + 0.92rem, 1.19rem);
  line-height: 1.62;
  font-weight: 300;
  padding-left: var(--rail-w);
  overflow-x: hidden;
  transition: background 600ms ease;
}
@media (max-width: 860px) { body { padding-left: 0; padding-bottom: 64px; } }

/* Film grain. Sits above everything, ignores pointer events. Kept very low
   opacity, it should register as texture, never as noise. */
body::after {
  content: '';
  position: fixed;
  inset: -50%;
  pointer-events: none;
  z-index: 90;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--accent); color: var(--bg); }

/* ---- deep-time rail (injected by nav.js) ---- */
.rail {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--rail-w);
  border-right: 1px solid var(--rule);
  background: color-mix(in srgb, var(--bg) 86%, #000);
  display: flex;
  flex-direction: column;
  z-index: 80;
}
.rail__home {
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-dim);
  padding: 1.1rem 0;
  text-align: center;
  border-bottom: 1px solid var(--rule);
  transition: color 200ms;
}
.rail__home:hover { color: var(--accent); }
.rail__list { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.rail__item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--ink-faint);
  border-bottom: 1px solid color-mix(in srgb, var(--rule) 50%, transparent);
  transition: color 180ms, background 180ms;
}
.rail__item:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.rail__item[aria-current='page'] { color: var(--bg); background: var(--accent); font-weight: 600; }
/* Name slides out on hover instead of living permanently in a 76px column. */
.rail__item span {
  position: absolute;
  left: 100%;
  padding: 0.3rem 0.7rem;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 160ms, transform 160ms;
  pointer-events: none;
}
.rail__item:hover span { opacity: 1; transform: translateX(0); }

@media (max-width: 860px) {
  .rail {
    top: auto; right: 0;
    width: auto; height: 56px;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--rule);
  }
  .rail__home { padding: 0 0.9rem; display: flex; align-items: center; border-bottom: 0; border-right: 1px solid var(--rule); }
  .rail__list { flex-direction: row; }
  .rail__item { border-bottom: 0; border-right: 1px solid color-mix(in srgb, var(--rule) 50%, transparent); }
  .rail__item span { display: none; }
}

/* ---- shared shell ---- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 var(--pad); }
.narrow { max-width: var(--measure); }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

h2.section-title {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.9rem, 3.4vw, 3rem);
  line-height: 0.95;
  letter-spacing: 0.005em;
  text-transform: uppercase;
  margin-bottom: 1.6rem;
}

section { padding-block: clamp(3.5rem, 8vw, 7rem); }
section + section { border-top: 1px solid var(--rule); }

/* ---- hero ---- */
.hero { padding-top: clamp(3rem, 9vh, 6rem); padding-bottom: clamp(2rem, 5vw, 3.5rem); }
.hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.6rem;
  align-items: baseline;
  margin-bottom: 1.2rem;
}
.hero__num {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--accent);
}
.hero__name {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(4.2rem, 17vw, 15rem);
  line-height: 0.82;
  letter-spacing: -0.005em;
  text-transform: uppercase;
  /* Optical margin: the condensed caps carry a little left sidebearing. */
  margin-left: -0.02em;
}
.hero__dates {
  font-family: var(--mono);
  font-size: clamp(0.78rem, 1.4vw, 0.95rem);
  color: var(--ink-dim);
  letter-spacing: 0.06em;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}
.hero__lede {
  font-size: clamp(1.15rem, 1.6vw, 1.45rem);
  line-height: 1.5;
  font-weight: 200;
  max-width: 46ch;
  margin-top: 2rem;
  color: color-mix(in srgb, var(--ink) 88%, var(--bg));
}

/* The verdict block. This is the one thing a reader should remember per page. */
.verdict {
  margin-top: clamp(2.5rem, 6vw, 4rem);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 1.8rem;
  align-items: end;
}
.verdict__label {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
  grid-column: 1 / -1;
  margin-bottom: 0.7rem;
}
.verdict__value {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(3rem, 10vw, 8rem);
  line-height: 0.8;
  text-transform: uppercase;
  color: var(--accent);
  grid-column: 1 / -1;
}
.verdict__note {
  grid-column: 1 / -1;
  margin-top: 1.1rem;
  font-family: var(--mono);
  font-size: 0.96rem;
  line-height: 1.7;
  color: var(--ink-dim);
  max-width: 54ch;
}

/* ---- era scene (generated image per page) ---- */
.scene {
  position: relative;
  margin-top: clamp(2.5rem, 6vw, 4.5rem);
  border: 1px solid var(--rule);
  background: var(--sky-1);
  overflow: hidden;
}
.scene svg, .scene img { width: 100%; height: auto; display: block; }
.scene__cap {
  position: absolute;
  left: 0; bottom: 0;
  padding: 0.55rem 0.9rem;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(6px);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-dim);
  border-top: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}

/* ---- vitals ---- */
.vitals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(268px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}
.vital {
  background: var(--bg);
  padding: 1.4rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.vital__k {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.vital__v {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.7rem, 2.6vw, 2.3rem);
  line-height: 1;
  letter-spacing: 0.01em;
}
.vital__v small {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  margin-left: 0.45rem;
  text-transform: uppercase;
}
.vital__note { font-family: var(--mono); font-size: 0.88rem; line-height: 1.55; color: var(--ink-faint); }

/* Comparison meter: the filled bar is this era, the tick is today's value.
   --pct (0-100) is the era value, --now (0-100) is where modern Earth sits. */
.meter { position: relative; height: 4px; background: color-mix(in srgb, var(--ink) 12%, transparent); margin-top: 0.15rem; margin-bottom: 0.7rem; }
.meter__fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--pct, 0) * 1%); background: var(--accent); }
.meter__now { position: absolute; top: -4px; bottom: -4px; left: calc(var(--now, 0) * 1%); width: 1px; background: var(--ink); }
/* Caption hangs below the bar. Above it would collide with the value's inline
   <small>, which sits on the same baseline band at every card width. */
.meter__now::after {
  content: 'now';
  position: absolute;
  top: calc(100% + 2px); left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 0.52rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
}
.vital--danger .meter__fill { background: var(--accent-2); }

/* ---- death timeline ---- */
.clock { border-left: 1px solid var(--rule); margin-left: 0.4rem; }
.beat { position: relative; padding: 0 0 2.2rem 2rem; }
.beat:last-child { padding-bottom: 0; }
.beat::before {
  content: '';
  position: absolute;
  left: -4.5px; top: 0.5rem;
  width: 8px; height: 8px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 50%;
}
.beat--fatal::before { background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.beat__t {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent);
  display: block;
  margin-bottom: 0.3rem;
}
.beat__h { font-family: var(--display); font-weight: 700; font-size: 1.5rem; line-height: 1.05; text-transform: uppercase; letter-spacing: 0.01em; }
.beat p { max-width: var(--measure); margin-top: 0.45rem; color: color-mix(in srgb, var(--ink) 82%, var(--bg)); }

/* ---- survival cards ---- */
.kit { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; }
.kit__item { border-top: 2px solid var(--accent); padding-top: 1rem; }
.kit__item h3 {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 0.5rem;
}
.kit__item p { font-size: 0.98rem; }
.kit__item--none { border-top-color: var(--ink-faint); opacity: 0.72; }

/* ---- uncertainty ---- */
/* Distinguished by a raised background, not a left accent bar. */
.caveat {
  border: 1px solid var(--rule);
  padding: 1.5rem 1.6rem;
  background: var(--bg-raise);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.75;
  color: var(--ink-dim);
  max-width: 74ch;
}
.caveat strong { color: var(--ink); font-weight: 600; }
.caveat + .caveat { margin-top: 1rem; }

/* ---- pager (injected by nav.js) ---- */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--rule);
  border-top: 1px solid var(--rule);
}
.pager__link {
  background: var(--bg);
  padding: clamp(1.8rem, 4vw, 3rem) var(--pad);
  text-decoration: none;
  display: block;
  transition: background 200ms;
}
.pager__link:hover { background: var(--bg-raise); }
.pager__link--next { text-align: right; }
.pager__dir { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-dim); }
.pager__name {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  text-transform: uppercase;
  margin-top: 0.4rem;
}
.pager__verdict { font-family: var(--mono); font-size: 0.68rem; color: var(--accent); letter-spacing: 0.08em; margin-top: 0.35rem; }
.pager__empty { background: var(--bg); }

.foot {
  padding: 2.5rem var(--pad) 3.5rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
}
.foot a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid var(--rule); }
.foot a:hover { color: var(--accent); border-color: var(--accent); }

/* ---- entrance: one orchestrated load, staggered by depth ---- */
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.hero > .wrap > * { animation: rise 800ms cubic-bezier(.2,.7,.2,1) backwards; }
.hero > .wrap > *:nth-child(1) { animation-delay: 60ms; }
.hero > .wrap > *:nth-child(2) { animation-delay: 140ms; }
.hero > .wrap > *:nth-child(3) { animation-delay: 220ms; }
.hero > .wrap > *:nth-child(4) { animation-delay: 320ms; }
.hero > .wrap > *:nth-child(5) { animation-delay: 440ms; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* ---- section figures: menu and kills ----
   The hero is 21:9 and full width; these two are 3:2 and sit beside their
   section's text so they read as evidence rather than as second heroes. The
   figure is sticky because the death timeline is much taller than the image -
   without it you scroll past the picture in the first beat and read the
   remaining five with nothing on screen. */
.split {
  display: grid;
  grid-template-columns: minmax(0, 41%) minmax(0, 1fr);
  gap: clamp(1.6rem, 4vw, 3.5rem);
  align-items: start;
}
.split__fig { position: sticky; top: clamp(1rem, 5vh, 3rem); }
.split__fig img { width: 100%; height: auto; border: 1px solid var(--rule); }
.split__fig figcaption {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.65;
  color: var(--ink-dim);
  margin-top: 0.75rem;
  padding-left: 0.7rem;
  border-left: 1px solid var(--rule);
}

/* Inside a split the kit grid has half the room, so let it fall to two columns
   rather than squeezing three. */
.split .kit { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1.3rem; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; gap: 1.8rem; }
  /* Sticky is wrong once the figure is stacked above its text: it would pin the
     image to the top and let the words scroll out from under it. */
  .split__fig { position: static; }
}

/* ---- lightbox ----
   Native <dialog>, so the focus trap, inert background and Esc-to-close are the
   platform's job rather than ours. See assets/lightbox.js. */
.is-zoomable { cursor: pointer; }
.is-zoomable:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }
.is-zoomable:hover { outline: 2px solid var(--accent-2); outline-offset: 3px; }

.lb {
  /* Override the UA's dialog box, which is position:absolute, margin:auto and
     width:fit-content, so 100vw/100vh alone sizes it without anchoring it, and
     it lands wherever the containing block puts it. Fixed + inset is what
     actually pins it to the viewport. */
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  border: 0;
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  background: transparent;
  color: var(--ink);
  overflow: hidden;
}
.lb::backdrop { background: rgba(0, 0, 0, 0.93); }
.lb[open] { display: grid; grid-template-rows: 1fr auto; }

.lb__stage {
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
  padding: clamp(0.75rem, 3vw, 2.5rem);
}
.lb__img { max-width: 100%; max-height: 100%; width: auto; height: auto; cursor: zoom-out; }

.lb__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 1.4rem;
  padding: 0.9rem clamp(0.9rem, 3vw, 2.5rem) 1.2rem;
  border-top: 1px solid var(--rule);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
}
.lb__count { color: var(--ink); font-weight: 600; letter-spacing: 0.1em; }
.lb__cap { color: var(--ink-dim); flex: 1 1 20ch; }
.lb__hint { color: var(--ink-faint); font-size: 0.72rem; letter-spacing: 0.08em; }

.lb__close {
  position: absolute;
  top: 0; right: 0;
  z-index: 2;
  width: 3rem; height: 3rem;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}
.lb__close:hover { color: var(--ink); }
.lb__close:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -4px; }

@media (max-width: 700px) { .lb__hint { display: none; } }
