/* chip — explainer site.
 * Schematic vernacular: blueprint-navy dark, cool paper light. Two semantic
 * colours run through every diagram: blue for code, amber for the model,
 * grey for an abstention. IBM Plex Sans for text, IBM Plex Mono for code
 * and receipts; both fall back to system faces.
 */

:root {
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --fs-0: 0.8125rem;
  --fs-1: 0.9375rem;
  --fs-2: 1.0625rem;
  --fs-3: 1.25rem;
  --fs-4: 1.5rem;
  --fs-5: 2rem;
  --fs-6: clamp(1.9rem, 1.2rem + 2.8vw, 3.1rem);

  --sp-1: 4px;  --sp-2: 8px;   --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px;  --sp-7: 48px; --sp-8: 72px; --sp-9: 112px;

  --max: 1080px;
  --measure: 66ch;
  --gutter: 16px;
  --radius: 3px;
  --motion: 160ms;

  /* light: cool paper */
  --bg:        #f3f4f1;
  --bg-raise:  #fbfbf9;
  --bg-code:   #e9ebe6;
  --paper:     #fffffb;
  --fg:        #1b2432;
  --fg-muted:  #4b5668;
  --fg-dim:    #7a8494;
  --line:      #cfd4cc;
  --line-soft: #e0e4dd;

  --code:      #1f4fbf;   /* deterministic member */
  --code-soft: #d7e1fa;
  --model:     #a86f12;   /* probabilistic member */
  --model-soft:#f3e3c2;
  --abstain:   #7a8494;
  --disagree:  #b23a3a;

  --syn-k: #1f4fbf;
  --syn-s: #2f6b3a;
  --syn-c: #7a8494;
  --syn-b: #a86f12;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1626;
    --bg-raise:  #141d30;
    --bg-code:   #0b111e;
    --paper:     #18223a;
    --fg:        #e6eaf0;
    --fg-muted:  #aeb7c7;
    --fg-dim:    #7d8799;
    --line:      #2a3650;
    --line-soft: #1f2a40;

    --code:      #8fb1ff;
    --code-soft: #1d2c52;
    --model:     #e2a63b;
    --model-soft:#3d2e12;
    --abstain:   #8a94a6;
    --disagree:  #f07a7a;

    --syn-k: #8fb1ff;
    --syn-s: #9ed4a4;
    --syn-c: #7d8799;
    --syn-b: #e2a63b;
  }
}

:root[data-theme="dark"] {
  --bg:        #0f1626;
  --bg-raise:  #141d30;
  --bg-code:   #0b111e;
  --paper:     #18223a;
  --fg:        #e6eaf0;
  --fg-muted:  #aeb7c7;
  --fg-dim:    #7d8799;
  --line:      #2a3650;
  --line-soft: #1f2a40;
  --code:      #8fb1ff;
  --code-soft: #1d2c52;
  --model:     #e2a63b;
  --model-soft:#3d2e12;
  --abstain:   #8a94a6;
  --disagree:  #f07a7a;
  --syn-k: #8fb1ff;
  --syn-s: #9ed4a4;
  --syn-c: #7d8799;
  --syn-b: #e2a63b;
}

/* ---------- base ---------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--fs-2)/1.6 var(--font-sans);
  overflow-x: hidden;
}

h1, h2, h3 { font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-5); margin-bottom: var(--sp-4); }
h3 { font-size: var(--fs-3); margin: var(--sp-7) 0 var(--sp-3); }
p { margin: 0 0 var(--sp-4); max-width: var(--measure); }
a { color: var(--code); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--model);
  outline-offset: 3px;
}
em { font-style: italic; }
code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-code);
  padding: 0.05em 0.35em;
  border-radius: var(--radius);
}
pre code { background: none; padding: 0; font-size: inherit; }
dl { margin: 0; }
dt { font-weight: 600; }
dd { margin: 0 0 var(--sp-4); color: var(--fg-muted); }
ul, ol { padding-left: 1.25em; }
li { margin-bottom: var(--sp-2); }
svg text { font-family: var(--font-sans); fill: var(--fg); }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }
/* grid items may not force the page wider than the viewport */
.hero-grid > *, .two-col > *, .code-notes > *, .call > *, .vocab dl > * { min-width: 0; }
.skip {
  position: absolute; left: var(--gutter); top: -3em;
  background: var(--paper); padding: var(--sp-2) var(--sp-3); z-index: 10;
}
.skip:focus { top: var(--sp-2); }

