/* Night nursery: dim plum ink, warm moonlight text, one soft hue per event type. */
:root {
  --bg: #1e1a2e;
  --surface: #2a2540;
  --surface-2: #352f4f;
  --line: #3f3860;
  --text: #f1e8da;
  --muted: #a99fbf;
  --pee: #8ec5e8;
  --poop: #d2a660;
  --feed: #eba3b5;
  --weight: #a5d39e;
  --danger: #ff8f80;
  --on-pad: #1e1a2e;
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --pad-h: 76px;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f1f9;
  --surface: #ffffff;
  --surface-2: #ebe6f4;
  --line: #ddd5ea;
  --text: #2a2440;
  --muted: #6e6587;
  --pee: #2f86bf;
  --poop: #a06d1c;
  --feed: #c4486a;
  --weight: #3f8a36;
  --danger: #c0392b;
  --on-pad: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 3px solid var(--feed); outline-offset: 2px; }
[hidden] { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top, 0px);
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 4px;
}
.baby { display: flex; align-items: baseline; gap: 8px; text-align: left; min-width: 0; flex: 1; }
.baby-name { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
.baby-age { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); border-radius: 50%; }
.sync { width: 9px; height: 9px; border-radius: 50%; background: var(--weight); opacity: .8; }
.sync.pending { background: var(--poop); }
.sync.offline { background: var(--muted); opacity: .5; }

.tabs {
  display: flex;
  gap: 4px;
  margin: 6px 16px 8px;
  padding: 4px;
  background: var(--surface);
  border-radius: 999px;
}
.tabs button {
  flex: 1;
  height: 36px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 700;
  font-size: 15px;
}
.tabs button.on { background: var(--surface-2); color: var(--text); }

main {
  flex: 1;
  padding: 4px 16px calc(var(--pad-h) + 28px + env(safe-area-inset-bottom, 0px));
}

