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

:root {
  --bg: #f5f2eb;
  --bg2: #ede9e0;
  --bg3: #e4dfd3;
  --ink: #1a1714;
  --ink2: #5a5650;
  --ink3: #8a857e;
  --accent: #c0392b;
  --accent2: #2c6e49;
  --blue: #1a4a8a;
  --amber: #b5620a;
  --purple: #4a3a8a;
  --border: rgba(26,23,20,0.12);
  --radius: 4px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
}

/* HEADER */
header {
  background: var(--ink);
  color: var(--bg);
  padding: 3.5rem 2rem 3rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 40px,
    rgba(255,255,255,0.02) 40px,
    rgba(255,255,255,0.02) 41px
  );
}
header .eyebrow {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(245,242,235,0.5);
  margin-bottom: 1rem;
  font-weight: 400;
}
header h1 {
  font-family: 'Fraunces', serif;
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-weight: 600;
  line-height: 1.1;
  margin-bottom: 1rem;
  position: relative;
}
header h1 em {
  font-style: italic;
  color: #e8b4a0;
}
header p.lead {
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  color: rgba(245,242,235,0.65);
  max-width: 560px;
  margin: 0 auto;
  font-weight: 300;
  line-height: 1.7;
}

/* MAIN LAYOUT */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

/* CONTROLS CARD */
.controls-card {
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2.5rem;
}
.controls-card h2 {
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 300;
  font-style: italic;
  color: rgba(245,242,235,0.5);
  margin-bottom: 1.5rem;
  letter-spacing: 0.03em;
}
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem 2rem;
}
@media (max-width: 560px) {
  .controls-grid { grid-template-columns: 1fr; gap: 1rem; }
}

.control-group label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(245,242,235,0.45);
  margin-bottom: 0.5rem;
  font-weight: 400;
}
.control-group .val-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.control-group input[type=range] {
  flex: 1;
  -webkit-appearance: none;
  height: 3px;
  background: rgba(245,242,235,0.15);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.control-group input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  transition: transform 0.1s;
}
.control-group input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
.control-group input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  border: none;
}
.control-group .val-display {
  font-size: 1rem;
  font-weight: 500;
  color: var(--bg);
  min-width: 80px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* STAT STRIP */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 2.5rem;
}
@media (max-width: 600px) {
  .stat-strip { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 360px) {
  .stat-strip { grid-template-columns: 1fr; }
}
.stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.1rem;
}
.stat-label {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink3);
  margin-bottom: 0.35rem;
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stat-sub {
  font-size: 12px;
  color: var(--ink3);
  margin-top: 0.2rem;
}

/* CHART SECTIONS */
.chart-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.chart-title {
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
}
.chart-desc {
  font-size: 13px;
  color: var(--ink3);
  margin-top: 2px;
}
.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--ink2);
  flex-wrap: wrap;
  align-items: center;
}
.legend span { display: flex; align-items: center; gap: 5px; }
.swatch {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  display: inline-block;
}
.swatch.dashed {
  background: linear-gradient(90deg, var(--sw-color) 50%, transparent 50%);
  background-size: 6px 2px;
  background-repeat: repeat-x;
  background-position: center;
  background-color: transparent;
  height: 2px;
  width: 18px;
  border-radius: 0;
}
.chart-wrap {
  position: relative;
  width: 100%;
}

/* INSIGHT BOX */
.insight {
  background: var(--bg2);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
  color: var(--ink2);
  line-height: 1.65;
}
.insight strong { color: var(--ink); font-weight: 500; }

/* EXPLAINER */
.explainer {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.75rem 2rem;
  margin-top: 2rem;
}
.explainer h3 {
  font-family: 'Fraunces', serif;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.explainer p {
  font-size: 0.95rem;
  color: var(--ink2);
  margin-bottom: 0.75rem;
  line-height: 1.7;
}
.explainer p:last-child { margin-bottom: 0; }
.explainer strong { color: var(--ink); font-weight: 500; }

/* FORMULA */
.formula-box {
  background: var(--ink);
  color: var(--bg);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  font-family: 'DM Sans', monospace;
  font-size: 0.9rem;
  margin: 1rem 0;
  letter-spacing: 0.02em;
  line-height: 1.8;
}
.formula-box span { color: #e8b4a0; }

/* STAMP */
.stamp {
  display: inline-block;
  position: relative;
  margin-top: 2rem;
  padding: 0.55rem 1.1rem;
  border: 3px solid #e8b4a0;
  border-radius: 4px;
  font-family: 'Fraunces', serif;
  font-size: clamp(0.75rem, 2.5vw, 0.95rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #e8b4a0;
  opacity: 0.72;
  transform: rotate(-4deg);
  box-shadow: inset 0 0 0 2px rgba(232,180,160,0.18);
  user-select: none;
}
.stamp::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(232,180,160,0.3);
  border-radius: 2px;
  pointer-events: none;
}

/* SMALL DIFF BANNER */
.small-diff-banner {
  background: var(--accent);
  color: #fff;
  padding: 1rem 2rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: clamp(0.88rem, 2vw, 1rem);
  line-height: 1.6;
}
.small-diff-banner strong { font-weight: 500; }
.sd-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 2px; }

/* FOOTER */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 12px;
  color: var(--ink3);
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}
footer a { color: var(--ink3); }

/* RESPONSIVE CHART HEIGHTS */
.h-240 { height: 240px; }
.h-200 { height: 200px; }
@media (max-width: 480px) {
  .h-240 { height: 200px; }
  .h-200 { height: 170px; }
  .chart-section { padding: 1rem; }
  main { padding: 1.5rem 1rem 3rem; }
  .controls-card { padding: 1.25rem; }
  .explainer { padding: 1.25rem; }
}
