/* Vector Dusk
   A page drawn like a cinematic platform game of 1991: flat polygons, sixteen
   colours on screen at one time, and no display over the picture. The scene is
   fixed behind the text, and its palette is replaced as the page scrolls. */

:root {
  /* The palette. Hex values appear only in this block.
     Seven colours are fixed. Nine belong to the scene and come in three sets. */
  --c-black: #04060d;
  --c-slab: #0d1530;
  --c-facet: #3d5f9e;
  --c-text: #b7c9d6;
  --c-bright: #f1f3e4;
  --c-laser: #ff5a3c;
  --c-spark: #ffd166;

  --dusk-a: #101a3f;
  --dusk-b: #1c3a6e;
  --dusk-c: #2f6a94;
  --dusk-d: #5fa3b0;
  --dusk-e: #a9d3c2;
  --dusk-moon: #f0ead0;
  --dusk-far: #4a7f9c;
  --dusk-mid: #26496f;
  --dusk-near: #0b1630;

  --night-a: #03050c;
  --night-b: #080e2a;
  --night-c: #0f1a44;
  --night-d: #182a5e;
  --night-e: #254377;
  --night-moon: #c9d6e8;
  --night-far: #14234b;
  --night-mid: #0c1533;
  --night-near: #05081a;

  --dawn-a: #2a1f4d;
  --dawn-b: #5b3a6e;
  --dawn-c: #a85a6c;
  --dawn-d: #e08a5e;
  --dawn-e: #f6c98a;
  --dawn-moon: #fff3d6;
  --dawn-far: #7a4a66;
  --dawn-mid: #452a4f;
  --dawn-near: #1c1230;

  /* Jobs: fixed */
  --black: var(--c-black);
  --slab: var(--c-slab);
  --facet: var(--c-facet);
  --text: var(--c-text);
  --bright: var(--c-bright);
  --laser: var(--c-laser);
  --spark: var(--c-spark);

  /* Jobs: the scene. The palette animation below replaces these nine. */
  --sky-a: var(--dusk-a);
  --sky-b: var(--dusk-b);
  --sky-c: var(--dusk-c);
  --sky-d: var(--dusk-d);
  --sky-e: var(--dusk-e);
  --moon: var(--dusk-moon);
  --far: var(--dusk-far);
  --mid: var(--dusk-mid);
  --near: var(--dusk-near);

  /* Which palette is on: 1 or 0. They show the stars and the label in the bar. */
  --is-dusk: 1;
  --is-night: 0;
  --is-dawn: 0;

  --bar: 2.75rem;
  --cut: 2.75rem;
  --gutter: max(1rem, 11vw);

  --sans: "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--black);
  scroll-padding-block: calc(var(--bar) + 1rem);
}

body {
  margin: 0;
  min-height: 100dvh;
  padding: var(--bar) 0;
  overflow-x: clip;
  font: 400 1.0625rem/1.7 var(--sans);
  color: var(--text);
}

::selection { background: var(--laser); color: var(--black); }

/* ── The scene ────────────────────────────────────────────────────────────
   Fixed between the two black bars. Every shape is one flat colour. The sky
   is five bands with hard edges. */

.scene {
  position: fixed;
  inset: var(--bar) 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(
    var(--sky-a) 0 22%,
    var(--sky-b) 22% 40%,
    var(--sky-c) 40% 53%,
    var(--sky-d) 53% 62%,
    var(--sky-e) 62%);
}

/* One element, many box-shadows. They show in the night palette only. */
.stars {
  position: absolute;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  opacity: var(--is-night);
  box-shadow:
    7vw 6vh 0 var(--moon), 15vw 19vh 0 var(--moon), 23vw 9vh 0 var(--moon),
    31vw 27vh 0 var(--moon), 38vw 4vh 0 var(--moon), 44vw 15vh 0 var(--moon),
    52vw 31vh 0 var(--moon), 58vw 8vh 0 var(--moon), 66vw 21vh 0 var(--moon),
    71vw 3vh 0 var(--moon), 79vw 12vh 0 var(--moon), 85vw 26vh 0 var(--moon),
    92vw 7vh 0 var(--moon), 96vw 18vh 0 var(--moon), 11vw 34vh 0 var(--moon),
    62vw 37vh 0 var(--moon);
}

