:root {
  color-scheme: light;
  --page: #f4f5fb;
  --surface: #ffffff;
  --border: #e3e4ee;
  --grid: #e8e8ef;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --link: #1f5fae;
  --series-1: #2a78d6;
  /* Deep blue for the checked segment: ≥4.5:1 with white text in both themes. */
  --accent-strong: #1f66c9;
  --hero-from: #1c5cab;
  --hero-to: #4a3aa7;
  --family: #eb6834;
  --employment: #1baf7a;
  --notice-bg: #fff4d6;
  --notice-border: #e0b84a;
  /* Status colors: always paired with an icon and a text label. */
  --good: #0ca30c;
  --serious: #ec835a;
  --critical: #d03b3b;
  --neutral: #8a8984;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #121211;
    --surface: #1a1a19;
    --border: #33332f;
    --grid: #2f2f2d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --link: #8ab8f0;
    --series-1: #3987e5;
    --hero-from: #184f95;
    --hero-to: #3b2e8c;
    --family: #d95926;
    --employment: #199e70;
    --notice-bg: #3a3016;
    --notice-border: #8a6d1f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211;
  --surface: #1a1a19;
  --border: #33332f;
  --grid: #2f2f2d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --link: #8ab8f0;
  --series-1: #3987e5;
  --hero-from: #184f95;
  --hero-to: #3b2e8c;
  --family: #d95926;
  --employment: #199e70;
  --notice-bg: #3a3016;
  --notice-border: #8a6d1f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a {
  color: var(--link);
  text-underline-offset: 0.15em;
  text-decoration-thickness: 1px;
}

/* Browser surfaces themed from the palette, not left to the UA. */
::selection { background: color-mix(in srgb, var(--series-1) 26%, transparent); }
:where(input, select, textarea) { caret-color: var(--series-1); }
:where(a, button, summary, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}
.chart-box, .table-toggle {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-secondary) 45%, transparent) transparent;
}

main, footer, .notice, .hero-inner {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}

.notice {
  padding-top: 10px;
  padding-bottom: 10px;
  background: var(--notice-bg);
  border-bottom: 1px solid var(--notice-border);
  font-size: 14px;
  max-width: none;
  text-align: center;
}

/* Header: a blue-to-violet band with a couple of soft circles for depth. */
.hero {
  position: relative;
  overflow: hidden;
  color: #ffffff;
  background: linear-gradient(120deg, var(--hero-from), var(--hero-to));
  padding: 40px 0 72px;
}
.hero::before, .hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}
.hero::before { width: 320px; height: 320px; right: -80px; top: -120px; }
.hero::after { width: 180px; height: 180px; right: 180px; bottom: -110px; }
.hero-inner { position: relative; }
.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}
.theme-toggle svg { width: 20px; height: 20px; }
/* Show the icon for the mode a click switches to: moon while bright, sun while dark. */
.theme-toggle .icon-sun, :root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
.theme-toggle:hover { background: rgba(255, 255, 255, 0.25); }
.freshness {
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--notice-border);
  border-radius: 8px;
  background: var(--notice-bg);
  font-size: 14px;
}
@media (max-width: 520px) { .theme-toggle { position: static; margin-bottom: 12px; } }
.theme-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(28px, 6vw, 40px); line-height: 1.1; letter-spacing: -0.02em; }
.hero-lede { margin: 0; max-width: 600px; color: rgba(255, 255, 255, 0.9); }

/* Cards: the picker overlaps the bottom of the header. */
main { margin-top: -48px; position: relative; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 6px 20px rgba(20, 20, 40, 0.06);
}

h2 { margin: 0 0 6px; font-size: 20px; }
.small { font-size: 14px; color: var(--text-secondary); }

.picker { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; }
.field { display: flex; flex-direction: column; min-width: 0; max-width: 100%; border: 0; margin: 0; padding: 0; }
.field > span, .field legend { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; padding: 0; }
.field select {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  max-width: 100%;
}

