/* Wafer Map Manager — one stylesheet, no build step (root ADR 0405). */

:root {
  --paper: #f5f4ef;
  --paper-raised: #fbfaf7;
  --paper-sunk: #ebe9e2;
  --ink: #101114;
  --ink-body: #2a2c31;
  --ink-2: #4a4d55;
  --ink-3: #74777f;
  --line: rgba(16, 17, 20, 0.1);
  --line-strong: rgba(16, 17, 20, 0.22);
  --accent: #d4442a;
  --amber: #c98a1c;

  --die-pass: #d3d0c6;
  --die-pass-2: #a9b7cf;
  --die-fail: var(--accent);
  --die-param: var(--amber);

  --cta-bg: #0b0c10;
  --cta-fg: #f2f3f7;
  --cta-fg-2: #a9aebc;

  --serif: 'Instrument Serif', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --gutter: 16px;
  --header-h: 60px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d0e11;
    --paper-raised: #14161a;
    --paper-sunk: #08090b;
    --ink: #eeeff1;
    --ink-body: #cdd0d6;
    --ink-2: #a8acb5;
    --ink-3: #80848e;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.2);
    --accent: #f0603f;
    --amber: #e3a43a;

    --die-pass: #2b2e35;
    --die-pass-2: #34466a;

    --cta-bg: #15171c;
  }
}

@media (min-width: 768px) { :root { --gutter: 32px; } }
@media (min-width: 1200px) { :root { --gutter: 48px; } }

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 24px);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-body);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.68;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }

a { color: inherit; }

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

h1, h2, h3 { color: var(--ink); margin: 0; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.1em 0.38em;
  border-radius: 5px;
  background: var(--paper-sunk);
  border: 1px solid var(--line);
}

.wrap {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.875rem;
  text-decoration: none;
}
.skip:focus { top: 12px; }

.eyebrow, .label {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0;
}

/* ---------- Reading progress ---------- */

.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 60;
  pointer-events: none;
}
.progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(var(--read, 0));
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s var(--ease);
}
.site-header.is-scrolled { border-bottom-color: var(--line); }

