:root {
  --bg: #f3ead9;
  --paper: rgba(255, 251, 244, 0.9);
  --ink: #261c16;
  --muted: #66584c;
  --line: rgba(38, 28, 22, 0.14);
  --teal: #21525f;
  --women: #c57641;
  --men: #9657dc;
  --shadow: 0 18px 60px rgba(46, 30, 15, 0.12);
  --radius: 1rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.65), transparent 28%),
    linear-gradient(180deg, #efe2ca 0%, var(--bg) 48%, #f7f3ec 100%);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2,
.formula-card strong,
.total-value {
  font-family: Iowan Old Style, Palatino Linotype, Book Antiqua, Georgia, serif;
}

.tool-header,
.page-shell,
.tool-footer {
  width: min(1380px, calc(100vw - 2rem));
  margin: 0 auto;
}

.tool-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  color: var(--muted);
  font-weight: 800;
}

.brand-link {
  color: var(--ink);
}

.back-link:hover,
.back-link:focus-visible {
  color: var(--ink);
}

.page-shell {
  padding: 0 0 2rem;
}

.tool-panel {
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
  gap: 1rem;
  align-items: stretch;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.55rem);
  line-height: 1;
}

.intro {
  max-width: 72ch;
  margin-top: 0.7rem;
  color: var(--muted);
  line-height: 1.55;
}

.formula-card,
.result-card {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(246, 239, 228, 0.85));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.formula-card {
  display: grid;
  align-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
}

.card-kicker {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.formula-card strong {
  font-size: clamp(1.2rem, 1.6vw, 1.55rem);
  line-height: 1.15;
  white-space: nowrap;
}

.chart-shell {
  position: relative;
  margin-top: 1rem;
  overflow: hidden;
  border: 1px solid rgba(38, 28, 22, 0.1);
  border-radius: 0.9rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 235, 220, 0.62)),
    repeating-linear-gradient(
      90deg,
      rgba(38, 28, 22, 0.025) 0,
      rgba(38, 28, 22, 0.025) 1px,
      transparent 1px,
      transparent 36px
    );
}

.chart-canvas {
  position: relative;
  min-height: 420px;
}

.threshold-control {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(38, 28, 22, 0.1);
  border-radius: 0.9rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(246, 239, 228, 0.72));
}

.threshold-control label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.threshold-control strong {
  color: var(--ink);
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
}

.threshold-control input {
  width: 100%;
  accent-color: var(--teal);
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.axis-line,
.tick-line {
  stroke: rgba(38, 28, 22, 0.14);
  stroke-width: 1;
}

.tick-line {
  stroke: rgba(38, 28, 22, 0.08);
}

.axis-label,
.tick-text {
  fill: var(--muted);
  font: 13px "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

.series-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.threshold-fill-included {
  fill: rgba(15, 124, 79, 0.2);
}

.threshold-fill-excluded {
  fill: rgba(179, 55, 55, 0.16);
}

.threshold-line {
  stroke: rgba(38, 28, 22, 0.82);
  stroke-width: 3;
  stroke-dasharray: 10 8;
}

.threshold-drag-line {
  stroke: transparent;
  stroke-width: 20;
  cursor: ew-resize;
}

.threshold-handle {
  fill: #fff8ef;
  stroke: rgba(38, 28, 22, 0.82);
  stroke-width: 3;
  cursor: ew-resize;
}

.threshold-chip {
  fill: rgba(38, 28, 22, 0.92);
}

.threshold-chip-text {
  fill: #fff8ef;
  font: 700 15px "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.result-card {
  padding: 1rem 1.05rem;
  border-left: 4px solid var(--accent, var(--teal));
}

.totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  margin-top: 0.35rem;
}

.total {
  padding: 0.7rem 0.8rem;
  border-radius: 0.7rem;
}

.total.included {
  background: rgba(15, 124, 79, 0.08);
}

.total.excluded {
  background: rgba(179, 55, 55, 0.08);
}

.total-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.total-value {
  display: block;
  margin-top: 0.18rem;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
}

.meter {
  height: 0.78rem;
  margin: 0.9rem 0 0.7rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(38, 28, 22, 0.08);
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--accent, var(--teal));
}

.split {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.35;
}

.meta {
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.94rem;
}

.references {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(38, 28, 22, 0.1);
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.62);
}

.references h2 {
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  line-height: 1;
}

.references ul {
  display: grid;
  gap: 0.55rem;
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.45;
}

.references a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.references a:hover,
.references a:focus-visible {
  color: var(--ink);
}

.tool-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.8rem 1rem;
  padding: 1.8rem 0 2.3rem;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1100px) {
  .hero-row,
  .results-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .tool-header,
  .page-shell,
  .tool-footer {
    width: min(100vw - 1rem, 100%);
  }

  .tool-panel {
    padding: 0.9rem;
  }

  .chart-canvas {
    min-height: 340px;
  }

  .threshold-control label {
    align-items: flex-start;
    flex-direction: column;
  }

  .split,
  .totals {
    grid-template-columns: 1fr;
    flex-direction: column;
  }
}