/* Chart A/B as a two-button switch; still plain radio buttons underneath. */
.segmented { display: inline-flex; flex-wrap: wrap; background: var(--page); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 6px 12px; border-radius: 7px; font-size: 14px; color: var(--text-secondary); }
.segmented input:checked + span { background: var(--accent-strong); color: #ffffff; font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.status { color: var(--text-secondary); }

/* Current cutoff: the chip carries the category group's color. */
.current p { margin: 0; }
.current-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.current-label { font-size: 14px; color: var(--text-secondary); }
.current-value { font-size: clamp(30px, 7vw, 42px); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 6px 0 !important; }
.current-note { font-size: 14px; color: var(--text-secondary); margin-top: 8px !important; }
.chart-help { font-size: 13px; color: var(--text-secondary); margin-top: 8px !important; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--group-color) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--group-color) 45%, transparent);
}

/* Status badge: tinted background, colored icon, label in normal text color. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--status) 16%, transparent);
}
.badge .icon { display: inline-flex; color: var(--status); }
.badge .icon svg { width: 0.95em; height: 0.95em; display: block; }
.badge.good { --status: var(--good); }
.badge.serious { --status: var(--serious); }
.badge.critical { --status: var(--critical); }
.badge.neutral { --status: var(--neutral); }

/* Estimator */
.estimator h2 { margin-bottom: 12px; }
.pd-field input {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  max-width: 220px;
}
.pd-hint { margin: 6px 0 14px; }
#estimate-result p { margin: 0 0 8px; }
.estimate-summary { font-size: 17px; }
.estimate-text { color: var(--text-secondary); font-size: 15px; }
.scenarios { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0 4px; }
@media (max-width: 640px) { .scenarios { grid-template-columns: 1fr; } }
/* Scenarios: a dot in light-to-dark steps of one blue marks fastest to slowest. */
.scenario { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--page); }
.scenario.optimistic { --step: #86b6ef; }
.scenario.likely { --step: #2a78d6; }
.scenario.pessimistic { --step: #184f95; }
#estimate-result .scenario p { margin: 0; }
.scenario-label { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.scenario-label::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--step); }
.scenario-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0 !important; }
.scenario-note, .scenario-pace { font-size: 13px; color: var(--text-secondary); }
.scenario-pace { margin-top: 6px !important; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 640px) { .tiles { grid-template-columns: 1fr; } }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.tiles .card { margin-bottom: 0; }
.tile p { margin: 0; }
.tile-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.tile-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0 !important; }
.tile-note { font-size: 13px; color: var(--text-secondary); margin-top: 6px !important; }
.tiles + .small { margin: 8px 0 16px; }

.chart-box { position: relative; height: 300px; margin-top: 8px; }
.chart-box[hidden] { display: none; }

/* Key for the shaded bands drawn over Current / Unavailable months. */
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.chart-legend:empty { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-swatch { width: 24px; height: 13px; border-radius: 3px; border: 1px solid; flex: none; }

.table-toggle { margin-top: 12px; }
.table-toggle summary { cursor: pointer; font-size: 14px; color: var(--link); }
.history-table { border-collapse: collapse; margin: 12px 0 0; font-size: 14px; width: 100%; font-variant-numeric: tabular-nums; }
.history-table caption { text-align: left; color: var(--text-secondary); padding-bottom: 4px; }
.history-table th, .history-table td { text-align: left; padding: 6px 12px 6px 0; border-bottom: 1px solid var(--border); }

/* One authored moment: the result rises into place once, when data first loads.
   The default (and reduced-motion) state is the finished, visible one. */
@media (prefers-reduced-motion: no-preference) {
  #result { animation: result-in 620ms cubic-bezier(0.16, 1, 0.3, 1) both; }
  @keyframes result-in {
    from { opacity: 0; transform: translateY(14px); filter: blur(5px); }
  }
}

footer {
  margin-top: 32px;
  padding-top: 16px;
  padding-bottom: 32px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-secondary);
}
