/* TinyTots: a bedside instrument that counts like the family whiteboard.
   Graphite-to-paper neutrals, one coral accent for the live feed and the
   primary action, five muted category marks, tabular figures, 1px rules. */

:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --sunken: #ececea;
  --line: #d6d6d2;
  --line-strong: #a9a9a4;
  --text: #18181a;
  --text-2: #4e4e52;
  --text-3: #626266;
  --accent: #b8432f;
  --accent-hover: #a03a28;
  --on-accent: #ffffff;
  --accent-tint: #f8e7e2;
  --lit: #ffffff;
  --lit-line: var(--line-strong);
  --danger: #a3302a;
  --feed: #3d6fb6;
  --diaper: #2e8a6e;
  --spitup: #a67c12;
  --weight: #6b5fb0;
  --milestone: #b8457a;
  --shadow: 0 -8px 32px rgb(24 24 26 / 0.18);
  --radius: 10px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --gutter: 16px;
}

/* Dark: a warm near-black for the 3 a.m. room. Text is dimmed, never pure
   white, and the coral lifts so it still reads as the live signal. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141312;
  --surface: #1c1b1a;
  --sunken: #232120;
  --line: #34312e;
  --line-strong: #57534e;
  --text: #e9e6e1;
  --text-2: #a9a49c;
  --text-3: #9a958d;
  --accent: #e8775f;
  --accent-hover: #f08a74;
  --on-accent: #141312;
  --accent-tint: #3a231d;
  --lit: #262421;
  --lit-line: var(--line-strong);
  --danger: #f08a7d;
  --feed: #7ea6e0;
  --diaper: #5fbf9f;
  --spitup: #d4ad4a;
  --weight: #a59ae0;
  --milestone: #e083ae;
  --shadow: 0 -8px 32px rgb(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141312;
    --surface: #1c1b1a;
    --sunken: #232120;
    --line: #34312e;
    --line-strong: #57534e;
    --text: #e9e6e1;
    --text-2: #a9a49c;
    --text-3: #9a958d;
    --accent: #e8775f;
    --accent-hover: #f08a74;
    --on-accent: #141312;
    --accent-tint: #3a231d;
    --lit: #262421;
    --lit-line: var(--line-strong);
    --danger: #f08a7d;
    --feed: #7ea6e0;
    --diaper: #5fbf9f;
    --spitup: #d4ad4a;
    --weight: #a59ae0;
    --milestone: #e083ae;
    --shadow: 0 -8px 32px rgb(0 0 0 / 0.5);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
  scrollbar-color: var(--line-strong) transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  caret-color: var(--text);
}

::selection { background: var(--accent-tint); color: var(--text); }

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
img, svg { display: block; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: 8px; top: -60px;
  z-index: 50;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.skip:focus { top: 8px; }

.num, .tally-count, .now-elapsed, .entry-time, .facts dd, .stepper input, .count {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.icon { width: 24px; height: 24px; flex: none; }

/* ---- Buttons and fields ---------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.button:hover { background: var(--sunken); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.quiet { border-color: transparent; background: transparent; color: var(--text-2); }
.button.quiet:hover { background: var(--sunken); color: var(--text); }
.button.danger { border-color: transparent; background: transparent; color: var(--danger); }
.button.danger:hover { background: var(--sunken); }
.button.wide { width: 100%; }
.button:disabled { opacity: 0.55; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
}
.icon-button:hover { background: var(--sunken); color: var(--text); }
.icon-button:disabled { opacity: 0.35; background: transparent; }

.text-button {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.field { display: grid; gap: 6px; }
.field label, fieldset legend { font-size: 14px; font-weight: 600; color: var(--text-2); }

input[type="text"], input[type="email"], input[type="url"], input[type="password"], input[type="date"], input[type="time"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 1; }
input[type="file"] { min-height: 44px; font-size: 14px; color: var(--text-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--text); outline-offset: 0; border-color: var(--text); }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
fieldset legend { padding: 0; margin-bottom: 6px; }

.hint { font-size: 14px; color: var(--text-2); }

/* Segmented choices: radio inputs drawn as one ruled strip. */
.segments {
  display: flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segments label { flex: 1 1 0; position: relative; display: flex; }
.segments label + label { border-left: 1px solid var(--line-strong); }
.segments input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segments span {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 6px 8px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.segments input:checked + span { background: var(--text); color: var(--bg); }
.segments:focus-within { outline: 2px solid var(--text); outline-offset: 2px; }
.segments:has(input:focus:not(:focus-visible)) { outline: none; }

/* ---- Sign in ---------------------------------------------------------- */

.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px var(--gutter);
}
.signin-card {
  width: 100%;
  max-width: 400px;
  display: grid;
  gap: 16px;
}
.signin-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 18px; }
.signin-brand img { border-radius: 10px; }
.signin-brand small { display: block; font-weight: 400; font-size: 13px; color: var(--text-2); }
.signin h1 { font-size: 32px; line-height: 1.15; margin-top: 16px; }
.signin p { color: var(--text-2); }
.signin [data-signin-step] { display: grid; gap: 14px; }
.signin form { display: grid; gap: 14px; }
.signin-note { padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); color: var(--text) !important; background: var(--surface); }
.signin-foot { font-size: 13px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ---- App frame -------------------------------------------------------- */

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* The Now bar. Elapsed time is the loudest thing on the page. */
.now {
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 4px 12px;
  padding: calc(env(safe-area-inset-top) + 4px) var(--gutter) 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.now-top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
}
.baby { font-weight: 700; font-size: 16px; margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.baby-picker { margin-right: auto; }
.baby-picker select { min-height: 40px; padding: 6px 32px 6px 10px; font-weight: 700; width: auto; max-width: 52vw; }

.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  font-size: 13px;
  color: var(--text-2);
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--diaper); }
.sync[data-sync="saving"] .sync-dot, .sync[data-sync="unsent"] .sync-dot { background: var(--spitup); }
.sync[data-sync="offline"] .sync-dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-2); }

