/* ═══════════════════════════════════════════
   Houston Engine Design — Mirrors learn/style.css
   ═══════════════════════════════════════════ */

:root {
  --background: #ffffff;
  --foreground: #0d0d0d;
  --secondary: #f9f9f9;
  --muted-foreground: #5d5d5d;
  --border: #e5e5e5;
  --gray-50: #f9f9f9;
  --gray-100: #ececec;
  --gray-200: #e3e3e3;
  --gray-300: #cdcdcd;
  --gray-400: #b4b4b4;
  --gray-500: #9b9b9b;
  --gray-600: #676767;
  --gray-700: #424242;
  --gray-900: #1a1a1a;
  --gray-950: #0d0d0d;
  --success: #00a240;
  --info: #2964aa;
  --warning: #e0ac00;
  --danger: #e02e2a;
  --border-light: rgba(13, 13, 13, 0.05);
  --border-medium: rgba(0, 0, 0, 0.12);
  --border-heavy: rgba(13, 13, 13, 0.15);
}

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

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.6;
  padding-top: 65px;
}

code, .mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

a { color: inherit; text-decoration: none; }

/* ─── Top nav ─── */
nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 16px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
}

.nav-logo {
  font-family: 'General Sans', sans-serif;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--gray-950);
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-logo .nav-sub {
  font-size: 14px;
  color: var(--gray-500);
  font-weight: 400;
  margin-left: 4px;
}

.nav-right {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 14px;
  color: var(--gray-600);
}

@media (max-width: 700px) {
  nav { padding: 16px 20px; }
  .nav-logo .nav-sub { display: none; }
}

/* ─── Layout ─── */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  max-width: 1280px;
  margin: 0 auto;
  gap: 48px;
  padding: 48px 32px 120px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 32px 24px 80px;
  }
}

/* ─── Sidebar ─── */
.sidebar {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding-right: 8px;
}

@media (max-width: 900px) {
  .sidebar {
    position: static;
    max-height: none;
    margin-bottom: 32px;
    padding-right: 0;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-light);
  }
}

.sidebar-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  margin-bottom: 12px;
  padding: 0 10px;
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--gray-700);
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.sidebar-nav a:hover {
  background: var(--gray-50);
  color: var(--gray-950);
}

.sidebar-nav a.active {
  background: var(--gray-100);
  color: var(--gray-950);
  font-weight: 500;
}

.sidebar-nav .num {
  color: var(--gray-400);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  min-width: 18px;
}

.sidebar-nav a.active .num {
  color: var(--gray-600);
}

.sidebar-nav .sb-status {
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sidebar-nav .sb-status.shipped { background: var(--success); }
.sidebar-nav .sb-status.partial { background: var(--warning); }
.sidebar-nav .sb-status.progress { background: var(--info); }
.sidebar-nav .sb-status.planned { background: var(--gray-300); }

/* ─── Content ─── */
.content {
  max-width: 880px;
  min-width: 0;
}

.content-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.content h1 {
  font-size: clamp(32px, 4vw, 44px);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--gray-950);
  margin-bottom: 20px;
}

.content .lead {
  font-size: 19px;
  line-height: 1.55;
  color: var(--muted-foreground);
  margin-bottom: 48px;
  max-width: 640px;
}

.content h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  color: var(--gray-950);
  margin-top: 56px;
  margin-bottom: 16px;
  scroll-margin-top: 88px;
}
.content h2:first-of-type { margin-top: 0; }

.content h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--gray-950);
  margin-top: 32px;
  margin-bottom: 10px;
}

.content p {
  font-size: 16px;
  line-height: 1.65;
  color: var(--gray-700);
  margin-bottom: 16px;
}
.content p strong { color: var(--gray-950); font-weight: 600; }

.content ul, .content ol {
  margin-bottom: 20px;
  padding-left: 22px;
  color: var(--gray-700);
}

.content li { margin-bottom: 8px; line-height: 1.65; }
.content li::marker { color: var(--gray-400); }

.content code {
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--gray-950);
}

.content pre {
  background: var(--gray-950);
  color: #f0f0f0;
  padding: 20px 24px;
  border-radius: 12px;
  overflow-x: auto;
  margin-bottom: 24px;
  font-size: 14px;
  line-height: 1.6;
}

.content pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 14px;
}

/* ─── Status pills ─── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.status.shipped {
  background: color-mix(in oklch, var(--success) 12%, white);
  color: var(--success);
}
.status.shipped::before { background: var(--success); }
.status.partial {
  background: color-mix(in oklch, var(--warning) 14%, white);
  color: #a07b00;
}
.status.partial::before { background: var(--warning); }
.status.progress {
  background: color-mix(in oklch, var(--info) 12%, white);
  color: var(--info);
}
.status.progress::before { background: var(--info); }
.status.planned {
  background: var(--gray-100);
  color: var(--gray-600);
}
.status.planned::before { background: var(--gray-400); }

/* ─── On-this-page TOC ─── */
.toc {
  background: var(--gray-50);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 48px;
}

.toc-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  margin-bottom: 12px;
}