.header-row {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.mark { width: 24px; height: 24px; flex: none; }
.mark-fail { fill: var(--accent); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.25s var(--ease);
}
.btn svg { width: 16px; height: 16px; transition: transform 0.3s var(--ease); }
.btn:hover svg { transform: translate(2px, -2px); }
.btn:active { transform: scale(0.98); }

.btn-quiet {
  height: 38px;
  padding: 0 14px 0 16px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-size: 0.875rem;
}
.btn-quiet:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.btn-light { background: var(--cta-fg); color: var(--cta-bg); }
.btn-light:hover { background: #fff; }

.btn-ghost { color: var(--cta-fg); border: 1px solid rgba(255, 255, 255, 0.22); }
.btn-ghost:hover { border-color: rgba(255, 255, 255, 0.5); }

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

.hero {
  display: grid;
  gap: 40px;
  padding-top: 40px;
  padding-bottom: 72px;
  align-items: center;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3rem, 12.5vw, 6.75rem);
  line-height: 0.94;
  letter-spacing: -0.025em;
  margin-top: 20px;
  text-wrap: balance;
}
.hero h1 em { font-style: italic; color: var(--ink-2); }

.lede {
  margin: 28px 0 0;
  max-width: 34rem;
  font-size: clamp(1.125rem, 1.6vw, 1.3125rem);
  line-height: 1.55;
  color: var(--ink-2);
  text-wrap: pretty;
}

.byline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 32px 0 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}
.byline a { color: var(--ink); text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.byline a:hover { text-decoration-color: var(--accent); }

.hero-figure { margin: 0; justify-self: center; width: 100%; max-width: 520px; }

.wafer {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  color: var(--ink);
}
.wafer svg { display: block; width: 100%; height: 100%; overflow: visible; }

.wafer .disc { fill: var(--paper-raised); stroke: var(--line-strong); stroke-width: 1; }
.wafer .reticle { stroke: var(--line); stroke-width: 1; fill: none; }
.wafer .die { transition: opacity 0.45s var(--ease); }
.wafer.is-sweeping .die { opacity: 0; }
.wafer.is-sweeping .die.on { opacity: 1; }
.wafer .b1 { fill: var(--die-pass); }
.wafer .b2 { fill: var(--die-pass-2); }
.wafer .b5 { fill: var(--die-fail); }
.wafer .b7 { fill: var(--die-param); }
.wafer .probe { fill: none; stroke: var(--ink); stroke-width: 1.5; transition: opacity 0.6s var(--ease); }
.wafer .cursor { fill: none; stroke: var(--ink); stroke-width: 2; pointer-events: none; opacity: 0; transition: opacity 0.15s; }
.wafer .cursor.on { opacity: 1; }
.wafer .tick { font-family: var(--mono); font-size: 11px; fill: var(--ink-3); }

.hero-figure figcaption {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.readout {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.legend > span { display: inline-flex; align-items: center; gap: 7px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw-pass { background: var(--die-pass); }
.sw-pass2 { background: var(--die-pass-2); }
.sw-fail { background: var(--die-fail); }
.sw-param { background: var(--die-param); }

/* Load-in: text rises once; nothing is hidden when scripts or motion are off. */
@media (prefers-reduced-motion: no-preference) {
  .hero-copy > * { animation: rise 0.9s var(--ease) both; }
  .hero-copy > :nth-child(2) { animation-delay: 0.06s; }
  .hero-copy > :nth-child(3) { animation-delay: 0.14s; }
  .hero-copy > :nth-child(4) { animation-delay: 0.22s; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 960px) {
  .hero {
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    gap: 64px;
    padding-top: 88px;
    padding-bottom: 120px;
    min-height: calc(100svh - var(--header-h));
  }
  .hero-figure { justify-self: end; }
}

/* ---------- Article layout ---------- */

.layout {
  display: grid;
  gap: 32px;
  padding-top: 8px;
  padding-bottom: 120px;
  border-top: 1px solid var(--line);
}

.toc { padding-top: 24px; }
.toc-details summary {
  list-style: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.toc-details summary::-webkit-details-marker { display: none; }
.toc-details summary::after { content: '+'; font-size: 1rem; line-height: 1; transition: transform 0.3s var(--ease); }
.toc-details[open] summary::after { transform: rotate(45deg); }

.toc ol { list-style: none; margin: 0; padding: 12px 0 0; }
.toc li a {
  display: flex;
  gap: 14px;
  padding: 7px 0;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--ink-3);
  text-decoration: none;
  transition: color 0.2s;
}
.toc li a span {
  font-family: var(--mono);
  font-size: 0.6875rem;
  padding-top: 0.2em;
  color: var(--ink-3);
  opacity: 0.7;
}
.toc li a:hover, .toc li a.is-active { color: var(--ink); }
.toc li a.is-active span { color: var(--accent); opacity: 1; }

.article { min-width: 0; max-width: 680px; padding-top: 32px; }

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: 220px minmax(0, 680px);
    gap: 96px;
    padding-top: 0;
  }
  .toc { padding-top: 72px; }
  .toc-details { position: sticky; top: calc(var(--header-h) + 40px); }
  .toc-details summary { pointer-events: none; }
  .toc-details summary::after { content: none; }
  .article { padding-top: 72px; }
}

@media (min-width: 1280px) {
  .layout { grid-template-columns: 240px minmax(0, 700px); gap: 128px; }
  .article { max-width: 700px; }
}

/* ---------- Article content ---------- */

.article p { margin: 0 0 1.15em; text-wrap: pretty; }
.article strong { color: var(--ink); font-weight: 600; }
.article a:not(.arrow-link) {
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s;
}
.article a:not(.arrow-link):hover { text-decoration-color: var(--accent); }

.summary {
  padding: 24px 24px 8px;
  border-radius: 14px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
}
.summary ul { margin: 14px 0 0; padding: 0; list-style: none; }
.summary li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 14px;
  color: var(--ink);
  line-height: 1.55;
}
.summary li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--die-pass);
}
.summary li:nth-child(3)::before { background: var(--accent); }

