/* ChainSolve — holding page.
   Zero JS by necessity: the _headers CSP is `default-src 'none'` with no script-src, so every
   moving part here is CSS/SVG. Colours and type are lifted verbatim from the brand package
   (GodfreyEngineering/chainsolve-brand, tokens/tokens.css) — do not eyeball new ones.

   The signature is the solver graph: a real powertrain-cooling DAG that resolves left to right
   on a 10s loop. One shared timeline drives everything; each dependency tier has its own
   keyframes with explicit percentage stops, so the propagation order is legible in the CSS
   rather than hidden in a pile of animation-delays. */

@font-face {
  font-family: 'Montserrat';
  src: url('/fonts/montserrat-latin-wght-normal.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Terracotta ramp + warm neutrals — brand tokens, dark theme (the product default). */
  --bg: #14110F;
  --surface: #1C1815;
  --border: #2A2420;
  --border-strong: #3B342F;
  --text: #FAF4F0;
  --text-muted: #C9BAB0;
  --text-subtle: #7A6E66;
  --accent: #E06A4E;
  --accent-soft: #E8977C;

  --font-display: 'Montserrat', system-ui, sans-serif;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --ease-standard: cubic-bezier(.2, 0, 0, 1);
  --loop: 10s;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 3.4vw, 40px);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  /* The node-editor canvas, quoted quietly: the same dot grid the workbench draws behind
     a graph. Two layers so the glow sits under the dots, not over them. */
  background-image:
    radial-gradient(circle at 50% 38%, rgba(224, 106, 78, .10), transparent 62%),
    radial-gradient(circle at 1px 1px, rgba(250, 244, 240, .055) 1px, transparent 0);
  background-size: 100% 100%, 26px 26px;
}

.page {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 3vw, 32px);
}

/* ---- brand lockup ---------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: none;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -.014em;
  color: var(--text);
}

/* ---- hero ------------------------------------------------------------ */

.eyebrow {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--accent-soft);
}

.headline {
  margin: 0;
  font-family: var(--font-display);
  /* 800 with tight tracking — the brand's display weight, set large enough that the
     counters carry the page rather than a graphic doing it for them. */
  font-weight: 800;
  font-size: clamp(2.2rem, 6.4vw, 3.55rem);
  line-height: 1.02;
  letter-spacing: -.035em;
  text-wrap: balance;
}

.headline em {
  font-style: normal;
  color: var(--accent);
}

.lede {
  margin: 16px 0 0;
  max-width: 47ch;
  font-size: clamp(1rem, 1.55vw, 1.09rem);
  color: var(--text-muted);
  text-wrap: pretty;
}

/* Used on the app.chainsolve.co.uk variant only — the one place a visitor arrived wanting
   something specific, so it gets a real destination rather than a dead end. */
.cta {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 24px;
  padding: 11px 19px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .03em;
  text-decoration: none;
  transition: background-color 200ms var(--ease-standard), color 200ms var(--ease-standard);
}

.cta:hover,
.cta:focus-visible {
  background: var(--accent);
  color: #14110F;
}

.cta svg {
  width: 13px;
  height: 13px;
  flex: none;
}

/* ---- the solve (signature) ------------------------------------------- */

.solver {
  margin: 0;
  padding: clamp(14px, 2vw, 20px) clamp(12px, 2vw, 20px) clamp(10px, 1.4vw, 14px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(28, 24, 21, .92), rgba(20, 17, 15, .72));
}

/* Two layouts of the same solve, swapped at 560px. The wide DAG shrinks below roughly that
   width until the node values stop being readable — so narrow screens get a genuinely
   re-laid-out vertical version rather than a scaled-down one. Both reuse the tier classes
   verbatim, so there is exactly one animation timeline to maintain. */
.graph {
  width: 100%;
  height: auto;
  overflow: visible;
}

.graph--wide { display: block; }
.graph--tall { display: none; }

.n-box {
  fill: var(--surface);
  stroke: var(--border-strong);
  stroke-width: 1;
}

.n-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  fill: var(--text-subtle);
  letter-spacing: .04em;
}

.n-value,
.n-pending {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
}

.n-value { fill: var(--text); }
.n-pending { fill: #574E48; }

.edge {
  fill: none;
  stroke: var(--border-strong);
  stroke-width: 1.5;
}

.spark {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-dasharray: 12 240;
  opacity: 0;
}

/* The answer. Everything above is quiet so this one node can be loud. */
.n-out .n-box {
  stroke: var(--accent);
  fill: rgba(224, 106, 78, .085);
}
.n-out .n-value { fill: var(--accent); }
.n-out .n-label { fill: var(--accent-soft); }

.n-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1;
  opacity: 0;
}

/* ---- animation ------------------------------------------------------- */
/* One 10s timeline. Percentages are the schedule:
   0–13% build   ·  13–53% solve, tier by tier  ·  53–86% hold  ·  86–100% clear. */

@keyframes node-in {
  0%        { opacity: 0; transform: translateY(6px); }
  6%, 86%   { opacity: 1; transform: translateY(0); }
  96%, 100% { opacity: 1; transform: translateY(0); }
}

@keyframes edge-draw {
  0%        { stroke-dashoffset: 100; }
  100%      { stroke-dashoffset: 0; }
}

/* Inputs are known before the solve starts — they resolve first, together. */
@keyframes v-in-1 {
  0%, 10%   { opacity: 0; }
  14%, 86%  { opacity: 1; }
  93%, 100% { opacity: 0; }
}
@keyframes p-out-1 {
  0%, 10%   { opacity: 1; }
  14%, 86%  { opacity: 0; }
  93%, 100% { opacity: 1; }
}

