:root {
  --bg: #07111f;
  --panel: #101c31;
  --panel-2: #14243e;
  --ink: #f7fbff;
  --muted: #9fb0c8;
  --line: rgba(186, 205, 236, 0.18);
  --green: #3fdb83;
  --green-soft: rgba(63, 219, 131, 0.14);
  --red: #ff6878;
  --red-soft: rgba(255, 104, 120, 0.14);
  --blue: #66aaff;
  --blue-soft: rgba(102, 170, 255, 0.14);
  --gold: #ffd166;
  --gold-soft: rgba(255, 209, 102, 0.14);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.14);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 0%, rgba(102, 170, 255, 0.2), transparent 34rem),
    radial-gradient(circle at 94% 0%, rgba(167, 139, 250, 0.2), transparent 34rem),
    linear-gradient(135deg, #050914 0%, #08172b 55%, #06101d 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button {
  font: inherit;
}

.page {
  width: min(1500px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.topbar,
.stage,
.problem-card,
.method-contrast,
.artifact-replay,
.tree-card,
.panel,
.source-note {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(16, 28, 49, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  padding: 28px;
}

.language-toggle {
  display: inline-flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
}

.language-toggle button {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.language-toggle button.active {
  background: linear-gradient(135deg, var(--gold), var(--purple));
  color: #06101d;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.1rem, 4vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.07em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
  line-height: 1.15;
  letter-spacing: -0.035em;
}

h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.controls {
  display: flex;
  gap: 10px;
}

.controls button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 18px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  cursor: pointer;
}

.controls button:last-child {
  border: 0;
  background: linear-gradient(135deg, var(--purple), #55d5ff);
  color: #06101d;
  font-weight: 900;
}

.controls button.secondary {
  border-color: rgba(167, 139, 250, 0.42);
  background: var(--purple-soft);
  color: #efeaff;
  font-weight: 850;
}

.controls button.secondary.playing {
  border-color: rgba(255, 209, 102, 0.75);
  background: var(--gold-soft);
  color: #fff2c7;
}

.controls button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 22px 24px;
}

.demo-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.visual-area {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.stage-control-stack {
  display: grid;
  gap: 12px;
  justify-items: end;
}

#stage-copy {
  max-width: 840px;
  margin: 10px 0 0;
  color: var(--muted);
}

.dots {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stage-progress {
  grid-column: 1 / -1;
  overflow: hidden;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.stage-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--purple), var(--blue));
}

.stage-progress span.playing {
  animation: autoplay-progress 3.6s linear forwards;
}

@keyframes autoplay-progress {
  from {
    width: 0%;
  }

  to {
    width: 100%;
  }
}

.dot {
  width: 14px;
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.dot.active {
  border-color: var(--gold);
  background: var(--gold);
}

.problem-card {
  position: sticky;
  top: 16px;
  padding: 24px;
}

.problem-text {
  max-width: 100%;
  margin-bottom: 18px;
  color: #edf4ff;
  font-size: 1.02rem;
}

.katex {
  font-size: 1.03em;
  white-space: nowrap;
}

.tree-card-node .katex {
  font-size: 0.96em;
}

.trace .katex-display,
.node-popover .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

.answer-row {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(63, 219, 131, 0.35);
  border-radius: 999px;
  padding: 9px 14px;
  background: var(--green-soft);
}

.answer-row span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.answer-row strong {
  color: #dfffe9;
  font-size: 1.05rem;
}

.method-contrast {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 14px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.08), transparent 38%),
    rgba(16, 28, 49, 0.92);
}

.takeaway-banner {
  border: 1px solid rgba(255, 209, 102, 0.24);
  border-radius: 20px;
  padding: 18px;
  background: rgba(255, 209, 102, 0.075);
}

.takeaway-banner h2 {
  margin-bottom: 8px;
  font-size: clamp(1.45rem, 2.1vw, 2.2rem);
}

.takeaway-banner p:last-child {
  margin-bottom: 0;
  color: #e8f0ff;
  font-size: 1rem;
}

.signal-ledger {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ledger-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.045);
  transition:
    border-color 180ms ease,
    background 180ms ease,
    transform 180ms ease;
}

.ledger-card.active {
  transform: translateY(-2px);
}

.ledger-card.mcts.active {
  border-color: rgba(255, 104, 120, 0.42);
  background: var(--red-soft);
}

.ledger-card.crps.active {
  border-color: rgba(63, 219, 131, 0.42);
  background: var(--green-soft);
}

