:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efefeb;
  --border: #e0dfda;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7c7b76;
  --accent: #128a5f;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ea;
  --good: #0f7a3d;
  --bad: #b3261e;
  --grid: #e6e5e0;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  /* categorical series — fixed order, one per family member */
  --s0: #2a78d6; --s1: #eb6834; --s2: #1baf7a; --s3: #eda100;
  --s4: #e87ba4; --s5: #008300; --s6: #6250d6; --s7: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #2fbf87;
    --accent-ink: #06130d;
    --accent-soft: #15382a;
    --good: #4cc77f;
    --bad: #f2827c;
    --grid: #2a2a27;
    --s0: #3987e5; --s1: #d95926; --s2: #199e70; --s3: #c98500;
    --s4: #d55181; --s5: #0ca30c; --s6: #9085e9; --s7: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #2fbf87; --accent-ink: #06130d; --accent-soft: #15382a;
  --good: #4cc77f; --bad: #f2827c; --grid: #2a2a27;
  --s0: #3987e5; --s1: #d95926; --s2: #199e70; --s3: #c98500;
  --s4: #d55181; --s5: #0ca30c; --s6: #9085e9; --s7: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(96px + env(safe-area-inset-bottom));
}
h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.eyebrow { color: var(--text-2); font-size: 14px; margin: 0; }
a { color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

/* ---------- buttons & inputs */
button, .btn {
  font: inherit;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  min-height: 48px;
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.block { width: 100%; }
.big { font-size: 19px; min-height: 60px; border-radius: 18px; }
.link { background: none; color: var(--accent); padding: 8px 4px; min-height: 0; }
.danger { color: var(--bad); }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 48px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
label { display: block; font-size: 14px; color: var(--text-2); margin-bottom: 6px; }
.field + .field { margin-top: 14px; }

/* ---------- weigh-in entry */
.entry { text-align: center; }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; margin: 8px 0 14px; }
.stepper button { min-height: 64px; font-size: 30px; border-radius: 50%; width: 64px; padding: 0; }
.weight-input {
  font-size: 52px; font-weight: 700; text-align: center; letter-spacing: -.02em;
  border: 0; background: transparent; padding: 0; min-height: 70px;
  font-variant-numeric: tabular-nums;
}
.weight-input::-webkit-outer-spin-button, .weight-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.weight-input { -moz-appearance: textfield; }
.unit { color: var(--text-2); font-size: 15px; margin-top: -8px; }
.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 0 0 14px; }
.chip {
  background: var(--surface-2); border-radius: 999px; padding: 8px 14px; min-height: 40px; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip input { min-height: 0; padding: 0; border: 0; background: transparent; width: auto; font-size: 14px; }
.done-badge {
  display: inline-flex; gap: 8px; align-items: center; background: var(--accent-soft); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 14px;
}
.done-badge svg { width: 18px; height: 18px; stroke: var(--accent); fill: none; stroke-width: 3; }

/* ---------- stat tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; }
.tile .k { font-size: 13px; color: var(--text-2); }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .v small { font-size: 14px; font-weight: 500; color: var(--text-2); }
.tile .d { font-size: 13px; color: var(--text-2); }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* ---------- charts */
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.tall { height: 280px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { min-height: 34px; padding: 4px 12px; font-size: 14px; border-radius: 9px; background: transparent; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 4px; display: inline-block; flex: none; }
.swatch.line { height: 3px; border-radius: 2px; width: 16px; }
.swatch.dash { height: 0; border-top: 2px dashed var(--text-3); width: 16px; border-radius: 0; }
details.table-view { margin-top: 10px; font-size: 14px; }
details.table-view summary { color: var(--text-2); cursor: pointer; padding: 4px 0; }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 500; }

/* family cards */
.person { display: grid; grid-template-columns: 1fr 96px; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.person .name { font-weight: 650; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.person .lost { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.spark { width: 96px; height: 44px; }
.status { font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* toggles */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch input { appearance: none; width: 52px; height: 32px; min-height: 0; border-radius: 999px; background: var(--border); position: relative; flex: none; padding: 0; border: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgb(0 0 0 / .3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

/* ---------- tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; color: var(--text-3); text-decoration: none; font-size: 12px; font-weight: 600; border-radius: 12px; }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent); }

/* ---------- misc */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 20;
  max-width: calc(100% - 32px); font-size: 15px; box-shadow: var(--shadow);
}
.splash { display: grid; place-items: center; height: 60dvh; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hero { text-align: center; padding: 30px 0 10px; }
.hero .logo { width: 84px; height: 84px; }
.back { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--accent); font-weight: 600; padding: 6px 0; }
.banner { background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
.banner p { margin: 0; flex: 1; font-size: 14px; }
.banner button { min-height: 40px; padding: 8px 14px; }
.celebrate { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .celebrate, .spinner { animation: none; } }
