/* Ratchet — one stylesheet, no framework, no build step. */

:root {
  color-scheme: light dark;

  --bg:        #ffffff;
  --bg-sunk:   #f6f7f9;
  --bg-raised: #ffffff;
  --border:    #e3e6ea;
  --border-strong: #c9ced6;
  --text:      #14171c;
  --text-dim:  #5b626d;
  --text-faint:#868d99;
  --accent:    #1c5cff;
  --accent-ink:#ffffff;
  --ok:        #0f7b4f;
  --warn:      #8a5a00;
  --stop:      #b0341f;
  --unknown:   #6b4bb8;

  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --measure: 68ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e1014;
    --bg-sunk:   #14171d;
    --bg-raised: #171b22;
    --border:    #262c36;
    --border-strong: #3a4250;
    --text:      #e8ebf0;
    --text-dim:  #a2abb9;
    --text-faint:#6f7885;
    --accent:    #6f9bff;
    --accent-ink:#0e1014;
    --ok:        #4ec98b;
    --warn:      #e0a83a;
    --stop:      #ff8b74;
    --unknown:   #b39dff;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

code, pre, .mono { font-family: var(--mono); }
code { font-size: 0.9em; }

.skip {
  position: absolute; left: -9999px;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.6rem 1rem; border-radius: var(--radius); z-index: 100;
}
.skip:focus { left: 1rem; top: 1rem; }

/* ------------------------------------------------------------------ layout */
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 1.25rem; }
.narrow { max-width: 780px; }

header.site {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
header.site .wrap {
  display: flex; align-items: center; gap: 1.5rem;
  height: 58px;
}
.brand {
  font-weight: 650; letter-spacing: -0.02em; font-size: 1.05rem;
  color: var(--text); display: inline-flex; align-items: center; gap: 0.55rem;
}
.brand:hover { text-decoration: none; }
.brand svg { display: block; }
nav.site { margin-left: auto; display: flex; gap: 1.35rem; align-items: center; }
nav.site a { color: var(--text-dim); font-size: 0.92rem; }
nav.site a:hover, nav.site a[aria-current="page"] { color: var(--text); text-decoration: none; }

@media (max-width: 640px) {
  header.site .wrap { height: auto; padding-top: 0.7rem; padding-bottom: 0.7rem; flex-wrap: wrap; gap: 0.75rem; }
  nav.site { margin-left: 0; width: 100%; gap: 1rem; overflow-x: auto; }
}

main { display: block; }
section { padding: 4.5rem 0; }
section + section { border-top: 1px solid var(--border); }
@media (max-width: 640px) { section { padding: 3rem 0; } }

footer.site {
  border-top: 1px solid var(--border);
  padding: 2.5rem 0 3.5rem;
  color: var(--text-faint); font-size: 0.88rem;
}
footer.site .cols { display: flex; flex-wrap: wrap; gap: 2.5rem; }
footer.site h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
                 color: var(--text-faint); margin: 0 0 0.6rem; }
footer.site ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }

/* --------------------------------------------------------------- typography */
h1, h2, h3 { letter-spacing: -0.022em; line-height: 1.2; margin: 0 0 0.6rem; }
h1 { font-size: clamp(2rem, 5.5vw, 3.1rem); font-weight: 660; }
h2 { font-size: clamp(1.4rem, 3.2vw, 1.85rem); font-weight: 640; }
h3 { font-size: 1.05rem; font-weight: 620; }
p  { margin: 0 0 1rem; max-width: var(--measure); }
.lede { font-size: clamp(1.05rem, 2.2vw, 1.22rem); color: var(--text-dim); max-width: 60ch; }
.eyebrow {
  font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--text-faint); font-weight: 600; margin-bottom: 0.9rem;
}
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 0.88rem; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.62rem 1.15rem; border-radius: var(--radius);
  border: 1px solid transparent; font: inherit; font-weight: 550; font-size: 0.94rem;
  cursor: pointer; background: var(--accent); color: var(--accent-ink);
  transition: opacity 0.12s ease;
}
.btn:hover { opacity: 0.88; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn.small { padding: 0.38rem 0.75rem; font-size: 0.85rem; }
.btn.danger { background: transparent; color: var(--stop); border-color: var(--border-strong); }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.6rem; }

/* -------------------------------------------------------------------- cards */
.card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.35rem;
}
.grid { display: grid; gap: 1rem; }
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

