/*
 * Palette note: the thinness bands are a blue ordinal ramp (light -> dark with
 * severity) and the excess bands a status severity ramp (amber -> deep red),
 * both validated for lightness gaps and surface contrast in each mode. Colour
 * never carries meaning alone — every band is named in the table and in the
 * chart's hover/focus tooltip.
 */
:root {
  color-scheme: light;

  --surface: #fcfcfb;
  --plane: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --focus: #2a78d6;

  --band-severeThinness: #184f95;
  --band-moderateThinness: #2a78d6;
  --band-mildThinness: #6da7ec;
  --band-normal: #0ca30c;
  --band-overweight: #f0a500;
  --band-obeseI: #e06a2b;
  --band-obeseII: #c02f2f;
  --band-obeseIII: #761414;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --surface: #1a1a19;
    --plane: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --focus: #6da7ec;

    --band-severeThinness: #1c5cab;
    --band-moderateThinness: #3987e5;
    --band-mildThinness: #9ec5f4;
    --band-normal: #0ca30c;
    --band-overweight: #fab219;
    --band-obeseI: #ec835a;
    --band-obeseII: #d03b3b;
    --band-obeseIII: #a02a2a;
  }
}

* {
  box-sizing: border-box;
}

/* `display: flex` on .input-group would otherwise beat the UA rule for [hidden]. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.page {
  max-width: 56rem;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

/* ---------- masthead ---------- */

.masthead {
  margin-bottom: 1.75rem;
}

h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0;
  color: var(--ink-2);
  max-width: 46ch;
}

.lang-switch {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.lang-switch button {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.lang-switch button:hover {
  background: var(--surface);
  color: var(--ink);
}

.lang-switch button[aria-current="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

/* ---------- controls ---------- */

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1rem;
  margin: 0 0 1.25rem;
  padding: 0;
  border: 0;
}

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

.field legend {
  padding: 0 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.legend-note {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-muted);
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 8rem;
  min-width: 0;
}

.input-group--split {
  gap: 0.5rem;
}

.sub-input {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

input[type="number"] {
  font: inherit;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
  width: 100%;
  min-width: 3.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--plane);
  color: var(--ink);
}

input[type="number"]:focus-visible,
.toggle button:focus-visible,
.lang-switch button:focus-visible,
.segment:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.unit-suffix {
  font-size: 0.9375rem;
  color: var(--ink-muted);
  white-space: nowrap;
}

.toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  background: var(--plane);
}

.toggle button {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.3rem 0.7rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}

.toggle button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
}

/* ---------- messages & summary ---------- */

.message {
  margin: 0 0 1.25rem;
  color: var(--ink-2);
}

.message:empty {
  display: none;
}

.message[data-tone="error"] {
  color: var(--band-obeseII);
  font-weight: 500;
}

.summary {
  margin: 0 0 1.5rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--band-normal);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.0625rem;
}

.summary[data-band-tone="out"] {
  border-left-color: var(--band-overweight);
}

.summary b {
  font-weight: 600;
}

/* ---------- panels ---------- */

.panel {
  margin: 0 0 1.75rem;
  padding: 1.1rem 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel h2 {
  margin: 0 0 0.9rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink-2);
}

/* ---------- chart ---------- */

.chart {
  margin: 0;
}

.chart-bar {
  display: flex;
  gap: 2px;
  position: relative;
  height: 2.5rem;
  margin-bottom: 0.4rem;
}

.segment {
  border: 0;
  padding: 0;
  min-width: 2px;
  border-radius: 2px;
  background: var(--band, var(--axis));
  cursor: default;
}

.segment:first-child {
  border-radius: 4px 2px 2px 4px;
}

.segment:last-child {
  border-radius: 2px 4px 4px 2px;
}

.segment[data-active="true"] {
  box-shadow: inset 0 0 0 2px var(--surface), 0 0 0 2px var(--ink);
}

.marker {
  position: absolute;
  top: -0.35rem;
  bottom: -0.35rem;
  width: 2px;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--surface);
  transform: translateX(-1px);
  pointer-events: none;
}

.marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--surface);
  transform: translateX(-50%);
}

.chart-ticks {
  position: relative;
  height: 1.6rem;
  border-top: 1px solid var(--grid);
}

.tick {
  position: absolute;
  top: 0.25rem;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  white-space: nowrap;
}

.tick[data-minor="true"] {
  display: none;
}

@media (min-width: 40rem) {
  .tick[data-minor="true"] {
    display: block;
  }
}

.chart-caption {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--ink-2);
}

.chart-caption .swatch {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 2px;
  background: var(--band-normal);
  margin-right: 0.35rem;
  vertical-align: baseline;
}

/* ---------- table ---------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

td.num,
th.num {
  text-align: right;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr[data-normal="true"] {
  background: color-mix(in srgb, var(--band-normal) 8%, transparent);
}

tbody tr[data-current="true"] {
  box-shadow: inset 3px 0 0 var(--ink);
  font-weight: 600;
}

/* The header row labels the columns on wide screens, so the per-cell labels
   stay out of the page and out of the accessibility tree. */
.cell-label {
  display: none;
}

/* The weight column is the point of the app, and three columns of it will not
   fit a phone. Below this width each row stacks: name on one line, BMI and
   weight on the next, and the per-cell labels take over from the header row. */
@media (max-width: 27rem) {
  table,
  tbody {
    display: block;
  }

  thead {
    display: none;
  }

  .page {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .panel {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }

  tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 0 0.4rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--grid);
  }

  tbody tr:last-child {
    border-bottom: 0;
  }

  tbody td {
    padding: 0.1rem 0;
    border: 0;
  }

  tbody td:first-child {
    grid-column: 1 / -1;
    white-space: normal;
  }

  tbody td.num {
    text-align: left;
    font-size: 0.875rem;
  }

  tbody td.num:last-child {
    text-align: right;
  }

  tbody tr[data-current="true"] {
    padding-left: 0.5rem;
  }

  .cell-label {
    display: inline;
    margin-right: 0.25rem;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--ink-muted);
  }

  /* The row already reads as current: inset bar plus bold text. */
  .you-are-here {
    display: none;
  }
}

.band-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: normal;
}

.band-dot {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  background: var(--band, var(--axis));
}

.you-are-here {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* ---------- footer & tooltip ---------- */

.footnotes {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--grid);
  font-size: 0.8125rem;
  color: var(--ink-2);
  max-width: 60ch;
}

.footnotes p {
  margin: 0 0 0.5rem;
}

.muted {
  color: var(--ink-muted);
}

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 16rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.8125rem;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.tooltip strong {
  display: block;
  font-weight: 600;
}

.tooltip span {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: no-preference) {
  .segment,
  .marker {
    transition: all 120ms ease-out;
  }
}
