:root {
  --bg: #f4f5f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6b6a66;
  --border: #e3e2de;
  --grid: #ecebe7;
  --accent: #1c5cab;
  --accent-text: #ffffff;
  --series: #2a78d6;
  --ref-1: #8a8984;
  --ref-2: #52514e;
  --disclaimer-bg: #3a2a00;
  --disclaimer-text: #fff4d6;
  --low: #0ca30c;
  --moderate: #fab219;
  --high: #d03b3b;
  --band-bg: #f0efec;
  --danger: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 15, 15, 0.06);
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110;
    --surface: #1a1a19;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #a3a29b;
    --border: #383835;
    --grid: #2a2a28;
    --accent: #3987e5;
    --accent-text: #0b0b0b;
    --series: #3987e5;
    --ref-1: #8a8984;
    --ref-2: #c3c2b7;
    --band-bg: #262624;
    --danger: #f97066;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 15px;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.4rem;
}

h1 {
  font-size: 1.45rem;
}

h2 {
  font-size: 1.1rem;
}

h3 {
  font-size: 0.98rem;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

/* --- frame --- */

.disclaimer {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--disclaimer-bg);
  color: var(--disclaimer-text);
  padding: 0.45rem 16px;
  font-size: 0.85rem;
  text-align: center;
}

.disclaimer strong {
  color: #fff;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.8rem 16px;
}

.brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text);
}

.brand__name {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 1.2rem;
}

.brand__sub {
  color: var(--muted);
  font-size: 0.8rem;
}

.site-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.rule-chip {
  font-size: 0.78rem;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

.rule-chip:empty {
  display: none;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 2rem;
}

.site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 16px 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin: 1rem 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(560px, calc(100% - 32px));
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.toast--error {
  background: var(--danger);
  color: #fff;
}

.loading,
.error {
  padding: 2rem 0;
}

.error {
  color: var(--danger);
}

.note {
  font-size: 0.82rem;
  color: var(--text-2);
  background: var(--band-bg);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  margin: 0.8rem 0 0;
}

/* --- buttons and forms --- */

.btn {
  display: inline-block;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 40px;
}

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

.btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: currentColor;
}

.btn--link {
  background: none;
  border: none;
  color: var(--danger);
  padding: 0.2rem 0;
  min-height: 0;
  font-weight: 500;
}

.btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0.8rem 0;
}

.field--wide {
  grid-column: 1 / -1;
}

label,
legend {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 0.25rem;
}

input,
select {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  min-height: 42px;
}

input:focus,
select:focus,
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.concern {
  border: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
}

.concern legend {
  width: 100%;
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text);
  margin: 0;
}

.radio input {
  width: auto;
  min-height: 0;
}

/* --- list --- */

.intro p {
  max-width: 62ch;
  color: var(--text-2);
}

.intro .btn {
  margin-right: 0.6rem;
}

.list-title {
  margin-top: 1.6rem;
}

.baby-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.baby-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.15rem 0.8rem;
  align-items: center;
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}

.baby-row:hover {
  border-color: var(--accent);
}

.baby-row__id {
  font-weight: 700;
}

.baby-row__story,
.baby-row__meta {
  grid-column: 1;
  font-size: 0.86rem;
  color: var(--text-2);
}

.baby-row__meta {
  color: var(--muted);
}

.baby-row__band {
  grid-column: 2;
  grid-row: 1 / span 3;
}

.tag {
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--band-bg);
  color: var(--text-2);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  margin-left: 0.25rem;
}

/* --- band chips (status colour + label, never colour alone) --- */

.band {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.86rem;
  white-space: nowrap;
  background: var(--band-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
}

.band__dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--muted);
}

.band--low .band__dot {
  background: var(--low);
}

.band--moderate .band__dot {
  background: var(--moderate);
}

.band--high .band__dot {
  background: var(--high);
}

.band--none {
  font-weight: 600;
  color: var(--text-2);
}

.band__score {
  font-weight: 500;
  color: var(--text-2);
}

.band--large {
  font-size: 1.15rem;
  padding: 0.35rem 0.9rem;
}

.band--large .band__dot {
  width: 0.95rem;
  height: 0.95rem;
}

/* --- baby view --- */

.back {
  display: inline-block;
  margin: 0.3rem 0 0.8rem;
  text-decoration: none;
  font-size: 0.9rem;
}

.baby-head {
  display: grid;
  gap: 1rem;
}

.baby-head p {
  margin: 0.15rem 0;
}

.summary__text {
  margin: 0.4rem 0 0;
  color: var(--text-2);
}

.chart-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
  margin: 0 0 0.6rem;
}

.key {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px solid var(--series);
  margin-left: 0.4rem;
}

.key--ref1 {
  border-top: 1.5px dashed var(--ref-1);
}

.key--ref2 {
  border-top: 1.5px dashed var(--ref-2);
}

.chart-grid {
  display: grid;
  gap: 1rem;
}

.chart {
  margin: 0;
  min-width: 0;
}

.chart figcaption {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-2);
}

.chart__plot {
  position: relative;
  min-height: 170px;
}

.chart__plot svg {
  display: block;
  overflow: visible;
}

.chart-empty {
  color: var(--muted);
  font-size: 0.88rem;
}

.chart__plot .grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart__plot .axis {
  stroke: var(--border);
}

.chart__plot .tick,
.chart__plot .axis-label,
.chart__plot .ref-label {
  fill: var(--muted);
  font-size: 10px;
}

.chart__plot .ref-label {
  fill: var(--text-2);
}

.chart__plot .ref {
  fill: none;
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.chart__plot .ref-1 {
  stroke: var(--ref-1);
}

.chart__plot .ref-2 {
  stroke: var(--ref-2);
}

.chart__plot .series {
  fill: none;
  stroke: var(--series);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart__plot .point {
  fill: var(--series);
  stroke: var(--surface);
  stroke-width: 2;
}

.chart__plot .point--unscored {
  fill: var(--surface);
  stroke: var(--series);
}

.chart__plot .hit {
  fill: transparent;
  cursor: pointer;
  outline: none;
}

.tooltip {
  position: absolute;
  min-width: 120px;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font-size: 0.78rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  line-height: 1.35;
}

.scan {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 0.7rem 0;
}

.scan__head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  justify-content: space-between;
  align-items: flex-start;
}

.calc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.measures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 1rem;
  margin: 0.7rem 0;
}

.measures dt {
  font-size: 0.75rem;
  color: var(--muted);
}

.measures dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.why summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
}

.layers {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.layers th,
.layers td {
  padding: 0.3rem 0.4rem;
  text-align: right;
  border-bottom: 1px solid var(--grid);
}

.layers th[scope="row"],
.layers thead th:first-child {
  text-align: left;
  font-weight: 600;
}

.layers thead th {
  color: var(--muted);
  font-weight: 600;
}

.layers tfoot th,
.layers tfoot td {
  font-weight: 700;
  border-bottom: none;
}

.reasons {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
  color: var(--text-2);
}

.reasons li {
  margin: 0.2rem 0;
}

.unscored {
  font-size: 0.88rem;
  color: var(--text-2);
  background: var(--band-bg);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
}

.scan__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.3rem 1rem;
  margin-top: 0.6rem;
  font-size: 0.8rem;
}

@media (min-width: 720px) {
  .baby-head {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .summary {
    text-align: right;
    max-width: 320px;
  }

  .chart-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .field-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .measures {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .add-baby,
  .add-scan {
    max-width: 760px;
  }
}
