/* ── Reset & base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f4f1ea;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --panel: #fffdf8;
  --line: #2a2a2a;
  --edge: #8a8578;
  --node: #fff;
  --node-stroke: #1a1a1a;

  --poly: #c45c26;
  --poly-soft: #f3d9c8;
  --typeops: #2a6f6f;
  --typeops-soft: #c8e4e4;
  --dep: #3d4f9c;
  --dep-soft: #d0d6ef;

  --active: #1a1a1a;
  --disabled: #b8b4a8;

  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", "Menlo", "Consolas", monospace;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────── */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  max-width: 42rem;
}

.main {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 1.1fr);
  gap: 1.5rem;
  margin-top: 1.5rem;
  align-items: start;
}

@media (max-width: 860px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* ── Viz panel ────────────────────────────────────────────── */
.viz-panel {
  position: sticky;
  top: 0.75rem;
}

.cube-stage {
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 1rem 1rem 1.15rem;
}

.axis-legend {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
}

.axis-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.axis-item .swatch {
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  flex-shrink: 0;
}

.axis-item.poly .swatch { background: var(--poly); }
.axis-item.typeops .swatch { background: var(--typeops); }
.axis-item.dep .swatch { background: var(--dep); }

/* ── Cube SVG ─────────────────────────────────────────────── */
.cube-wrap {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  user-select: none;
}

#cube-svg {
  width: 100%;
  height: auto;
  display: block;
}

.edges line {
  stroke: var(--edge);
  stroke-width: 2;
  fill: none;
}

.edges line.active-edge {
  stroke-width: 3.5;
}

.edges line.poly-edge.active-edge { stroke: var(--poly); }
.edges line.typeops-edge.active-edge { stroke: var(--typeops); }
.edges line.dep-edge.active-edge { stroke: var(--dep); }

.edges line.travel-edge {
  stroke-width: 4.5;
  stroke-dasharray: 6 4;
  animation: dash-move 0.6s linear infinite;
}

@keyframes dash-move {
  to { stroke-dashoffset: -20; }
}

.axis-arrows text {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  fill: var(--muted);
}

.axis-arrows .arrow-poly { fill: var(--poly); stroke: var(--poly); }
.axis-arrows .arrow-typeops { fill: var(--typeops); stroke: var(--typeops); }
.axis-arrows .arrow-dep { fill: var(--dep); stroke: var(--dep); }

.node {
  cursor: pointer;
}

.node circle {
  fill: var(--node);
  stroke: var(--node-stroke);
  stroke-width: 2;
  transition: r 0.15s ease, fill 0.15s ease;
}

.node:hover circle {
  r: 14;
}

.node.selected circle {
  fill: var(--ink);
  stroke: var(--ink);
  r: 15;
}

.node.selected text.label {
  fill: #fff;
  font-weight: 700;
}

.node text.label {
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--ink);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

.node text.caption {
  font-family: var(--font);
  font-size: 10px;
  fill: var(--muted);
  pointer-events: none;
  text-anchor: middle;
}

.node.reachable:not(.selected) circle {
  stroke-width: 2.5;
}

.node.poly-on:not(.selected) circle { stroke: var(--poly); }
.node.typeops-on:not(.selected) circle { stroke: var(--typeops); }
.node.dep-on:not(.selected) circle { stroke: var(--dep); }
/* multi-feature corners get a thicker dark ring via stroke */
.node.multi:not(.selected) circle {
  stroke: var(--ink);
  stroke-width: 2.5;
}

/* ── Nav pad ──────────────────────────────────────────────── */
.nav-pad {
  margin-top: 0.75rem;
  border-top: 1px solid #d8d2c4;
  padding-top: 0.85rem;
}

.nav-hint {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.55rem 0.65rem;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}

.nav-btn:hover:not(:disabled) {
  background: #f0ebe0;
}

.nav-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.nav-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.nav-btn .dir {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
}

.nav-btn .label {
  font-size: 0.82rem;
  font-weight: 650;
}

.nav-btn .sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.nav-btn.poly { border-left: 5px solid var(--poly); }
.nav-btn.typeops { border-left: 5px solid var(--typeops); }
.nav-btn.dep { border-left: 5px solid var(--dep); }

/* ── Detail panel ─────────────────────────────────────────── */
.detail-panel {
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 1.15rem 1.25rem 1.4rem;
  min-height: 28rem;
}

.corner-badge {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.85rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--line);
}

