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

:root {
  --bg: #0d0d0d;
  --surface: #141414;
  --surface-2: #1e1e1e;
  --border: #2a2a2a;
  --text: #b8b8b8;
  --text-dim: #484848;
  --text-bright: #f0f0f0;
  --blue: #60a5fa;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #c084fc;
  --radius: 6px;
  --mono: 'Courier New', 'Lucida Console', monospace;
}

html {
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 28px;
}

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--blue);
  border: 1px solid var(--border);
}

/* ── NAV ──────────────────────────────── */

.nav {
  padding: 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(13, 13, 13, 0.95);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.nav .container {
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 52px;
}

.nav-brand {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: bold;
  color: var(--text-bright);
  letter-spacing: 0.12em;
  text-decoration: none;
  display: flex;
  align-items: center;
  padding-right: 28px;
  margin-right: 8px;
  border-right: 1px solid var(--border);
}

.nav-links {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.nav-link {
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.01em;
}

.nav-link:hover {
  color: var(--text);
}

/* Active page highlighting via body class */
.page-index    .nav-link[href="index.html"],
.page-pattern  .nav-link[href="pattern.html"],
.page-ecosystem .nav-link[href="ecosystem.html"],
.page-prior-art .nav-link[href="prior-art.html"] {
  color: var(--text-bright);
  border-bottom-color: var(--blue);
}

/* ── HERO (main) ──────────────────────── */

.hero {
  padding: 88px 0 72px;
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 700;
  color: var(--text-bright);
  line-height: 1.04;
  letter-spacing: -0.03em;
  margin-bottom: 24px;
}

.hero-sub {
  font-size: 20px;
  color: var(--blue);
  margin-bottom: 18px;
  font-weight: 400;
}

.hero-desc {
  font-size: 15px;
  color: var(--text);
  max-width: 560px;
  line-height: 1.75;
}

/* ── PAGE HERO (sub-pages) ────────────── */

.page-hero {
  padding: 52px 0 44px;
  border-bottom: 1px solid var(--border);
}

.page-hero h1 {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-bottom: 12px;
}

.page-hero p {
  font-size: 15px;
  color: var(--text);
  max-width: 560px;
  line-height: 1.7;
}

/* ── SECTION SHARED ───────────────────── */

section {
  padding: 56px 0;
  border-bottom: 1px solid var(--border);
}

section.alt {
  background: var(--surface);
}

.section-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.section-heading {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.section-intro {
  font-size: 15px;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 28px;
  max-width: 680px;
}

/* ── PROBLEM ──────────────────────────── */

.problem-heading {
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-bottom: 20px;
}

.problem-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  max-width: 640px;
  margin-bottom: 20px;
}

.problem-fix {
  font-size: 15px;
  color: var(--green);
  font-weight: 500;
}

/* ── INSIGHT ──────────────────────────── */

.insight-grid {
  display: grid;
  grid-template-columns: 1fr 40px 1fr;
  gap: 20px;
  align-items: center;
}

.insight-divider {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
}

.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 22px;
}

.insight-card.before { border-left: 3px solid var(--text-dim); }
.insight-card.after  { border-left: 3px solid var(--green); }

.insight-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.insight-card blockquote {
  font-size: 14px;
  color: var(--text-bright);
  font-style: italic;
  margin-bottom: 20px;
  line-height: 1.55;
}

.mini-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-node {
  font-size: 11px;
  font-family: var(--mono);
  padding: 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  white-space: nowrap;
}

.mini-node.faded { color: var(--text-dim); border-style: dashed; }
.mini-node.lit   { color: var(--green); border-color: rgba(74,222,128,0.4); background: rgba(74,222,128,0.05); }

.mini-arrow { color: var(--text-dim); font-size: 11px; flex-shrink: 0; }

/* ── PAGE CARDS (index overview) ─────── */

.page-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.page-card {
  background: var(--surface);
  padding: 24px 20px;
  text-decoration: none;
  display: block;
  transition: background 0.15s;
}

.page-card:hover {
  background: var(--surface-2);
}

.page-card-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.page-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.page-card p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.55;
}

.page-card-arrow {
  display: block;
  font-size: 12px;
  color: var(--blue);
  margin-top: 14px;
}

