:root {
  --bg: #ffffff;
  --bg-alt: #f8fafc;
  --card: #ffffff;
  --card-border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #ea580c;
  --accent-light: #c2410c;
  --direct-color: #0284c7;
  --reasoning-color: #ea580c;
  --green: #059669;
  --rose: #e11d48;
  --code-bg: #f8fafc;
  --radius: 10px;
}

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

html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  max-width: 100%;
  overflow-x: hidden;
}

.container {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-light);
  text-decoration: underline;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(234, 88, 12, 0.1);
  color: #9a3412;
  padding: 2px 6px;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--card-border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  min-width: 0;
}

.brand-badge {
  background: var(--accent);
  color: #fff;
  padding: 3px 9px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.nav-toggle,
.nav-toggle-btn {
  display: none;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.88rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.topnav a {
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  padding: 4px 2px;
}

.topnav a:hover {
  color: var(--accent);
}

/* Hero */
.hero {
  padding: 64px 0 52px;
  border-bottom: 1px solid var(--card-border);
  background: radial-gradient(circle at 50% 0%, rgba(249, 115, 22, 0.1), transparent 65%);
}

.eyebrow {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 10px;
}

.hero-title {
  font-size: clamp(2.2rem, 4vw, 3.1rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  margin-bottom: 8px;
}

.hero-tagline {
  font-size: clamp(1.2rem, 2.2vw, 1.55rem);
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 16px;
}

.hero-body {
  max-width: 820px;
  color: #334155;
  font-size: 1.02rem;
  margin-bottom: 24px;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid var(--card-border);
  text-decoration: none;
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s;
}

.btn:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-light);
  color: #fff;
}

.btn-secondary {
  background: #fff7ed;
  border-color: #fed7aa;
  color: var(--accent-light);
}

.btn-secondary:hover {
  background: #ffedd5;
  color: #9a3412;
}

/* Sections */
#top {
  scroll-margin-top: 72px;
}

.section {
  padding: 52px 0;
  scroll-margin-top: 72px;
}

.section-alt {
  background: var(--bg-alt);
  border-top: 1px solid var(--card-border);
  border-bottom: 1px solid var(--card-border);
}

.section-eyebrow {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 4px;
}

.section h2 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.section-intro {
  max-width: 820px;
  color: var(--text-muted);
  font-size: 0.96rem;
  margin-bottom: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  min-width: 0;
  max-width: 100%;
}

/* Archetypes */
.archetype-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.archetype-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.archetype-header h3 {
  font-size: 1.05rem;
}

.tag {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.tag-green {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.tag-amber {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.tag-rose {
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
}

.synthetic-callout {
  margin-top: 8px;
}

.synthetic-header {
  margin-bottom: 14px;
}

.badge-synthetic {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fdba74;
  padding: 2px 9px;
  border-radius: 999px;
  margin-bottom: 6px;
}

.synthetic-header h3 {
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.synthetic-note {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Chart Card */
.chart-legend-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.88rem;
}

.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border-radius: 3px;
  flex-shrink: 0;
}

.swatch-reasoning {
  background: var(--reasoning-color);
}

.swatch-direct {
  background: var(--direct-color);
}

#two-conditions-svg,
#dream-rat-svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  background: var(--code-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
}

.chart-caption {
  margin-top: 12px;
  font-size: 0.86rem;
  color: var(--text-muted);
  padding: 10px 12px;
  background: #fff7ed;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.step-inspector {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
}

.inspector-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

#sample-step-slider {
  flex: 1;
  min-width: 180px;
  max-width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.inspector-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.inspector-pane {
  background: var(--code-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.verdict-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: #ffedd5;
  color: #9a3412;
  font-weight: 600;
  white-space: nowrap;
}

.canvas-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: #1e293b;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 92px;
}

/* Tables */
.table-card {
  padding: 0;
  overflow: hidden;
  margin-bottom: 14px;
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--card-border);
}

.data-table th {
  background: #f1f5f9;
  color: #334155;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table th.num,
.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.compact-table th,
.compact-table td {
  padding: 8px 12px;
}

.note-card {
  margin-bottom: 20px;
  font-size: 0.92rem;
  background: #fff7ed;
  border-left: 3px solid var(--accent);
}

.dream-rat-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 18px;
}

.dream-rat-grid h3 {
  font-size: 1.04rem;
  margin-bottom: 6px;
}

.sub-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Metrics & Install & Caveats */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 16px;
}

.metric-def-card h3 {
  font-size: 0.98rem;
  margin-bottom: 8px;
}

.metric-def-card p {
  font-size: 0.88rem;
  color: #334155;
}

.install-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 18px;
}

