/* ===========================================================
   Quantum Cookbook — design tokens, v2
   Combination direction: Making Software (illustrated book,
   diagrams-do-the-explaining, editorial whitespace) +
   AI Engineering from Scratch (deliberately plain, dense
   phase/lesson catalog, hand-written-doc feel).
   Light paper base, single ink-blue signal color, hairline rules.
   =========================================================== */
:root {
  --paper: #f7f4ec;
  --paper-raised: #fcfaf4;
  --ink: #1c1a16;
  --ink-muted: #6e6a60;
  --ink-faint: #a39d8e;
  --rule: #ddd7c8;
  --rule-strong: #c9c1ac;
  --signal: #2748c9;
  --signal-dim: #c4cdf0;
  --amber: #a8702b;
  --amber-bg: #f1e6d4;
  --green: #3f7d52;
  --green-bg: #e1ebe2;

  --font-display: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --font-body: "Work Sans", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", monospace;

  --radius: 2px;
  --max-width: 740px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--signal); text-decoration: none; border-bottom: 1px solid var(--signal-dim); }
a:hover { border-bottom-color: var(--signal); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

code, .mono { font-family: var(--font-mono); }

/* ---------- Status tags (borrowed from AIEFS's Complete/In Progress/Planned) ---------- */
.status-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: var(--radius);
  white-space: nowrap;
}
.status-tag.is-live { background: var(--green-bg); color: var(--green); }
.status-tag.is-cooking { background: var(--amber-bg); color: var(--amber); }
.status-tag.is-planned { background: transparent; color: var(--ink-faint); border: 1px solid var(--rule); }

/* ---------- Top nav ---------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 50;
}
.site-header-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.brand .brand-mark { color: var(--signal); font-family: var(--font-mono); font-weight: 400; }
.brand a { color: inherit; text-decoration: none; border: none; }
.site-nav a {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-left: 22px;
  border: none;
}
.site-nav a:hover { color: var(--signal); }

/* ---------- Page shell ---------- */
.page {
  display: flex;
  max-width: 980px;
  margin: 0 auto;
  align-items: flex-start;
}
.toc-rail {
  width: 200px;
  flex-shrink: 0;
  padding: 36px 16px 80px 24px;
  position: sticky;
  top: 60px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  border-right: 1px solid var(--rule);
}
.toc-part { margin-bottom: 16px; }
.toc-part-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.toc-chapter {
  display: block;
  font-size: 13px;
  color: var(--ink-muted);
  padding: 3px 0;
  border: none;
}
.toc-chapter.is-live { color: var(--ink); }
.toc-chapter.is-live:hover { color: var(--signal); }
.toc-chapter.is-current { color: var(--signal); font-weight: 600; }
.toc-chapter.is-locked { color: var(--ink-faint); cursor: default; }

main.content { flex: 1; min-width: 0; padding: 44px 36px 120px; }
@media (max-width: 820px) {
  .toc-rail { display: none; }
  main.content { padding: 30px 20px 100px; }
}

.lede { max-width: var(--max-width); font-size: 19px; color: var(--ink-muted); font-family: var(--font-body); }

article.chapter-body { max-width: var(--max-width); }
article.chapter-body p { margin: 0 0 1.1em; }
article.chapter-body h2 { font-size: 25px; margin: 2.2em 0 0.6em; }
article.chapter-body h3 { font-size: 19px; margin: 1.7em 0 0.5em; color: var(--ink); }

/* ---------- Lesson header (plain doc metadata row — replaces "recipe card") ---------- */
.lesson-header {
  max-width: var(--max-width);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  padding: 14px 0 16px;
  margin: 22px 0 36px;
}
.lesson-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-muted);
}
.lesson-meta-row span b { color: var(--ink); font-weight: 500; }

/* ---------- Figure block: the signature element ---------- */
/* Every interactive widget is framed as a numbered, captioned textbook figure. */
figure.qc-figure {
  max-width: var(--max-width);
  margin: 34px 0;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
}
figure.qc-figure .figure-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
figure.qc-figure .figure-body { padding: 20px; }
figure.qc-figure figcaption {
  padding: 10px 16px 14px;
  font-size: 14px;
  color: var(--ink-muted);
  border-top: 1px solid var(--rule);
  font-family: var(--font-body);
}