.chapter { margin-top: 104px; }

.chapter-head {
  display: grid;
  gap: 14px;
  margin-bottom: 28px;
}
.chapter-head .num {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 14px;
}
.chapter-head .num::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.chapter h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.25rem, 5vw, 3.25rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.chapter h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}
.chapter > h3 { margin: 40px 0 12px; }

.terms { margin: 32px 0; display: grid; border-top: 1px solid var(--line); }
.terms > div {
  display: grid;
  gap: 4px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.terms dt { font-weight: 600; color: var(--ink); font-size: 0.9375rem; }
.terms dd { margin: 0; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.55; }
@media (min-width: 640px) {
  .terms > div { grid-template-columns: 168px 1fr; gap: 24px; }
}

.points { margin: 24px 0 32px; padding: 0; list-style: none; }
.points li {
  position: relative;
  padding-left: 28px;
  margin-bottom: 16px;
}
.points li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 12px;
  height: 1px;
  background: var(--ink-3);
}

/* Life-cycle steps */
.flow {
  list-style: none;
  margin: 36px 0 0;
  padding: 0;
  counter-reset: step;
  display: grid;
}
.flow li {
  counter-increment: step;
  position: relative;
  display: grid;
  grid-template-columns: 40px 1fr;
  column-gap: 16px;
  padding-bottom: 28px;
}
.flow li::before {
  content: counter(step, decimal-leading-zero);
  grid-row: 1 / span 2;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink);
  position: relative;
  z-index: 1;
}
.flow li::after {
  content: '';
  position: absolute;
  left: 20px;
  top: 40px;
  bottom: 0;
  width: 1px;
  background: var(--line-strong);
}
.flow li:last-child::after { content: none; }
.flow li:last-child { padding-bottom: 0; }
.flow h3 { margin: 9px 0 6px; }
.flow p { margin: 0; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.6; }
.flow li:first-child::before { border-color: var(--accent); color: var(--accent); }

/* Tables */
.table-scroll {
  margin: 32px 0;
  overflow-x: auto;
  border-top: 1px solid var(--line-strong);
  -webkit-overflow-scrolling: touch;
}
.table-scroll:focus-visible { outline-offset: 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; line-height: 1.5; }
caption {
  caption-side: bottom;
  text-align: left;
  padding-top: 12px;
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}
thead th {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: left;
  padding: 12px 16px 12px 0;
  white-space: nowrap;
}
tbody th, tbody td {
  text-align: left;
  vertical-align: top;
  padding: 14px 16px 14px 0;
  border-top: 1px solid var(--line);
}
tbody th { font-weight: 600; color: var(--ink); white-space: nowrap; }
tbody td { color: var(--ink-2); }
tbody td:nth-child(2), tbody td:nth-child(3) { white-space: nowrap; }
table:not(.compact) tbody td:last-child { min-width: 240px; }
table.compact { max-width: 480px; }
table.compact tbody td:last-child { white-space: normal; }
td.mono { font-family: var(--mono); color: var(--ink); }

/* MapX callouts */
.callout {
  margin: 40px 0 8px;
  padding: 22px 24px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background:
    linear-gradient(var(--paper-raised), var(--paper-raised)) padding-box,
    linear-gradient(120deg, #2bd9d2, #4e8dff 40%, #7c5cff 70%, #e5679e) border-box;
  border-color: transparent;
}
.callout .label { color: var(--ink); }
.callout p:not(.label) { margin: 10px 0 14px; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.6; }
.arrow-link {
  display: inline-flex;
  gap: 8px;
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--ink);
  text-decoration: none;
}
.arrow-link span { transition: transform 0.3s var(--ease); }
.arrow-link:hover span { transform: translateX(4px); }

