:root {
  --paper: oklch(0.985 0.002 80);
  --paper-deep: #f3efe7;
  --ink: rgba(42, 44, 56, 0.94);
  --muted: rgba(42, 44, 56, 0.68);
  --line: rgba(42, 44, 56, 0.12);
  --line-strong: rgba(42, 44, 56, 0.26);
  --panel: rgba(255, 252, 247, 0.52);
  --panel-strong: rgba(255, 255, 255, 0.82);
  --shadow: 0 10px 20px rgba(42, 44, 56, 0.04);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --body: "IBM Plex Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--body);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(250, 248, 243, 0.94)),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(42, 44, 56, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.018) 1px, transparent 1px),
    linear-gradient(rgba(42, 44, 56, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.045) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px, 128px 128px, 128px 128px;
  opacity: 0.42;
}

a {
  color: inherit;
}

.module-shell {
  width: min(1280px, calc(100vw - 28px));
  margin: 14px auto 36px;
}

.module-toolbar {
  position: sticky;
  top: 14px;
  z-index: 40;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 12px 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(250, 248, 243, 0.9));
  backdrop-filter: blur(18px);
  box-shadow: none;
}

.llm-page .module-toolbar {
  position: relative;
  top: auto;
}

.toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.toolbar-link,
.toolbar-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 252, 247, 0.84);
  color: var(--ink);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toolbar-button {
  appearance: none;
  cursor: pointer;
  font: inherit;
}

.toolbar-center {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.toolbar-title {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.toolbar-subtitle {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.module-main {
  display: grid;
  gap: 28px;
  margin-top: 24px;
}

.llm-info-panel[hidden] {
  display: none;
}

.llm-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 18px;
  padding: 0 16px 16px;
}

.llm-info-card {
  padding-top: 14px;
}

.llm-info-card p:last-child {
  margin-bottom: 0;
}

.panel,
.surface-panel,
.side-panel,
.stat-card,
.log-card {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.panel {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.08)),
    linear-gradient(rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.014) 1px, transparent 1px);
  background-size: auto, 26px 26px, 26px 26px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-panel .hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.78fr);
  gap: 20px;
  padding: 18px 0;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3.8vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: -0.05em;
}

.eyebrow,
.panel-label,
.metric-label,
.section-label {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero-copy p,
.hero-meta p,
.metric-note,
.log-card p,
.control-card p,
.summary-list li {
  color: var(--muted);
  line-height: 1.72;
}

.hero-copy p {
  max-width: 62ch;
}

.hero-copy .eyebrow {
  margin: 0 0 10px;
}

.hero-meta {
  display: grid;
  gap: 14px;
}

.meta-card,
.control-card,
.log-card,
.stat-card {
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
}

.meta-card h2,
.control-card h2,
.log-card h2 {
  margin: 6px 0 8px;
  font-size: 1rem;
  line-height: 1.2;
}

.meta-card p {
  margin: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 18px;
}

.stat-card {
  min-height: 0;
}

.metric-value {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: clamp(1.05rem, 2.5vw, 1.45rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric-note {
  margin-top: 4px;
  font-size: 0.88rem;
}

.workbench-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.surface-panel {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.llm-panel {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.08)),
    linear-gradient(rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.014) 1px, transparent 1px);
  background-size: auto, 26px 26px, 26px 26px;
}

.llm-panel .panel-head {
  padding: 12px 16px;
}

.llm-frame,
.llm-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
}

.graph-stage {
  position: relative;
  min-height: 510px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: pan-y pinch-zoom;
  background:
    linear-gradient(rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(rgba(42, 44, 56, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.04) 1px, transparent 1px),
    rgba(255, 255, 255, 0.4);
  background-size: 24px 24px, 24px 24px, 120px 120px, 120px 120px, auto;
}

.graph-stage svg {
  display: block;
  width: 100%;
  min-height: 510px;
}

.graph-stage.is-dragging {
  cursor: grabbing;
}

.llm-frame .graph-stage,
.llm-workbench .graph-stage {
  border-right: 1px solid var(--line);
}

.llm-sidebar {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 252, 247, 0.34);
}

.graphlab-panel {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.08)),
    linear-gradient(rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.014) 1px, transparent 1px);
  background-size: auto, 26px 26px, 26px 26px;
}