.now-main { min-width: 0; }
.now-label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.now-elapsed {
  font-size: 48px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 2px 0 4px;
}
.now-elapsed .u { font-size: 24px; font-weight: 600; letter-spacing: 0; margin-left: 2px; color: var(--text-2); }
.now-detail { font-size: 14px; color: var(--text-2); overflow-wrap: anywhere; }
.now[data-state="running"] .now-label { color: var(--accent); }
.now[data-state="running"] .now-elapsed { color: var(--accent); }
.now[data-state="running"] .now-elapsed .u { color: var(--accent); opacity: 0.85; }
.now[data-state="empty"] .now-elapsed { color: var(--text-3); }

.finish {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 16px 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  margin-bottom: 2px;
}
.finish:hover { background: var(--accent-hover); }

.views { padding: 8px var(--gutter) 24px; min-width: 0; }
.view { display: grid; gap: 16px; align-content: start; max-width: 720px; }
.view h1:focus { outline: none; }

/* ---- Today ------------------------------------------------------------ */

.day-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 -10px;
}
.day-heading { flex: 1; font-size: 20px; line-height: 1.2; text-align: center; }
.day-date { font-weight: 400; color: var(--text-2); }

/* Tally gates: counts as the fridge whiteboard keeps them. */
.tally {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.tally-cell {
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 10px 6px 12px;
  min-width: 0;
}
.tally-cell + .tally-cell { border-left: 1px solid var(--line); }
.tally-label { font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tally-count { font-size: 24px; font-weight: 700; line-height: 1.1; }
.tally-count .u { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 1px; }
.tally-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gates { margin-top: 4px; max-width: 100%; height: 20px; stroke-width: 2; stroke-linecap: round; fill: none; }
.tally-cell.feed .gates { stroke: var(--feed); }
.tally-cell.diaper .gates { stroke: var(--diaper); }
.tally-cell.spitup .gates { stroke: var(--spitup); }
.gates .gate-empty { stroke: var(--line-strong); stroke-dasharray: 2 4; }
.gates .fresh { stroke-dasharray: 24; stroke-dashoffset: 24; animation: draw 700ms var(--ease) 120ms forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.timeline-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 8px; }
.timeline-head h2 { font-size: 16px; }
.count { font-size: 13px; color: var(--text-2); }

.timeline { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  transition: background-color 600ms var(--ease);
}
.entry-edit {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 4.6em 28px 1fr;
  align-items: start;
  gap: 10px;
  min-height: 56px;
  padding: 12px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 0;
}
.entry-edit:hover { background: var(--sunken); }
.entry-time { font-size: 14px; color: var(--text-2); padding-top: 2px; white-space: nowrap; }
.entry-mark { color: var(--text-2); }
.entry.feed .entry-mark { color: var(--feed); }
.entry.diaper .entry-mark { color: var(--diaper); }
.entry.spitup .entry-mark { color: var(--spitup); }
.entry.weight .entry-mark { color: var(--weight); }
.entry.milestone .entry-mark { color: var(--milestone); }
.entry-text { display: grid; gap: 2px; min-width: 0; }
.entry-title { font-weight: 600; }
.entry-detail, .entry-note { font-size: 14px; color: var(--text-2); overflow-wrap: anywhere; }
.entry-note { font-style: italic; }
.entry-by { font-size: 13px; color: var(--text-2); }
.entry.lit { background: var(--lit); box-shadow: inset 0 1px 0 var(--lit-line), inset 0 -1px 0 var(--lit-line); }
.entry.lit .entry-by { color: var(--text); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.entry.lit .entry-by::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--entry-color, var(--text-2)); flex: none; }
.entry.feed { --entry-color: var(--feed); }
.entry.diaper { --entry-color: var(--diaper); }
.entry.spitup { --entry-color: var(--spitup); }
.entry.weight { --entry-color: var(--weight); }
.entry.milestone { --entry-color: var(--milestone); }
.finish-inline {
  flex: none;
  min-height: 44px;
  padding: 0 14px;
  margin-right: 4px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}
.finish-inline:hover { background: var(--accent-tint); }
.timeline-empty { padding: 24px 4px; display: grid; gap: 4px; }
.timeline-empty p:first-child { font-weight: 600; }
.timeline-empty p + p { color: var(--text-2); font-size: 14px; }

/* ---- Patterns --------------------------------------------------------- */

.view-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.view-head h1 { font-size: 24px; }
.range { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.range button { min-height: 44px; padding: 0 12px; border: 0; background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 14px; }
.range button + button { border-left: 1px solid var(--line-strong); }
.range button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.facts {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.fact { padding: 12px 12px 14px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 2px; }
.fact:nth-child(2n) { padding-left: 12px; border-left: 1px solid var(--line); }
.facts dt { font-size: 13px; color: var(--text-2); }
.facts dd { margin: 0; font-size: 26px; font-weight: 700; line-height: 1.1; }
.facts dd .u { font-size: 15px; font-weight: 600; color: var(--text-2); margin-left: 1px; }
.facts-empty { grid-column: 1 / -1; padding: 16px 0; color: var(--text-2); }

.chart-block { display: grid; gap: 8px; padding-top: 8px; }
.chart-block h2 { font-size: 16px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 13px; color: var(--text-2); }
.key { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.key:first-child { margin-left: 0; }
.key.feed { background: var(--feed); }
.key.diaper { background: var(--diaper); }
.key.spitup { background: var(--spitup); }
.chart { width: 100%; height: auto; overflow: visible; }
.chart .chart-label, .chart .chart-value { font-size: 13px; fill: var(--text-2); font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .chart-value { fill: var(--text); font-weight: 600; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .mark.feed { fill: var(--feed); }
.chart .mark.diaper { fill: var(--diaper); }
.chart .mark.spitup { fill: var(--spitup); }
.chart .mark.weight { fill: var(--weight); }
.chart .line.weight { fill: none; stroke: var(--weight); stroke-width: 2; stroke-linejoin: round; }
.chart-empty { color: var(--text-2); font-size: 14px; padding: 12px 0; }
.footnote, .settings-footnote { font-size: 13px; color: var(--text-2); padding-top: 8px; }

/* ---- Settings --------------------------------------------------------- */

#settingsBody { display: grid; gap: 8px; }
.settings-section { display: grid; gap: 14px; padding: 20px 0; border-top: 1px solid var(--line); }
.settings-section:first-child { border-top: 0; padding-top: 4px; }
.settings-section h2 { font-size: 18px; }
.settings-section h3 { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.settings-meta { font-size: 14px; color: var(--text-2); }
.settings-form { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: end; }
.settings-form > .button { justify-self: start; }
.settings-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.settings-list li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: 56px; }
.settings-list .li-main { font-weight: 600; overflow-wrap: anywhere; }
.settings-list .li-sub { grid-column: 1; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.settings-list li .button { grid-column: 2; grid-row: 1 / span 2; }
.settings-links { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-more summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; color: var(--text); }
.settings-more[open] summary { margin-bottom: 8px; }
.settings-error { color: var(--danger); }
.import-result:empty { display: none; }
.import-result { font-size: 14px; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--text); flex: none; }

/* ---- Admin panel: readiness strip, secrets, people, system ------------ */
.admin-head { justify-content: flex-start; gap: 4px; margin-left: -10px; }
.admin-status {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.admin-status + .settings-section { border-top: 0; }
.admin-cell { display: grid; gap: 2px; padding: 10px 12px 12px; min-width: 0; }
.admin-cell:nth-child(even) { border-left: 1px solid var(--line); }
.admin-cell:nth-child(n + 3) { border-top: 1px solid var(--line); }
.admin-cell-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.admin-cell-value { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-cell-sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-2); }
.admin-cell[data-state="ready"] .status-dot, .status-dot[data-on="true"] { background: var(--diaper); box-shadow: none; }
.admin-cell[data-state="late"] .status-dot { background: var(--spitup); box-shadow: none; }
.secret { grid-template-columns: 1fr auto; align-items: center; column-gap: 8px; }
.secret label, .secret input { grid-column: 1 / -1; }
.secret-state { display: flex; align-items: center; gap: 8px; }
.secret-clear { justify-self: end; min-height: 44px; }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 12px; font-weight: 600; color: var(--text-2); vertical-align: 2px; }
.admin-facts { margin: 0; border-top: 1px solid var(--line); }
.admin-facts div { display: grid; grid-template-columns: 9rem 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.admin-facts dt { font-size: 14px; font-weight: 600; color: var(--text-2); }
.admin-facts dd { margin: 0; overflow-wrap: anywhere; }
.admin-facts .u { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 1px; }
.admin-path { display: block; font-size: 13px; color: var(--text-2); }
.admin-alert { padding: 10px 12px; border: 1px solid var(--danger); border-radius: var(--radius-sm); color: var(--danger); background: var(--surface); }
.settings-section code, .settings-meta code { font-size: 13px; padding: 1px 4px; border-radius: 4px; background: var(--sunken); color: var(--text); overflow-wrap: anywhere; }
.settings-meta a, .hint a { color: var(--text); text-underline-offset: 2px; }
@media (min-width: 560px) {
  .admin-status { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .admin-cell:nth-child(n + 3) { border-top: 0; }
  .admin-cell + .admin-cell { border-left: 1px solid var(--line); }
}
@media (max-width: 380px) {
  .admin-facts div { grid-template-columns: 1fr; gap: 2px; }
}

/* ---- Dock: log buttons in thumb reach, then the tabs ------------------ */

.dock {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  padding: 10px var(--gutter) calc(env(safe-area-inset-bottom) + 4px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.log-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  grid-template-rows: 64px 64px;
  gap: 8px;
}
.log {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 6px 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  transition: background-color 160ms var(--ease), transform 160ms var(--ease);
}
.log:hover { background: var(--sunken); }
.log:active { transform: scale(0.97); }
.log .icon { width: 24px; height: 24px; }
.log.diaper .icon { color: var(--diaper); }
.log.spitup .icon { color: var(--spitup); }
.log.weight .icon { color: var(--weight); }
.log.milestone .icon { color: var(--milestone); }
.log.feed {
  grid-row: 1 / span 2;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-size: 20px;
  gap: 6px;
}
.log.feed:hover { background: var(--accent-hover); }
.log.feed .icon { width: 32px; height: 32px; }
.log-hint { font-size: 13px; font-weight: 500; opacity: 0.92; text-align: center; }
.log-hint:empty { display: none; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); margin: 0 calc(var(--gutter) * -1); }
.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.tabs button .icon { width: 22px; height: 22px; }
.tabs button[aria-current="page"] { color: var(--text); }
.tabs button[aria-current="page"] .icon { stroke-width: 2.25; }
.tabs button[aria-current="page"]::after { content: ""; width: 20px; height: 2px; border-radius: 1px; background: var(--text); margin-top: 1px; }

/* ---- Bottom sheet ----------------------------------------------------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 100dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}
.sheet::backdrop { background: rgb(10 10 10 / 0.45); }
.sheet[open] { animation: rise 280ms var(--ease); }
.sheet[open]::backdrop { animation: fade 200ms ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0.4; } }
@keyframes fade { from { opacity: 0; } }
.sheet-panel {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
}
.sheet form { display: grid; }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 6px var(--gutter);
  background: var(--surface);
}
.sheet-head h2 { font-size: 20px; }
.sheet-body { display: grid; gap: 18px; padding: 6px var(--gutter) 16px; }
.sheet-body > [data-show] { display: grid; gap: 18px; }
.sheet-error { margin: 0 var(--gutter) 12px; padding: 10px 12px; border: 1px solid var(--danger); border-radius: var(--radius-sm); color: var(--danger); font-weight: 600; }
.sheet-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px var(--gutter) calc(env(safe-area-inset-bottom) + 12px);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.sheet-foot .button.primary { min-height: 56px; font-size: 18px; }
.sheet-foot:not(:has(> :not([hidden]))) { display: none; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stepper {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.step { height: 52px; border: 0; background: var(--sunken); color: var(--text); display: grid; place-items: center; }
.step:hover { background: var(--line); }
.step-value { display: flex; align-items: baseline; justify-content: center; gap: 2px; min-width: 0; }
.stepper input {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  border: 0;
  border-radius: 0;
  padding: 0 2px;
  text-align: right;
  font-size: 22px;
  font-weight: 700;
  background: transparent;
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .unit { font-size: 14px; font-weight: 600; color: var(--text-2); padding-right: 8px; flex: none; }

.when { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.chips span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
}
.chips input:checked + span { background: var(--text); border-color: var(--text); color: var(--bg); }
.chips input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.when-exact { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.note summary { min-height: 44px; display: inline-flex; align-items: center; font-weight: 600; color: var(--text-2); cursor: pointer; }
.note[open] summary { margin-bottom: 6px; }

.choice-lead { font-size: 14px; font-weight: 600; color: var(--text-2); margin-bottom: -10px; }
.choice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice-save {
  min-height: 64px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}
.choice-save:hover { background: var(--sunken); }
.choice-save.current { border: 2px solid var(--text); }

/* ---- Toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 210px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 4px;
  width: max-content;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 6px 6px 6px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
  font-size: 15px;
  transform: translate(-50%, 8px);
  opacity: 0;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast-text { padding: 8px 0; }
.toast-action {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.toast-action:hover { background: var(--sunken); }

/* ---- Screen height ---------------------------------------------------- */

/* Tall phones keep the Now bar pinned; short ones let it scroll away and
   tighten the dock so the timeline still has room. */
@media (min-height: 741px) {
  .now { position: sticky; top: 0; }
}
@media (max-height: 740px) {
  .now { padding-bottom: 10px; }
  .views { padding-top: 0; }
  .day-nav { margin-block: -4px; }
  .tabs button { min-height: 44px; }
  .tally-cell { padding: 8px 6px 10px; }
}

/* ---- Larger screens --------------------------------------------------- */

@media (min-width: 560px) {
  .settings-form { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) auto; }
  .settings-form.stack { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .fact { padding-left: 12px; border-left: 1px solid var(--line); }
  .fact:first-child { padding-left: 0; border-left: 0; }
  .log-row { grid-template-columns: 2fr repeat(4, 1fr); grid-template-rows: 64px; }
  .log.feed { grid-row: auto; flex-direction: row; gap: 10px; }
  .log.feed .log-hint { display: none; }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 150px); }
}

/* Desktop: the instrument on the left, the record on the right. */
@media (min-width: 1024px) {
  :root { --gutter: 24px; }
  .app {
    grid-template-columns: 400px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "now main" "dock main";
    max-width: 1280px;
    margin: 0 auto;
    column-gap: 32px;
  }
  .now { grid-area: now; position: static; border-bottom: 0; padding-top: 24px; }
  .now-elapsed { font-size: 64px; }
  .dock {
    grid-area: dock;
    position: sticky;
    top: 0;
    align-self: start;
    border-top: 0;
    padding-top: 0;
    background: transparent;
  }
  .log-row { grid-template-columns: 1fr 1fr; grid-template-rows: 80px 64px 64px; }
  .log.feed { grid-column: 1 / -1; grid-row: auto; font-size: 22px; }
  .tabs { order: -1; margin: 0 0 8px; border-top: 0; border-bottom: 1px solid var(--line); }
  .views { grid-area: main; padding: 24px 0 48px; border-left: 1px solid var(--line); padding-left: 32px; }
  .toast { bottom: 32px; }
  .sheet { margin: auto; }
  .sheet-panel { border-radius: 16px; max-height: calc(100dvh - 64px); }
  .sheet-foot { border-radius: 0 0 16px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
  .gates .fresh { stroke-dashoffset: 0; }
}
