@font-face {
  font-family: "Instrument Serif";
  src: url("fonts/instrument-serif-latin-400-normal.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  font-style: italic;
  src: url("fonts/instrument-serif-latin-400-italic.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  font-weight: 400;
  src: url("fonts/geist-latin-400-normal.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  font-weight: 600;
  src: url("fonts/geist-latin-600-normal.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("fonts/geist-mono-latin-400-normal.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #0b0910;
  --surface: #13101b;
  --line: #2a2436;
  --text: #ece8f4;
  --muted: #9d94b0;
  --fire: #00ff00;
  --fire-deep: #005500;
  --husk: #5b1f8f;
  --smoke: #aa00ff;
  --dusekkar: #ff9a33;
  --ghosdeeri: #3459ff;

  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Geist", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;

  --width: 1120px;
  --gutter: 16px;
  --gap: 160px;
  --header: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--husk); color: var(--text); }

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--fire-deep);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { text-decoration-color: var(--fire); }

:focus-visible { outline: 2px solid var(--fire); outline-offset: 3px; border-radius: 2px; }

.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.fire { color: var(--fire); }

h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; }
h2 { font-size: 2.75rem; line-height: 1.05; letter-spacing: -0.01em; }
h3 { font-size: 1.75rem; line-height: 1.2; }

p { margin: 0 0 1em; max-width: 64ch; }
.lead { font-size: 1.25rem; line-height: 1.5; color: var(--text); }
strong { font-weight: 600; }

.skip {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  background: var(--bg);
  padding: 8px 12px;
  z-index: 10;
}
.skip:focus { top: 8px; }

/* Every 3D view: a canvas filling its box, turned by dragging. */
canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; }
canvas.grabbing { cursor: grabbing; }
canvas:focus-visible { outline-offset: -6px; }

/* The light of a fire falls on the box around its viewer. Position, strength
   and colour come from viewer.js. */
.lamp { position: relative; isolation: isolate; }
.lamp::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    circle var(--glow-r, 46vmax) at var(--glow-x, 50%) var(--glow-y, 50%),
    rgb(var(--glow-c, 0 255 0) / calc(var(--glow-a, 0) * 0.14)),
    rgb(var(--glow-c, 0 255 0) / calc(var(--glow-a, 0) * 0.04)) 40%,
    transparent 100%
  );
}

/* Header */

.top {
  position: fixed;
  inset: 0 0 auto;
  z-index: 5;
  height: var(--header);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 0 max(var(--gutter), calc((100% - var(--width)) / 2 + var(--gutter)));
  background: var(--bg);
  border-bottom: 1px solid transparent;
}
.brand { font-family: var(--mono); font-size: 0.875rem; text-decoration: none; }
.brand span { color: var(--muted); }
.top nav { display: flex; gap: 24px; font-size: 0.875rem; }
.top nav a { color: var(--muted); text-decoration: none; transition: color 0.2s; }
.top nav a:hover, .top nav a[aria-current] { color: var(--text); }

/* Hero: the hat gets the room above the name and never sits on it. */

.hero {
  min-height: max(680px, 100svh);
  display: flex;
  flex-direction: column;
  padding-top: var(--header);
}
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 380px;
}
.stage canvas { position: absolute; inset: 0; }

.fallback { display: none; }
.no-webgl .fallback {
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(420px, 80vw);
  height: auto;
  transform: translate(-50%, -50%);
}
.no-webgl canvas { display: none; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  pointer-events: none;
  transition: opacity 0.6s;
}
.touched .hint, .no-webgl .hint { opacity: 0; }

.hero-base {
  width: 100%;
  max-width: var(--width);
  margin: 0 auto;
  padding: 16px var(--gutter) 40px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 32px;
}

.kicker { color: var(--muted); margin: 0 0 8px; }

h1 {
  font-size: clamp(4.5rem, 13vw, 10rem);
  line-height: 0.9;
  letter-spacing: -0.03em;
  margin-left: -0.04em;
}