.toc ol { list-style: none; padding: 0; counter-reset: toc; margin: 0; }
.toc li {
  counter-increment: toc;
  margin-bottom: 6px;
  font-size: 14px;
  padding-left: 0;
}
.toc li::marker { color: transparent; }
.toc li::before {
  content: counter(toc) ".";
  color: var(--gray-400);
  margin-right: 10px;
  font-variant-numeric: tabular-nums;
}
.toc a { color: var(--gray-700); transition: color 0.15s; }
.toc a:hover { color: var(--gray-950); text-decoration: underline; text-underline-offset: 3px; }

/* ─── Callouts ─── */
.callout {
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 24px 0;
  background: var(--gray-50);
}
.callout-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}
.callout p { margin-bottom: 0; font-size: 15px; color: var(--gray-700); }
.callout p + p { margin-top: 10px; }

.callout-info {
  background: color-mix(in oklch, var(--info) 6%, white);
  border-color: color-mix(in oklch, var(--info) 20%, transparent);
}
.callout-info .callout-label { color: var(--info); }

.callout-warning {
  background: color-mix(in oklch, var(--warning) 6%, white);
  border-color: color-mix(in oklch, var(--warning) 20%, transparent);
}
.callout-warning .callout-label { color: var(--warning); }

.callout-success {
  background: color-mix(in oklch, var(--success) 6%, white);
  border-color: color-mix(in oklch, var(--success) 20%, transparent);
}
.callout-success .callout-label { color: var(--success); }

.callout-danger {
  background: color-mix(in oklch, var(--danger) 6%, white);
  border-color: color-mix(in oklch, var(--danger) 20%, transparent);
}
.callout-danger .callout-label { color: var(--danger); }

/* ─── Diagrams ─── */
.diagram {
  background: var(--gray-50);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 28px 24px 24px;
  margin: 32px 0;
  overflow-x: auto;
}
.diagram .caption {
  color: var(--gray-500);
  font-size: 13px;
  margin-top: 18px;
  text-align: center;
}

/* Host-runtime grid (Ch3) */
.host-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.host-card {
  background: white;
  border: 1px solid var(--border-medium);
  border-radius: 12px;
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.host-card .host-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-500);
}
.host-card .runtime-pill {
  font-size: 13px;
  color: var(--gray-700);
  padding: 7px 12px;
  background: var(--gray-50);
  border-radius: 8px;
  border: 1px dashed var(--border-medium);
  text-align: center;
}
.host-card .engine-pill {
  background: var(--gray-950);
  color: white;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.005em;
}
.host-card .engine-pill .engine-sub {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
  font-weight: 400;
}

/* Deployment grid (Ch10) — vertical flow per column */
.deploy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.deploy-col {
  background: white;
  border: 1px solid var(--border-medium);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deploy-col .deploy-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-500);
  margin-bottom: 6px;
}
.deploy-col .deploy-layer {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  background: var(--gray-50);
  border: 1px solid var(--border-light);
  color: var(--gray-700);
}
.deploy-col .deploy-layer.engine {
  background: var(--gray-950);
  border-color: var(--gray-950);
  color: white;
  font-weight: 600;
}
.deploy-col .deploy-arrow {
  text-align: center;
  color: var(--gray-300);
  font-size: 14px;
  line-height: 1;
}

/* Flow steps (replaces sequence diagram) */
.flow-list {
  margin: 32px 0;
  display: grid;
  gap: 8px;
}
.flow-step {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 16px;
  padding: 14px 18px;
  background: white;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  align-items: start;
}
.flow-step .num {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-400);
  font-variant-numeric: tabular-nums;
  padding-top: 4px;
}
.flow-step .from-to {
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 4px;
  letter-spacing: 0.01em;
}
.flow-step .from-to .actor {
  font-weight: 600;
  color: var(--gray-700);
}
.flow-step .from-to .arrow {
  margin: 0 6px;
  color: var(--gray-400);
}
.flow-step .action {
  font-size: 14.5px;
  color: var(--gray-950);
  line-height: 1.5;
}
.flow-step .action code { font-size: 13px; }
.flow-step.db-write {
  background: color-mix(in oklch, var(--success) 5%, white);
  border-color: color-mix(in oklch, var(--success) 18%, transparent);
}
.flow-step.db-write .num { color: var(--success); }
.flow-step.db-write .from-to .actor.db { color: var(--success); }
.flow-loop {
  border: 1.5px dashed var(--border-medium);
  border-radius: 12px;
  padding: 14px;
  background: var(--gray-50);
  display: grid;
  gap: 8px;
}
.flow-loop-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-600);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 2px;
  padding-left: 4px;
}

/* HTML/CSS stack diagram */
.stack {
  display: grid;
  gap: 12px;
  max-width: 460px;
  margin: 32px auto;
}
.stack-layer {
  padding: 22px 24px;
  border-radius: 10px;
  text-align: left;
  background: white;
  border: 1px solid var(--border-medium);
}
.stack-layer .name {
  font-weight: 700;
  font-size: 17px;
  margin-bottom: 4px;
  color: var(--gray-950);
}
.stack-layer .desc {
  font-size: 14px;
  color: var(--gray-600);
}
.stack-layer.top { border-top: 3px solid var(--info); }
.stack-layer.mid { border-top: 3px solid var(--success); }
.stack-layer.bot { border-top: 3px solid var(--warning); }