/* ---------- header ---------- */

.site { border-bottom: 1px solid var(--line-soft); }
.bar { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-4) var(--gutter); flex-wrap: wrap; }
.logo { text-decoration: none; color: var(--fg); display: inline-flex; align-items: baseline; gap: var(--sp-3); }
.mark { font-weight: 600; font-size: var(--fs-3); }
.mark-sub { font-family: var(--font-mono); font-size: var(--fs-0); color: var(--fg-dim); }
.site nav { display: flex; gap: var(--sp-4); flex-wrap: wrap; font-size: var(--fs-1); }
.site nav a { color: var(--fg-muted); text-decoration: none; }
.site nav a:hover, .site nav a:focus-visible { color: var(--fg); text-decoration: underline; }
.site nav .gh { color: var(--fg); }

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

.hero { padding: var(--sp-8) 0 var(--sp-7); }
.hero-grid { display: grid; gap: var(--sp-6); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .hero-grid { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); align-items: start; gap: var(--sp-8); }
}
h1 { font-size: var(--fs-6); max-width: 22ch; margin-bottom: var(--sp-5); }
.lede { font-size: var(--fs-3); line-height: 1.5; color: var(--fg-muted); max-width: 56ch; }
.lede a { color: var(--fg); }
.install .code { margin-top: 0; white-space: pre-wrap; word-break: break-all; }
.note { font-size: var(--fs-0); color: var(--fg-dim); }

/* ---------- sections ---------- */

.section { padding: var(--sp-8) 0; border-top: 1px solid var(--line-soft); }
.section-lede { font-size: var(--fs-2); color: var(--fg-muted); max-width: 62ch; margin-bottom: var(--sp-6); }
.aside { font-size: var(--fs-1); color: var(--fg-muted); max-width: 62ch; margin-top: var(--sp-6); }
.two-col { display: grid; gap: var(--sp-6); }
@media (min-width: 900px) { .two-col { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-8); } }

.btn {
  display: inline-block; font: 500 var(--fs-1)/1 var(--font-sans);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); cursor: pointer;
  background: var(--fg); color: var(--bg); border: 1px solid var(--fg); text-decoration: none;
}
.btn:hover { opacity: .9; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--line); }

/* ---------- code ---------- */

.code {
  font: 400 var(--fs-0)/1.6 var(--font-mono);
  background: var(--bg-code);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-4) 0 var(--sp-5);
  overflow-x: auto;
  max-width: 100%;
}
.code .prompt { color: var(--fg-dim); user-select: none; }
.code .c, .paper .c { color: var(--syn-c); }
.code .s, .paper .s { color: var(--syn-s); }
.code .kw { color: var(--syn-k); }
.code .dec { color: var(--model); }
.code .b, .paper .b { color: var(--syn-b); }
.paper .k { color: var(--fg-muted); }

/* ---------- ladder ---------- */

.ladder { margin: var(--sp-6) 0 var(--sp-4); }
.rungs {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--sp-2);
  grid-template-columns: 1fr;
  position: relative;
}
.rungs li { margin: 0; position: relative; }
.rung {
  width: 100%; text-align: left;
  font: 500 var(--fs-1)/1.3 var(--font-sans);
  color: var(--fg); background: var(--bg-raise);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4); cursor: pointer;
  transition: border-color var(--motion), background var(--motion);
}
.rung:hover { border-color: var(--fg-dim); }
.rung[aria-pressed="true"] { border-color: var(--fg); background: var(--paper); box-shadow: inset 3px 0 0 var(--fg); }
/* chip rungs carry the governance envelope: mark them */
.rungs li:nth-child(3) .rung, .rungs li:nth-child(4) .rung { border-style: double; border-width: 3px; }