.graphlab-panel .panel-head {
  padding: 12px 16px;
}

.graphlab-frame {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}

.graphlab-visual-column {
  display: grid;
  grid-template-rows: auto auto;
  min-width: 0;
  border-right: 1px solid var(--line);
}

.graphlab-compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

.graphlab-graph-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.graphlab-graph-card + .graphlab-graph-card {
  border-left: 1px solid var(--line);
}

.graphlab-graph-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mini-graph-stage {
  min-height: 340px;
  background:
    linear-gradient(rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.014) 1px, transparent 1px),
    linear-gradient(rgba(42, 44, 56, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 44, 56, 0.04) 1px, transparent 1px),
    rgba(255, 255, 255, 0.4);
  background-size: 24px 24px, 24px 24px, 120px 120px, 120px 120px, auto;
}

.mini-graph-stage svg {
  display: block;
  width: 100%;
  height: 340px;
}

.graphlab-sidebar {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 252, 247, 0.34);
}

.graphlab-distribution-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr);
  gap: 0;
  border-top: 1px solid var(--line);
}

.graphlab-distribution-card {
  padding: 14px 16px 16px;
}

.graphlab-distribution-card + .graphlab-distribution-card {
  border-left: 1px solid var(--line);
}

.distribution-stage {
  min-height: 200px;
  margin-top: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.46);
}

.distribution-stage svg {
  display: block;
  width: 100%;
  height: 200px;
}

.graphlab-summary-card .summary-list {
  margin-top: 10px;
}

.compact-card {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.compact-card .panel-label {
  margin: 0 0 8px;
}

.side-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr));
  gap: 22px;
  padding: 0;
}

.sequence-side-panel {
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.2fr) minmax(0, 0.95fr);
}

.control-card label {
  display: grid;
  gap: 6px;
  margin-top: 9px;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 500;
}

.control-card label:first-of-type {
  margin-top: 0;
}

.control-card input[type="range"],
.control-card select {
  width: 100%;
  margin: 0;
}

