:root {
  --bg: #f6efe4;
  --bg-accent: #ead6b8;
  --surface: rgba(255, 250, 244, 0.86);
  --surface-strong: #fffdf8;
  --ink: #1b140f;
  --muted: #69594d;
  --line: rgba(77, 53, 35, 0.18);
  --primary: #8a3b12;
  --primary-strong: #61280d;
  --source: #2d7c71;
  --derived: #c26f22;
  --node-stroke: rgba(41, 27, 17, 0.25);
  --shadow: 0 20px 60px rgba(74, 44, 18, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 248, 234, 0.95), transparent 30%),
    radial-gradient(circle at bottom right, rgba(223, 176, 123, 0.3), transparent 25%),
    linear-gradient(135deg, var(--bg), #f9f4ec 45%, #efe0cf 100%);
}

button,
textarea {
  font: inherit;
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  min-height: 100vh;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 28px;
  border-right: 1px solid var(--line);
  background: rgba(255, 252, 248, 0.72);
  backdrop-filter: blur(14px);
}

.hero h1,
.canvas-header h2,
.panel-card h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  line-height: 1.05;
}

.hero h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
}

.subcopy,
.selection-empty,
.summary-empty,
.note-list,
.graph-stats {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  color: var(--primary);
  font-weight: 700;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), #b44f19);
  color: #fff8f2;
  box-shadow: 0 12px 28px rgba(138, 59, 18, 0.25);
}

.secondary-button {
  background: rgba(255, 247, 239, 0.96);
  color: var(--ink);
  border: 1px solid rgba(97, 40, 13, 0.12);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.editor-label {
  font-size: 0.88rem;
  font-weight: 600;
}

#code-input {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  border-radius: 22px;
  border: 1px solid rgba(55, 35, 20, 0.12);
  padding: 18px;
  background: var(--surface-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  line-height: 1.45;
}

.panel-card,
.graph-container {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-card {
  padding: 18px;
}

.compact-card {
  padding: 16px 18px;
}

.panel-card h2 {
  margin-bottom: 12px;
  font-size: 1.1rem;
}

.toggle-group {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: rgba(97, 40, 13, 0.08);
  gap: 4px;
}

.toggle-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.toggle-button.is-active {
  background: var(--surface-strong);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(74, 44, 18, 0.1);
}

.note-list {
  padding-left: 20px;
  margin: 0;
  line-height: 1.5;
}

.canvas-panel {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.canvas-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
}

.graph-container {
  position: relative;
  overflow: auto;
  min-height: 640px;
  padding: 18px;
}

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

.selection-card {
  display: grid;
  gap: 10px;
}

.summary-card {
  display: grid;
  gap: 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.summary-metric {
  padding: 12px;
  border-radius: 16px;
  background: rgba(84, 62, 42, 0.06);
}

.summary-metric-label {
  margin: 0 0 6px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  font-weight: 700;
}

.summary-metric-value {
  margin: 0;
  font-size: 0.98rem;
  color: var(--ink);
  line-height: 1.35;
}

.summary-line {
  margin: 0;
  line-height: 1.5;
  color: var(--muted);
}

.debug-list {
  display: grid;
  gap: 8px;
}

.debug-item {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(84, 62, 42, 0.06);
  color: var(--ink);
  line-height: 1.45;
  word-break: break-word;
}

.stage-list {
  display: grid;
  gap: 8px;
}

.stage-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(194, 111, 34, 0.1);
  color: var(--ink);
}

.stage-pill-name {
  font-weight: 600;
}

.stage-pill-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.selection-title {
  margin: 0;
  font-size: 1rem;
}

.selection-meta {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.94rem;
}

.selection-code {
  margin: 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(84, 62, 42, 0.06);
  overflow-x: auto;
}

.graph-svg {
  min-width: 100%;
}

.edge-path {
  fill: none;
  stroke: rgba(90, 65, 44, 0.45);
  stroke-width: 2;
}

.edge-primary {
  stroke: rgba(138, 59, 18, 0.78);
  stroke-width: 2.8;
}

.edge-highlight {
  stroke: rgba(138, 59, 18, 0.88);
}

.node-group {
  cursor: pointer;
}

.node-rect {
  stroke: var(--node-stroke);
  stroke-width: 1.2;
  rx: 18;
}

.node-rect.source {
  fill: rgba(45, 124, 113, 0.15);
}

.node-rect.derived {
  fill: rgba(194, 111, 34, 0.18);
}

.node-rect.selected {
  stroke: rgba(27, 20, 15, 0.86);
  stroke-width: 2;
}

.node-name {
  font-size: 15px;
  font-weight: 700;
  fill: var(--ink);
}

.node-label {
  font-size: 12px;
  fill: var(--muted);
}

.node-shape {
  font-size: 11px;
  fill: var(--primary-strong);
}

.stage-caption {
  font-size: 12px;
  fill: var(--primary);
  font-weight: 700;
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .graph-container {
    min-height: 520px;
  }
}