@media (min-width: 760px) {
  .rungs { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--sp-5); padding-top: var(--sp-5); }
  .rungs::before {
    content: ""; position: absolute; left: 2%; right: 2%; top: 0;
    border-top: 1px solid var(--line);
  }
  .rungs::after {
    content: "\2194"; position: absolute; left: 50%; top: -0.72em; transform: translateX(-50%);
    background: var(--bg); padding: 0 var(--sp-2); color: var(--fg-dim); font-size: var(--fs-2);
  }
  .rungs li::before {
    content: ""; position: absolute; left: 50%; top: calc(-1 * var(--sp-5)); height: var(--sp-5);
    border-left: 1px solid var(--line);
  }
  .rung { min-height: 4.6em; text-align: center; }
  .rung[aria-pressed="true"] { box-shadow: inset 0 3px 0 var(--fg); }
}
.rail-note { display: none; max-width: none; }
@media (min-width: 760px) {
  .rail-note {
    display: flex; justify-content: space-between; margin: var(--sp-3) 0 0;
    font-size: var(--fs-0); color: var(--fg-dim);
  }
}
.rung-detail {
  margin-top: var(--sp-5); border-left: 3px solid var(--fg); padding: var(--sp-2) var(--sp-5);
  min-height: 6em;
}
.rung-pane { display: none; }
.rung-pane.is-active { display: block; }
.rung-pane h3 { margin: 0 0 var(--sp-2); font-size: var(--fs-3); }
.rung-pane p { margin: 0; color: var(--fg-muted); }

/* ---------- the call ---------- */

.call { display: grid; gap: var(--sp-6); margin-top: var(--sp-6); }
@media (min-width: 960px) {
  .call { grid-template-columns: minmax(0, 11fr) minmax(0, 9fr); gap: var(--sp-7); align-items: start; }
}
.call-flow svg { width: 100%; height: auto; display: block; color: var(--line); }
.call-flow .sock { fill: none; stroke: var(--line); stroke-dasharray: 4 4; }
.call-flow .sock-label { font-family: var(--font-mono); font-size: 11px; fill: var(--fg-dim); }
.call-flow .node rect { fill: var(--bg-raise); stroke: var(--line); stroke-width: 1.5; transition: fill var(--motion), stroke var(--motion); }
.call-flow .node text { font-size: 14px; font-weight: 500; }
.call-flow .node .sub { font-size: 11px; font-weight: 400; fill: var(--fg-dim); font-family: var(--font-mono); }
.call-flow .edge { fill: none; stroke: var(--line); stroke-width: 1.5; }
.call-flow .tag { font-family: var(--font-mono); font-size: 11.5px; fill: var(--fg-dim); opacity: 0; transition: opacity var(--motion); }
.call-flow .t-abstain { fill: var(--abstain); }
.call-flow .t-value { fill: var(--code); }
.call-flow .t-disagree { fill: var(--disagree); }
.call-flow .t-receipt { fill: var(--fg); }