/* Coordinates figure */
.figure { margin: 40px 0; }
.figure svg { display: block; width: 100%; height: auto; }
.figure figcaption { margin-top: 14px; font-size: 0.875rem; color: var(--ink-3); line-height: 1.55; }
.fig-cell { fill: var(--paper-sunk); }
.fig-origin { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.fig-hit { fill: var(--accent); }
.fig-hit-text { font-family: var(--mono); font-size: 10px; fill: #fff; text-anchor: middle; }
.fig-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; fill: var(--ink-3); }
.fig-axis { stroke: var(--ink-3); stroke-width: 1; fill: none; }
.fig-arrow { fill: var(--ink-3); }
.fig-axis-text { font-family: var(--mono); font-size: 11px; fill: var(--ink-3); }

/* Failure modes */
.failures { list-style: none; margin: 0; padding: 0; counter-reset: fail; border-top: 1px solid var(--line); }
.failures li {
  counter-increment: fail;
  display: grid;
  grid-template-columns: 44px 1fr;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}
.failures li::before {
  content: counter(fail, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  padding-top: 0.25em;
  grid-row: 1 / span 2;
}
.failures h3 { margin-bottom: 4px; }
.failures p { margin: 0; color: var(--ink-2); font-size: 0.9375rem; line-height: 1.6; }

/* Checklist */
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.checks li {
  position: relative;
  padding: 16px 18px 16px 50px;
  border-radius: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.checks li::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 18px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
}
.checks li::after {
  content: '';
  position: absolute;
  left: 24px;
  top: 21.5px;
  width: 6px;
  height: 10px;
  border: solid var(--paper);
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg);
}

/* FAQ */
.faq { border-top: 1px solid var(--line); }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 20px 0;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary h3 { font-size: 1.0625rem; }
.faq summary::after {
  content: '+';
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
  color: var(--ink);
  transition: transform 0.35s var(--ease), background-color 0.2s;
}
.faq details[open] summary::after { transform: rotate(45deg); }
.faq summary:hover::after { background: var(--paper-sunk); }
.faq details p { margin: -4px 0 22px; padding-right: 52px; color: var(--ink-2); }

/* ---------- Closing call to action ---------- */

.cta {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: var(--cta-bg);
  color: var(--cta-fg-2);
  padding: 104px 0 112px;
}
.cta::before {
  content: '';
  position: absolute;
  inset: -40% -10% auto auto;
  width: 900px;
  height: 900px;
  z-index: -1;
  background:
    radial-gradient(closest-side at 40% 45%, rgba(43, 217, 210, 0.2), transparent 70%),
    radial-gradient(closest-side at 62% 58%, rgba(124, 92, 255, 0.24), transparent 70%),
    radial-gradient(closest-side at 72% 30%, rgba(229, 103, 158, 0.14), transparent 70%);
  filter: blur(10px);
}
.cta .eyebrow { color: var(--cta-fg-2); }
.cta h2 {
  margin-top: 20px;
  max-width: 14ch;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.75rem, 8vw, 5.5rem);
  line-height: 0.98;
  letter-spacing: -0.025em;
  color: var(--cta-fg);
}
.cta h2 em { color: var(--cta-fg-2); }
.cta-inner > p:not(.eyebrow) { max-width: 36rem; margin: 28px 0 0; font-size: 1.0625rem; line-height: 1.65; }
.cta-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 36px; }

/* ---------- Footer ---------- */

.site-footer { border-top: 1px solid var(--line); padding: 40px 0 48px; font-size: 0.875rem; color: var(--ink-3); }
.footer-row { display: grid; gap: 8px; }
.footer-row p { margin: 0; }
.footer-row a { color: var(--ink); text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.footer-row .fine { font-family: var(--mono); font-size: 0.6875rem; letter-spacing: 0.04em; margin-top: 12px; }
@media (min-width: 900px) {
  .footer-row { grid-template-columns: 1fr auto; align-items: baseline; column-gap: 48px; }
  .footer-row .fine { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- 404 ---------- */

.not-found { min-height: 100svh; display: grid; align-content: center; gap: 24px; }
.not-found h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(2.75rem, 9vw, 5.5rem); line-height: 1; letter-spacing: -0.02em; }
.not-found p { margin: 0; }