.ledger-label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ledger-card strong {
  display: block;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.24;
}

.artifact-replay {
  padding: 18px;
}

.artifact-head {
  display: flex;
  gap: 18px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.artifact-head h2 {
  font-size: clamp(1.1rem, 1.5vw, 1.35rem);
}

.artifact-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.artifact-block {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  overflow: hidden;
}

.artifact-block.full {
  grid-column: 1 / -1;
}

.artifact-block.green {
  border-color: rgba(63, 219, 131, 0.35);
}

.artifact-block.red {
  border-color: rgba(255, 104, 120, 0.35);
}

.artifact-block.purple {
  border-color: rgba(167, 139, 250, 0.35);
}

.artifact-block.blue {
  border-color: rgba(102, 170, 255, 0.35);
}

.artifact-block h3 {
  margin: 0;
  border-bottom: 1px solid var(--line);
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.045);
  font-size: 0.9rem;
}

.artifact-block pre {
  max-height: 230px;
  margin: 0;
  padding: 13px;
  overflow: auto;
  color: #e2eafb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
}

.comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.tree-card {
  position: relative;
  padding: 22px 24px 18px;
}

.tree-head {
  display: flex;
  gap: 18px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.tree-mode {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

#trajectory-tree {
  display: block;
  width: 100%;
  min-height: 620px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    rgba(4, 9, 18, 0.55);
  background-size: 32px 32px;
  cursor: grab;
}

#trajectory-tree:active {
  cursor: grabbing;
}

.tree-link,
.join-link {
  fill: none;
  stroke-linecap: round;
  transition:
    opacity 180ms ease,
    stroke-width 180ms ease,
    filter 180ms ease;
}

.tree-link {
  stroke: rgba(159, 176, 200, 0.72);
  stroke-width: 3;
}

.join-link {
  stroke: var(--purple);
  stroke-width: 3.5;
  stroke-dasharray: 10 8;
}

.edge-chip {
  paint-order: stroke;
  stroke: rgba(4, 9, 18, 0.9);
  stroke-width: 5px;
  fill: #dbe6f8;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.tree-card-node {
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 15px;
  background: rgba(13, 24, 43, 0.96);
  box-shadow: 0 16px 35px rgba(0, 0, 0, 0.28);
  color: var(--ink);
  overflow: hidden;
}

.tree-card-node.root {
  border-color: rgba(255, 209, 102, 0.6);
  background: linear-gradient(135deg, var(--gold-soft), rgba(13, 24, 43, 0.96));
}

.tree-card-node.shared {
  border-color: rgba(102, 170, 255, 0.55);
  background: linear-gradient(135deg, var(--blue-soft), rgba(13, 24, 43, 0.96));
}

.tree-card-node.positive {
  border-color: rgba(63, 219, 131, 0.58);
  background: linear-gradient(135deg, var(--green-soft), rgba(13, 24, 43, 0.96));
}

.tree-card-node.negative {
  border-color: rgba(255, 104, 120, 0.58);
  background: linear-gradient(135deg, var(--red-soft), rgba(13, 24, 43, 0.96));
}

.tree-card-node.synthesis {
  border-color: rgba(167, 139, 250, 0.62);
  background: linear-gradient(135deg, var(--purple-soft), rgba(13, 24, 43, 0.96));
}

.tree-card-node strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.98rem;
  line-height: 1.15;
}

.tree-card-node > span {
  display: block;
  color: #dce6f8;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: normal;
  word-break: normal;
}

.tree-card-node .formula-line {
  display: block;
  margin-top: 7px;
}

.tree-card-node em {
  display: inline-flex;
  margin-top: 8px;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.09);
  color: var(--gold);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 950;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.d3-node {
  cursor: pointer;
  transition: opacity 180ms ease;
}

.d3-node.important .tree-card-node {
  border-color: #fff;
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.32),
    0 0 0 2px rgba(255, 255, 255, 0.3),
    0 0 30px rgba(255, 255, 255, 0.16);
}

.d3-faded {
  opacity: 0.12;
}

.d3-muted {
  opacity: 0.35;
}

.node-popover {
  position: absolute;
  z-index: 20;
  width: min(380px, calc(100% - 48px));
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 18px;
  padding: 16px;
  background: rgba(8, 14, 27, 0.96);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  backdrop-filter: blur(16px);
}

.node-popover.hidden {
  display: none;
}