blockquote { margin: 20px 0 0; }
blockquote p { font-family: var(--serif); font-style: italic; font-size: 1.5rem; line-height: 1.3; margin: 0; }
blockquote footer { color: var(--muted); font-size: 0.8125rem; margin-top: 4px; }

.facts { margin: 0 0 6px; min-width: 240px; border-top: 1px solid var(--line); }
.facts div {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.facts dt { color: var(--muted); font-size: 0.875rem; }
.facts dd { margin: 0; font-size: 0.9375rem; }

/* Chapters */

.chapter {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 32px;
  max-width: var(--width);
  margin: 0 auto;
  padding: var(--gap) var(--gutter) 0;
}
.num { color: var(--muted); margin: 0; padding-top: 24px; border-top: 1px solid var(--line); }
.body { padding-top: 24px; min-width: 0; border-top: 1px solid var(--line); }
.body > h2 { margin-bottom: 24px; }
.body > .lead { margin-bottom: 32px; }

/* 01: the night */

.night {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 400px);
  gap: 48px;
  align-items: start;
}
.night-text .lead { margin-bottom: 1.2em; }

.box { margin: 0; }
.box-stage {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
}
.box figcaption { color: var(--muted); font-size: 0.8125rem; margin-top: 12px; max-width: 48ch; }
.box figcaption .mono { display: block; color: var(--text); margin-bottom: 2px; }
.no-webgl .box { display: none; }

.figures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
  margin: 72px 0 0;
}
.figures div {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.figures dd {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.5rem, 8vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
}
.figures dt { color: var(--muted); font-size: 0.875rem; }

/* 02: the family */

.family {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 32px;
  margin-top: 48px;
}
.family-stage {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  --glow-r: 70%;
}
.no-webgl .family-stage { display: none; }
.no-webgl .family { grid-template-columns: 1fr; }

.picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }

button, .switch {
  font: 600 0.875rem/1 var(--sans);
  color: var(--text);
  background: none;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 10px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.2s;
}
button:hover, .switch:hover { border-color: var(--fire); }
button[aria-pressed="true"] { border-color: var(--text); }

.dot, .sw {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  display: inline-block;
  flex: none;
}
.dot.dus { --c: var(--dusekkar); }
.dot.doom { --c: var(--fire); }
.dot.ghos { --c: var(--ghosdeeri); }
.sw { border-radius: 1px; width: 10px; height: 10px; margin: 0 8px -1px 0; }
.sw.fire-a { --c: var(--fire); }
.sw.fire-b { --c: var(--fire-deep); }
.sw.smoke { --c: var(--smoke); }

.card h3 { margin-bottom: 4px; }
.meta { color: var(--muted); margin-bottom: 16px; }

.mini { margin: 16px 0 0; border-top: 1px solid var(--line); }
.mini div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9375rem;
}
.mini dt { color: var(--muted); }
.mini dd { margin: 0; text-align: right; }

.switches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 24px; }
.switch input { accent-color: var(--fire); margin: 0; width: 14px; height: 14px; }
.switch:has(input:focus-visible) { outline: 2px solid var(--fire); outline-offset: 3px; }
.note { color: var(--muted); font-size: 0.8125rem; margin: 0 0 0 8px; }

/* 03: the fire. The pumpkin waits beside the timeline and only catches when
   the 2018 entry reaches the middle of the screen. */

