/* ============================================================
   DANTZIG INTERACTIVE ARTICLE — DISTILL-INSPIRED DESIGN SYSTEM
   ============================================================ */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400;1,500&family=JetBrains+Mono:wght@400;500&family=Spectral+SC:wght@400;500&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Typography */
  --font-body: 'Spectral', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-sc: 'Spectral SC', serif;

  /* Colors — warm academic palette */
  --c-bg: #faf9f6;
  --c-bg-warm: #f5f0eb;
  --c-bg-code: #f0ece6;
  --c-text: #1a1a1a;
  --c-text-secondary: #555;
  --c-text-muted: #888;
  --c-accent: #c2553a;
  --c-accent-light: #e8c4b8;
  --c-link: #2a6496;
  --c-link-hover: #1a4060;
  --c-border: #ddd;
  --c-border-light: #eee;

  /* Interactive colors */
  --c-interactive-bg: #fff;
  --c-interactive-border: #d0cec8;
  --c-node: #2a6496;
  --c-node-terminal: #c2553a;
  --c-node-hover: #1a4060;
  --c-edge: #999;
  --c-edge-active: #2a6496;
  --c-route-1: #c2553a;
  --c-route-2: #2a6496;
  --c-route-3: #518c5a;
  --c-route-4: #9b6b2f;
  --c-feasible: #518c5a;
  --c-infeasible: #c2553a;
  --c-positive: #518c5a;
  --c-negative: #c2553a;

  /* Layout */
  --w-text: 720px;
  --w-page: 1080px;
  --w-full: 100%;
  --gutter: 24px;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;
  --sp-6: 48px;
  --sp-7: 64px;
  --sp-8: 96px;
  --sp-9: 128px;

  /* Transitions */
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 600ms;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);
  --shadow-interactive: 0 2px 20px rgba(42, 100, 150, 0.12);

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.72;
  overflow-x: hidden;
}

::selection {
  background: var(--c-accent-light);
  color: var(--c-text);
}

/* --- Article Layout --- */
.article {
  position: relative;
}

.article-body {
  max-width: var(--w-text);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* Full-bleed containers break out of text width */
.full-bleed {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
}

.wide {
  max-width: var(--w-page);
  margin-left: auto;
  margin-right: auto;
  padding: 0 var(--gutter);
}

/* --- Hero Section --- */
.hero {
  padding: var(--sp-9) 0 var(--sp-8);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(194, 85, 58, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(42, 100, 150, 0.04) 0%, transparent 60%),
    linear-gradient(to bottom, var(--c-bg-warm), var(--c-bg));
  z-index: 0;
}

.hero > * {
  position: relative;
  z-index: 1;
}

.hero-kicker {
  font-family: var(--font-sc);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--c-accent);
  margin-bottom: var(--sp-4);
  font-weight: 500;
}

.hero h1 {
  font-family: var(--font-body);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--c-text);
  max-width: 800px;
  margin: 0 auto var(--sp-5);
}

.hero-subtitle {
  font-size: 1.25rem;
  font-weight: 300;
  color: var(--c-text-secondary);
  max-width: 600px;
  margin: 0 auto var(--sp-6);
  line-height: 1.6;
}

.hero-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--c-text-muted);
}

.hero-meta .author {
  font-weight: 500;
  color: var(--c-text-secondary);
}

.hero-meta .separator {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--c-text-muted);
  display: inline-block;
}

.hero-divider {
  width: 60px;
  height: 2px;
  background: var(--c-accent);
  margin: var(--sp-6) auto 0;
  border: none;
}

/* --- Typography --- */
h2 {
  font-family: var(--font-body);
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: var(--sp-8) 0 var(--sp-4);
  color: var(--c-text);
}

h2 .section-number {
  font-family: var(--font-sc);
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--c-accent);
  display: block;
  margin-bottom: var(--sp-2);
}

h3 {
  font-family: var(--font-body);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.35;
  margin: var(--sp-6) 0 var(--sp-3);
  color: var(--c-text);
}

h3 .section-number {
  font-family: var(--font-sc);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--c-accent);
  margin-right: var(--sp-2);
}

p {
  margin-bottom: var(--sp-4);
}

p + p {
  text-indent: 1.5em;
  margin-top: -var(--sp-2);
}

.lead {
  font-size: 1.2rem;
  font-weight: 300;
  line-height: 1.65;
  color: var(--c-text-secondary);
  text-indent: 0 !important;
  margin-bottom: var(--sp-5);
}

strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

a {
  color: var(--c-link);
  text-decoration: none;
  border-bottom: 1px solid rgba(42, 100, 150, 0.3);
  transition: color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--c-link-hover);
  border-bottom-color: var(--c-link-hover);
}

