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

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-tertiary: #1a1a24;
  --text-primary: #e8e8ef;
  --text-secondary: #8888a0;
  --text-muted: #555566;

  --signal-color: #00d4ff;
  --signal-glow: rgba(0, 212, 255, 0.5);
  --computed-color: #a855f7;
  --computed-glow: rgba(168, 85, 247, 0.5);
  --effect-color: #00ff88;
  --effect-glow: rgba(0, 255, 136, 0.5);

  --edge-color: #64748b;
  --edge-active: #00d4ff;

  --border-radius: 12px;
  --transition-fast: 150ms ease;
  --transition-medium: 300ms ease;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 2.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--signal-color), var(--computed-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.4rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Main Content */
.main-content {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 1.5rem;
  flex: 1;
}

/* Graph Panel */
.graph-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.graph-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.graph-header label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.5rem 2.25rem 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238888a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

select:hover {
  border-color: rgba(255, 255, 255, 0.2);
  background-color: var(--bg-tertiary);
}

select:focus {
  border-color: var(--signal-color);
  outline: none;
}

/* Graph Container */
.graph-container {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  height: 480px;
  position: relative;
  overflow: hidden;
}

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

/* Step Badge - fixed position inside graph */
.step-badge {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.6rem 1.25rem;
  border-radius: 100px;
  max-width: 90%;
}

#step-description {
  color: var(--text-primary);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* Info Panel */
.info-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.info-card {
  background: var(--bg-secondary);
  padding: 1.25rem;
  border-radius: var(--border-radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

#preset-description {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* Legend */
.legend {
  background: var(--bg-secondary);
  padding: 1rem 1.25rem;
  border-radius: var(--border-radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.legend-code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: #1e1e2e;
}

.legend-code.signal {
  color: var(--signal-color);
}

.legend-code.computed {
  color: var(--computed-color);
}

.legend-code.effect {
  color: var(--effect-color);
}

/* Graph Nodes - IDE/Terminal Style */
.node {
  cursor: default;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.node:hover .node-rect {
  filter: brightness(1.2);
}

.node-signal:hover .node-rect {
  filter: drop-shadow(0 0 12px var(--signal-glow)) brightness(1.1);
}

.node-computed:hover .node-rect {
  filter: drop-shadow(0 0 12px var(--computed-glow)) brightness(1.1);
}

.node-effect:hover .node-rect {
  filter: drop-shadow(0 0 12px var(--effect-glow)) brightness(1.1);
}

.node-rect {
  fill: #1e1e2e;
  stroke: none;
  transition: all var(--transition-medium);
}

/* Type indicator bar */
.type-bar {
  opacity: 0.9;
}

.type-bar-signal {
  fill: var(--signal-color);
}

.type-bar-computed {
  fill: var(--computed-color);
}

.type-bar-effect {
  fill: var(--effect-color);
}

/* Code syntax highlighting */
.code-line {
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  fill: var(--text-primary);
}

.code-const {
  fill: #c792ea;
}

.code-name {
  fill: var(--text-primary);
}

.code-punct {
  fill: var(--text-secondary);
}

.node-signal .code-fn {
  fill: var(--signal-color);
}

.node-computed .code-fn {
  fill: var(--computed-color);
}

.node-effect .code-fn {
  fill: var(--effect-color);
}

.code-value {
  fill: #f78c6c;
}

.code-formula {
  fill: var(--text-primary);
  font-size: 11px;
  opacity: 0.8;
}

.code-comment {
  fill: var(--text-muted);
  font-size: 11px;
}

.code-result {
  font-size: 11px;
}

.code-result .code-value {
  fill: #f78c6c;
}

/* Node animations */
.node-signal.updating .node-rect {
  animation: node-pulse-signal 0.6s ease-out;
}

@keyframes node-pulse-signal {
  0% { filter: none; }
  50% {
    filter: drop-shadow(0 0 16px var(--signal-glow)) brightness(1.3);
  }
  100% { filter: none; }
}

.node-computed.updating .node-rect {
  animation: node-pulse-computed 0.6s ease-out;
}

@keyframes node-pulse-computed {
  0% { filter: none; }
  50% {
    filter: drop-shadow(0 0 16px var(--computed-glow)) brightness(1.3);
  }
  100% { filter: none; }
}

.node-effect.updating .node-rect {
  animation: node-pulse-effect 0.6s ease-out;
}

@keyframes node-pulse-effect {
  0% { filter: none; }
  50% {
    filter: drop-shadow(0 0 16px var(--effect-glow)) brightness(1.3);
  }
  100% { filter: none; }
}

/* Edges - animated flowing dashes with arrowheads */
.edge {
  stroke: var(--edge-color);
  stroke-width: 2;
  fill: none;
  stroke-dasharray: 8 6;
  animation: dash-flow 1s linear infinite;
  marker-end: url(#arrowhead);
}

@keyframes dash-flow {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -14; }
}

.edge.active {
  stroke: var(--edge-active);
  stroke-width: 2.5;
  stroke-dasharray: none;
  animation: none;
  marker-end: url(#arrowhead-active);
}

.edge.removing {
  animation: edge-fade-out 0.4s ease-out forwards;
}

.edge.adding {
  animation: edge-fade-in 0.4s ease-out forwards;
}

@keyframes edge-fade-out {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes edge-fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Edge pulse animation */
.edge-pulse {
  fill: var(--signal-color);
  opacity: 0;
  filter: drop-shadow(0 0 6px var(--signal-glow));
}

.edge-pulse.animating {
  opacity: 1;
}

/* No-op indicator */
.noop-indicator {
  fill: none;
  stroke: var(--effect-color);
  stroke-width: 3;
  opacity: 0;
  filter: drop-shadow(0 0 8px var(--effect-glow));
}

.noop-indicator.show {
  animation: noop-check 1s ease-out forwards;
}

@keyframes noop-check {
  0% {
    opacity: 0;
    stroke-dasharray: 0 100;
  }
  30% { opacity: 1; }
  70% { opacity: 1; }
  100% {
    opacity: 0;
    stroke-dasharray: 100 0;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .app {
    padding: 1rem;
  }

  .header h1 {
    font-size: 1.75rem;
  }

  .graph-container {
    height: 400px;
  }

  .info-panel {
    flex-direction: row;
  }

  .info-card, .legend {
    flex: 1;
  }
}