.popover-head {
  display: flex;
  gap: 12px;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.popover-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.popover-close {
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  cursor: pointer;
}

.popover-badge {
  display: inline-flex;
  margin-bottom: 12px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--purple-soft);
  color: #efeaff;
  font-size: 0.7rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.popover-section {
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

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

.popover-section p {
  margin-bottom: 0;
  color: #dfe8f8;
  font-size: 0.92rem;
}

.tree-edge {
  fill: none;
  stroke-linecap: round;
  transition:
    opacity 180ms ease,
    stroke 180ms ease,
    stroke-width 180ms ease;
}

.tree-node {
  transition: opacity 180ms ease;
}

.tree-node rect {
  transition:
    fill 180ms ease,
    stroke 180ms ease,
    stroke-width 180ms ease,
    filter 180ms ease;
}

.tree-node text,
.tree-edge-label {
  pointer-events: none;
  user-select: none;
}

.tree-node .node-title {
  fill: var(--ink);
  font-size: 16px;
  font-weight: 900;
}

.tree-node .node-body {
  fill: #dce6f7;
  font-size: 14px;
  font-weight: 650;
}

.tree-edge-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.tree-faded {
  opacity: 0.14;
}

.tree-muted {
  opacity: 0.42;
}

.tree-important rect {
  stroke: #fff;
  stroke-width: 3;
  filter: drop-shadow(0 0 18px rgba(255, 255, 255, 0.28));
}

.tree-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.tree-legend span {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.tree-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.tree-legend .green {
  background: var(--green);
}

.tree-legend .red {
  background: var(--red);
}

.tree-legend .purple {
  background: var(--purple);
}

.panel {
  overflow: hidden;
}

.panel-head {
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.process {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 18px;
}

.step {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.step.active {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.075);
  color: var(--ink);
}

.step.current {
  border-color: rgba(255, 209, 102, 0.72);
  background: var(--gold-soft);
}

.step strong {
  display: block;
  margin-bottom: 5px;
  font-size: 0.92rem;
}

.step span {
  display: block;
  font-size: 0.82rem;
}

.output {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.empty,
.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.045);
}

.empty {
  display: grid;
  min-height: 270px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.card.green {
  border-color: rgba(63, 219, 131, 0.35);
  background: linear-gradient(135deg, var(--green-soft), rgba(255, 255, 255, 0.04));
}

.card.red {
  border-color: rgba(255, 104, 120, 0.35);
  background: linear-gradient(135deg, var(--red-soft), rgba(255, 255, 255, 0.04));
}

.card.blue {
  border-color: rgba(102, 170, 255, 0.35);
  background: linear-gradient(135deg, var(--blue-soft), rgba(255, 255, 255, 0.04));
}

.card.purple {
  border-color: rgba(167, 139, 250, 0.35);
  background: linear-gradient(135deg, var(--purple-soft), rgba(255, 255, 255, 0.04));
}

.card h3 {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tag.green {
  color: #dfffe9;
  background: var(--green-soft);
}

.tag.red {
  color: #ffe0e4;
  background: var(--red-soft);
}

.tag.blue {
  color: #dcecff;
  background: var(--blue-soft);
}

.tag.purple {
  color: #efeaff;
  background: var(--purple-soft);
}

.trace {
  margin: 0;
  color: #e2eafb;
  white-space: pre-wrap;
}

.trace.compact {
  max-height: 260px;
  overflow: auto;
}

.key-point {
  margin: 0;
  color: #e8f0ff;
}

.source-note {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  padding: 16px 18px;
  color: var(--muted);
}

code {
  color: #e7ddff;
}

@media (max-width: 1050px) {
  .topbar,
  .stage,
  .comparison {
    grid-template-columns: 1fr;
  }

  .demo-layout {
    grid-template-columns: 1fr;
  }

  .method-contrast,
  .artifact-content,
  .signal-ledger {
    grid-template-columns: 1fr;
  }

  .visual-area {
    order: 1;
  }

  .problem-card {
    position: static;
    order: 2;
  }

  .topbar,
  .source-note {
    display: block;
  }

  .language-toggle {
    margin-top: 16px;
  }

  .topbar .controls {
    margin-top: 16px;
  }

  .stage-control-stack,
  .dots {
    justify-items: start;
    justify-content: flex-start;
  }

  .process {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 650px) {
  .page {
    width: min(100vw - 24px, 1280px);
    padding-top: 16px;
  }

  .topbar,
  .stage,
  .problem-card {
    padding: 18px;
  }

  .process {
    grid-template-columns: 1fr;
  }
}
