:root {
  color-scheme: light;
  --bg: #f7f3ee;
  --surface: #fffdfa;
  --surface-2: #f1ece5;
  --line: #e4ddd3;
  --text: #1f1d1a;
  --text-2: #5c5852;
  --muted: #8a857d;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --feed: #2a78d6;
  --nappy: #eb6834;
  --growth: #1baf7a;
  --vaccine: #4a3aa7;
  --warn-bg: #fff1e6;
  --warn-ink: #9a3b0a;
  --danger: #c0362c;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #ebe5dc;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .06);
  --radius: 16px;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413;
    --surface: #1f1f1d;
    --surface-2: #2a2a27;
    --line: #34342f;
    --text: #f4f3ee;
    --text-2: #c3c2b7;
    --muted: #8e8d84;
    --accent: #3987e5;
    --feed: #3987e5;
    --nappy: #d95926;
    --growth: #199e70;
    --vaccine: #9085e9;
    --warn-bg: #3a2414;
    --warn-ink: #ffb68a;
    --danger: #ff6b5e;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c29;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1f1f1d; --surface-2: #2a2a27; --line: #34342f;
  --text: #f4f3ee; --text-2: #c3c2b7; --muted: #8e8d84; --accent: #3987e5;
  --feed: #3987e5; --nappy: #d95926; --growth: #199e70; --vaccine: #9085e9;
  --warn-bg: #3a2414; --warn-ink: #ffb68a; --danger: #ff6b5e;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c29; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
.muted { color: var(--muted); margin: 0; font-size: .875rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 1.4rem; }
.sync {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-size: .8rem; color: var(--text-2);
}
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync.ok .dot { background: #1baf7a; }
.sync.busy .dot { background: #eda100; animation: pulse 1s infinite; }
.sync.err .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat .label { font-size: .8rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.stat .big { font-size: 1.6rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.hero { grid-column: 1 / -1; }
.stat.hero .big { font-size: 2.2rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.quick button {
  border: none; border-radius: 14px; padding: 12px 4px 10px;
  background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600;
}
.quick button .ic {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  color: #fff; font-size: 1.2rem;
}

.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: none; }
.item .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; font-size: .95rem; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .meta { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { font-size: .85rem; color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; }
.item.clickable { cursor: pointer; }
.pending-badge { font-size: .7rem; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 1px 6px; margin-left: 6px; }

.day { margin-top: 18px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.day-head h3 { font-size: .95rem; }
.day-head .sum { font-size: .78rem; color: var(--muted); text-align: right; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: .9rem;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip .swatch { width: 14px; height: 14px; border-radius: 50%; margin-right: 6px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.15); }
.filters { margin: 4px 0 6px; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
.filters .chip { white-space: nowrap; padding: 6px 12px; font-size: .85rem; }

.banner {
  background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px;
  padding: 10px 14px; font-size: .875rem; margin-top: 8px;
}
.banner button { border: none; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }

/* Bottom sheet */
.sheet {
  border: none; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px;
  max-height: 92vh; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.35); }
.sheet form { padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); display: grid; gap: 14px; }
.sheet .head { display: flex; justify-content: space-between; align-items: center; }
.sheet .head h2 { margin: 0; font-size: 1.2rem; }
.x { border: none; background: var(--surface-2); border-radius: 50%; width: 32px; height: 32px; font-size: 1.1rem; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .8rem; color: var(--text-2); font-weight: 600; }
.input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); min-height: 44px;
}
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { flex: none; width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.3rem; }
.stepper input { text-align: center; font-size: 1.4rem; font-weight: 650; }
.switch { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--nappy); }
.switch input:checked::after { transform: translateX(20px); }
.actions { display: flex; gap: 10px; margin-top: 4px; }
.btn {
  flex: 1; min-height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 650;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { flex: none; padding: 0 16px; color: var(--danger); background: none; }
.hint { font-size: .8rem; color: var(--warn-ink); background: var(--warn-bg); padding: 8px 10px; border-radius: 10px; }
[hidden] { display: none !important; }

/* Charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .hit { fill: transparent; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--text-2); margin: 2px 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
details.tbl { margin-top: 8px; font-size: .85rem; }
details.tbl summary { color: var(--accent); cursor: pointer; }
details.tbl table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
details.tbl th, details.tbl td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tip {
  position: fixed; pointer-events: none; z-index: 20; opacity: 0;
  background: var(--text); color: var(--bg); font-size: .8rem; padding: 6px 10px; border-radius: 8px;
  transition: opacity .1s; white-space: nowrap;
}
.tip.show { opacity: 1; }

/* Tabs */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: none; background: none; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: .72rem; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  opacity: 0; transition: all .2s; z-index: 30; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.who .chip { text-align: center; padding: 14px; font-weight: 700; font-size: 1.1rem; border-radius: 14px; }
.settings .card { margin-top: 10px; display: grid; gap: 12px; }
.settings p { margin: 0; font-size: .875rem; color: var(--text-2); }
.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: .9rem; }

/* Milestone checklist */
.chip.wide { width: 100%; text-align: left; border-radius: 12px; padding: 10px 12px 10px 38px; position: relative; white-space: normal; }
.chip.wide::before { content: ""; position: absolute; left: 12px; top: 12px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); }
.chip.wide[aria-pressed="true"]::before { content: "✓"; border-color: var(--accent-ink); color: var(--accent-ink); font-size: 11px; line-height: 16px; text-align: center; font-weight: 800; }
.chip.wide small { display: block; font-size: .72rem; opacity: .7; margin-top: 2px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #c98500; border-radius: 4px; }
.card.clickable { cursor: pointer; }
.chip.wide small + small { margin-top: 0; }
.chip.wide em.due, .due { font-style: normal; font-size: .7rem; font-weight: 700; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.chip.wide[aria-pressed="true"] em.due { background: rgba(255,255,255,.25); color: inherit; }
.chip.wide.shot.done { opacity: .55; }
.chip.wide.shot.upcoming em.due { display: none; }
ul.plain { margin: 4px 0 0; padding-left: 18px; font-size: .85rem; color: var(--text-2); }
ul.plain li { margin: 3px 0; }
.chip.wide.shot.done em.due { background: transparent; color: var(--muted); }

/* History filter: sticky 5x2 grid under the top bar */
.hfilter {
  position: sticky; top: var(--topbar-h, 64px); z-index: 4;
  margin: 0 -16px; padding: 4px 16px 8px;
  background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.hfilter-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.hf {
  display: grid; justify-items: center; gap: 1px; padding: 6px 2px 5px; min-height: 58px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
}
.hf-ic { font-size: 1.05rem; line-height: 1.2; }
.hf-label { font-size: clamp(.62rem, 2.9vw, .72rem); font-weight: 600; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.hf-n { font-size: .65rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.hf[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.hf[aria-pressed="true"] .hf-n { color: inherit; opacity: .8; }
.hf:disabled { opacity: .4; cursor: default; }
.hfilter-status { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: .8rem; color: var(--text-2); }
.linkbtn { border: none; background: none; color: var(--accent); font-weight: 600; font-size: .8rem; padding: 4px 0; }
@media (min-width: 560px) { .hfilter-grid { grid-template-columns: repeat(10, minmax(0, 1fr)); } }
@media (max-width: 380px) {
  .hfilter-grid { gap: 4px; }
  .hf { padding: 6px 0 5px; }
  .hf-label { font-size: clamp(.58rem, 2.8vw, .68rem); letter-spacing: -.01em; }
}

/* Night Mode: dark, low-brightness, warm (less blue light). Overrides light and dark themes. */
:root[data-night] {
  color-scheme: dark;
  --bg: #0e0d0b; --surface: #171512; --surface-2: #211e1a; --line: #2a2723;
  --text: #b9ad97; --text-2: #958a77; --muted: #6e665a;
  --accent: #9a6a2c; --accent-ink: #0e0d0b;
  --feed: #5a4a33; --nappy: #6b3d22; --growth: #3d4a32; --vaccine: #4a3d52; --danger: #b0503f;
  --warn-bg: #2a1d12; --warn-ink: #c08a5c;
  --series-1: #8a6a3c; --series-2: #7a4a2c; --grid: #221f1b; --shadow: none;
}
:root[data-night] .item .ic, :root[data-night] .quick .ic, :root[data-night] .hf-ic, :root[data-night] img { filter: saturate(.5) brightness(.8); }
.night-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-size: .875rem; color: var(--text-2);
}
.night-row .chip { flex: none; padding: 6px 14px; }
:root[data-night] .switch input::after { background: #8a8170; box-shadow: none; }
.qr { width: 220px; margin: 12px auto 4px; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; }