/* --------------------------------------------------------------------- code */
pre {
  background: var(--bg-sunk); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem;
  overflow-x: auto; font-size: 0.845rem; line-height: 1.62;
}
pre code { font-size: inherit; }
.c-key { color: var(--accent); }
.c-str { color: var(--ok); }
.c-com { color: var(--text-faint); font-style: italic; }
.c-hi  { color: var(--stop); font-weight: 600; }

.tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.tab {
  padding: 0.36rem 0.8rem; border-radius: 7px; border: 1px solid transparent;
  background: none; color: var(--text-dim); font: inherit; font-size: 0.86rem; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--bg-sunk); border-color: var(--border); color: var(--text); }

/* ------------------------------------------------------------------- tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.62rem 0.8rem; border-bottom: 1px solid var(--border); }
th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em;
     color: var(--text-faint); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.mono { font-family: var(--mono); font-size: 0.83rem; }

/* -------------------------------------------------------------------- pills */
.pill {
  display: inline-block; padding: 0.13rem 0.55rem; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.01em;
  border: 1px solid currentColor; white-space: nowrap;
}
.pill.go   { color: var(--ok); }
.pill.stop { color: var(--stop); }
.pill.wait { color: var(--warn); }
.pill.unk  { color: var(--unknown); }
.pill.flat { color: var(--text-faint); }

/* -------------------------------------------------------------------- forms */
label { display: block; font-size: 0.86rem; font-weight: 550; margin-bottom: 0.3rem; }
input, select {
  width: 100%; padding: 0.55rem 0.7rem; font: inherit; font-size: 0.94rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px;
}
fieldset { border: none; margin: 0; padding: 0; }
.field { margin-bottom: 0.9rem; }
.hint { font-size: 0.82rem; color: var(--text-faint); margin-top: 0.3rem; }

/* ------------------------------------------------------------------- states */
.notice {
  padding: 0.8rem 1rem; border-radius: 8px; font-size: 0.9rem;
  border: 1px solid var(--border); background: var(--bg-sunk); margin-bottom: 1rem;
}
.notice.bad  { border-color: var(--stop); color: var(--stop); }
.notice.good { border-color: var(--ok);   color: var(--ok); }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-faint); font-size: 0.92rem; }
.loading { color: var(--text-faint); font-size: 0.9rem; padding: 1.25rem 0; }

.secret {
  font-family: var(--mono); font-size: 0.82rem; word-break: break-all;
  background: var(--bg-sunk); border: 1px dashed var(--border-strong);
  border-radius: 8px; padding: 0.7rem 0.85rem; margin: 0.5rem 0;
}

hr.rule { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1.25rem; font-size: 0.9rem; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; font-weight: 550; }

ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.55rem; }
ul.checks { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.5rem; }
ul.checks li { padding-left: 1.5rem; position: relative; font-size: 0.93rem; }
ul.checks li::before {
  content: ""; position: absolute; left: 0.25rem; top: 0.62em;
  width: 0.42rem; height: 0.42rem; border-radius: 50%; background: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}


/* ══════════════════════════════════════════════ scroll-driven hero explainer
   A single agent request travels to the gate and back while the reader
   scrolls, then a retry storm arrives, then a crash, then a rollback. Every
   frame corresponds to something the API actually does — the motion is the
   explanation, not decoration on top of one.

   Scroll-driven so the reader sets the pace and can stop anywhere. Under
   prefers-reduced-motion the whole thing becomes a stacked static diagram. */

.stage { position: relative; height: 620vh; }

