/* Home page only. The picture carries the meaning; text is a label per stage. */
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("fonts/manrope-latin-wght-normal.woff2") format("woff2");
}

:root {
  --ink: #17243b;
  --soft: #4a5870;
  --muted: #7d8698;
  --cobalt: #4267ee;
  --teal: #2f8f83;
  --amber: #f2a33a;
  --warm: #f8f7f3;
  --line: #e3e0d8;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --pad: clamp(16px, 4vw, 40px);
  --header-h: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--warm);
  color: var(--ink);
  font-family: "Manrope", system-ui, sans-serif;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
a { color: var(--cobalt); -webkit-tap-highlight-color: transparent; }
a:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 3px; border-radius: 6px; }
h1, h2, p { margin: 0; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--pad); }

.skip {
  position: absolute;
  left: 16px;
  top: -80px;
  z-index: 6;
  min-height: 44px;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--warm);
  font-weight: 700;
  text-decoration: none;
  border-radius: 8px;
}
.skip:focus { top: 8px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Translucent bar: the page scrolls under it */
.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  height: var(--header-h);
  background: rgba(248, 247, 243, 0.82);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  box-shadow: 0 1px 0 rgba(23, 36, 59, 0.07);
}
.bar { display: flex; align-items: center; justify-content: space-between; height: 100%; }
.brand { display: flex; align-items: center; min-height: 44px; }
.brand img { width: 116px; height: auto; display: block; }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}
.nav a:hover { background: rgba(66, 103, 238, 0.08); }

.hero { padding: clamp(28px, 6svh, 80px) 0 0; text-align: center; }
.hero h1 {
  max-width: 15em;
  margin: 0 auto;
  font-size: clamp(2rem, 1.25rem + 3.2vw, 3.8rem);
  font-weight: 800;
  line-height: 1.03;
  letter-spacing: -0.038em;
  text-wrap: balance;
}
.hero .sub {
  max-width: 30em;
  margin: 14px auto 0;
  color: var(--soft);
  font-size: clamp(1.06rem, 0.98rem + 0.45vw, 1.38rem);
  font-weight: 550;
  line-height: 1.35;
  letter-spacing: -0.014em;
  text-wrap: balance;
}

/* The story: one sticky stage, scrubbed by scroll */
#construction-story { margin-top: clamp(8px, 2svh, 24px); }
#construction-story.is-scroll-linked::after { content: ""; display: block; height: 420svh; }
.construction-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--warm);
}
#construction-story.is-scroll-linked .construction-stage {
  position: sticky;
  top: var(--header-h);
  z-index: 1;
  height: calc(88svh - var(--header-h));
}
.stage-text { padding: 6px var(--pad) 0; text-align: center; }
#construction-feature {
  font-size: clamp(1.4rem, 1.05rem + 1.4vw, 2.2rem);
  font-weight: 780;
  line-height: 1.15;
  letter-spacing: -0.032em;
}
#construction-caption {
  margin-top: 4px;
  color: var(--soft);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0;
  text-wrap: balance;
}
/* Keep the line's height so the picture never jumps between stages */
#construction-caption[hidden] { display: block; visibility: hidden; }
#construction-caption:empty::before { content: "\00a0"; }

#construction-viewport { position: relative; flex: 1 1 auto; min-height: 0; }
/* Without scroll-linking, the complete picture fits the first screen */
#construction-story:not(.is-scroll-linked) #construction-viewport { flex: none; height: clamp(240px, calc(100svh - 400px), 640px); }
#construction-viewport:not(:has(canvas)), #construction-viewport[hidden] { display: none; }
#construction-viewport canvas { display: block; width: 100%; height: 100%; }
#construction-poster { display: block; margin: 8px auto 0; max-height: 70svh; width: auto; }
#construction-poster[hidden] { display: none; }
#construction-annotations { position: absolute; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.construction-stems { position: absolute; inset: 0; width: 100%; height: 100%; }
.construction-stems line { stroke: var(--ink); stroke-opacity: 0.45; stroke-width: 1.5; shape-rendering: crispEdges; }
.construction-stems circle { fill: var(--ink); fill-opacity: 0.7; }

/* One chip per part. State is colour + icon, never a sentence. */
.construction-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px 0 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px #c3c9d3;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}
#construction-annotations .construction-chip { position: absolute; }
.construction-chip[hidden] { display: none; }
.chip-icon { display: inline-flex; align-items: center; }
.chip-icon:empty { display: none; }
.chip-icon svg { width: 12px; height: 12px; display: block; }
.chip-icon b { font-family: var(--mono); font-size: 11px; font-weight: 700; color: #9cc7a5; letter-spacing: -0.04em; }
.construction-chip[data-state="ready"] { background: #fff; color: var(--cobalt); box-shadow: inset 0 0 0 1.5px var(--cobalt); }
.construction-chip[data-state="running"] { background: var(--ink); color: #fff; box-shadow: none; }
.construction-chip[data-state="checked"] { background: var(--teal); color: #fff; box-shadow: none; }
.construction-chip[data-state="reused"] { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1px #d6d2c8; }
.construction-chip[data-state="redo"] { background: var(--amber); color: var(--ink); box-shadow: none; }

.stage-key { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 8px var(--pad) 12px; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0; padding: 0; list-style: none; }

/* The real call, then the way in */
.usage { padding: clamp(48px, 10svh, 112px) 0 clamp(40px, 8svh, 88px); }
.usage .wrap { max-width: 1000px; }
.usage-tag {
  display: inline-block;
  margin-bottom: 14px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(66, 103, 238, 0.1);
  color: var(--cobalt);
  font-size: 13px;
  font-weight: 750;
}
.usage-code {
  margin: 0 0 24px;
  padding: 20px 22px;
  overflow-x: auto;
  border-radius: 16px;
  background: var(--ink);
  color: #e6ebf5;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.75;
  letter-spacing: 0;
  -webkit-overflow-scrolling: touch;
}
.usage-code code { font: inherit; white-space: pre; }
.usage-code i { color: #9cc7a5; font-style: normal; }
/* Phones: long lines wrap under a hanging indent and each result sits on
   its own line under its call, so nothing is cut off at the edge */
@media (max-width: 719px) {
  .usage-code { overflow-x: visible; font-size: 12px; padding: 16px 16px 16px 18px; }
  .usage-code code { white-space: pre-wrap; overflow-wrap: anywhere; }
  .usage-code .l { display: block; padding-left: 4ch; text-indent: -4ch; }
  .usage-code i { display: block; text-indent: 0; }
}
.button {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 24px;
  border-radius: 999px;
  background: var(--cobalt);
  color: #fff;
  font-size: 16px;
  font-weight: 750;
  text-decoration: none;
  transition: transform 100ms ease-out, background-color 150ms ease;
}
.button:hover { background: #3556d4; }
.button:active { transform: scale(0.97); }

.close { padding: 24px 0 40px; border-top: 1px solid var(--line); }
.close p { color: var(--soft); font-size: 14px; font-weight: 600; text-align: center; }

@media (min-width: 720px) {
  :root { --header-h: 64px; }
  .brand img { width: 128px; }
  .stage-key { flex-direction: row; justify-content: center; gap: 18px; }
}
@media (max-width: 719px) {
  #construction-caption { font-size: 13px; }
  .legend { gap: 4px; }
  .legend .construction-chip { height: 22px; gap: 4px; padding: 0 7px 0 6px; font-size: 11.5px; }
}
@media (max-width: 380px) {
  .construction-chip { height: 22px; padding: 0 8px 0 6px; font-size: 12px; }
  #construction-caption { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
  .button:active { transform: none; }
}