/* Twelve sides, not a circle */
.moon,
.moon-small {
  position: absolute;
  aspect-ratio: 1;
  background: var(--moon);
  clip-path: polygon(100% 50%, 93.3% 75%, 75% 93.3%, 50% 100%, 25% 93.3%, 6.7% 75%,
    0 50%, 6.7% 25%, 25% 6.7%, 50% 0, 75% 6.7%, 93.3% 25%);
}

.moon { left: 60%; top: 24%; width: 40vmin; }
.moon-small { left: 87%; top: 9%; width: 5vmin; }

/* Three rows of rock. Each is taller than the scene, so that it can rise. */
.far,
.mid,
.near {
  position: absolute;
  inset: 0 0 -16vh;
}

.far {
  background: var(--far);
  clip-path: polygon(0 55%, 6% 55%, 8% 50%, 19% 50%, 21% 54%, 30% 54%, 33% 47%,
    37% 47%, 39% 53%, 52% 53%, 55% 48%, 68% 48%, 70% 54%, 84% 54%, 86% 49%,
    95% 49%, 97% 54%, 100% 54%, 100% 100%, 0 100%);
}

.mid {
  background: var(--mid);
  clip-path: polygon(0 62%, 4% 60%, 7% 43%, 9% 41%, 11% 44%, 13% 59%, 24% 62%,
    27% 57%, 31% 58%, 34% 63%, 47% 64%, 49% 55%, 50% 37%, 52% 35%, 54% 39%,
    55% 57%, 58% 62%, 72% 64%, 76% 58%, 80% 46%, 82% 45%, 84% 49%, 86% 60%,
    93% 63%, 100% 59%, 100% 100%, 0 100%);
}

.near {
  background: var(--near);
  clip-path: polygon(0 60%, 5% 58%, 9% 64%, 12% 74%, 22% 76%, 30% 72%, 38% 78%,
    50% 80%, 61% 76%, 66% 70%, 70% 72%, 78% 79%, 90% 77%, 95% 68%, 100% 64%,
    100% 100%, 0 100%);
}

/* ── The bars ─────────────────────────────────────────────────────────────
   The picture is letterboxed. The bars hold the only interface. */

.bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  height: var(--bar);
  padding: 0 max(1rem, 3vw);
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--black);
}

.bar-top { top: 0; }
.bar-bottom { bottom: 0; }

.bar a {
  color: var(--text);
  text-decoration: none;
}

.bar a:hover { color: var(--spark); }
.bar .name { color: var(--bright); }
.bar nav { display: flex; gap: 1.75rem; }

/* How far down the page: a beam along the top edge of the bottom bar */
.bar-bottom::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--laser);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.reel {
  position: relative;
  flex: 1;
  height: 1.2em;
  margin: 0;
  line-height: 1.2;
}

.reel > span {
  position: absolute;
  inset: 0;
}

.reel .p-dusk { opacity: var(--is-dusk); }
.reel .p-night { opacity: var(--is-night); }
.reel .p-dawn { opacity: var(--is-dawn); }

.bar-bottom { color: var(--text); }
.bar-bottom .count { color: var(--bright); }

/* ── The title card ───────────────────────────────────────────────────────
   Set on the two dark bands at the top of the sky, with nothing behind it. */

.title-card {
  min-height: 52vh;
  max-width: 62rem;
  padding: 9vh var(--gutter) 3rem;
}

.dateline {
  margin: 0 0 1.4rem;
  font-size: 0.75rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--laser);
}