.stage-pin {
  position: sticky; top: 58px;
  height: calc(100vh - 58px); min-height: 600px;
  display: grid; place-items: center; overflow: hidden;
  background:
    radial-gradient(1100px 520px at 50% 18%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--bg);
}
/* faint moving grid, purely atmospheric — sits behind everything */
.stage-pin::before {
  content: ""; position: absolute; inset: -2px;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 46px 46px;
  opacity: 0.34;
  mask-image: radial-gradient(circle at 50% 45%, #000 30%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 50% 45%, #000 30%, transparent 78%);
}
.stage-inner {
  width: min(1080px, 94vw);
  /* Must have real height. Every .beat inside is absolutely positioned, so
     without this the box collapses to 0px, and `place-items: center` then
     centres nothing — the content hangs below the midpoint instead of on it. */
  height: 100%;
  position: relative; z-index: 1;
}

.beat {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  /* Sits a touch above true centre: the progress rail occupies the bottom of
     the pin, and optical centre reads slightly high anyway. */
  padding-bottom: 4.5rem;
  opacity: 0; transform: translateY(26px) scale(0.985);
  transition: opacity 0.5s cubic-bezier(.22,.8,.3,1), transform 0.5s cubic-bezier(.22,.8,.3,1);
  pointer-events: none; padding-inline: 1.25rem;
}
.beat[data-active="true"] { opacity: 1; transform: none; pointer-events: auto; }
.beat-body { text-align: center; width: 100%; }

.beat .eyebrow { margin-bottom: 0.6rem; }
.beat h2 {
  font-size: clamp(1.9rem, 5.2vw, 3.4rem);
  line-height: 1.05; margin-bottom: 0.7rem;
}
.beat p {
  color: var(--text-dim); max-width: 58ch; margin-inline: auto;
  font-size: clamp(0.98rem, 1.6vw, 1.12rem);
}

/* ---------------------------------------------------------------- the scene */
.scene { position: relative; margin: 2.1rem auto 0; max-width: 760px; height: 170px; }

.wire {
  position: absolute; top: 50%; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--border-strong) 10%, var(--border-strong) 90%, transparent);
}
/* energy pulse that runs along the wire while a beat is live */
.wire::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 220px 100%; background-repeat: no-repeat;
  opacity: 0; animation: none;
}
.beat[data-active="true"] .wire::after { opacity: 0.85; animation: wire-run 2.6s linear infinite; }
@keyframes wire-run { from { background-position: -240px 0; } to { background-position: 780px 0; } }

.node {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 0.55rem;
  font-size: 0.76rem; color: var(--text-faint); white-space: nowrap; letter-spacing: 0.02em;
}
.node .dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--border-strong);
  transition: box-shadow 0.4s ease, border-color 0.4s ease, transform 0.4s ease;
}
.node span { position: absolute; top: 26px; }
.node.agent  { left: 7%; }
.node.gate   { left: 50%; }
.node.vendor { left: 93%; }
.node.gate .dot { border-color: var(--accent); background: var(--accent); }
/* the gate visibly decides */
.beat[data-active="true"] .node.gate .dot { animation: gate-pulse 2.2s ease-in-out infinite; }
@keyframes gate-pulse {
  0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50%     { box-shadow: 0 0 0 14px color-mix(in srgb, var(--accent) 0%, transparent); }
}

.packet {
  position: absolute; top: 50%; left: 7%;
  transform: translate(-50%, -50%);
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 700;
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 16%, transparent),
              0 8px 24px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: left 0.75s cubic-bezier(.45,.05,.2,1), top 0.5s ease,
              background 0.4s ease, box-shadow 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
}
.packet.at-gate   { left: 50%; }
.packet.at-vendor { left: 93%; }
.packet.blocked {
  background: var(--stop);
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--stop) 18%, transparent),
              0 8px 24px color-mix(in srgb, var(--stop) 26%, transparent);
}
.packet.unknown {
  background: var(--unknown);
  box-shadow: 0 0 0 7px color-mix(in srgb, var(--unknown) 18%, transparent);
  animation: unsure 1.7s ease-in-out infinite;
}
@keyframes unsure {
  0%,100% { transform: translate(-50%,-50%) rotate(-4deg); }
  50%     { transform: translate(-50%,-50%) rotate(4deg); }
}
.packet.ghost { opacity: 0.26; box-shadow: none; }
.packet.tiny  { width: 26px; height: 26px; font-size: 0.66rem; border-radius: 8px; }

/* the retry swarm — stacked callers all bouncing off the gate */
.packet.s1 { top: calc(50% - 46px); transition-delay: 0.05s; }
.packet.s2 { top: calc(50% - 16px); transition-delay: 0.13s; }
.packet.s3 { top: calc(50% + 16px); transition-delay: 0.21s; }
.packet.s4 { top: calc(50% + 46px); transition-delay: 0.29s; }

/* the counter that never moves — the whole point, made visible */
.tally {
  position: absolute; right: -4px; top: 50%; transform: translateY(-50%);
  text-align: right; font-size: 0.72rem; color: var(--text-faint);
}
.tally strong {
  display: block; font-size: clamp(1.8rem, 4vw, 2.6rem); color: var(--ok);
  font-variant-numeric: tabular-nums; line-height: 1;
}
@media (max-width: 720px) { .tally { display: none; } }