/* step-driven states */
.call[data-step="0"] .node rect { opacity: .55; }
.call .n-input rect { opacity: .55; }
.call:not([data-step="0"]) .n-input rect { opacity: 1; stroke: var(--fg); }
.call.s2 .n-code rect, .call.s3 .n-code rect, .call.s4 .n-code rect, .call.s5 .n-code rect, .call.s6 .n-code rect { opacity: 1; stroke: var(--code); fill: var(--code-soft); }
.call.s2 .t-abstain, .call.s3 .t-abstain, .call.s4 .t-abstain, .call.s5 .t-abstain, .call.s6 .t-abstain { opacity: 1; }
.call.s3 .n-model rect, .call.s4 .n-model rect, .call.s5 .n-model rect, .call.s6 .n-model rect { opacity: 1; stroke: var(--model); fill: var(--model-soft); }
.call.s3 .e-abstain, .call.s4 .e-abstain, .call.s5 .e-abstain, .call.s6 .e-abstain { stroke: var(--abstain); }
.call.s3 .t-value:not(.t-noise), .call.s4 .t-value:not(.t-noise), .call.s5 .t-value:not(.t-noise), .call.s6 .t-value:not(.t-noise) { opacity: 1; }
.call.s4 .n-shadow rect, .call.s5 .n-shadow rect, .call.s6 .n-shadow rect { opacity: 1; stroke: var(--model); fill: var(--model-soft); }
.call.s4 .e-shadow, .call.s5 .e-shadow, .call.s6 .e-shadow { stroke: var(--model); stroke-dasharray: 3 3; }
.call.s4 .t-disagree, .call.s5 .t-disagree, .call.s6 .t-disagree { opacity: 1; }
.call.s5 .n-noise rect, .call.s6 .n-noise rect { opacity: 1; stroke: var(--model); fill: var(--model-soft); }
.call.s5 .t-noise, .call.s6 .t-noise { opacity: 1; }
.call.s6 .n-out rect { opacity: 1; stroke: var(--fg); }
.call.s6 .e-out { stroke: var(--fg); }
.call.s6 .t-receipt { opacity: 1; }