@keyframes v-in-2 {
  0%, 25%   { opacity: 0; }
  29%, 86%  { opacity: 1; }
  93%, 100% { opacity: 0; }
}
@keyframes p-out-2 {
  0%, 25%   { opacity: 1; }
  29%, 86%  { opacity: 0; }
  93%, 100% { opacity: 1; }
}

@keyframes v-in-3 {
  0%, 39%   { opacity: 0; }
  43%, 86%  { opacity: 1; }
  93%, 100% { opacity: 0; }
}
@keyframes p-out-3 {
  0%, 39%   { opacity: 1; }
  43%, 86%  { opacity: 0; }
  93%, 100% { opacity: 1; }
}

@keyframes v-in-4 {
  0%, 51%   { opacity: 0; }
  55%, 86%  { opacity: 1; }
  93%, 100% { opacity: 0; }
}
@keyframes p-out-4 {
  0%, 51%   { opacity: 1; }
  55%, 86%  { opacity: 0; }
  93%, 100% { opacity: 1; }
}

/* The pulse: a 12-unit dash walking a pathLength-normalised edge. */
@keyframes spark-2 {
  0%, 16%   { stroke-dashoffset: 12; opacity: 0; }
  18%       { opacity: 1; }
  27%       { opacity: 1; }
  29%, 100% { stroke-dashoffset: -100; opacity: 0; }
}
@keyframes spark-3 {
  0%, 30%   { stroke-dashoffset: 12; opacity: 0; }
  32%       { opacity: 1; }
  41%       { opacity: 1; }
  43%, 100% { stroke-dashoffset: -100; opacity: 0; }
}
@keyframes spark-4 {
  0%, 44%   { stroke-dashoffset: 12; opacity: 0; }
  46%       { opacity: 1; }
  53%       { opacity: 1; }
  55%, 100% { stroke-dashoffset: -100; opacity: 0; }
}

@keyframes ring-settle {
  0%, 55%   { opacity: 0; transform: scale(.985); }
  62%       { opacity: .55; transform: scale(1); }
  78%       { opacity: .12; transform: scale(1.012); }
  86%, 100% { opacity: 0; transform: scale(1.012); }
}

.node {
  opacity: 0;
  animation: node-in var(--loop) var(--ease-standard) infinite;
}
.node--t1 { animation-delay: 0s; }
.node--t2 { animation-delay: .28s; }
.node--t3 { animation-delay: .56s; }
.node--t4 { animation-delay: .84s; }

.edge {
  stroke-dasharray: 100;
  animation: edge-draw 1.05s var(--ease-standard) both;
}
.edge--t2 { animation-delay: .5s; }
.edge--t3 { animation-delay: 1.1s; }
.edge--t4 { animation-delay: 1.7s; }

.spark--t2 { animation: spark-2 var(--loop) linear infinite; }
.spark--t3 { animation: spark-3 var(--loop) linear infinite; }
.spark--t4 { animation: spark-4 var(--loop) linear infinite; }

.n-t1 .n-value { opacity: 0; animation: v-in-1 var(--loop) var(--ease-standard) infinite; }
.n-t1 .n-pending { animation: p-out-1 var(--loop) var(--ease-standard) infinite; }
.n-t2 .n-value { opacity: 0; animation: v-in-2 var(--loop) var(--ease-standard) infinite; }
.n-t2 .n-pending { animation: p-out-2 var(--loop) var(--ease-standard) infinite; }
.n-t3 .n-value { opacity: 0; animation: v-in-3 var(--loop) var(--ease-standard) infinite; }
.n-t3 .n-pending { animation: p-out-3 var(--loop) var(--ease-standard) infinite; }
.n-t4 .n-value { opacity: 0; animation: v-in-4 var(--loop) var(--ease-standard) infinite; }
.n-t4 .n-pending { animation: p-out-4 var(--loop) var(--ease-standard) infinite; }

.n-ring {
  transform-box: fill-box;
  transform-origin: center;
  animation: ring-settle var(--loop) var(--ease-standard) infinite;
}

/* ---- status + footer ------------------------------------------------- */

.status {
  margin: 10px 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .05em;
  color: var(--text-subtle);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-subtle);
}

.foot a {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
  transition: color 200ms var(--ease-standard), border-color 200ms var(--ease-standard);
}

.foot a:hover,
.foot a:focus-visible {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- narrow ---------------------------------------------------------- */

@media (max-width: 560px) {
  body { align-items: flex-start; }
  .solver { padding-left: 10px; padding-right: 10px; }
  .graph--wide { display: none; }
  .graph--tall { display: block; }
  /* The tall viewBox is 320 units wide against ~350px of screen, so these land at close to
     their nominal pixel size rather than the ~6px the wide graph collapsed to. */
  .n-label { font-size: 11px; }
  .n-value,
  .n-pending { font-size: 14px; }
}

/* ---- reduced motion -------------------------------------------------- */
/* Not "less motion" — no motion. The graph is shown in its solved end state, which is
   the only frame that carries the meaning anyway. */

@media (prefers-reduced-motion: reduce) {
  .node,
  .edge,
  .spark,
  .n-ring,
  .n-value,
  .n-pending,
  .foot a {
    animation: none !important;
    transition: none !important;
  }
  .node { opacity: 1; }
  .edge { stroke-dashoffset: 0; }
  .n-value { opacity: 1; }
  .n-pending { opacity: 0; }
  .spark { opacity: 0; }
  .n-ring { opacity: .45; }
}