/* Bloch sphere widget layout */
.bloch-layout { display: flex; gap: 20px; flex-wrap: wrap; }
.bloch-canvas-wrap { flex: 1 1 280px; min-width: 240px; }
#bloch-canvas { width: 100%; height: 280px; display: block; background: var(--paper); border: 1px solid var(--rule); }
.bloch-controls { flex: 1 1 220px; min-width: 220px; display: flex; flex-direction: column; gap: 14px; }
.slider-row label { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 12px; color: var(--ink-muted); margin-bottom: 4px; }
.slider-row input[type=range] { width: 100%; accent-color: var(--signal); }
.state-readout {
  font-family: var(--font-mono);
  font-size: 13.5px;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 10px 12px;
  color: var(--signal);
}
.bloch-2d-wrap { display: flex; justify-content: center; margin-top: 10px; }

/* Code cell */
.code-cell textarea {
  width: 100%;
  min-height: 110px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  border: 1px solid var(--rule);
  padding: 12px;
  resize: vertical;
}
.code-cell-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.btn {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 7px 13px;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.is-signal { border-color: var(--signal); color: var(--signal); }
.btn.is-signal:hover { background: var(--signal); color: var(--paper); }
.code-status { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); }
.code-output {
  margin-top: 10px;
  background: var(--paper);
  border-left: 3px solid var(--signal);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: pre-wrap;
  color: var(--ink);
  display: none;
}
.code-output.is-visible { display: block; }

/* Quiz card — "Check your understanding" (AIEFS's /check-understanding language) */
.quiz-card {
  max-width: var(--max-width);
  margin: 28px 0;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink);
  padding: 16px 20px;
}
.quiz-card .eyebrow { display: block; margin-bottom: 8px; }
.quiz-question { font-size: 16.5px; margin: 0 0 12px; font-family: var(--font-body); }
.quiz-answer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); display: none; }
.quiz-answer.is-visible { display: block; }
.quiz-actions { display: flex; gap: 8px; margin-top: 12px; }
.quiz-rate { display: none; gap: 8px; margin-top: 12px; }
.quiz-rate.is-visible { display: flex; }
.quiz-rate button { flex: 1; }

/* Resource links — "Further reading", plain endnote list */
.resource-panel { max-width: var(--max-width); margin: 22px 0; }
.resource-toggle {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--signal);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.resource-list { display: none; list-style: none; margin: 8px 0 0; padding: 0; border-left: 2px solid var(--rule); padding-left: 16px; }
.resource-list.is-visible { display: block; }
.resource-list li { margin-bottom: 10px; font-size: 14.5px; }
.resource-list .res-type { font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; color: var(--ink-faint); margin-right: 6px; }
.resource-list .res-note { display: block; color: var(--ink-muted); font-size: 13px; }

/* Floating review button */
#review-fab {
  position: fixed; bottom: 22px; right: 22px;
  background: var(--ink); color: var(--paper);
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 500;
  border: none; border-radius: var(--radius);
  padding: 11px 16px; cursor: pointer;
  box-shadow: 0 6px 16px -6px rgba(28,26,22,0.35);
  z-index: 80;
}
#review-fab:hover { background: var(--signal); }
#review-fab[data-due="0"] { opacity: 0.6; }

#review-overlay { position: fixed; inset: 0; background: rgba(28,26,22,0.45); display: none; align-items: center; justify-content: center; z-index: 90; padding: 24px; }
#review-overlay.is-visible { display: flex; }
.review-modal { background: var(--paper-raised); border: 1px solid var(--rule); max-width: 520px; width: 100%; padding: 24px 26px; }
.review-modal-close { float: right; background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 13px; }

/* Catalog list (landing page TOC, replaces card grid) */
.catalog-part { border-top: 1px solid var(--ink); padding: 18px 0; }
.catalog-part-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.catalog-part-head h3 { margin: 0; font-size: 18px; }
.catalog-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: 14.5px; }
.catalog-row:last-child { border-bottom: none; }
.catalog-row .row-title { color: var(--ink-muted); }
.catalog-row .row-title.is-live a { color: var(--ink); font-weight: 500; border: none; }
.catalog-row .row-title.is-live a:hover { color: var(--signal); }
.catalog-num { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); width: 28px; flex-shrink: 0; }

.locked-banner {
  border: 1px dashed var(--rule-strong);
  padding: 16px 18px;
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--amber-bg);
}

/* Landing hero */
.hero { max-width: var(--max-width); padding: 10px 0 16px; }
.hero h1 { font-size: 40px; margin: 14px 0 10px; }

