/* ═══════════════════════════════════════════
   THE MISSING CHAPTERS — Shared Design System
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;0,900;1,400;1,700&family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #faf8f3;
  --bg-deep: #f3efe6;
  --text: #1a1a1a;
  --text-muted: #5c5c5c;
  --accent: #c0392b;
  --accent-light: #e74c3c;
  --accent-bg: #fdf0ef;
  --blue: #2c6fbb;
  --blue-light: #3a8fd9;
  --green: #27864a;
  --green-bg: #edf7f0;
  --gold: #b8860b;
  --border: #e0dcd3;
  --code-bg: #2d2d2d;
  --code-text: #f8f8f2;
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

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

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

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

::selection {
  background: var(--accent);
  color: white;
}

/* ——— HERO ——— */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 2rem 1.5rem;
  background: linear-gradient(175deg, var(--bg) 0%, var(--bg-deep) 100%);
  position: relative;
}

.hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
}

.hero-subtitle {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2.8rem, 7vw, 5rem);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -0.02em;
  max-width: 14ch;
  margin-bottom: 1.5rem;
}

.hero h1 em {
  font-style: italic;
  color: var(--accent);
}

.hero-tagline {
  font-family: var(--sans);
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 38ch;
  line-height: 1.65;
  margin-bottom: 2.5rem;
}

.hero-meta {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.6;
  letter-spacing: 0.05em;
}

.scroll-hint {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  animation: bob 2s ease-in-out infinite;
}

.scroll-hint svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-muted);
  opacity: 0.4;
}

@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(8px); }
}

/* ——— ARTICLE ——— */
.article {
  max-width: 680px;
  margin: 0 auto;
  padding: 4rem 1.5rem 6rem;
}

.article h2 {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  margin: 4rem 0 1.5rem;
  letter-spacing: -0.01em;
}

.article h2:first-child {
  margin-top: 0;
}

.article h3 {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 3rem 0 1rem;
}

.article p {
  margin-bottom: 1.5rem;
}

.article p + p {
  margin-top: -0.25rem;
}

.lead {
  font-size: 1.15rem;
  color: var(--text-muted);
  line-height: 1.7;
  border-left: 3px solid var(--accent);
  padding-left: 1.25rem;
  margin: 2rem 0;
}

/* ——— PULLQUOTES ——— */
.pullquote {
  font-family: var(--serif);
  font-size: clamp(1.3rem, 3vw, 1.7rem);
  font-style: italic;
  line-height: 1.45;
  color: var(--accent);
  text-align: center;
  max-width: 32ch;
  margin: 3rem auto;
  padding: 2rem 0;
  position: relative;
}

.pullquote::before {
  content: '\201C';
  font-size: 4rem;
  position: absolute;
  top: -0.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: var(--accent);
  opacity: 0.15;
  font-family: var(--serif);
}

/* ——— STORY BOXES ——— */
.story-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  margin: 2.5rem 0;
  position: relative;
}

.story-box::before {
  content: attr(data-label);
  position: absolute;
  top: -0.7rem;
  left: 1.5rem;
  background: var(--bg);
  padding: 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}

.story-box p:last-child {
  margin-bottom: 0;
}

/* ——— FORMULA ——— */
.formula-block {
  background: var(--code-bg);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  margin: 2.5rem 0;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.formula-block::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--blue), var(--green));
}

.formula-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 1.5rem;
}

.formula {
  font-family: var(--mono);
  font-size: clamp(1.3rem, 3.5vw, 1.8rem);
  color: var(--code-text);
  line-height: 1.6;
  letter-spacing: 0.02em;
}

.formula .var {
  color: var(--accent-light);
  font-style: italic;
}

.formula .op {
  color: #888;
}

.formula .eq {
  color: var(--blue-light);
}

.formula-note {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: #888;
  margin-top: 1.5rem;
  line-height: 1.5;
}

/* ——— VARIABLE LEGEND ——— */
.var-legend {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1.2rem;
  margin: 2rem 0;
  padding: 1.5rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.var-legend dt {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 700;
}

.var-legend dd {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* ——— INSIGHT BOXES ——— */
.insight {
  background: var(--green-bg);
  border-left: 4px solid var(--green);
  border-radius: 0 10px 10px 0;
  padding: 1.5rem;
  margin: 2rem 0;
}

.insight-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 0.5rem;
}

.insight p:last-child {
  margin-bottom: 0;
}

/* ——— COMPARISON TABLE ——— */
.comparison {
  overflow-x: auto;
  margin: 2rem 0;
}

.comparison table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.comparison th {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border);
}