/* Walls (isolation diagram) */
.walls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  margin: 32px 0;
  align-items: stretch;
}
.agent-col {
  background: white;
  border: 1px solid var(--border-medium);
  border-radius: 12px;
  padding: 24px;
}
.agent-col h4 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--gray-950);
  font-weight: 600;
}
.agent-col ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--gray-600);
}
.agent-col ul li { margin-bottom: 4px; }
.wall {
  position: relative;
  width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
}
.wall::before, .wall::after {
  content: '';
  position: absolute;
  width: 3px;
  background: repeating-linear-gradient(0deg, var(--danger) 0 8px, transparent 8px 14px);
  top: 0;
  bottom: 0;
}
.wall::before { left: 22px; }
.wall::after { right: 22px; }
@media (max-width: 700px) {
  .walls { grid-template-columns: 1fr; gap: 12px; }
  .wall { width: 100%; height: 36px; }
  .wall::before, .wall::after { width: auto; height: 3px; left: 0; right: 0; bottom: auto; }
  .wall::before { top: 16px; background: repeating-linear-gradient(90deg, var(--danger) 0 8px, transparent 8px 14px); }
  .wall::after { top: 22px; background: repeating-linear-gradient(90deg, var(--danger) 0 8px, transparent 8px 14px); }
}

/* Failure cards (a row of small problem callouts) */
.fail-grid {
  display: grid;
  gap: 12px;
  margin: 24px 0;
}
.fail-card {
  background: color-mix(in oklch, var(--danger) 5%, white);
  border: 1px solid color-mix(in oklch, var(--danger) 18%, transparent);
  border-left: 3px solid var(--danger);
  border-radius: 10px;
  padding: 16px 20px;
}
.fail-card .label {
  font-size: 11px;
  font-weight: 700;
  color: var(--danger);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.fail-card p { margin: 0; font-size: 14px; color: var(--gray-700); }
.fail-card strong { color: var(--gray-950); }

/* Tech detail box */
.tech-box {
  background: var(--gray-50);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--gray-400);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 24px 0;
  font-size: 13.5px;
  color: var(--gray-600);
}
.tech-box .label {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.tech-box code { font-size: 12.5px; background: white; }

/* ─── Tables ─── */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-light);
  font-size: 14px;
}
.content th {
  text-align: left;
  padding: 12px 16px;
  background: var(--gray-50);
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-light);
}
.content td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  color: var(--gray-700);
}
.content tr:last-child td { border-bottom: none; }
.content td code { font-size: 12.5px; }

/* ─── Index page bits ─── */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 48px;
}
@media (max-width: 700px) { .chapter-grid { grid-template-columns: 1fr; } }

.chapter-card {
  display: block;
  padding: 22px 24px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  background: white;
  transition: border-color 0.15s, box-shadow 0.2s, transform 0.15s;
}
.chapter-card:hover {
  border-color: var(--border-medium);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 24px rgba(0, 0, 0, 0.04);
  transform: translateY(-1px);
}
.chapter-card .chapter-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-400);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chapter-card .chapter-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-950);
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}
.chapter-card .chapter-desc {
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted-foreground);
}

.hero { padding-top: 24px; padding-bottom: 24px; }
.hero h1 {
  font-size: clamp(36px, 5vw, 52px);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 24px;
}
.hero .lead { font-size: 20px; margin-bottom: 36px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 22px;
  border-radius: 9999px;
  font-size: 15px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--gray-950); color: white; }
.btn-primary:hover { background: var(--gray-700); }
.btn-secondary { background: white; color: var(--gray-950); border: 1px solid var(--border-medium); }
.btn-secondary:hover { background: var(--gray-50); }

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

/* ─── Pager ─── */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 72px;
  padding-top: 32px;
  border-top: 1px solid var(--border-light);
}
.pager a {
  display: flex;
  flex-direction: column;
  padding: 18px 22px;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  transition: border-color 0.15s, background 0.15s;
}
.pager a:hover { border-color: var(--border-medium); background: var(--gray-50); }
.pager .pager-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 4px;
  font-weight: 500;
}
.pager .pager-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-950);
}
.pager .next { text-align: right; }
.pager .spacer { border: none; background: transparent; cursor: default; }
.pager .spacer:hover { background: transparent; border: none; }

/* ─── File tree ─── */
.tree {
  background: var(--gray-50);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 20px 24px;
  margin: 24px 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 13.5px;
  color: var(--gray-700);
  line-height: 1.75;
  white-space: pre;
  overflow-x: auto;
}
.tree .dir { color: var(--gray-950); font-weight: 600; }
.tree .comment { color: var(--gray-500); }

/* ─── Footer ─── */
.footer {
  border-top: 1px solid var(--border-light);
  padding: 32px;
  text-align: center;
  color: var(--gray-500);
  font-size: 13px;
}