footer.site-footer {
  border-top: 1px solid var(--rule);
  margin-top: 56px;
  padding: 24px 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* ---------- Gate buttons (added per feedback: real interactive gates) ---------- */
.gate-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.gate-btn {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  width: 42px;
  height: 36px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  border-radius: var(--radius);
}
.gate-btn:hover { background: var(--ink); color: var(--paper); }
.drag-hint {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 8px;
}

/* States reference table */
table.qc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 14.5px;
}
table.qc-table th, table.qc-table td {
  border-bottom: 1px solid var(--rule);
  padding: 8px 10px;
  text-align: left;
}
table.qc-table th {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}
table.qc-table td.mono { color: var(--signal); }

/* ---------- Gate reference cards ---------- */
.gate-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin: 20px 0 30px;
}
.gate-card {
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  padding: 16px 18px;
}
.gate-card h4 {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--signal);
}
.gate-card .gate-matrix { margin: 8px 0; font-size: 14px; }
.gate-card .gate-effect {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--amber);
  background: var(--amber-bg);
  display: inline-block;
  padding: 2px 7px;
  margin-bottom: 8px;
}
.gate-card p { font-size: 14px; color: var(--ink-muted); margin: 0; }

/* ---------- Circuit builder ---------- */
.palette-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.gate-tile {
  width: 44px; height: 40px;
  border: 1px solid var(--ink);
  background: var(--paper-raised);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 14px;
  cursor: grab;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
}
.gate-tile:active { cursor: grabbing; }

.circuit-rail {
  display: flex;
  gap: 6px;
  padding: 14px;
  background: var(--paper);
  border: 1px dashed var(--rule-strong);
  margin-bottom: 14px;
  overflow-x: auto;
}
.circuit-slot {
  width: 48px; height: 48px;
  flex-shrink: 0;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--ink-faint);
}
.circuit-slot.is-filled { color: var(--ink); border-color: var(--ink); cursor: pointer; }
.circuit-slot.is-over { border-color: var(--signal); background: var(--signal-dim); }
.circuit-slot.is-active { background: var(--amber-bg); border-color: var(--amber); color: var(--amber); }

.circuit-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.circuit-steps {
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 12px 14px;
  color: var(--ink);
  line-height: 1.6;
}

/* ---------- Multi-qubit circuit (CNOT, IBM-composer-style) ---------- */
.mq-palette { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.mq-tile {
  min-width: 44px; height: 40px;
  border: 1px solid var(--ink);
  background: var(--paper-raised);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 13px;
  cursor: grab;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  padding: 0 8px;
}
.mq-tile:active { cursor: grabbing; }
.mq-tile.is-cnot { border-color: var(--signal); color: var(--signal); }

.mq-circuit-wrap { position: relative; margin-bottom: 14px; }
.qubit-row { display: flex; align-items: stretch; position: relative; }
.qubit-row::before {
  content: "";
  position: absolute;
  left: 30px; right: 30px;
  top: 50%; height: 1px;
  background: var(--ink-faint);
  z-index: 0;
}
.qubit-label {
  width: 30px; flex-shrink: 0;
  display: flex; align-items: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-muted);
  z-index: 1;
}
.q-cell {
  width: 44px; height: 44px;
  flex-shrink: 0;
  margin-right: 5px;
  border: 1px solid transparent;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--ink-faint);
  cursor: pointer;
  z-index: 1;
  border-radius: var(--radius);
}
.q-cell.is-filled { background: var(--paper-raised); border-color: var(--ink); color: var(--ink); }
.q-cell.is-selected { border-color: var(--signal); box-shadow: 0 0 0 2px var(--signal-dim) inset; }
.q-cell.is-over { border-color: var(--signal); background: var(--signal-dim); }
.q-cell.is-cnot-ctrl { background: var(--paper-raised); border-color: var(--signal); color: var(--signal); font-size: 18px; }
.q-cell.is-cnot-targ { background: var(--paper-raised); border-color: var(--signal); color: var(--signal); font-size: 16px; }
.q-meter {
  width: 36px; height: 44px;
  flex-shrink: 0;
  margin-left: 4px;
  border: 1px solid var(--rule-strong);
  background: var(--amber-bg);
  color: var(--amber);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  z-index: 1;
  border-radius: var(--radius);
}
.mq-connectors { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.cnot-connector { position: absolute; top: 22px; width: 2px; height: 44px; background: var(--signal); z-index: 0; }

.mq-actions { display: flex; gap: 10px; margin: 14px 0; }
.mq-steps {
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 12px 14px;
  color: var(--ink);
  line-height: 1.6;
  overflow-x: auto;
}

/* Histogram */
.histogram-panel { display: flex; align-items: flex-end; gap: 18px; height: 160px; padding: 10px 10px 0; margin-top: 16px; border-top: 1px solid var(--rule); }
.hist-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.hist-bar-track { width: 100%; max-width: 56px; height: 120px; display: flex; align-items: flex-end; background: var(--paper); border: 1px solid var(--rule); }
.hist-bar { width: 100%; background: var(--signal); height: 0%; transition: height 0.6s cubic-bezier(0.2,0.8,0.2,1); }
.hist-label { font-family: var(--font-mono); font-size: 12px; color: var(--ink); margin-top: 6px; }
.hist-val { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); margin-top: 2px; }