.story {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
  grid-template-areas: "timeline stage";
  gap: 48px;
  margin-top: 48px;
}
.story-stage {
  grid-area: stage;
  position: sticky;
  top: calc(var(--header) + 32px);
  align-self: start;
  height: min(68svh, 560px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  --glow-r: 80%;
}
.story-stage canvas { flex: 1 1 auto; min-height: 0; }
.story-caption {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  max-width: none;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
}
.story-caption .mono { color: var(--muted); }
.no-webgl .story-stage { display: none; }
.no-webgl .story { grid-template-columns: 1fr; }

/* Room after the last entry, so it can reach the middle of the screen
   while the pumpkin beside it is still fully in view. */
.timeline { grid-area: timeline; list-style: none; margin: 0; padding: 0 0 30svh; }
.timeline li {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 24px;
  padding: 28px 0;
  border-top: 1px solid var(--line);
}
.timeline time { color: var(--muted); padding-top: 2px; }
.timeline p { margin: 0; transition: color 0.4s; }
.timeline:has(.now) li:not(.now) p { color: var(--muted); }
.timeline .lit time { color: var(--fire); }

/* 04: the file */

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree { margin-top: 48px; font-size: 0.9375rem; }
.tree ul { margin-left: 6px; padding-left: 22px; border-left: 1px solid var(--line); }
.tree li { position: relative; padding: 10px 0; }
.tree ul > li::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 22px;
  width: 14px;
  border-top: 1px solid var(--line);
}
.cls { color: var(--muted); }
.obj { color: var(--text); }
.hot > .cls, .hot > .obj { color: var(--fire); }
.props { display: flex; flex-wrap: wrap; gap: 4px 24px; margin: 6px 0 0; font-size: 0.8125rem; }
.props div { display: flex; gap: 8px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }
.why { font-family: var(--sans); font-size: 0.875rem; color: var(--muted); margin: 6px 0 0; max-width: 56ch; }

.catalog {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
  margin: 48px 0 0;
}
.catalog div { padding-top: 12px; border-top: 1px solid var(--line); }
.catalog dt { color: var(--muted); font-size: 0.8125rem; }
.catalog dd { margin: 4px 0 0; font-size: 0.9375rem; }

/* 05: small things */

.notes { margin: 0; padding: 0; list-style: none; max-width: 64ch; }
.notes li { padding: 16px 0; border-top: 1px solid var(--line); }
.notes li:last-child { border-bottom: 1px solid var(--line); }

/* Footer */

.end {
  max-width: var(--width);
  margin: var(--gap) auto 0;
  padding: 32px var(--gutter) 64px;
  color: var(--muted);
  font-size: 0.8125rem;
}
.end::before { content: ""; display: block; border-top: 1px solid var(--line); margin-bottom: 32px; }
.end p { margin-bottom: 8px; }
.end a { color: var(--muted); }

.lost .chapter { min-height: 100svh; align-content: center; padding-top: 0; }

/* Smaller screens */

@media (max-width: 1080px) {
  .hero-base { grid-template-columns: 1fr; }
  .facts { display: grid; grid-template-columns: 1fr 1fr; column-gap: 32px; }
  .catalog { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .night { grid-template-columns: 1fr; }
  .box { max-width: 420px; }
  .family { grid-template-columns: 1fr; }
  .family-stage { aspect-ratio: 4 / 3; }
  .story { grid-template-columns: 1fr; grid-template-areas: "stage" "timeline"; gap: 0; }
  .story-stage {
    top: var(--header);
    z-index: 2;
    height: 42svh;
    margin: 0 calc(var(--gutter) * -1);
    border-width: 0 0 1px;
  }
}

@media (max-width: 720px) {
  :root { --gap: 96px; }
  h2 { font-size: 2.25rem; }
  .top nav { display: none; }
  .hero { min-height: 0; }
  .stage { flex: none; height: min(60svh, 520px); min-height: 0; }
  .hero-base { padding-top: 8px; }
  .facts { grid-template-columns: 1fr; }
  .chapter { grid-template-columns: 1fr; gap: 0; }
  .body { border-top: 0; padding-top: 8px; }
  .figures { grid-template-columns: 1fr; gap: 0; margin-top: 48px; }
  .figures div { flex-direction: row-reverse; justify-content: space-between; align-items: baseline; padding: 16px 0; }
  .figures dd { font-size: 3.5rem; }
  .timeline li { grid-template-columns: 1fr; gap: 4px; }
  .tree ul { padding-left: 14px; }
  .tree ul > li::before { left: -14px; width: 8px; }
  .catalog { grid-template-columns: 1fr; gap: 0; }
  .catalog div { padding: 10px 0; }
}