.sys-name {
  font-family: var(--mono);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.sys-aka {
  font-size: 1.05rem;
  color: var(--muted);
}

.feature-bits {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

/* ── Dependency matrix ────────────────────────────────────── */
.matrix-section {
  margin-bottom: 1.15rem;
}

.matrix-intro {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.dep-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  border: 2px solid var(--line);
}

.dep-matrix th,
.dep-matrix td {
  border: 1px solid #cfc8b8;
  padding: 0.45rem 0.5rem;
  vertical-align: top;
  text-align: left;
}

.dep-matrix thead th {
  background: #f0ebe0;
  font-weight: 650;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.dep-matrix tbody th {
  background: #f0ebe0;
  font-weight: 650;
  width: 5.5rem;
  font-size: 0.78rem;
}

.dep-matrix .cell {
  background: #f7f3ea;
  opacity: 0.55;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.dep-matrix .cell.always {
  opacity: 1;
  background: #eeebe3;
}

.dep-matrix .cell.on {
  opacity: 1;
}

.dep-matrix .cell.poly.on {
  background: var(--poly-soft);
  box-shadow: inset 3px 0 0 var(--poly);
}

.dep-matrix .cell.typeops.on {
  background: var(--typeops-soft);
  box-shadow: inset 3px 0 0 var(--typeops);
}

.dep-matrix .cell.dep.on {
  background: var(--dep-soft);
  box-shadow: inset 3px 0 0 var(--dep);
}

.dep-matrix .cell-title {
  display: block;
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 0.15rem;
}

.dep-matrix .cell-body {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.dep-matrix .cell.on .cell-body {
  color: var(--ink);
}

.dep-matrix code {
  font-family: var(--mono);
  font-size: 0.74rem;
  background: rgba(0, 0, 0, 0.05);
  padding: 0.05rem 0.2rem;
}

.bit {
  font-size: 0.75rem;
  font-weight: 650;
  padding: 0.2rem 0.5rem;
  border: 2px solid var(--line);
  background: #eeebe3;
  color: var(--muted);
}

.bit.on.poly {
  background: var(--poly-soft);
  color: var(--poly);
  border-color: var(--poly);
}

.bit.on.typeops {
  background: var(--typeops-soft);
  color: var(--typeops);
  border-color: var(--typeops);
}

.bit.on.dep {
  background: var(--dep-soft);
  color: var(--dep);
  border-color: var(--dep);
}

.transition-banner {
  margin-bottom: 1rem;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--line);
  background: #f7f3ea;
  animation: fade-in 0.35s ease;
}

.transition-banner[hidden] {
  display: none;
}

.transition-axis {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.transition-banner.poly .transition-axis { color: var(--poly); }
.transition-banner.typeops .transition-axis { color: var(--typeops); }
.transition-banner.dep .transition-axis { color: var(--dep); }

.transition-banner.poly { border-color: var(--poly); background: var(--poly-soft); }
.transition-banner.typeops { border-color: var(--typeops); background: var(--typeops-soft); }
.transition-banner.dep { border-color: var(--dep); background: var(--dep-soft); }

.transition-text {
  margin: 0;
  font-size: 0.95rem;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section {
  margin-bottom: 1.15rem;
}

.section h2 {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.section .muted {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
}

.blurb {
  margin: 0;
  font-size: 0.98rem;
}

.axis-gains {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.axis-gains li {
  padding: 0.5rem 0.65rem;
  border-left: 4px solid var(--line);
  background: #f7f3ea;
  font-size: 0.9rem;
}

.axis-gains li.poly { border-color: var(--poly); }
.axis-gains li.typeops { border-color: var(--typeops); }
.axis-gains li.dep { border-color: var(--dep); }

.axis-gains li strong {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.15rem;
}

.axis-gains .empty {
  color: var(--muted);
  font-style: italic;
  border-left-color: #ccc;
  background: transparent;
}

.code-intro {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.lean-code {
  margin: 0;
  padding: 0.85rem 0.95rem;
  background: #1e1e1c;
  color: #e8e4d9;
  border: 2px solid var(--line);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre;
}

.lean-code .kw { color: #c792ea; }
.lean-code .ty { color: #82aaff; }
.lean-code .fn { color: #c3e88d; }
.lean-code .cm { color: #6a6a60; }
.lean-code .st { color: #c3e88d; }
.lean-code .num { color: #f78c6c; }

.code-note {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.contrast {
  border-top: 1px solid #d8d2c4;
  padding-top: 0.9rem;
}

.contrast p {
  margin: 0;
  font-size: 0.92rem;
}

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #cfc8b8;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 52rem;
}

.footer p {
  margin: 0;
}