/* ---------- time since last: the memorable bit ---------- */
.since {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.since-cell {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 12px 12px 10px;
  text-align: left;
  min-width: 0;
}
.since-label { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; gap: 4px; align-items: center; }
.since-val {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  white-space: nowrap;
}
.since-val small { font-size: 16px; font-weight: 700; margin-left: 1px; margin-right: 3px; opacity: .8; }
.since-sub { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.since-cell.feed .since-val { color: var(--feed); }
.since-cell.pee .since-val { color: var(--pee); }
.since-cell.poop .since-val { color: var(--poop); }
.since-val.none { color: var(--muted) !important; font-size: 17px; white-space: normal; padding-top: 6px; }

/* ---------- today totals ---------- */
.totals {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 15px;
  color: var(--muted);
  margin: 0 2px 16px;
}
.totals b { color: var(--text); font-weight: 800; }

/* ---------- timeline ---------- */
.day-h { font-size: 14px; font-weight: 700; color: var(--muted); margin: 18px 2px 6px; }
.day-h:first-child { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: 52px 30px 1fr auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 52px;
  padding: 6px 4px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.row-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; }
.row-ico { font-size: 20px; text-align: center; }
.row-main { min-width: 0; }
.row-title { font-weight: 700; display: block; }
.row-detail { display: block; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-who {
  font-size: 12px; font-weight: 800; color: var(--muted);
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface);
}
.row.pending .row-time::after { content: " •"; color: var(--poop); }
.row.flag .row-detail { color: var(--danger); }
.empty { color: var(--muted); padding: 24px 4px; line-height: 1.5; }

/* ---------- history ---------- */
.hday { border-bottom: 1px solid var(--line); }
.hday-btn { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; width: 100%; padding: 12px 4px; text-align: left; }
.hday-date { font-weight: 800; }
.hday-stats { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; color: var(--muted); }
.hday-stats b { color: var(--text); }
.hday-chev { color: var(--muted); transition: transform .2s; }
.hday.open .hday-chev { transform: rotate(90deg); }
.hday .list { padding-bottom: 8px; }

/* ---------- growth ---------- */
.chart { background: var(--surface); border-radius: var(--r-lg); padding: 10px 6px 4px; margin-bottom: 12px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .pct { fill: none; stroke: var(--muted); stroke-width: 1.2; opacity: .55; }
.chart .pct.p50 { stroke-width: 2; opacity: .9; }
.chart .band { fill: var(--weight); opacity: .08; }
.chart .pt { fill: var(--weight); stroke: var(--bg); stroke-width: 2; }
.chart .ln { fill: none; stroke: var(--weight); stroke-width: 2.5; }
.hint { font-size: 14px; color: var(--muted); margin: 0 2px 14px; line-height: 1.5; }
.link { color: var(--feed); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- bottom action pads (thumb zone) ---------- */
.actions {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  z-index: 5;
}
.pad {
  height: var(--pad-h);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
  font-size: 15px;
  color: var(--on-pad);
  transition: transform .08s;
}
.pad:active { transform: scale(.95); }
.pad-ico { font-size: 26px; line-height: 1; }
.pad.pee { background: var(--pee); }
.pad.poop { background: var(--poop); }
.pad.feed { background: var(--feed); }
.pad.weight { background: var(--weight); }

/* ---------- breastfeeding timer ---------- */
.timer-bar {
  margin: 0 16px 10px;
  padding: 10px 10px 10px 16px;
  border-radius: var(--r-lg);
  background: var(--feed);
  color: var(--on-pad);
  display: flex;
  align-items: center;
  gap: 8px;
}
.timer-info { flex: 1; min-width: 0; }
.timer-side { font-weight: 800; font-size: 14px; }
.timer-clock { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.timer-bar .btn { background: rgba(0,0,0,.14); color: inherit; height: 44px; padding: 0 14px; }
.timer-bar .btn.stop { background: var(--on-pad); color: var(--feed); }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.backdrop { position: absolute; inset: 0; background: rgba(10, 8, 20, .55); animation: fade .15s; }
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  animation: rise .2s cubic-bezier(.2,.8,.2,1);
}
.sheet::before {
  content: ""; display: block; width: 40px; height: 5px; border-radius: 3px;
  background: var(--line); margin: 0 auto 10px;
}
.sheet h2 { margin: 0 0 12px; font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 15px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--text); color: var(--surface); }
.seg { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.seg .chip { flex: 1; justify-content: center; background: none; min-height: 40px; }
.seg .chip.on { background: var(--feed); color: var(--on-pad); }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }
.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; align-items: center; }
.stepper button { height: 56px; border-radius: var(--r-md); background: var(--surface-2); font-size: 26px; font-weight: 800; }
.stepper input { text-align: center; font-size: 32px; font-weight: 800; }
.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 17px; /* ≥16px stops iOS zoom-on-focus */
}
input.bare { background: none; border: 0; width: 100%; min-width: 0; padding: 0; }
.warn { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); border-radius: var(--r-md); padding: 10px 12px; font-size: 14px; font-weight: 700; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn {
  min-height: 52px;
  padding: 0 18px;
  border-radius: var(--r-md);
  font-weight: 800;
  font-size: 17px;
  background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center;
}
a.btn { color: inherit; text-decoration: none; }
.btn.primary { background: var(--text); color: var(--surface); flex: 1; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.sub-h { font-size: 17px; font-weight: 800; margin: 26px 0 10px; }
.inline { display: flex; gap: 8px; }
.inline .input { flex: 1; min-width: 0; }
.input.static { display: flex; align-items: center; color: var(--muted); }
.back { min-height: 40px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.form-err { color: var(--danger); font-weight: 700; margin: 0 0 12px; }
.datetime { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.datetime .input { text-align: center; font-variant-numeric: tabular-nums; }
.input.pick { display: flex; align-items: center; justify-content: center; font-weight: 700; cursor: pointer; }
.pick .ph { color: var(--muted); font-weight: 600; }
.picker-wrap { z-index: 25; }
.picker .pick-value { text-align: center; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 0 0 10px; }
.cal-nav { display: grid; grid-template-columns: 44px 44px 1fr 44px 44px; align-items: center; margin-bottom: 6px; }
.cal-nav button { height: 44px; border-radius: var(--r-sm); font-size: 22px; font-weight: 800; color: var(--muted); }
.cal-month { text-align: center; font-weight: 800; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 10px; }
.cal-wd { text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); padding: 4px 0; text-transform: capitalize; }
.cal-day { height: 44px; border-radius: 50%; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--muted); }
.cal-day.on { background: var(--text); color: var(--surface); }
.cal-day:disabled { opacity: .25; }
.tp-value button { padding: 0 6px; border-radius: var(--r-sm); font: inherit; color: var(--muted); }
.tp-value button.on { color: var(--text); background: var(--surface-2); }
.tp-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 10px; }
.tp-cell { height: 48px; border-radius: var(--r-md); background: var(--surface-2); font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.tp-cell.on { background: var(--text); color: var(--surface); }
.tp-fine { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 4px; }
.date-row { grid-template-columns: 96px 30px 1fr auto; }
.user-row { grid-template-columns: 34px 1fr auto; }
.meta { font-size: 13px; color: var(--muted); margin-top: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--pad-h) + 30px + env(safe-area-inset-bottom, 0px));
  max-width: 536px;
  margin: 0 auto;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-md);
  padding: 6px 6px 6px 16px;
  display: flex; align-items: center; gap: 4px;
  font-weight: 700;
  z-index: 15;
  animation: rise .18s;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
.toast-msg { flex: 1; min-width: 0; }
.toast button { min-height: 44px; padding: 0 10px; font-weight: 800; color: inherit; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: grid; place-items: center; padding: 24px 20px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0 0 8px; font-size: 40px; font-weight: 800; }
.login-mark { font-size: 44px; }
.login label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; color: var(--muted); font-size: 14px; }
.login input { min-height: 52px; padding: 10px 14px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); font-size: 18px; color: var(--text); }
.login-err { color: var(--danger); font-weight: 700; margin: 0; }

@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* very narrow phones (Galaxy S20 = 360px) */
@media (max-width: 370px) {
  .since-val { font-size: 26px; }
  .since-val small { font-size: 14px; }
  .pad { font-size: 14px; }
}
