/* ==========================================================================
   Refract project page: red, black and white.
   ========================================================================== */

:root,
[data-theme="light"] {
  --paper: #ffffff;
  --ink: #000000;
  --grey: #5c5c5c;     /* secondary text, 6.6:1 on white */
  --rule: #e2e2e2;
  --red: #e3000f;
  --red-deep: #a3000b; /* red text on white at small sizes */
  --red-pale: #fff0f1;
  --code-note: #4a4a4a;
  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #000000;
  --ink: #ffffff;
  --grey: #a3a3a3;
  --rule: #2b2b2b;
  --red: #ff1f2d;
  --red-deep: #ff5a64;
  --red-pale: #2b0407;
  --code-note: #4a4a4a;
  color-scheme: dark;
}

:root {
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --wrap: 1180px;
  --pad: clamp(20px, 5vw, 56px);
}

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

html { scroll-behavior: smooth; }
html { background: var(--paper); }
body {
  margin: 0;
  transition: background-color .3s ease, color .3s ease;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;  /* 17px */
  line-height: 1.6;
  font-stretch: 100%;
}
p, h1, h2, h3, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; }
code { font-family: var(--mono); font-size: .86em; }

::selection { background: var(--red); color: var(--paper); }
:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  padding: 10px 14px; background: var(--ink); color: var(--paper);
}
.skip:focus { top: 12px; }

/* ---------- Top bar ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(var(--wrap), 100% - 2 * var(--pad));
  margin: 0 auto;
  padding: 24px 0;
  font-size: 0.9375rem;
}
.crumbs { display: flex; gap: 10px; color: var(--grey); }
.crumbs a { color: var(--grey); text-decoration: none; }
.crumbs a:hover { color: var(--red-deep); }
.crumbs [aria-current] { color: var(--ink); font-weight: 600; }
.top-link { font-weight: 700; text-decoration: none; border-bottom: 2px solid var(--red); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-stretch: 125%; font-size: 1.125rem; letter-spacing: -0.02em; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; overflow: visible; }
.bm-beam { fill: none; stroke: var(--ink); stroke-width: 3.2; stroke-linecap: round; }
.bm-rays path { fill: none; stroke: var(--red); stroke-width: 2.8; stroke-linecap: round; }
.bm-prism { fill: var(--paper); stroke: var(--ink); stroke-width: 3.2; stroke-linejoin: round; }
.bm-fan { fill: var(--red); opacity: .45; }
.top .crumbs { margin-right: auto; padding-left: 20px; border-left: 1px solid var(--rule); }
.top-actions { display: flex; align-items: center; gap: 18px; }
.theme-toggle { --tt-track: var(--paper); --tt-border: var(--ink); --tt-knob: var(--red); --tt-icon-on: #fff; color: var(--ink); }

/* Example tabs above the prism */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: -12px 0 32px; }
.tab {
  padding: 9px 16px;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s;
}
.tab:hover { border-color: var(--red); color: var(--red-deep); }
.tab[aria-selected="true"] { background: var(--red); border-color: var(--red); color: #fff; }
.top-link:hover { color: var(--red-deep); }

main, .foot {
  width: min(var(--wrap), 100% - 2 * var(--pad));
  margin: 0 auto;
}

/* ---------- Hero ---------- */

.hero { padding: clamp(32px, 6vw, 72px) 0 clamp(32px, 5vw, 56px); }
.hero-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: clamp(24px, 4vw, 56px);
  align-items: center;
}
.hero-copy { min-width: 0; }

/* The wave: a beam that refracts where you point at it. */
.wave { margin: 0; }
.wave canvas {
  display: block;
  width: 100%;
  height: clamp(200px, 22vw, 280px);
  cursor: crosshair;
  touch-action: pan-y;
}
.wave figcaption { margin-top: 6px; color: var(--grey); font-size: 0.8125rem; }
.title {
  font-size: clamp(4rem, 15vw, 11.5rem);
  font-weight: 900;
  font-stretch: 125%;
  line-height: .86;
  letter-spacing: -0.045em;
  margin-left: -0.04em;
}
.lede {
  max-width: 36ch;
  margin-top: clamp(24px, 3vw, 36px);
  font-size: clamp(1.3125rem, 2.4vw, 1.75rem);
  font-stretch: 100%;
  line-height: 1.35;
  font-weight: 500;
}
.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 56px;
  margin-top: 40px;
}
.facts dt { font-size: 0.8125rem; color: var(--grey); }
.facts dd { font-weight: 600; }

/* ---------- The prism figure ---------- */

.refraction {
  padding: clamp(32px, 5vw, 56px) 0;
  border-top: 3px solid var(--ink);
}
.fig-intro { max-width: 52ch; margin-bottom: 40px; font-size: 1.1875rem; }