/* rollback beat: steps unwinding in reverse */
.unwind { display: grid; gap: 0.5rem; max-width: 430px; margin: 1.75rem auto 0; }
.unwind div {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.9rem; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-raised); font-size: 0.88rem;
  opacity: 0; transform: translateX(-14px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.beat[data-active="true"] .unwind div { opacity: 1; transform: none; }
.beat[data-active="true"] .unwind div:nth-child(1) { transition-delay: 0.25s; }
.beat[data-active="true"] .unwind div:nth-child(2) { transition-delay: 0.45s; }
.beat[data-active="true"] .unwind div:nth-child(3) { transition-delay: 0.65s; }
.unwind em { color: var(--stop); font-style: normal; font-weight: 600; }
.unwind b  { color: var(--ok); font-weight: 600; margin-left: auto; }

.verdict {
  display: inline-flex; align-items: center; gap: 0.55rem;
  margin-top: 1.4rem; padding: 0.55rem 1.15rem;
  border: 1px solid currentColor; border-radius: 999px;
  font-size: 0.92rem; font-weight: 600;
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.45s ease 0.4s, transform 0.45s ease 0.4s;
}
.beat[data-active="true"] .verdict { opacity: 1; transform: none; }
.verdict::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor;
}
.verdict.go   { color: var(--ok); }
.verdict.stop { color: var(--stop); }
.verdict.unk  { color: var(--unknown); }

/* progress rail */
.rail {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 1.6rem;
  display: flex; gap: 0.45rem; z-index: 3;
}
.rail button {
  width: 34px; height: 4px; border: none; border-radius: 2px; padding: 0;
  background: var(--border-strong); cursor: pointer;
  transition: background 0.3s ease, transform 0.3s ease;
}
.rail button[aria-current="true"] { background: var(--accent); transform: scaleY(1.8); }

@media (prefers-reduced-motion: reduce) {
  .stage { height: auto; }
  .stage-pin { position: static; height: auto; display: block; background: none; }
  .stage-pin::before { display: none; }
  .beat {
    position: static; opacity: 1; transform: none; pointer-events: auto;
    padding: 2.75rem 1.25rem; border-top: 1px solid var(--border);
  }
  .beat:first-child { border-top: none; }
  .rail { display: none; }
  .packet, .wire::after, .node.gate .dot { animation: none !important; transition: none; }
  .verdict, .unwind div { opacity: 1; transform: none; transition: none; }
}
@media (max-width: 640px) {
  .stage { height: 520vh; }
  .scene { height: 150px; }
  .node span { font-size: 0.68rem; }
}

/* ── Works-with ─────────────────────────────────────────────────────────── */

.finder { margin-top: 2rem; max-width: 46ch; }
.finder label {
  display: block; font-size: .82rem; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: .5rem;
}
.finder input {
  width: 100%; padding: .8rem 1rem; font: inherit; font-size: 1rem;
  color: var(--text); background: var(--bg-raised);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
.finder input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.path { padding: 3.5rem 0 1rem; }
.path .path-head { max-width: 62ch; }
.path h2 { margin: 0 0 .4rem; }
.path .path-head p { margin: 0; }

.names {
  list-style: none; padding: 0;
  margin: 1.6rem 0 1.8rem;
  display: grid; gap: .5rem;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}
.names li {
  display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap;
  padding: .6rem .8rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.names .n { font-weight: 550; }
.names .tag {
  font-size: .72rem; color: var(--text-faint);
  border: 1px solid var(--border); border-radius: 100px;
  padding: .05rem .5rem; white-space: nowrap;
}
.names .tag.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

.snippet {
  margin: 0; padding: 1rem 1.1rem; overflow-x: auto;
  background: var(--bg-sunk); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono); font-size: .82rem; line-height: 1.65;
}

/* Reveal on scroll. Everything starts visible and is only hidden once the
   observer is known to be running, so a script failure cannot leave the page
   blank — the content is the point, the motion is not. */
@media (prefers-reduced-motion: no-preference) {
  .js-motion .path,
  .js-motion .names li {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .5s cubic-bezier(.22,.61,.36,1),
                transform .5s cubic-bezier(.22,.61,.36,1);
    transition-delay: var(--d, 0ms);
  }
  .js-motion .path.in,
  .js-motion .names li.in { opacity: 1; transform: none; }
}
