@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500..700&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;1,400&display=swap");

/* ============================================================
   QEC-Bank viewer. Design system shared with the QEC interactive
   tutorials: lab graph paper, X-type = amber, Z-type = blue,
   alarms = magenta. All colors are token-routed.
   ============================================================ */

:root {
  --bg: #f6f8f9;
  --bg2: #fdfefe;
  --bg3: #eef2f4;
  --ink: #1e2429;
  --ink2: #4b565e;
  --ink3: #7c878f;
  --line: #d5dde2;
  --line2: #c1ccd3;
  --grid: rgba(43, 108, 212, 0.075);

  --cx: #c2570f;
  --cx-ink: #a34a0c;
  --cx-soft: rgba(194, 87, 15, 0.1);
  --cz: #2b6cd4;
  --cz-ink: #2159b1;
  --cz-soft: rgba(43, 108, 212, 0.1);
  --cd: #c9257e;
  --good: #2f7d46;
  --good-soft: rgba(47, 125, 70, 0.12);
  --bad: #b3392e;
  --bad-soft: rgba(179, 57, 46, 0.1);

  --sel: rgba(43, 108, 212, 0.22);
  --shadow: 0 1px 2px rgba(30, 36, 41, 0.06), 0 8px 24px -12px rgba(30, 36, 41, 0.14);
  --plate: #fbfcfc;           /* widget canvases draw with fixed light ink */
  --plate-line: #c1ccd3;

  --f-display: "Fraunces", Georgia, "Times New Roman", serif;
  --f-body: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;

  /* aliases used by generated markup */
  --muted: var(--ink2);
  --soft: var(--bg3);
  --accent: var(--cz-ink);
  --accent-soft: var(--cz-soft);
  --paper: var(--bg2);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d;
    --bg2: #1b2127;
    --bg3: #10141a;
    --ink: #e8eaed;
    --ink2: #aeb7be;
    --ink3: #7d868e;
    --line: #2b333b;
    --line2: #39434c;
    --grid: rgba(91, 141, 219, 0.1);
    --cx: #ce7b2b;
    --cx-ink: #e0954a;
    --cx-soft: rgba(206, 123, 43, 0.16);
    --cz: #5b8ddb;
    --cz-ink: #7ba5e6;
    --cz-soft: rgba(91, 141, 219, 0.16);
    --cd: #c74e86;
    --good: #58a16c;
    --good-soft: rgba(88, 161, 108, 0.16);
    --bad: #cf6a5f;
    --bad-soft: rgba(207, 106, 95, 0.14);
    --sel: rgba(91, 141, 219, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px -12px rgba(0, 0, 0, 0.55);
    --plate: #eef2f4;
    --plate-line: #39434c;
  }
}
:root[data-theme="dark"] {
  --bg: #14181d;
  --bg2: #1b2127;
  --bg3: #10141a;
  --ink: #e8eaed;
  --ink2: #aeb7be;
  --ink3: #7d868e;
  --line: #2b333b;
  --line2: #39434c;
  --grid: rgba(91, 141, 219, 0.1);
  --cx: #ce7b2b;
  --cx-ink: #e0954a;
  --cx-soft: rgba(206, 123, 43, 0.16);
  --cz: #5b8ddb;
  --cz-ink: #7ba5e6;
  --cz-soft: rgba(91, 141, 219, 0.16);
  --cd: #c74e86;
  --good: #58a16c;
  --good-soft: rgba(88, 161, 108, 0.16);
  --bad: #cf6a5f;
  --bad-soft: rgba(207, 106, 95, 0.14);
  --sel: rgba(91, 141, 219, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px -12px rgba(0, 0, 0, 0.55);
  --plate: #eef2f4;
  --plate-line: #39434c;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { overflow-x: clip; scroll-behavior: smooth; background: var(--bg); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16.5px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--cz-ink); text-decoration-thickness: 1px; text-underline-offset: 2.5px; }
a:hover { color: var(--cz); }
strong { font-weight: 600; }
::selection { background: var(--sel); }
:focus-visible { outline: 2px solid var(--cz); outline-offset: 2px; border-radius: 2px; }

/* ---------- top bar (full bleed) ---------- */
nav {
  position: sticky;
  top: 0;
  z-index: 50;
  margin: 0 calc(50% - 50vw) 0;
  padding: .6rem calc(50vw - 50% + 0rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink3);
  font-size: .9rem;
}
nav a { color: var(--ink2); text-decoration: none; }
nav a:hover { color: var(--ink); text-decoration: underline; }
nav a:first-child {
  color: var(--ink);
  font-family: var(--f-display);
  font-size: 1rem;
  font-weight: 600;
}

/* ---------- headings ---------- */
h1, h2, h3, h4 { font-family: var(--f-display); font-weight: 600; line-height: 1.22; text-wrap: balance; }
h1 { margin: .3rem 0 1rem; font-size: clamp(2.1rem, 5.4vw, 3.4rem); letter-spacing: -.01em; }
h2 { margin-top: 2rem; font-size: 1.6rem; }
h3 { margin: 1.5rem 0 .55rem; font-size: 1.12rem; }

.eyebrow {
  margin: 0;
  color: var(--cz-ink);
  font-family: var(--f-mono);
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
}

/* ---------- graph-paper heroes (full bleed) ---------- */
.index-header,
.entry-header,
.facet-header,
.tour-header {
  position: relative;
}
.index-header,
.entry-header,
.facet-header {
  margin-inline: calc(50% - 50vw);
  padding: 3.2rem calc(50vw - 50%) 2.6rem;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 26px 26px;
  background-color: var(--bg);
}
.index-header > *,
.entry-header > *,
.facet-header > * { max-width: 820px; }

.index-header { margin-bottom: 2rem; }
.index-header h1 { margin-bottom: .35rem; }
.index-header p:last-child { margin: 0; color: var(--ink2); font-size: 1.08rem; }

.entry-header { padding-bottom: 2.4rem; }
.entry-description {
  margin: 0;
  color: var(--ink2);
  font-size: clamp(1.05rem, 2.1vw, 1.2rem);
  line-height: 1.75;
}
.entry-description-missing {
  border-left: 3px solid var(--cx);
  border-radius: 0 8px 8px 0;
  padding: .7rem 1rem;
  background: var(--cx-soft);
  color: var(--cx-ink);
  font-size: 1rem;
}

.facet-page { max-width: none; }
.facet-page > :not(.facet-header) { max-width: 820px; }
.back-link { display: inline-block; margin-bottom: 1.4rem; font-size: .9rem; }
.facet-header { margin-bottom: 2.5rem; }
.facet-header h1 { margin-bottom: .6rem; }
.facet-header > p:last-child { margin: 0; color: var(--ink2); font-size: 1.08rem; }

/* ---------- sections ---------- */
.entry-ontology-v2-live {
  margin: 1rem 0 0;
  border-left: 3px solid var(--cz);
  border-radius: 0 8px 8px 0;
  padding: .45rem .8rem;
  background: var(--bg2);
  color: var(--ink3);
  font-size: .82rem;
  line-height: 1.5;
}
.landing-section {
  border-top: 1px solid var(--line);
  padding: 2.25rem 0;
}
.entry-header + .landing-section { border-top: 0; }
.section-heading { max-width: 690px; margin-bottom: 1.25rem; }
.section-heading h2 {
  margin: .3rem 0 .5rem;
  padding-bottom: .6rem;
  border-bottom: 2px solid var(--ink);
}
.section-heading p:last-child { margin: 0; color: var(--ink2); }

/* ---------- entry index ---------- */
.entry-index-wrap {
  overflow-x: auto;
  border: 1px solid var(--line2);
  border-radius: 14px;
  background: var(--bg2);
  box-shadow: var(--shadow);
}
.entry-index { min-width: 1060px; margin: 0; border: 0; }
.entry-index th { white-space: nowrap; background: var(--bg3); }
.entry-index td { vertical-align: middle; }
.entry-index tbody tr:hover { background: var(--cz-soft); }
.entry-index-name { display: block; font-weight: 600; white-space: nowrap; }
.identity-variant { margin-top: .35rem; color: var(--ink2); }

/* ---------- badges & chips ---------- */
.parameter-badge,
.capability-badge {
  display: inline-block;
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: .16rem .55rem;
  background: var(--bg2);
  color: var(--ink2);
  font-family: var(--f-mono);
  font-size: .78rem;
  white-space: nowrap;
}
.parameter-bounded,
.parameter-claimed,
.parameter-unknown,
.capability-planned {
  border-color: var(--cx);
  background: var(--cx-soft);
  color: var(--cx-ink);
}
.capability-available {
  border-color: var(--good);
  background: var(--good-soft);
  color: var(--good);
}
.capability-not-applicable {
  border-color: var(--line2);
  background: var(--bg3);
  color: var(--ink3);
}

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  display: inline-block;
  margin-right: .2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .1rem .55rem;
  background: var(--bg3);
  color: var(--ink2);
  font-size: .8em;
}
.chip.tier {
  border-color: var(--good);
  background: var(--good-soft);
  color: var(--good);
  font-family: var(--f-mono);
  font-weight: 600;
}

.badge {
  display: inline-block;
  border-radius: 5px;
  padding: .1rem .42rem;
  font-family: var(--f-mono);
  font-size: .78em;
  white-space: nowrap;
}
.badge-verified { background: var(--good-soft); color: var(--good); }
.badge-bounded { background: var(--cx-soft); color: var(--cx-ink); }
.badge-claimed { background: var(--bad-soft); color: var(--bad); }
.badge-none { background: var(--bg3); color: var(--ink3); }

/* ---------- widgets ---------- */
.orienting-view canvas {
  display: block;
  width: min(100%, 560px);
  height: auto;
  max-width: 100%;
  border: 1px solid var(--plate-line);
  border-radius: 12px;
  background: var(--plate);
  box-shadow: var(--shadow);
}
.orienting-view [data-scene-canvas] {
  width: min(100%, 760px);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.orienting-view [data-scene-canvas]:active { cursor: grabbing; }
.orienting-view canvas:focus-visible { outline: 3px solid var(--cz); outline-offset: 3px; }

.lattice-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  margin-bottom: .75rem;
  color: var(--ink2);
  font-size: .88rem;
}
.scene-toolbar,
.scene-camera-controls,
.scene-round-control {
  display: flex;
  width: min(100%, 760px);
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  margin-bottom: .7rem;
  color: var(--ink2);
  font-size: .88rem;
}
.scene-toolbar [data-scene-filter-control] {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
}
.scene-toolbar [data-scene-filter-control][hidden] { display: none; }
.scene-static-value {
  border-radius: 999px;
  padding: .28rem .7rem;
  background: var(--bg3);
  color: var(--ink);
}
.scene-camera-controls output {
  min-width: 3.5rem;
  color: var(--ink);
  font-family: var(--f-mono);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.scene-camera-controls > span { margin-left: auto; color: var(--ink3); }
.scene-round-control input[type="range"] { width: min(300px, 54vw); accent-color: var(--cz); }
.scene-round-control output {
  min-width: 12.5rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.scene-round-control[hidden] { display: none; }

.schedule-controls { display: grid; gap: .7rem; margin-bottom: .75rem; }
.schedule-round-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem;
  color: var(--ink2);
  font-size: .88rem;
}
.schedule-round-control input[type="range"] { width: min(280px, 52vw); accent-color: var(--cz); }
.schedule-round-control output {
  min-width: 12.5rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.schedule-detail,
.lattice-detail,
.scene-detail {
  width: min(100%, 560px);
  min-height: 2.8rem;
  margin-top: .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .65rem .75rem;
  background: var(--bg2);
  color: var(--ink2);
  font-family: var(--f-mono);
  font-size: .82rem;
}
.scene-detail { width: min(100%, 760px); }

.periodic-note { width: min(100%, 760px); margin: .6rem 0 0; color: var(--ink2); font-size: .84rem; }
.periodic-pair {
  display: inline-block;
  min-width: 1.7rem;
  margin-right: .15rem;
  border-bottom: 3px dashed currentColor;
  text-align: center;
  font-weight: 600;
}
.periodic-pair-a { color: var(--cz-ink); }
.periodic-pair-b { color: var(--cd); }
.scene-instance { white-space: nowrap; }

.layout-note { max-width: 560px; margin: .55rem 0 0; color: var(--ink3); font-size: .82rem; }

button {
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: .26rem .75rem;
  background: var(--bg2);
  color: var(--ink2);
  cursor: pointer;
  font: inherit;
  font-size: .84rem;
  font-weight: 500;
}
button:hover { border-color: var(--cz); color: var(--ink); background: var(--cz-soft); }
button:focus-visible { outline: 2px solid var(--cz); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .55; }
button[aria-pressed="true"],
.scene-toolbar button[aria-pressed="true"],
.lattice-toolbar button[aria-pressed="true"],
.schedule-controls button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

/* ---------- definitions & tables ---------- */
.parameter-definitions { display: grid; gap: .5rem; margin: .7rem 0 1.4rem; }
.parameter-definitions div {
  display: grid;
  grid-template-columns: minmax(3rem, .25fr) 1fr;
  gap: 1rem;
  border-left: 2px solid var(--cz);
  padding: .35rem 0 .35rem .8rem;
}
.parameter-definitions dt { font-family: var(--f-mono); font-weight: 600; }
.parameter-definitions dd { margin: 0; color: var(--ink2); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
td, th { border-bottom: 1px solid var(--line); padding: .62rem .7rem; text-align: left; }
th {
  color: var(--ink3);
  font-family: var(--f-mono);
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.markdown-table-wrap { margin: 1.25rem 0 1.75rem; }
.markdown-table { min-width: 620px; }
.markdown-table th {
  background: var(--bg3);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: .86rem;
  letter-spacing: 0;
  text-transform: none;
  vertical-align: bottom;
}
.markdown-table td { min-width: 8rem; vertical-align: top; }
.markdown-table .align-center { text-align: center; }
.markdown-table .align-right { text-align: right; }

/* ---------- cards ---------- */
.facet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .9rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.facet-card {
  display: flex;
  min-height: 118px;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--line2);
  border-radius: 14px;
  padding: 1rem 1.15rem;
  background: var(--bg2);
  box-shadow: var(--shadow);
  color: var(--ink2);
  text-decoration: none;
  transition: border-color 120ms ease, transform 120ms ease;
}
.facet-card:hover { transform: translateY(-1px); border-color: var(--cz); color: var(--ink2); }
.facet-card-title {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 600;
}
.facet-card > span:last-child { font-size: .9rem; }

.detail-list, .document-list { padding-left: 1.25rem; }
.detail-list > li { margin-bottom: 1.6rem; }
.detail-list p { margin: .38rem 0; }
.document-list li { margin: .45rem 0; }

.representation-ladder { display: grid; gap: 1rem; padding: 0; list-style: none; }
.representation-rung {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  background: var(--bg2);
}
.representation-rung-heading {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .85rem;
  align-items: start;
}
.representation-rung-heading h2,
.representation-rung-heading p { margin: 0; }
.representation-rung-heading p { color: var(--ink2); }
.representation-rung-id {
  display: inline-block;
  border-radius: 999px;
  padding: .2rem .55rem;
  background: var(--cz-soft);
  color: var(--cz-ink);
  font-family: var(--f-mono);
  font-weight: 600;
}
.representation-rung .detail-list { margin-bottom: 0; }
.gap-link { text-decoration-thickness: 2px; }
.gap-action { font-weight: 600; }

.reference-list { display: grid; gap: .75rem; padding: 0; list-style: none; }
.reference-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .85rem 1rem;
  background: var(--bg2);
}
.reference-list p { margin: 0; }
.reference-title { font-weight: 600; }
.reference-authors { margin-top: .35rem !important; color: var(--ink2); font-size: .9rem; }
.reference-key { display: inline-block; margin-top: .45rem; color: var(--ink3); font-family: var(--f-mono); font-size: .85rem; }

.decoder, .operation { border-bottom: 1px solid var(--line); padding-bottom: 1.2rem; }
.empty-state { color: var(--ink3); font-style: italic; }

.intuition { border-left: 3px solid var(--cz); padding-left: 1.2rem; }
.intuition p.note { color: var(--ink2); font-style: italic; }

/* ---------- math & code ---------- */
.math-inline { white-space: nowrap; }
.math-display {
  max-width: 100%;
  margin: 1.25rem 0;
  padding: .35rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.math-display mjx-container[display="true"] { margin: 0 !important; }

code { font-family: var(--f-mono); font-size: .88em; }
:not(pre) > code {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .05em .35em;
  background: var(--bg3);
}
pre {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  background: var(--bg2);
  font-family: var(--f-mono);
}

@media (max-width: 680px) {
  body { padding: 0 1rem 3rem; }
  .index-header, .entry-header, .facet-header { padding-top: 2.2rem; padding-bottom: 1.8rem; }
  .facet-grid { grid-template-columns: 1fr; }
  .parameter-definitions div { grid-template-columns: 1fr; gap: .15rem; }
  .schedule-round-control input[type="range"] { order: 4; width: 100%; }
  .scene-camera-controls > span { flex-basis: 100%; margin-left: 0; }
}