h1 {
  margin: 0 0 1.3rem;
  font: 300 clamp(2rem, 6.2vw, 4.4rem) / 1.12 var(--sans);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--bright);
}

.standfirst {
  max-width: 30rem;
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

/* ── The slab ─────────────────────────────────────────────────────────────
   Two corners are cut off. The lighter triangle at each cut is the only
   shading on the page. */

.slab {
  position: relative;
  max-width: 44rem;
  margin: 0 var(--gutter) 38vh;
  padding: 3.25rem 3.5rem 3rem;
  background: var(--slab);
  clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%,
    var(--cut) 100%, 0 calc(100% - var(--cut)));
}

.slab::before,
.slab::after {
  content: "";
  position: absolute;
  width: var(--cut);
  height: var(--cut);
  background: var(--facet);
}

.slab::before { top: 0; right: 0; clip-path: polygon(0 0, 100% 100%, 0 100%); }
.slab::after { bottom: 0; left: 0; clip-path: polygon(0 0, 100% 0, 100% 100%); }

.slab > :first-child { margin-top: 0; }

p { margin: 0 0 1.2rem; }

.opening {
  font-size: 1.28rem;
  line-height: 1.55;
  color: var(--bright);
}

h2 {
  margin: 3rem 0 1.1rem;
  font: 600 0.95rem/1.4 var(--sans);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--bright);
}

h2::before {
  content: "";
  display: inline-block;
  width: 0.65em;
  height: 0.75em;
  margin-right: 0.9em;
  background: var(--laser);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

h3 {
  margin: 2.2rem 0 0.6rem;
  font: 600 0.8rem/1.4 var(--sans);
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--spark);
}

a {
  color: var(--laser);
  text-decoration: underline 1px;
  text-underline-offset: 0.2em;
}

a:hover { color: var(--spark); }

a:focus-visible {
  outline: 2px solid var(--spark);
  outline-offset: 3px;
}

strong { font-weight: 600; color: var(--bright); }

ul, ol { margin: 0 0 1.3rem; padding-left: 1.4rem; }
li { margin: 0.35rem 0; padding-left: 0.3rem; }
.slab ul > li::marker { content: "▸"; color: var(--laser); }
.slab ol > li::marker { color: var(--spark); }

/* A subtitle, as under a film */
blockquote {
  margin: 2.6rem 0;
  text-align: center;
}

blockquote p {
  margin: 0;
  font-size: 1.25rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--spark);
}

blockquote footer {
  margin-top: 0.7rem;
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

/* A beam with one bright bolt on it */
hr {
  height: 2px;
  margin: 3.2rem 0;
  border: 0;
  background: linear-gradient(90deg, var(--laser) 0 47%, var(--spark) 47% 53%, var(--laser) 53%) 0 0 / 200% 100%;
  animation: bolt 2.6s linear infinite;
}

@keyframes bolt {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

code { font: 0.88em var(--mono); }

:not(pre) > code {
  padding: 0.12em 0.4em;
  white-space: nowrap;
  color: var(--bright);
  background: var(--black);
}

pre {
  margin: 1.8rem 0;
  padding: 1.2rem 1.4rem;
  overflow-x: auto;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--black);
  border-left: 0.4rem solid var(--facet);
  clip-path: polygon(0 0, calc(100% - 1.4rem) 0, 100% 1.4rem, 100% 100%, 0 100%);
}

pre code { font-size: inherit; }

.kw { color: var(--laser); }
.fn { color: var(--bright); }
.typ { color: var(--text); }
.num, .str { color: var(--spark); }
.com { color: var(--facet); font-style: italic; }

.table-scroll { margin: 1.8rem 0; overflow-x: auto; }

table {
  width: 100%;
  min-width: 26rem;
  border-collapse: collapse;
  font-size: 0.98rem;
}

th, td {
  padding: 0.55rem 0.9rem 0.55rem 0;
  text-align: left;
  border-bottom: 1px solid var(--facet);
}

th {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--laser);
}