/* ---------- Ch.1 vector/matrix widgets ---------- */
.vec-plane-wrap { display: flex; justify-content: center; }
.vec-plane-wrap svg { background: var(--paper); border: 1px solid var(--rule); touch-action: none; }
.vec-readout {
  font-family: var(--font-mono); font-size: 13px; color: var(--signal);
  background: var(--paper); border: 1px solid var(--rule); padding: 8px 12px; margin-top: 10px;
}
.matrix-controls { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 12px; }
.matrix-input-grid {
  display: grid; grid-template-columns: repeat(2, 50px); gap: 6px;
  padding: 8px 10px; border-left: 3px solid var(--ink); border-right: 3px solid var(--ink);
}
.matrix-input-grid input {
  width: 50px; height: 36px; text-align: center;
  font-family: var(--font-mono); font-size: 14px;
  border: 1px solid var(--rule); background: var(--paper-raised); color: var(--ink);
}
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }
.matrix-preset {
  font-family: var(--font-mono); font-size: 11.5px;
  border: 1px solid var(--ink); background: var(--paper); color: var(--ink);
  padding: 6px 10px; cursor: pointer; border-radius: var(--radius);
}
.matrix-preset:hover { background: var(--ink); color: var(--paper); }
.transform-eq { margin-top: 12px; font-size: 15px; }

/* ---------- Ch.2 inner/outer product widgets ---------- */
.outer-matrix-wrap { display: flex; justify-content: center; margin-top: 16px; font-size: 16px; }

/* ---------- Ch.4 matrix property checker ---------- */
.complex-grid { display: grid; grid-template-columns: repeat(2, auto); gap: 10px; margin-bottom: 16px; }
.complex-cell {
  display: flex; align-items: center; gap: 3px;
  border: 1px solid var(--rule); background: var(--paper-raised);
  padding: 6px 8px; font-family: var(--font-mono); font-size: 13px;
}
.complex-cell input { width: 44px; text-align: center; font-family: var(--font-mono); font-size: 13px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); padding: 4px 2px; }
.complex-cell span { color: var(--ink-faint); }
.op-status-row { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.op-status {
  font-family: var(--font-mono); font-size: 13px; padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--rule);
}
.op-status.is-yes { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.op-status.is-no { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }
.op-output-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 12px; }
.op-output-grid h4 { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 6px; }
.eigen-readout-box { font-family: var(--font-mono); font-size: 13px; color: var(--signal); margin-top: 10px; }

/* ---------- Ch.5 tensor/Kronecker product widgets ---------- */
.tensor-vec-inputs { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 14px; }
.tensor-vec-group { display: flex; flex-direction: column; gap: 6px; }
.tensor-vec-group .vec-label { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); }
.tensor-vec-group input { width: 60px; text-align: center; font-family: var(--font-mono); font-size: 14px; border: 1px solid var(--rule); background: var(--paper-raised); color: var(--ink); padding: 6px 4px; margin-bottom: 4px; display: block; }
.tensor-result-list { font-family: var(--font-mono); font-size: 13.5px; background: var(--paper); border: 1px solid var(--rule); padding: 10px 14px; line-height: 1.8; }
.tensor-result-list .term { color: var(--ink-faint); }
.tensor-result-list .val { color: var(--signal); font-weight: 600; }