/* --- Blockquote (for paper excerpts) --- */
blockquote {
  border-left: 3px solid var(--c-accent);
  padding: var(--sp-3) var(--sp-5);
  margin: var(--sp-5) 0;
  background: var(--c-bg-warm);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--c-text-secondary);
}

blockquote cite {
  display: block;
  font-style: normal;
  font-size: 0.85rem;
  margin-top: var(--sp-2);
  color: var(--c-text-muted);
}

/* --- Sidenotes / Margin Notes --- */
.sidenote {
  float: right;
  clear: right;
  margin-right: calc(-1 * (100vw - var(--w-text)) / 2 + var(--gutter));
  width: 220px;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--c-text-muted);
  padding-left: var(--sp-4);
  border-left: 2px solid var(--c-border-light);
}

.sidenote-number {
  font-family: var(--font-sc);
  font-size: 0.65rem;
  vertical-align: super;
  color: var(--c-accent);
  cursor: help;
}

/* --- Math --- */
.math-block {
  margin: var(--sp-5) 0;
  overflow-x: auto;
  padding: var(--sp-3) 0;
}

.math-inline {
  font-size: 0.95em;
}

.definition {
  background: var(--c-bg-warm);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
}

.definition-label {
  font-family: var(--font-sc);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--c-accent);
  margin-bottom: var(--sp-2);
  font-weight: 500;
}

/* --- Interactive Figure Container --- */
.interactive-figure {
  margin: var(--sp-6) 0;
  background: var(--c-interactive-bg);
  border: 1px solid var(--c-interactive-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--duration-normal) var(--ease-out);
}

.interactive-figure:hover {
  box-shadow: var(--shadow-interactive);
}

.interactive-figure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  background: linear-gradient(to bottom, #fafafa, #f5f5f3);
  border-bottom: 1px solid var(--c-border-light);
}

.interactive-figure-label {
  font-family: var(--font-sc);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c-accent);
  font-weight: 500;
}

.interactive-figure-title {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--c-text);
}

.interactive-figure-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.interactive-figure-body {
  padding: var(--sp-4);
  min-height: 300px;
  position: relative;
}

.interactive-figure-body svg {
  width: 100%;
  height: 100%;
  display: block;
}

.interactive-figure-caption {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-border-light);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--c-text-muted);
}

/* --- Controls UI --- */
.control-group {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--c-border-light);
  background: #fafafa;
}

.control-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--c-text-muted);
  white-space: nowrap;
}

.control-value {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--c-accent);
  font-weight: 500;
  min-width: 50px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--c-border);
  border-radius: 2px;
  outline: none;
  flex: 1;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c-accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-spring);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-sc);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--c-text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  text-transform: uppercase;
  user-select: none;
}

.btn:hover {
  background: var(--c-bg-warm);
  border-color: var(--c-text-muted);
  color: var(--c-text);
}

.btn.active {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: white;
}

.btn-primary {
  background: var(--c-accent);
  border-color: var(--c-accent);
  color: white;
}

.btn-primary:hover {
  background: #a8432d;
  border-color: #a8432d;
  color: white;
}

.btn-group {
  display: inline-flex;
  gap: 0;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.btn-group .btn + .btn {
  border-left: none;
}

/* --- Step Counter / Progress --- */
.step-indicator {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--c-text-muted);
}

.step-indicator .current {
  color: var(--c-accent);
  font-weight: 500;
}

/* --- Distance Counter --- */
.distance-counter {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--c-text);
  text-align: center;
  padding: var(--sp-3);
}

.distance-counter .value {
  color: var(--c-accent);
  transition: color var(--duration-fast);
}

.distance-counter .value.improved {
  color: var(--c-positive);
}

.distance-counter .unit {
  font-size: 0.65rem;
  color: var(--c-text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-left: var(--sp-1);
}

/* --- Tooltip --- */
.tooltip {
  position: absolute;
  background: var(--c-text);
  color: white;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
  z-index: 100;
  white-space: nowrap;
}

.tooltip.visible {
  opacity: 1;
}

/* --- SVG Styles (for D3 figures) --- */
.node {
  cursor: grab;
  transition: opacity var(--duration-fast);
}

.node:active {
  cursor: grabbing;
}

.node circle {
  fill: var(--c-node);
  stroke: white;
  stroke-width: 2;
  transition: fill var(--duration-fast) var(--ease-out),
              r var(--duration-fast) var(--ease-spring);
}

.node.terminal circle {
  fill: var(--c-node-terminal);
}

.node:hover circle {
  fill: var(--c-node-hover);
}

.node text {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--c-text);
  text-anchor: middle;
  pointer-events: none;
  font-weight: 500;
}