.prism {
  display: grid;
  grid-template-columns: minmax(180px, 250px) minmax(260px, 1fr) minmax(280px, 400px);
  height: 500px;
}
.prism-in {
  align-self: center;
  padding-right: 12px;
}
.in-label { font-size: 0.8125rem; color: var(--grey); }
.in-text {
  margin-bottom: 20px;
  font-size: 1.3125rem;
  font-weight: 700;
  font-stretch: 112%;
  line-height: 1.2;
}
.in-text--small { margin-bottom: 0; font-size: 1rem; font-weight: 500; font-stretch: 100%; line-height: 1.4; }

.prism-svg { width: 100%; height: 100%; overflow: visible; }
.beam { stroke: var(--ink); stroke-width: 4; }
.ray {
  stroke: var(--red);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  transition: stroke-width .2s, opacity .2s;
}
.ray[data-i="1"] { opacity: .85; }
.ray[data-i="2"] { opacity: .72; }
.ray[data-i="3"] { opacity: .6; }
.ray[data-i="4"] { opacity: .48; }
.beam { vector-effect: non-scaling-stroke; }
.glass { fill: var(--paper); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.fan { fill: var(--red); opacity: .35; }

.prism-out {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
}
.prism-out li {
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 0 0 0 20px;
  border-left: 3px solid transparent;
  transition: border-color .2s, background-color .2s;
}
.out-kind { font-size: 0.8125rem; font-weight: 700; color: var(--red-deep); }
.prism-out p { font-size: 0.9375rem; line-height: 1.4; }
.ref { display: block; margin-top: 2px; font-family: var(--mono); font-size: 0.75rem; color: var(--grey); }

/* Hovering an output lights up its ray. */
.prism.is-focus .ray { opacity: .18; }
.prism.is-focus .ray.is-on { opacity: 1; stroke-width: 5; }
.prism-out li.is-on { border-left-color: var(--red); background: var(--red-pale); }

.fig-source { margin-top: 20px; font-size: 0.8125rem; color: var(--grey); }

/* Entrance: the beam enters, then the rays split out. */
html.js .prism:not(.is-lit) .beam,
html.js .prism:not(.is-lit) .ray { stroke-dasharray: 1; stroke-dashoffset: 1; }
html.js .prism:not(.is-lit) .prism-out li { opacity: 0; }
html.js .prism:not(.is-lit) .fan { opacity: 0; }
.prism.is-lit .beam { stroke-dasharray: 1; animation: draw .55s ease-out both; }
.prism.is-lit .ray { stroke-dasharray: 1; animation: draw .6s ease-out both; animation-delay: calc(.5s + var(--i) * .09s); }
.prism.is-lit .prism-out li { animation: show .5s ease-out both; animation-delay: calc(.75s + var(--i) * .09s); }
.prism.is-lit .fan { animation: fan .4s ease-out .45s both; }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes show { from { opacity: 0; } to { opacity: 1; } }
@keyframes fan { from { opacity: 0; } to { opacity: .35; } }

/* Provenance tags */
.prov {
  display: inline-block;
  margin-right: 4px;
  padding: 0 7px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.6;
  vertical-align: 1px;
  white-space: nowrap;
  border: 2px solid var(--red);
}
.prov--fact { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.prov--house { background: var(--red); color: var(--paper); }
.prov--ai { background: var(--paper); color: var(--red-deep); }
.prov--hyp { background: var(--paper); color: var(--ink); border-color: var(--ink); border-style: dashed; }

/* ---------- Sections ---------- */

.section {
  padding: clamp(56px, 8vw, 96px) 0;
  border-top: 3px solid var(--ink);
}
.h2 {
  max-width: 20ch;
  margin-bottom: clamp(28px, 4vw, 44px);
  font-size: clamp(2rem, 4.4vw, 3.5rem);
  font-weight: 800;
  font-stretch: 112%;
  line-height: 1;
  letter-spacing: -0.03em;
}
.section-lede { max-width: 58ch; margin-bottom: 32px; font-size: 1.1875rem; }
.muted { max-width: 58ch; color: var(--grey); }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(32px, 6vw, 96px);
}

/* Steps: a real sequence, so they are numbered */
.steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  counter-reset: step;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}
.step {
  position: relative;
  padding: 18px 20px 24px;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  counter-increment: step;
}
.step::before {
  content: counter(step);
  display: block;
  margin-bottom: 14px;
  font-size: 2.25rem;
  font-weight: 900;
  font-stretch: 125%;
  line-height: 1;
  color: var(--red);
}
.step h3 { margin-bottom: 6px; font-size: 1.0625rem; font-weight: 700; }
.step p { font-size: 0.9375rem; color: var(--grey); line-height: 1.5; }
.step--loop { background: var(--red-pale); }
.step--loop::after {
  content: "↺ loops until clean";
  display: inline-block;
  margin-top: 12px;
  padding: 2px 8px;
  background: var(--red);
  color: var(--paper);
  font-size: 0.75rem;
  font-weight: 700;
}
.steps-note { margin-top: 18px; color: var(--grey); font-size: 0.9375rem; }

