:root {
  --paper: #f4efe4;
  --paper-2: #e7dfd0;
  --card: #fffaf0;
  --ink: #171814;
  --ink-2: #35372f;
  --muted: #6b685d;
  --line: #cfc5b2;
  --accent: #2a5d57;
  --accent-2: #8a3a1f;
  --accent-3: #315f8d;
  --accent-wash: #dceae6;
  --blue-wash: #dfeaf4;
  --warn-wash: #f0d9ca;
  --serif: "Source Serif 4", "Iowan Old Style", "Charter", Georgia, serif;
  --sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.09  0 0 0 0 0.07  0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  z-index: 0;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }
h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.15; letter-spacing: 0; }
h1, h2, h3 { font-family: var(--serif); }
h1 { max-width: 17ch; font-size: clamp(38px, 5vw, 64px); font-weight: 400; }
h1 em { color: var(--accent); font-style: italic; }
h2 { font-size: clamp(25px, 2.5vw, 34px); font-weight: 400; }
h3 { font-size: 22px; }
p { margin: 0; }

.app {
  position: relative;
  z-index: 1;
  max-width: 1160px;
  margin: 0 auto;
  padding: 24px clamp(18px, 3vw, 40px) 72px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 34px;
}
.brand { display: flex; align-items: center; gap: 14px; color: inherit; border-bottom: 0; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--card);
  font-family: var(--serif);
  font-size: 18px;
  font-style: italic;
}
.brand-name { display: block; font-family: var(--serif); font-size: 19px; line-height: 1.1; }
.brand-meta { display: block; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.topbar-right { display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.topbar-right a { color: var(--muted); border-bottom-color: transparent; }
.topbar-right a:hover { color: var(--ink); border-bottom-color: var(--ink); }

.kicker {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}
.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  background: currentColor;
  border-radius: 50%;
  transform: translateY(-1px);
}

.hero { margin-bottom: 26px; }
.hero-sub {
  max-width: 66ch;
  margin: 18px 0 0;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: clamp(18px, 1.8vw, 22px);
  font-style: italic;
  line-height: 1.45;
}

.module { display: grid; gap: 22px; }

.scenario-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.scenario-choice {
  display: grid;
  gap: 5px;
  min-height: 78px;
  padding: 14px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-2);
}
.scenario-choice span {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.scenario-choice small { color: var(--muted); line-height: 1.35; }
.scenario-choice:hover { border-color: var(--accent); }
.scenario-choice.is-active {
  color: var(--card);
  background: var(--ink);
  border-color: var(--ink);
}
.scenario-choice.is-active small { color: rgba(255, 250, 240, 0.76); }

.preset-panel {
  display: grid;
  grid-template-columns: minmax(240px, 0.78fr) minmax(0, 1.5fr);
  gap: 18px;
  align-items: start;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.preset-panel p {
  margin-top: 10px;
  color: var(--ink-2);
  line-height: 1.6;
}
.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.preset-button {
  display: grid;
  gap: 6px;
  min-height: 132px;
  padding: 12px;
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.preset-button:hover {
  border-color: var(--accent);
  background: var(--accent-wash);
}
.preset-button.is-active {
  border-color: var(--accent);
  background: var(--accent-wash);
  box-shadow: inset 0 0 0 2px rgba(42, 93, 87, 0.22);
}
.preset-button span {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.preset-button strong {
  color: var(--ink);
  line-height: 1.25;
}
.preset-button small {
  color: var(--muted);
  line-height: 1.35;
}

.concept-strip {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(220px, 1fr) minmax(280px, 1.45fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}
.concept-strip article {
  display: grid;
  gap: 7px;
  padding: 16px;
  background: var(--card);
}
.concept-strip span,
.eyebrow {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.concept-strip strong {
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.45;
}

.workbench,
.two-column {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(0, 1.35fr);
  gap: 18px;
  align-items: start;
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.panel-copy,
.plain-note,
.projection-note,
.metric-row p {
  color: var(--ink-2);
  line-height: 1.65;
}
.panel-copy { margin-top: 10px; }
.projection-note {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.controls-panel,
.slider-stack,
.metric-card-list {
  display: grid;
  gap: 18px;
}
.slider-stack { margin-top: 18px; }

.range-control {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(48px, auto);
  gap: 8px 12px;
  align-items: center;
}
.range-control span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.range-control strong {
  min-width: 52px;
  text-align: right;
}
.range-control input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
}

.metric-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.metric-controls button {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}
.metric-controls button.is-active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--blue-wash);
  font-weight: 700;
}
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.plot-wrap {
  display: grid;
  gap: 14px;
}
.plot {
  width: 100%;
  max-height: 390px;
  display: block;
}
.plot rect { fill: #f8f3e8; stroke: var(--line); }
.plot line { stroke: rgba(107, 104, 93, 0.2); }
.plot text { fill: var(--muted); font-family: var(--mono); font-size: 11px; text-anchor: middle; }
.plot .axis-label { fill: var(--ink-2); font-weight: 700; }
.point-label,
.new-label { text-anchor: start !important; fill: var(--ink-2) !important; }
.data-point { stroke: var(--card); stroke-width: 2; }
.data-point.good { fill: var(--accent); }
.data-point.bad { fill: var(--accent-2); }
.data-point.neutral { fill: var(--accent-3); }
.data-point.nearest { stroke: var(--ink); stroke-width: 3; }
.distance-line { stroke: var(--accent-3) !important; stroke-width: 2; stroke-dasharray: 6 5; }
.new-point { fill: var(--ink); stroke: var(--card); stroke-width: 3; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  color: var(--muted);
  font-size: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}
.legend-dot.bad { background: var(--accent-2); }
.legend-dot.neutral { background: var(--accent-3); }
.legend-dot.new { background: var(--ink); }

.neighbor-list {
  display: grid;
  gap: 8px;
}
.ranking-note {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.neighbor-row {
  display: grid;
  grid-template-columns: 32px minmax(90px, 1fr) minmax(120px, 1.1fr) 76px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.neighbor-row span,
.mini-row span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--paper-2);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}
.neighbor-row em { color: var(--muted); font-style: normal; }
.neighbor-row em.good { color: var(--accent); font-weight: 700; }
.neighbor-row em.bad { color: var(--accent-2); font-weight: 700; }
.neighbor-row em.neutral { color: var(--accent-3); font-weight: 700; }
.neighbor-row small { color: var(--muted); font-family: var(--mono); font-size: 11px; text-align: right; }

.result-callout {
  margin-top: 16px;
  padding: 16px;
  background: var(--accent-wash);
  border: 1px solid rgba(42, 93, 87, 0.25);
  border-radius: 8px;
}
.result-callout.soft { background: var(--blue-wash); }
.result-callout span {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.result-callout strong { display: block; font-size: 18px; line-height: 1.25; }
.result-callout small { display: block; margin-top: 6px; color: var(--muted); }
.plain-note { margin-top: 14px; }

.breakdown {
  margin-top: 18px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.breakdown h3 { margin-bottom: 12px; font-size: 20px; }
.diff-list {
  display: grid;
  gap: 8px;
}
.diff-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 78px minmax(110px, 0.9fr);
  gap: 12px;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.diff-row span { color: var(--muted); }
.diff-row small { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.formula {
  margin-top: 14px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.metric-row {
  display: grid;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.metric-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--mono);
}
.metric-nearest {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.bar-track {
  height: 10px;
  overflow: hidden;
  background: var(--paper-2);
  border-radius: 999px;
}
.bar-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
}

.scale-comparison {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}
.scale-comparison h3 { margin-bottom: 8px; font-size: 20px; }
.mini-ranking {
  display: grid;
  gap: 6px;
}
.mini-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 64px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.mini-row small {
  color: var(--muted);
  font-family: var(--mono);
  text-align: right;
}

.colophon {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.colophon a { color: var(--muted); border-bottom-color: transparent; }
.colophon a:hover { color: var(--ink); border-bottom-color: var(--ink); }

@media (max-width: 940px) {
  .scenario-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .preset-panel,
  .concept-strip,
  .workbench,
  .two-column {
    grid-template-columns: 1fr;
  }
  .preset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .panel-head {
    display: grid;
  }
  .metric-controls {
    justify-content: start;
  }
}

@media (max-width: 620px) {
  .app { padding-inline: 16px; }
  .topbar { align-items: flex-start; }
  .topbar-right { justify-content: flex-start; }
  h1 { font-size: 42px; }
  .scenario-picker {
    grid-template-columns: 1fr;
  }
  .preset-grid {
    grid-template-columns: 1fr;
  }
  .neighbor-row {
    grid-template-columns: 30px minmax(0, 1fr);
  }
  .neighbor-row em,
  .neighbor-row small {
    grid-column: 2;
    text-align: left;
  }
  .diff-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .diff-row strong,
  .diff-row small {
    text-align: left;
  }
}