.edge {
  stroke: var(--c-edge);
  stroke-width: 1.5;
  fill: none;
  transition: stroke var(--duration-fast), stroke-width var(--duration-fast);
}

.edge.active {
  stroke: var(--c-edge-active);
  stroke-width: 2.5;
}

.edge.route-1 { stroke: var(--c-route-1); }
.edge.route-2 { stroke: var(--c-route-2); }
.edge.route-3 { stroke: var(--c-route-3); }
.edge.route-4 { stroke: var(--c-route-4); }

/* Demand bar on nodes */
.demand-bar {
  fill: var(--c-accent-light);
  rx: 2;
  transition: width var(--duration-normal) var(--ease-out);
}

.demand-bar.overloaded {
  fill: var(--c-infeasible);
}

/* --- Table of Contents --- */
.toc {
  margin: var(--sp-6) 0;
  padding: var(--sp-5);
  background: var(--c-bg-warm);
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border-light);
}

.toc-title {
  font-family: var(--font-sc);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  color: var(--c-text-muted);
  margin-bottom: var(--sp-3);
  text-transform: uppercase;
}

.toc ol {
  list-style: none;
  counter-reset: toc-counter;
}

.toc li {
  counter-increment: toc-counter;
  margin-bottom: var(--sp-2);
}

.toc li a {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-size: 0.9rem;
  border-bottom: none;
  color: var(--c-text-secondary);
  transition: color var(--duration-fast);
  padding: var(--sp-1) 0;
}

.toc li a:hover {
  color: var(--c-accent);
}

.toc li a::before {
  content: counter(toc-counter) ".";
  font-family: var(--font-sc);
  font-size: 0.75rem;
  color: var(--c-text-muted);
  min-width: 20px;
}

.toc li a .toc-badge {
  font-family: var(--font-sc);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  color: var(--c-accent);
  background: var(--c-accent-light);
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: auto;
  text-transform: uppercase;
}

/* --- Section Divider --- */
.section-divider {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--c-border), transparent);
  margin: var(--sp-8) 0;
}

/* --- Key Insight Box --- */
.insight {
  background: linear-gradient(135deg, rgba(42, 100, 150, 0.06), rgba(42, 100, 150, 0.02));
  border: 1px solid rgba(42, 100, 150, 0.15);
  border-left: 3px solid var(--c-link);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
}

.insight p {
  margin-bottom: 0;
  text-indent: 0 !important;
}

.insight-label {
  font-family: var(--font-sc);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--c-link);
  margin-bottom: var(--sp-2);
  font-weight: 500;
  text-transform: uppercase;
}

/* --- Footnotes --- */
.footnotes {
  margin-top: var(--sp-8);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--c-border);
  font-size: 0.85rem;
  color: var(--c-text-secondary);
}

.footnotes ol {
  padding-left: var(--sp-5);
}

.footnotes li {
  margin-bottom: var(--sp-2);
}

/* --- Responsive --- */
@media (max-width: 1100px) {
  .sidenote {
    float: none;
    width: 100%;
    margin: var(--sp-3) 0;
    padding: var(--sp-3);
    border-left: 2px solid var(--c-border-light);
    background: var(--c-bg-warm);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  .hero h1 {
    font-size: 2.2rem;
  }

  .hero-subtitle {
    font-size: 1.05rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.15rem;
  }

  .article-body {
    padding: 0 var(--sp-3);
  }

  .interactive-figure-body {
    padding: var(--sp-3);
  }

  .hero {
    padding: var(--sp-7) 0 var(--sp-6);
  }

  .control-group {
    flex-wrap: wrap;
  }
}

/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulseGlow {
  0%, 100% { 
    filter: drop-shadow(0 0 2px rgba(194, 85, 58, 0.3));
  }
  50% { 
    filter: drop-shadow(0 0 8px rgba(194, 85, 58, 0.5));
  }
}

@keyframes drawLine {
  from { stroke-dashoffset: 1000; }
  to { stroke-dashoffset: 0; }
}

.animate-in {
  animation: fadeInUp var(--duration-slow) var(--ease-out) forwards;
  opacity: 0;
}

.animate-delay-1 { animation-delay: 100ms; }
.animate-delay-2 { animation-delay: 200ms; }
.animate-delay-3 { animation-delay: 300ms; }
.animate-delay-4 { animation-delay: 400ms; }

/* --- Print Styles --- */
@media print {
  .interactive-figure {
    break-inside: avoid;
  }

  .interactive-figure-body {
    min-height: 200px;
  }

  .btn, .control-group {
    display: none;
  }
}