.install-grid h3 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.code-block {
  background: var(--code-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 14px;
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.84rem;
  line-height: 1.55;
}

.code-block code {
  background: transparent;
  color: #0f172a;
  padding: 0;
  overflow-wrap: anywhere;
}

.caveats-list {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.93rem;
}

/* Footer */
.footer {
  border-top: 1px solid var(--card-border);
  padding: 32px 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  background: #ffffff;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-status {
  margin-top: 4px;
  color: var(--accent-light);
  font-weight: 600;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

@media (max-width: 960px) {
  .brand-sub {
    display: none;
  }
}

@media (max-width: 820px) {
  .inspector-split,
  .dream-rat-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile phone layout (360 px - 760 px) */
@media (max-width: 760px) {
  .container {
    padding: 0 14px;
  }

  .hero {
    padding: 36px 0 32px;
  }

  .section {
    padding: 36px 0;
  }

  .card {
    padding: 14px;
  }

  /* Compact, non-overflowing sticky header with collapsible menu */
  .topbar-inner {
    min-height: 52px;
    padding-top: 8px;
    padding-bottom: 8px;
    flex-wrap: wrap;
  }

  .brand-sub {
    display: none;
  }

  .nav-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: 6px;
    border: 1px solid #fed7aa;
    background: #fff7ed;
    color: var(--accent-light);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
  }

  .topnav {
    display: none;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    padding: 10px 0 4px;
    margin-top: 6px;
    border-top: 1px solid var(--card-border);
  }

  .nav-toggle:checked ~ .topnav {
    display: grid;
  }

  .topnav a {
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--bg-alt);
    color: var(--text);
    font-size: 0.84rem;
    font-weight: 500;
  }

  /* Stacked card layout for wide multi-column tables (zero sideways scrolling) */
  .table-card {
    padding: 10px;
    background: var(--bg-alt);
  }

  #synthetic-table thead,
  #results-64-table thead {
    display: none;
  }

  #synthetic-table,
  #synthetic-table tbody,
  #results-64-table,
  #results-64-table tbody {
    display: block;
    width: 100%;
  }

  #synthetic-table tbody tr,
  #results-64-table tbody tr {
    display: block;
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  #synthetic-table tbody tr:last-child,
  #results-64-table tbody tr:last-child {
    margin-bottom: 0;
  }

  #synthetic-table tbody td,
  #results-64-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
    font-size: 0.85rem;
  }

  #synthetic-table tbody td:last-child,
  #results-64-table tbody td:last-child {
    border-bottom: none;
  }

  #synthetic-table tbody td::before,
  #results-64-table tbody td::before {
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  #synthetic-table tbody td:nth-child(1)::before { content: "Archetype"; }
  #synthetic-table tbody td:nth-child(2)::before { content: "Trajectories"; }
  #synthetic-table tbody td:nth-child(3)::before { content: "Final Accuracy"; }
  #synthetic-table tbody td:nth-child(4)::before { content: "Convergence Step"; }
  #synthetic-table tbody td:nth-child(5)::before { content: "Flip Rate"; }
  #synthetic-table tbody td:nth-child(6)::before { content: "Rationalization"; }

  #results-64-table tbody td:nth-child(1)::before { content: "Checkpoint"; }
  #results-64-table tbody td:nth-child(2)::before { content: "Task"; }
  #results-64-table tbody td:nth-child(3)::before { content: "Condition"; }
  #results-64-table tbody td:nth-child(4)::before { content: "n"; }
  #results-64-table tbody td:nth-child(5)::before { content: "Accuracy"; }
  #results-64-table tbody td:nth-child(6)::before { content: "Coverage"; }
  #results-64-table tbody td:nth-child(7)::before { content: "Cond. Accuracy"; }
  #results-64-table tbody td:nth-child(8)::before { content: "Mean Conv. Step"; }
  #results-64-table tbody td:nth-child(9)::before { content: "Notes"; }

  /* 3-column Dream rationalization table fits side-by-side cleanly */
  #dream-rat-table th,
  #dream-rat-table td {
    padding: 7px 8px;
    font-size: 0.81rem;
  }

  /* Trajectory SVG chart: >= 11px effective labels + every-32-step ticks on small screens */
  #two-conditions-svg text:nth-of-type(-n+3) {
    font-size: 24px !important;
    font-weight: 700 !important;
    text-anchor: start !important;
    transform: translate(12px, -14px);
  }

  #two-conditions-svg text:nth-of-type(5),
  #two-conditions-svg text:nth-of-type(7),
  #two-conditions-svg text:nth-of-type(9),
  #two-conditions-svg text:nth-of-type(11),
  #two-conditions-svg text:nth-of-type(13),
  #two-conditions-svg text:nth-of-type(15),
  #two-conditions-svg text:nth-of-type(17),
  #two-conditions-svg text:nth-of-type(19) {
    display: none;
  }

  #two-conditions-svg text:nth-of-type(n+4):nth-of-type(-n+20) {
    font-size: 23px !important;
    font-weight: 600;
  }

  #two-conditions-svg text:nth-of-type(21) {
    font-size: 23px !important;
    font-weight: 600;
  }

  /* Bar chart SVG: larger readable labels on phone */
  #dream-rat-svg text {
    font-size: 14px !important;
  }

  .code-block {
    padding: 11px;
    font-size: 0.79rem;
  }
}