.comparison td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.comparison tr:last-child td {
  border-bottom: none;
}

.comparison .highlight {
  background: var(--accent-bg);
  font-weight: 600;
}

/* ——— INTERACTIVE ——— */
.calculator {
  background: white;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  margin: 3rem 0;
  position: relative;
}

.calculator::before {
  content: '\26A1 INTERACTIVE';
  position: absolute;
  top: -0.7rem;
  left: 1.5rem;
  background: var(--bg);
  padding: 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--blue);
}

.calc-title {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.calc-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.slider-group { margin-bottom: 1.8rem; }

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.slider-label span:first-child {
  font-weight: 600;
  font-size: 0.9rem;
}

.slider-value {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 0.15rem 0.6rem;
  border-radius: 6px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(192, 57, 43, 0.3);
  transition: transform 0.15s ease;
}

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

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(192, 57, 43, 0.3);
}

.calc-result {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 1.5rem;
  margin-top: 1.5rem;
  text-align: center;
}

.calc-result-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 0.5rem;
}

.calc-result-value {
  font-family: var(--mono);
  font-size: 2.5rem;
  font-weight: 700;
  color: #4ade80;
  line-height: 1.2;
}

.calc-result-value.negative {
  color: var(--accent-light);
}

.calc-result-subtitle {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: #888;
  margin-top: 0.5rem;
}

.calc-breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.calc-stat {
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.calc-stat-label {
  font-size: 0.65rem;
  font-family: var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 0.25rem;
}

.calc-stat-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--code-text);
}

/* ——— SIMULATION ——— */
.sim-canvas-container {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 1.5rem;
  margin-top: 1.5rem;
}

.sim-canvas-container canvas {
  width: 100%;
  height: 250px;
  display: block;
}

.sim-controls {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.sim-btn {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.05em;
}

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

.sim-btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
}

.sim-btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #ccc;
}

.sim-btn-secondary:hover {
  background: rgba(255,255,255,0.15);
}

.sim-legend {
  display: flex;
  gap: 1.2rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.sim-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: #888;
  letter-spacing: 0.05em;
}

.sim-legend-color {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}

/* ——— CHAPTER NUMBERS ——— */
.chapter-num {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 0.5rem;
}

/* ——— DIVIDER ——— */
.divider {
  text-align: center;
  margin: 4rem 0;
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--border);
  letter-spacing: 0.3em;
}

/* ——— FOOTNOTES ——— */
.footnote-ref {
  font-family: var(--mono);
  font-size: 0.7em;
  color: var(--blue);
  text-decoration: none;
  vertical-align: super;
  cursor: pointer;
}

.footnote-ref:hover { color: var(--accent); }

.footnotes {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.footnotes h3 {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.footnotes ol {
  padding-left: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footnotes li { margin-bottom: 0.5rem; }

/* ——— BACK LINK ——— */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.05em;
  margin-bottom: 2rem;
  transition: color 0.15s;
}

.back-link:hover { color: var(--accent); }

.back-link svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* ——— FOOTER ——— */
.footer {
  max-width: 680px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  text-align: center;
  border-top: 1px solid var(--border);
}

.footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

/* ——— LINKS ——— */
.article a {
  color: var(--blue);
  text-decoration: underline;
  text-decoration-color: rgba(44, 111, 187, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s;
}

.article a:hover { text-decoration-color: var(--blue); }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: rgba(0,0,0,0.06);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

strong { font-weight: 700; }
em { font-style: italic; }

.article ul, .article ol {
  padding-left: 1.5rem;
  margin-bottom: 1.5rem;
}

.article li { margin-bottom: 0.5rem; }

/* ——— FADE IN ——— */
.fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ——— RESPONSIVE ——— */
@media (max-width: 640px) {
  html { font-size: 16px; }
  .article { padding: 3rem 1.25rem 4rem; }
  .calculator { padding: 1.5rem 1.25rem; }
  .story-box { padding: 1.5rem; }
  .formula-block { padding: 1.5rem 1rem; }
  .calc-breakdown { grid-template-columns: 1fr; }
  .var-legend { grid-template-columns: auto 1fr; gap: 0.3rem 0.8rem; }
}