tbody tr:last-child td { border-bottom: 0; }
td:first-child { white-space: nowrap; color: var(--bright); }

/* Six sides. A scene swatch changes with the palette. */
.swatch {
  display: inline-block;
  width: 1.15em;
  height: 1em;
  margin-right: 0.7em;
  vertical-align: -0.12em;
  background: var(--c);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

.colophon {
  margin-top: 3rem;
  padding-top: 1.2rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--facet);
}

.colophon p:last-child { margin-bottom: 0; }

/* ── The palette swap and the camera ──────────────────────────────────────
   Both follow the scroll position. The palette does not fade: step-end holds
   each set of nine colours, then jumps to the next. A browser without scroll
   timelines shows the dusk palette and a still scene. */

@keyframes palette {
  0% {
    --sky-a: var(--dusk-a); --sky-b: var(--dusk-b); --sky-c: var(--dusk-c);
    --sky-d: var(--dusk-d); --sky-e: var(--dusk-e); --moon: var(--dusk-moon);
    --far: var(--dusk-far); --mid: var(--dusk-mid); --near: var(--dusk-near);
    --is-dusk: 1; --is-night: 0; --is-dawn: 0;
  }
  34% {
    --sky-a: var(--night-a); --sky-b: var(--night-b); --sky-c: var(--night-c);
    --sky-d: var(--night-d); --sky-e: var(--night-e); --moon: var(--night-moon);
    --far: var(--night-far); --mid: var(--night-mid); --near: var(--night-near);
    --is-dusk: 0; --is-night: 1; --is-dawn: 0;
  }
  70%, 100% {
    --sky-a: var(--dawn-a); --sky-b: var(--dawn-b); --sky-c: var(--dawn-c);
    --sky-d: var(--dawn-d); --sky-e: var(--dawn-e); --moon: var(--dawn-moon);
    --far: var(--dawn-far); --mid: var(--dawn-mid); --near: var(--dawn-near);
    --is-dusk: 0; --is-night: 0; --is-dawn: 1;
  }
}

@keyframes reel { to { transform: scaleX(1); } }
@keyframes rise-far { to { transform: translateY(-3vh); } }
@keyframes rise-mid { to { transform: translateY(-8vh); } }
@keyframes rise-near { to { transform: translateY(-14vh); } }
@keyframes moonset { to { transform: translateY(26vh); } }

@supports (animation-timeline: scroll()) {
  :root {
    animation: palette step-end both;
    animation-timeline: scroll(root block);
  }

  .bar-bottom::before {
    animation: reel linear both;
    animation-timeline: scroll(root block);
  }

  @media (prefers-reduced-motion: no-preference) {
    .far, .mid, .near, .moon {
      animation: linear both;
      animation-timeline: scroll(root block);
    }

    .far { animation-name: rise-far; }
    .mid { animation-name: rise-mid; }
    .near { animation-name: rise-near; }
    .moon { animation-name: moonset; }
  }
}

/* ── Narrow screens ───────────────────────────────────────────────────── */

@media (max-width: 700px) {
  :root { --bar: 2.5rem; --cut: 1.75rem; --gutter: 0.75rem; }
  body { font-size: 1rem; }
  .bar { gap: 0.75rem; padding: 0 0.9rem; font-size: 0.62rem; letter-spacing: 0.22em; }
  .bar nav { gap: 0.9rem; }
  /* The moon hangs in the gap between the title card and the slab */
  .title-card { min-height: 60vh; padding: 6vh 1.25rem 2.5rem; }
  h1 { letter-spacing: 0.1em; }
  .slab { padding: 2.5rem 1.4rem 2.5rem; }
  .opening { font-size: 1.15rem; }
  .moon { left: 50%; top: 41%; width: 44vmin; }
  table { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  hr { animation: none; }
}