/* Provenance and rails */
.prov-list { display: grid; gap: 16px; }
.prov-list li { display: grid; grid-template-columns: 130px 1fr; align-items: baseline; gap: 16px; }
.prov-list .prov { justify-self: start; }
.rails { display: grid; gap: 0; border-top: 1px solid var(--ink); }
.rails li {
  position: relative;
  padding: 14px 0 14px 28px;
  border-bottom: 1px solid var(--rule);
}
.rails li::before {
  content: "";
  position: absolute;
  left: 0; top: 23px;
  width: 14px; height: 3px;
  background: var(--red);
}

/* Interfaces */
.use { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: clamp(32px, 5vw, 64px); align-items: start; }
.interfaces { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 32px; }
.interfaces h3 { margin-bottom: 4px; font-size: 1.0625rem; font-weight: 800; font-stretch: 112%; }
.interfaces p { font-size: 0.9375rem; color: var(--grey); line-height: 1.5; }
.interfaces code { color: var(--ink); }
.code-wrap { background: var(--ink); color: var(--paper); padding: 24px; }
.code-title { margin-bottom: 14px; font-weight: 700; }
.code {
  margin: 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.8;
}
.code code { font-size: inherit; }
.code-note { margin-top: 16px; font-size: 0.8125rem; color: #bdbdbd; line-height: 1.5; }
[data-theme="dark"] .code-note { color: var(--code-note); }

/* Evaluation */
.eval { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: clamp(32px, 6vw, 80px); align-items: start; }
.bars figcaption { margin-bottom: 20px; font-weight: 700; }
.bar-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-bottom: 22px;
}
.bar-name { font-size: 0.9375rem; color: var(--grey); }
.bar-track { position: relative; display: block; height: 28px; background: var(--red-pale); }
.bar {
  position: absolute; inset: 0 auto 0 0;
  width: calc(var(--v) * 1%);
  min-width: 3px;
}
.bar--agent { background: var(--ink); }
.bar--base { background: var(--red); }
.bar-row { position: relative; }
.bar-val {
  font-size: 2.25rem;
  font-weight: 900;
  font-stretch: 125%;
  line-height: 1;
}
.caveats { display: grid; gap: 14px; border-top: 1px solid var(--ink); padding-top: 14px; }
.caveats li { color: var(--ink); }
.caveats li:last-child { color: var(--red-deep); font-weight: 600; }

/* Built alone */
.numbers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--ink);
  align-self: start;
}
.numbers div { padding: 16px 0; border-bottom: 1px solid var(--rule); }
.numbers dt { font-size: 0.8125rem; color: var(--grey); }
.numbers dd { font-size: 1.75rem; font-weight: 800; font-stretch: 112%; line-height: 1.2; }

/* CTA */
.cta { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 24px; }
.cta .h2 { margin-bottom: 0; }
.cta-links { display: flex; flex-wrap: wrap; gap: 12px; }
.btn {
  display: inline-block;
  padding: 14px 22px;
  border: 2px solid var(--ink);
  font-weight: 700;
  text-decoration: none;
  transition: background-color .15s, color .15s, border-color .15s;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn--red { background: var(--red); border-color: var(--red); color: var(--paper); }
.btn--red:hover { background: var(--red-deep); border-color: var(--red-deep); }

/* Footer */
.foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 24px 0 40px;
  border-top: 3px solid var(--ink);
  font-weight: 600;
}
.foot a { text-decoration: none; }
.foot a:hover { color: var(--red-deep); }

/* ---------- Responsive ---------- */

@media (max-width: 1000px) {
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .use, .eval { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .hero-row { grid-template-columns: minmax(0, 1fr); }
  .wave canvas { height: 150px; }
  .prism { grid-template-columns: 1fr; height: auto; }
  .prism-in { padding: 0 0 8px; }
  .prism-svg { display: none; }
  .prism-out { grid-template-rows: none; gap: 0; border-top: 3px solid var(--red); }
  .prism-out li { padding: 14px 0 14px 16px; border-left: 3px solid var(--red); border-bottom: 1px solid var(--rule); }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .top { flex-wrap: wrap; }
  .top .crumbs { order: 3; flex-basis: 100%; padding-left: 0; border-left: 0; }
  .top-actions { margin-left: auto; }
}

@media (max-width: 560px) {
  body { font-size: 1rem; }
  .steps { grid-template-columns: 1fr; }
  .interfaces { grid-template-columns: 1fr; }
  .prov-list li { grid-template-columns: 1fr; gap: 4px; }
  .foot { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition-duration: 0s !important; }
  html.js .prism .beam, html.js .prism .ray { stroke-dasharray: none !important; stroke-dashoffset: 0 !important; }
  html.js .prism .prism-out li { opacity: 1 !important; }
  html.js .prism .fan { opacity: .35 !important; }
}