.steps { margin: var(--sp-5) 0 var(--sp-4); padding-left: 1.6em; counter-reset: step; list-style: none; }
.steps li {
  position: relative; color: var(--fg-dim); font-size: var(--fs-1); padding-left: var(--sp-2);
  transition: color var(--motion);
}
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: -1.6em; width: 1.3em; text-align: right;
  font-family: var(--font-mono); font-size: var(--fs-0); color: var(--fg-dim);
}
.steps li.is-done { color: var(--fg-muted); }
.steps li.is-current { color: var(--fg); }
.steps li.is-current::before { color: var(--fg); font-weight: 500; }
.call-controls { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.step-count { font-family: var(--font-mono); font-size: var(--fs-0); color: var(--fg-dim); }

/* the receipt */
.receipt { margin: 0; }
.paper {
  margin: 0;
  font: 400 12px/1.55 var(--font-mono);
  background: var(--paper);
  color: var(--fg);
  border: 1px solid var(--line);
  border-bottom: none;
  padding: var(--sp-5) var(--sp-5) var(--sp-6);
  overflow-x: auto;
  position: relative;
  min-height: 12em;
  /* torn edge */
  -webkit-mask: linear-gradient(#000, #000) top/100% calc(100% - 8px) no-repeat,
    radial-gradient(circle at 6px 100%, transparent 5px, #000 5.5px) bottom/12px 8px repeat-x;
  mask: linear-gradient(#000, #000) top/100% calc(100% - 8px) no-repeat,
    radial-gradient(circle at 6px 100%, transparent 5px, #000 5.5px) bottom/12px 8px repeat-x;
}
.paper .r { display: none; }
.paper .r.is-printed { display: inline; }
.paper.is-empty::before {
  content: "receipt prints as the call runs";
  color: var(--fg-dim); font-style: italic;
}
.receipt figcaption { font-size: var(--fs-0); color: var(--fg-dim); margin-top: var(--sp-3); }

@media (prefers-reduced-motion: no-preference) {
  .paper .r.is-printed { animation: print 260ms ease-out; }
  @keyframes print { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
}

/* vocab */
.vocab { margin-top: var(--sp-8); }
.vocab dl { display: grid; gap: var(--sp-5); }
@media (min-width: 760px) { .vocab dl { grid-template-columns: 1fr 1fr; gap: var(--sp-6) var(--sp-8); } }
.vocab dd { max-width: 48ch; }
.k-code { color: var(--code); font-weight: 500; }
.k-model { color: var(--model); font-weight: 500; }

/* ---------- measures ---------- */

.measures { border-collapse: collapse; width: 100%; max-width: 72ch; font-size: var(--fs-1); margin-bottom: var(--sp-6); }
.measures th, .measures td { text-align: left; vertical-align: top; padding: var(--sp-3) var(--sp-4) var(--sp-3) 0; border-top: 1px solid var(--line-soft); }
.measures thead th { border-top: none; color: var(--fg-dim); font-weight: 500; font-size: var(--fs-0); }
.measures tbody th { font-weight: 600; white-space: nowrap; width: 11em; }
.measures td { color: var(--fg-muted); }
@media (max-width: 560px) {
  .measures thead { display: none; }
  .measures tr, .measures th, .measures td { display: block; }
  .measures tbody th { width: auto; padding-bottom: 0; }
  .measures td { border-top: none; padding-top: var(--sp-1); }
}
.callout { border-left: 3px solid var(--model); padding: var(--sp-2) var(--sp-5); max-width: 70ch; }
.callout h3 { margin-top: 0; }
.callout p { margin: 0; color: var(--fg-muted); }

/* ---------- plug in ---------- */

.code-notes { display: grid; gap: var(--sp-4); }
@media (min-width: 1000px) { .code-notes { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--sp-6); align-items: start; } .code-notes .code { margin-top: 0; } }
.notes { list-style: none; padding: 0; margin: 0; font-size: var(--fs-1); color: var(--fg-muted); }
.notes li { padding-left: var(--sp-4); border-left: 2px solid var(--line); margin-bottom: var(--sp-3); }

.cuts { margin: var(--sp-5) 0; max-width: 72ch; }
.cuts svg { width: 100%; height: auto; display: block; }
.cuts .axis line { stroke: var(--line); stroke-width: 1.5; }
.cuts .axis text { font-family: var(--font-mono); font-size: 12px; fill: var(--fg-dim); }
.cuts .axis-label { font-family: var(--font-sans); font-size: 12px; }
.cuts .band-code { fill: var(--code-soft); stroke: var(--code); stroke-width: 1; }
.cuts .band-model { fill: var(--model-soft); stroke: var(--model); stroke-width: 1; }
.cuts .cut line { stroke: var(--fg); stroke-width: 1.5; }
.cuts .cut text { font-family: var(--font-mono); font-size: 12px; font-weight: 500; }
.cuts .band-text { font-size: 12px; fill: var(--code); font-weight: 500; }
.cuts .band-text-model { fill: var(--model); }
.cuts figcaption { font-size: var(--fs-1); color: var(--fg-muted); margin-top: var(--sp-3); }

/* ---------- chip, rubric, agents ---------- */

.envelope div, .skills div { display: grid; grid-template-columns: 9em minmax(0, 1fr); gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line-soft); }
.envelope dt, .skills dt { font-family: var(--font-mono); font-size: var(--fs-0); font-weight: 500; padding-top: 0.2em; }
.envelope dd, .skills dd { margin: 0; font-size: var(--fs-1); }
@media (max-width: 480px) { .envelope div, .skills div { grid-template-columns: 1fr; gap: var(--sp-1); } }

.rules { max-width: 66ch; padding-left: 1.6em; }
.rules li { margin-bottom: var(--sp-3); color: var(--fg-muted); }
.rules li strong { color: var(--fg); }
.rules li::marker { font-family: var(--font-mono); color: var(--fg-dim); }

.field { list-style: none; padding: 0; max-width: 66ch; }
.field li { padding-left: var(--sp-4); border-left: 2px solid var(--line); margin-bottom: var(--sp-3); color: var(--fg-muted); }

.next { list-style: none; padding: 0; font-size: var(--fs-1); }
.next li { padding: var(--sp-2) 0; border-top: 1px solid var(--line-soft); color: var(--fg-muted); }
#status h3 { margin-top: 0; }

/* ---------- footer ---------- */

footer { border-top: 1px solid var(--line-soft); padding: var(--sp-6) 0 var(--sp-8); font-size: var(--fs-1); color: var(--fg-muted); }
footer p { margin-bottom: var(--sp-2); }
.tiny { font-size: var(--fs-0); color: var(--fg-dim); }

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