/* ── COMPONENTS ───────────────────────── */

.component-list {
  display: flex;
  flex-direction: column;
}

.component {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 20px;
  padding: 28px 0;
  border-top: 1px solid var(--border);
}

.component:last-child { border-bottom: 1px solid var(--border); }

.component-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  padding-top: 3px;
}

.component-body h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 10px;
  font-family: var(--mono);
}

.component-body p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* ── LOOP ─────────────────────────────── */

.loop-wrap {
  display: flex;
  justify-content: center;
}

.loop-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 640px;
}

.loop-node {
  padding: 11px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
  color: var(--text);
  background: var(--surface-2);
  white-space: nowrap;
  text-align: center;
}

.loop-node.entry { color: var(--text-dim); border-style: dashed; }
.loop-node.gate  { color: var(--blue); border-color: rgba(96,165,250,0.4); background: rgba(96,165,250,0.04); }

.loop-down {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.loop-fan {
  display: flex;
  width: 100%;
  height: 28px;
  position: relative;
}

.loop-fan .fan-mid   { position: absolute; left: 50%; width: 1px; height: 100%; background: var(--border); }
.loop-fan .fan-left  { position: absolute; left: calc(16.66% + 0.5px); right: calc(50% + 0.5px); bottom: 0; height: 100%; border-top: 1px solid var(--border); border-left: 1px solid var(--border); border-radius: 4px 0 0 0; }
.loop-fan .fan-right { position: absolute; left: calc(50% + 0.5px); right: calc(16.66% + 0.5px); bottom: 0; height: 100%; border-top: 1px solid var(--border); border-right: 1px solid var(--border); border-radius: 0 4px 0 0; }

.loop-outcomes {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  width: 100%;
}

.outcome { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.outcome-label { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.outcome.pass .outcome-label     { color: var(--green); }
.outcome.fail .outcome-label     { color: var(--amber); }
.outcome.escalate .outcome-label { color: var(--red); }

.outcome-node { padding: 10px 16px; border-radius: var(--radius); font-size: 12px; font-family: var(--mono); text-align: center; border: 1px solid; width: 100%; }
.outcome.pass .outcome-node     { color: var(--green);  border-color: rgba(74,222,128,0.35);  background: rgba(74,222,128,0.04); }
.outcome.fail .outcome-node     { color: var(--amber);  border-color: rgba(251,191,36,0.35);  background: rgba(251,191,36,0.04); }
.outcome.escalate .outcome-node { color: var(--red);    border-color: rgba(248,113,113,0.35); background: rgba(248,113,113,0.04); }

.retry-arrow { font-size: 10px; font-family: var(--mono); color: var(--text-dim); text-align: center; }

/* ── QUAD GRID (properties / prevents) ── */

.quad-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.quad-item {
  background: var(--surface-2);
  padding: 24px 22px;
}

.quad-item h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 8px;
}

.quad-item p {
  font-size: 13px;
  color: var(--text);
  line-height: 1.65;
}

/* ── ECOSYSTEM ROLES ──────────────────── */

.role-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-bottom: 20px;
}

.role-table thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 16px 12px 0;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.role-table tbody tr { border-bottom: 1px solid var(--border); }

.role-table tbody td {
  padding: 14px 16px 14px 0;
  color: var(--text);
  vertical-align: top;
  line-height: 1.5;
}

.role-table tbody td:first-child { width: 160px; }

.role-tag {
  display: inline-block;
  font-size: 11px;
  font-family: var(--mono);
  padding: 3px 9px;
  border-radius: 4px;
  border: 1px solid;
  white-space: nowrap;
  font-weight: 600;
}

.role-tag.orchestrator { color: var(--blue);   border-color: rgba(96,165,250,0.35);  background: rgba(96,165,250,0.06); }
.role-tag.sub-skill    { color: var(--text);   border-color: var(--border);           background: var(--surface-2); }
.role-tag.gate         { color: var(--green);  border-color: rgba(74,222,128,0.35);  background: rgba(74,222,128,0.06); }
.role-tag.meta         { color: var(--purple); border-color: rgba(192,132,252,0.35); background: rgba(192,132,252,0.06); }

.table-note {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 600px;
}

/* ── INTEGRITY HOOK ───────────────────── */

.hook-checks {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.hook-check {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 16px;
  align-items: start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.hook-num {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: bold;
  color: var(--text-dim);
  padding-top: 1px;
}

.hook-check-body strong {
  font-size: 14px;
  color: var(--text-bright);
  display: block;
  margin-bottom: 6px;
}

.hook-check-body p {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
}

.aside-note {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.65;
  max-width: 640px;
  padding-left: 16px;
  border-left: 2px solid var(--border);
}

/* ── PRIOR ART TABLE ──────────────────── */

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 24px;
}

.comparison-table thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 12px 12px 0;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.comparison-table thead th:first-child { width: 34%; }
.comparison-table tbody tr { border-bottom: 1px solid var(--border); }

.comparison-table tbody td {
  padding: 12px 12px 12px 0;
  color: var(--text);
  vertical-align: top;
  line-height: 1.5;
}

.cell-no  { color: var(--text-dim); }
.cell-yes { color: var(--green); }

/* ── NOVEL LIST (fixed) ───────────────── */

.novel-list {
  list-style: none;
  counter-reset: novel-counter;
}

.novel-list li {
  counter-increment: novel-counter;
  position: relative;
  padding: 20px 0 20px 48px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.novel-list li:last-child {
  border-bottom: 1px solid var(--border);
}

.novel-list li::before {
  content: counter(novel-counter);
  position: absolute;
  left: 0;
  top: 20px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  width: 32px;
}

.novel-list li strong {
  color: var(--text-bright);
}

/* ── CODE BLOCK ───────────────────────── */

.code-block {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.8;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  overflow-x: auto;
  white-space: pre;
}

.c-comment { color: var(--text-dim); }
.c-key     { color: var(--blue); }
.c-val     { color: var(--text); }
.c-heading { color: var(--text-bright); font-weight: bold; }
.c-check   { color: var(--text-dim); }
.c-text    { color: var(--text); }

/* ── PAGE FOOTER (prev / next nav) ───── */

.page-footer {
  padding: 40px 0 52px;
}

.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 36px;
}

.page-nav-prev,
.page-nav-next {
  font-size: 13px;
  color: var(--blue);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.page-nav-prev:hover,
.page-nav-next:hover {
  color: var(--text-bright);
}

.page-nav-next { margin-left: auto; }

.footer-credits {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.02em;
}

.footer-credits a {
  color: var(--text-dim);
  text-decoration: none;
}

.footer-credits a:hover {
  color: var(--text-bright);
}

/* ── DIAGRAMS (Mermaid) ───────────────── */

.diagram {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 12px 14px;
  margin: 24px 0 0;
  overflow-x: auto;
  text-align: center;
}

.diagram .mermaid {
  display: inline-block;
  min-width: 0;
  max-width: 100%;
}

.diagram .mermaid svg {
  display: block;
  width: auto !important;
  max-width: min(100%, 920px);
  height: auto;
  margin: 0 auto;
}

.page-pattern .diagram .mermaid svg {
  max-width: min(100%, 620px);
}

.page-ecosystem .diagram .mermaid {
  max-width: none;
}

.page-ecosystem .diagram .mermaid svg {
  width: 720px !important;
  max-width: none;
}

.diagram figcaption {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
  font-style: italic;
}

/* ── RESPONSIVE ───────────────────────── */

@media (max-width: 640px) {
  .insight-grid     { grid-template-columns: 1fr; }
  .insight-divider  { text-align: left; }
  .page-cards       { grid-template-columns: 1fr; }
  .quad-grid        { grid-template-columns: 1fr; }
  .component        { grid-template-columns: 36px 1fr; }
  .loop-outcomes    { grid-template-columns: 1fr; gap: 12px; }
  .loop-fan         { display: none; }
  .outcome          { flex-direction: row; justify-content: space-between; align-items: center; }
  .outcome-node     { width: auto; }
  .role-table tbody td:first-child { width: auto; }
  .novel-list li    { padding-left: 32px; }
  .nav-links .nav-link { padding: 0 10px; font-size: 12px; }
}