.prompt-details {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.prompt-details summary {
  cursor: pointer;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prompt-meta {
  margin-top: 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.prompt-text {
  margin: 8px 0 0;
  max-height: 96px;
  overflow: auto;
  padding: 8px 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.42;
}

.button-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: nowrap;
}

.module-button {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  min-height: 34px;
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  flex: 1 1 0;
}

.module-button.primary {
  background: rgba(42, 44, 56, 0.9);
  border-color: rgba(42, 44, 56, 0.9);
  color: var(--paper);
}

.range-line,
.select-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.range-value {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.summary-list,
.sequence-log,
.distance-list {
  margin: 14px 0 0;
  padding-left: 1.1rem;
}

.summary-list li + li,
.distance-list li + li {
  margin-top: 8px;
}

.sequence-log {
  list-style: none;
  padding-left: 0;
  margin-top: 12px;
  max-height: 220px;
  overflow: auto;
}

.llm-sequence-card {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.24);
}

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

.sequence-card-head .panel-label {
  margin-bottom: 4px;
}

.sequence-current-line {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.sequence-ribbon {
  display: flex;
  gap: 8px;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  max-height: none;
  margin-top: 0;
  padding: 2px 0 6px;
}

.sequence-ribbon li {
  flex: 0 0 auto;
  min-width: 118px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
  color: var(--muted);
  font-size: 0.78rem;
}

.sequence-ribbon li.is-correct {
  border-color: rgba(47, 143, 78, 0.22);
}

.sequence-ribbon li.is-hallucinated {
  border-color: rgba(196, 71, 71, 0.22);
}

.sequence-ribbon li.is-emitted.is-correct {
  background: rgba(47, 143, 78, 0.1);
  color: rgba(33, 89, 49, 0.92);
}

.sequence-ribbon li.is-emitted.is-hallucinated {
  background: rgba(196, 71, 71, 0.1);
  color: rgba(140, 50, 50, 0.92);
}

.sequence-ribbon li.is-queued {
  opacity: 0.48;
}

.sequence-ribbon li.is-current {
  border-color: var(--line-strong);
  box-shadow: inset 0 0 0 1px rgba(42, 44, 56, 0.08);
  opacity: 1;
}

.sequence-ribbon li strong {
  display: block;
  margin-top: 3px;
  font-size: 0.8rem;
  line-height: 1.28;
}

.token-step {
  display: inline-block;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.llm-overlay-card {
  padding-top: 10px;
}

.llm-run-card {
  padding-top: 8px;
}

.metric-pairs {
  display: grid;
  gap: 0;
  margin: 0;
}

.metric-pair {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid rgba(42, 44, 56, 0.08);
  align-items: start;
}

.metric-pair:first-child {
  border-top: 0;
}

.metric-pair dt,
.metric-pair dd {
  margin: 0;
}

.metric-pair dt {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.metric-pair dd {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.sequence-log:not(.sequence-ribbon) li {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.sequence-log li.is-correct strong {
  color: #286f3a;
}

.sequence-log li.is-hallucinated strong {
  color: #ad3d3d;
}

.sequence-log:not(.sequence-ribbon) li:first-child {
  border-top: 0;
  padding-top: 0;
}

.sequence-log .step-id {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-line {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.footer-note {
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.footer-note a {
  color: var(--ink);
}

.legend-list {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.legend-swatch {
  width: 28px;
  height: 0;
  border-top: 3px solid rgba(42, 44, 56, 0.18);
}

.legend-swatch.ground {
  border-top-color: rgba(42, 44, 56, 0.18);
}

.legend-swatch.correct {
  border-top-color: #2f8f4e;
}

.legend-swatch.hallucinated {
  border-top-color: #c44747;
}

.graph-node {
  fill: rgba(42, 44, 56, 0.88);
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 2;
  cursor: pointer;
}

.graph-node.block-b {
  fill: rgba(42, 44, 56, 0.14);
  stroke: rgba(42, 44, 56, 0.9);
  stroke-width: 3;
}

.graph-node.selected {
  stroke: rgba(42, 44, 56, 0.95);
  stroke-width: 4;
}

.graph-node.current {
  fill: rgba(42, 44, 56, 0.6);
}

.graph-edge {
  stroke: rgba(42, 44, 56, 0.18);
  stroke-width: 1.2;
}

.graph-edge.path-edge,
.graph-edge.current-edge {
  stroke: rgba(42, 44, 56, 0.92);
  stroke-width: 2.4;
}

.graph-edge.ground-edge {
  stroke: rgba(42, 44, 56, 0.13);
  stroke-width: 0.9;
}

.graph-edge.correct-edge {
  stroke: #2f8f4e;
  stroke-width: 2.2;
}

.graph-edge.hallucinated-edge {
  stroke: #c44747;
  stroke-width: 2.2;
}

.graph-edge.current-correct-edge {
  stroke: #2f8f4e;
  stroke-width: 2.8;
  stroke-dasharray: 10 8;
  animation: dash-shift 1.2s linear infinite;
}

.graph-edge.current-hallucinated-edge {
  stroke: #c44747;
  stroke-width: 2.8;
  stroke-dasharray: 10 8;
  animation: dash-shift 1.2s linear infinite;
}

.graph-edge.current-edge {
  stroke-dasharray: 10 8;
  animation: dash-shift 1.2s linear infinite;
}

.graph-label {
  fill: rgba(42, 44, 56, 0.66);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
}

.graph-label.selected {
  fill: rgba(42, 44, 56, 0.94);
  font-weight: 600;
}

@keyframes dash-shift {
  to {
    stroke-dashoffset: -18;
  }
}

@media (max-width: 1080px) {
  .hero-panel .hero-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .llm-frame,
  .llm-workbench {
    grid-template-columns: 1fr;
  }

  .llm-info-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .llm-frame .graph-stage,
  .llm-workbench .graph-stage {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .graphlab-frame,
  .graphlab-compare-grid,
  .graphlab-distribution-row {
    grid-template-columns: 1fr;
  }

  .graphlab-visual-column {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .graphlab-graph-card + .graphlab-graph-card,
  .graphlab-distribution-card + .graphlab-distribution-card {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .toolbar-actions {
    gap: 8px;
  }

  .module-toolbar {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .toolbar-center {
    justify-items: start;
  }

  .graph-stage,
  .graph-stage svg,
  .mini-graph-stage,
  .mini-graph-stage svg {
    min-height: 300px;
  }

  .mini-graph-stage svg {
    height: 300px;
  }

  .sequence-card-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .button-row {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .graph-edge.current-edge {
    animation: none;
  }
}