.tensor-mat-inputs { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 14px; align-items: flex-start; }
.tensor-mat-group { display: flex; flex-direction: column; gap: 8px; }
.tensor-block-grid { display: grid; grid-template-columns: repeat(4, 38px); gap: 1px; background: var(--rule); border: 1px solid var(--ink); width: max-content; font-family: var(--font-mono); font-size: 12px; }
.tensor-block-grid .tb-cell { width: 38px; height: 32px; display: flex; align-items: center; justify-content: center; background: var(--paper-raised); }
.tensor-block-grid .tb-cell.q-00 { background: #e8eefb; }
.tensor-block-grid .tb-cell.q-01 { background: #fdeee0; }
.tensor-block-grid .tb-cell.q-10 { background: #e3f5ee; }
.tensor-block-grid .tb-cell.q-11 { background: #f3e9f7; }

/* ---------- Ch.6 commutator widget ---------- */
.commutator-output-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 14px; }
.commutator-output-grid h4 { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 6px; }
.commute-tag-row { margin: 14px 0; }

/* ---------- Ch.7 measurement widget ---------- */
.meas-controls { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 16px; }
.meas-basis-row { display: flex; gap: 8px; margin-bottom: 14px; }
.meas-basis-btn {
  font-family: var(--font-mono); font-size: 12.5px; border: 1px solid var(--ink); background: var(--paper);
  color: var(--ink); padding: 7px 14px; cursor: pointer; border-radius: var(--radius);
}
.meas-basis-btn.is-active { background: var(--ink); color: var(--paper); }
.meas-hist-panel { display: flex; align-items: flex-end; gap: 30px; height: 170px; padding: 10px 16px 0; border-top: 1px solid var(--rule); margin-top: 10px; }
.meas-hist-col { flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; position: relative; }
.meas-hist-track { width: 60px; height: 130px; display: flex; align-items: flex-end; background: var(--paper); border: 1px solid var(--rule); position: relative; }
.meas-hist-bar { width: 100%; background: var(--signal); height: 0%; transition: height 0.4s ease; }
.meas-hist-theory-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--amber); }
.meas-hist-label { font-family: var(--font-mono); font-size: 13px; color: var(--ink); margin-top: 8px; }
.meas-hist-val { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint); margin-top: 2px; }
.meas-readout { font-family: var(--font-mono); font-size: 13px; color: var(--signal); background: var(--paper); border: 1px solid var(--rule); padding: 10px 14px; margin-top: 10px; }

/* ---------- Part II shared widget styles ---------- */
.toggle-row { display: flex; gap: 8px; margin-bottom: 14px; }
.toggle-btn {
  font-family: var(--font-mono); font-size: 12.5px; border: 1px solid var(--ink); background: var(--paper);
  color: var(--ink); padding: 7px 14px; cursor: pointer; border-radius: var(--radius);
}
.toggle-btn.is-active { background: var(--ink); color: var(--paper); }
.purity-gauge-wrap { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.purity-gauge-track { flex: 1; height: 10px; background: var(--rule); border-radius: 6px; overflow: hidden; }
.purity-gauge-fill { height: 100%; background: var(--signal); transition: width 0.3s ease; }
.static-diagram-wrap { display: flex; justify-content: center; padding: 10px 0; }
.level-tag {
  display: inline-block; font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 3px 9px; border-radius: var(--radius); margin-bottom: 8px;
}
.level-tag.basic { background: var(--green-bg); color: var(--green); }
.level-tag.intermediate { background: var(--amber-bg); color: var(--amber); }
.level-tag.advanced { background: #ece3f5; color: #7a3fa6; }

/* ---------- Part III shared widget styles ---------- */
.protocol-step { border-left: 3px solid var(--rule); padding: 6px 0 6px 14px; margin-bottom: 4px; }
.protocol-step.is-active { border-left-color: var(--signal); }
.graph-node { fill: var(--paper-raised); stroke: var(--ink); stroke-width: 1.5; cursor: pointer; }
.graph-node.is-selected { stroke: var(--signal); fill: var(--signal-dim); }
.graph-edge { stroke: var(--ink-faint); stroke-width: 2; cursor: pointer; }
.graph-edge.is-active { stroke: var(--signal); }
.bipartition-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--rule); font-family: var(--font-mono); font-size: 13px; }
.op-status.is-mid { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }

/* ---------- Part V shared circuit-diagram & widget styles ---------- */
.circuit-diagram-wrap { display: flex; justify-content: center; overflow-x: auto; padding: 8px 0; }
.amp-bar-panel { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding: 10px 8px 0; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.amp-bar-col { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 34px; }
.amp-bar-track { width: 22px; height: 130px; display: flex; align-items: flex-end; background: var(--paper); border: 1px solid var(--rule); position: relative; }
.amp-bar-fill { width: 100%; background: var(--signal); transition: height 0.4s ease; }
.amp-bar-fill.is-neg { background: var(--amber); }
.amp-bar-label { font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint); margin-top: 4px; }
.truth-table-grid { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--ink); width: max-content; font-family: var(--font-mono); font-size: 12px; }
.truth-table-grid .tt-cell { padding: 6px 10px; background: var(--paper-raised); text-align: center; }
.truth-table-grid .tt-cell.is-header { background: var(--ink); color: var(--paper); font-size: 10px; text-transform: uppercase; }
.truth-table-grid .tt-cell.is-toggle { cursor: pointer; color: var(--signal); font-weight: 600; }
.truth-table-grid .tt-cell.is-toggle:hover { background: var(--signal-dim); }
.toff-bit-btn {
  width: 44px; height: 44px; font-family: var(--font-mono); font-size: 18px; font-weight: 600;
  border: 1px solid var(--ink); background: var(--paper); color: var(--ink-faint); cursor: pointer; border-radius: var(--radius); margin-right: 8px;
}
.toff-bit-btn.is-active { background: var(--ink); color: var(--paper); }
.qc-select {
  font-family: var(--font-mono); font-size: 13px; padding: 6px 10px;
  border: 1px solid var(--ink); background: var(--paper); color: var(--ink); border-radius: var(--radius);
}

/* ---------- Update badge + About/Updates pages ---------- */
.site-nav a.has-update { position: relative; }
.site-nav a.has-update::after {
  content: "";
  position: absolute;
  top: -2px; right: -8px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--amber);
}
.remember-box {
  max-width: 480px;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  padding: 18px 20px;
  margin: 20px 0;
}
.remember-box input[type="text"] {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  padding: 8px 10px;
  margin: 8px 0 12px;
}
.changelog-entry {
  border-left: 3px solid var(--rule);
  padding: 4px 0 16px 16px;
  margin-bottom: 16px;
  position: relative;
}
.changelog-entry.is-new { border-left-color: var(--amber); }
.changelog-entry .cl-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--amber-bg);
  color: var(--amber);
  padding: 2px 7px;
  border-radius: var(--radius);
  margin-left: 8px;
}
.changelog-entry h3 { margin: 0 0 4px; font-size: 18px; }
.changelog-entry .cl-date { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); margin-bottom: 8px; display: block; }
.contact-card {
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  padding: 16px 20px;
  max-width: 420px;
  margin: 16px 0;
}
.contact-card a { font-family: var(--font-mono); font-size: 14px; }

/* ---- AI tutor (Ask AI) ------------------------------------------------ */
.ai-fab {
  position: fixed; bottom: 22px; left: 22px;
  background: var(--signal); color: var(--paper);
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 500;
  border: none; border-radius: var(--radius);
  padding: 11px 16px; cursor: pointer;
  box-shadow: 0 6px 16px -6px rgba(39,72,201,0.45);
  z-index: 80;
}
.ai-fab:hover { background: var(--ink); }

.ai-panel {
  position: fixed; bottom: 70px; left: 22px;
  width: min(380px, calc(100vw - 44px));
  max-height: 400px;
  display: none; flex-direction: column;
  background: var(--paper-raised);
  border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: 0 12px 28px -10px rgba(28,26,22,0.35);
  z-index: 85;
}
.ai-panel.is-open { display: flex; }

.ai-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--rule);
}
.ai-panel-title {
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 600;
  color: var(--ink-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-panel-close {
  background: none; border: none; color: var(--ink-faint);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.ai-panel-close:hover { color: var(--ink); }

.ai-log {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 120px;
}
.ai-msg {
  font-family: var(--font-body); font-size: 14px; line-height: 1.55;
  padding: 8px 12px; border-radius: var(--radius);
  white-space: pre-wrap; word-break: break-word;
  max-width: 92%;
}
.ai-msg-user { align-self: flex-end; background: var(--signal-dim); color: var(--ink); }
.ai-msg-assistant { align-self: flex-start; background: var(--paper); border: 1px solid var(--rule); }
.ai-msg.is-pending { color: var(--ink-faint); font-style: italic; }
.ai-msg.is-error { color: var(--amber); border-color: var(--amber); }

.ai-form {
  display: flex; gap: 8px; padding: 10px 14px;
  border-top: 1px solid var(--rule);
}
.ai-input {
  flex: 1; font-family: var(--font-ui); font-size: 13.5px;
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
}
.ai-input:focus { outline: none; border-color: var(--signal); }
.ai-send {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 500;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: var(--radius);
  padding: 8px 14px; cursor: pointer;
}
.ai-send:hover { background: var(--signal); }
.ai-send:disabled { opacity: 0.5; cursor: default; }
