/* Palette and reasons live in DESIGN.md. Every text pairing below was run through contrast-check.py. */
:root {
  color-scheme: dark;
  --bg: #14121a;
  --surface: #1d1a24;
  --surface-2: #26222f;
  --line: #322d3c;          /* dividers only, never a control edge */
  --edge: #6e6680;          /* control edges: 3:1+ on surface and bg */
  --text: #f1ebe4;
  --muted: #a49cad;         /* 6.5:1 on surface */
  --faint: #8f879a;         /* 4.98:1 on surface, 4.51:1 on surface-2 */
  --bottle: #f2a65a;        /* the one brand colour: bottle feeds and the Save action */
  --breast: #a898f5;
  --accent-text: #f2a65a;   /* amber used as text (warnings) */
  --on-accent: #2a1806;
  --focus: #f1ebe4;
  --danger: #ef7a6c;
  --c-bottle: #cc7a2e;      /* chart pair, validated for colour-blind separation with --c-breast */
  --c-breast: #8a76ee;
  --c-neutral: #8a8496;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #faf6f1;
    --surface: #ffffff;
    --surface-2: #f2ece5;
    --line: #e5ddd3;
    --edge: #867d8e;        /* 3:1+ on bg, surface and surface-2 */
    --text: #231d27;
    --muted: #5f5766;
    --faint: #6f6676;
    --bottle: #d9792a;
    --breast: #7259d6;
    --accent-text: #a3521a; /* 5.2:1 on bg */
    --on-accent: #2a1806;   /* 5.45:1 on #d9792a */
    --focus: #231d27;
    --c-bottle: #d9792a;
    --c-breast: #7259d6;
    --c-neutral: #8f8696;
  }
}

* { 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;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px calc(var(--safe-b) + 24px);
}

.ico { width: 26px; height: 26px; display: block; fill: currentColor; flex: none; }
.ico-sm { width: 20px; height: 20px; }

/* ---------- top ---------- */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.top h1, .gate-card h1 { font-family: var(--serif); font-size: 1.75rem; margin: 0; letter-spacing: -0.01em; }
.age { margin: 0; color: var(--muted); font-size: 0.875rem; }
.top-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: none; border: 0; color: var(--muted); width: 44px; height: 44px;
  display: grid; place-items: center; border-radius: 50%;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.sync { font-size: 0.8125rem; color: var(--faint); }
.sync.warn { color: var(--accent-text); }

/* ---------- status ---------- */
.status {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 12px;
}
.status-label { margin: 0; color: var(--muted); font-size: 0.875rem; }
.since { margin: 2px 0 0; font-size: 2.75rem; font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; }
.since.none { font-size: 1.75rem; }
.since.late { color: var(--accent-text); }
.status-sub { margin: 4px 0 10px; color: var(--muted); }
/* A feed that's been started but not finished: needs someone to come back and add the amount. */
.open-feed {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px dashed var(--bottle); border-radius: 10px; padding: 8px 8px 8px 12px; margin-bottom: 10px;
}
.open-feed.stale { border-style: solid; border-width: 2px; }
.open-feed p { margin: 0; font-size: 0.9375rem; }
.open-feed p b { display: block; }
.open-feed p span { color: var(--muted); font-size: 0.875rem; }
.open-feed .btn { flex: none; min-height: 44px; padding: 0 16px; white-space: nowrap; }
.finish-hint { margin: 4px 0 0; color: var(--muted); font-size: 0.9375rem; }
.finish-hint b { color: var(--text); }
.start-hint { margin: 10px 0 0; }

/* The second, smaller clock: when the next feed is due, from the family's feed-gap setting. */
.next {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface-2); border-radius: 10px; padding: 9px 12px; margin-bottom: 12px;
}
.next-when { color: var(--muted); font-size: 0.875rem; }
.next-when b { color: var(--text); font-weight: 650; }
.next-in { font-weight: 700; font-size: 1.125rem; white-space: nowrap; }
.next.due .next-in { color: var(--text); }
.next.over .next-in { color: var(--accent-text); }
.today { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; border-top: 1px solid var(--line); padding-top: 10px; }
.today div { text-align: center; }
.today dt { color: var(--faint); font-size: 0.8125rem; }
.today dd { margin: 0; font-weight: 650; font-size: 1.125rem; }

/* ---------- quick buttons ---------- */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 16px; }
.quick.three { grid-template-columns: repeat(3, 1fr); }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 4px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 0.9375rem; color: var(--text);
}
.quick-btn .ico { color: var(--k); width: 30px; height: 30px; }
.quick-btn:active { transform: scale(0.97); background: var(--surface-2); }
.k-bottle { --k: var(--bottle); }
.k-breast { --k: var(--breast); }
.k-nappy, .k-note, .k-weight { --k: var(--muted); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tab { flex: 1; background: none; border: 0; min-height: 44px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--text); }

/* ---------- log ---------- */
.day { margin-bottom: 18px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  position: sticky; top: 0; background: var(--bg); padding: 8px 2px 6px; z-index: 1;
}
.day-head h3 { margin: 0; font-size: 0.9375rem; }
.day-sum { color: var(--muted); font-size: 0.8125rem; text-align: right; }
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px;
  width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line);
  padding: 11px 14px; min-height: 52px;
}
.rows li:first-child .row { border-top: 0; }
.row:active { background: var(--surface-2); }
.row:focus-visible { outline-offset: -2px; }
.row-time { font-weight: 650; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-what { display: flex; align-items: center; gap: 8px; }
/* Identity motif: a feed is a dot, sized by how much he took (same rule as the feed-time chart). */
.dot-wrap { width: 16px; display: grid; place-items: center; flex: none; }
.dot { width: var(--d, 8px); height: var(--d, 8px); border-radius: 50%; background: var(--k); }
.k-nappy .dot, .k-note .dot { background: none; border: 2px solid var(--k); }
.k-weight .dot { background: none; border: 2px solid var(--k); border-radius: 2px; }
.row-note { color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-gap { color: var(--faint); font-size: 0.8125rem; display: block; text-align: right; }
.tags { display: flex; gap: 4px; justify-content: flex-end; }
.tag { font-size: 0.75rem; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pending { opacity: 0.6; }
/* Unfinished feed in the log: shaded row, hollow dot, and a worded tag (never colour alone). */
.row.is-open { background: var(--surface-2); }
.row.is-open .dot { background: none; border: 2px dashed var(--k); }
.tag.todo { background: none; border: 1px dashed var(--bottle); color: var(--accent-text); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.log-more { display: grid; gap: 8px; justify-items: center; margin: 4px 0 8px; }
.log-more .hint { margin: 0; }
.log-more .btn { width: 100%; }

/* ---------- trends ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 2px; font-size: 0.9375rem; }
.card .sub { margin: 0 0 10px; color: var(--muted); font-size: 0.8125rem; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .val { fill: var(--text); font-weight: 600; }
.chart line { stroke: var(--line); }
.chart .grid { stroke: var(--line); stroke-dasharray: 2 3; }
.chart .row-line { stroke: var(--line); }
.chart .bar-bottle { fill: var(--c-bottle); }
.chart .bar-stretch, .chart .bar-count { fill: var(--c-neutral); }
.chart .partial { opacity: 0.45; }
.chart .line-bottle { fill: none; stroke: var(--c-bottle); stroke-width: 2; stroke-linejoin: round; }
.chart .dot-bottle { fill: var(--c-bottle); stroke: var(--surface); stroke-width: 2; }
.chart .dot-breast { fill: var(--c-breast); stroke: var(--surface); stroke-width: 2; }
.chart .poo-mark { fill: var(--muted); }
.chart .hit { fill: transparent; stroke: none; }
.chart .hit:focus { outline: none; }
.chart .hit:focus-visible { stroke: var(--focus); stroke-width: 2; }
.chart :not(.hit) { pointer-events: none; }
.legend { display: flex; gap: 14px; font-size: 0.8125rem; color: var(--muted); margin: -4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sw-bottle { background: var(--c-bottle); }
.sw-breast { background: var(--c-breast); }
.sw-poo { background: var(--muted); border-radius: 0; clip-path: polygon(0 100%, 100% 100%, 50% 0); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
@media (min-width: 520px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile p { margin: 0; }
.tile-k { color: var(--muted); font-size: 0.8125rem; }
.tile-v { font-size: 1.375rem; font-weight: 700; margin: 2px 0 !important; }
.tile-v.none { font-size: 1rem; color: var(--muted); padding: 4px 0; }
.tile-s { color: var(--faint); font-size: 0.8125rem; line-height: 1.3; }
.range { margin: 4px 0 12px; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.stats th { white-space: nowrap; text-align: right; color: var(--faint); font-weight: 500; font-size: 0.8125rem; padding: 4px 4px 6px; }
.stats td { white-space: nowrap; text-align: right; padding: 7px 4px; border-top: 1px solid var(--line); }
.stats td.nil { color: var(--faint); }
.stats th:first-child, .stats td:first-child { text-align: left; }
.tip {
  position: absolute; z-index: 10; pointer-events: none; max-width: 260px;
  background: var(--text); color: var(--bg); font-size: 0.8125rem; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; box-shadow: 0 4px 14px rgb(0 0 0 / 0.3);
}

/* ---------- sheet ---------- */
.sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; padding: 0;
  border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text); max-height: 92vh; overflow-y: auto;
}
.sheet::backdrop { background: rgb(0 0 0 / 0.55); }
.sheet form { padding: 14px 16px calc(var(--safe-b) + 16px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.field { margin: 12px 0; scroll-margin-bottom: 120px; }
.field > label { display: block; color: var(--muted); font-size: 0.875rem; margin-bottom: 6px; }
.field input[type="text"], .field input[type="date"], .field input[type="datetime-local"], .gate input {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--edge);
  border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips button {
  background: var(--surface-2); border: 1px solid var(--edge); border-radius: 999px;
  padding: 0 14px; font-size: 0.875rem; min-height: 44px; min-width: 48px;
}
.chips button.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 650; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--edge); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: none; border: 0; border-radius: 9px; padding: 0 4px; color: var(--muted); font-weight: 600; min-height: 44px; }
.seg button[aria-checked="true"] { background: var(--text); color: var(--bg); }
.ml-row { display: grid; grid-template-columns: 56px 1fr 56px; gap: 10px; align-items: center; }
.step {
  height: 56px; border-radius: 14px; border: 1px solid var(--edge); background: var(--surface-2);
  font-size: 1.75rem; font-weight: 500;
}
.step:active { background: var(--line); }
.ml-display { display: flex; align-items: baseline; justify-content: center; gap: 4px; }
.ml-display input {
  width: 4.2ch; background: none; border: 0; border-bottom: 1px solid var(--edge); color: var(--text); text-align: right;
  font-size: 2.5rem; font-weight: 700; padding: 0; -moz-appearance: textfield;
}
.ml-display input::-webkit-inner-spin-button, .ml-display input::-webkit-outer-spin-button { -webkit-appearance: none; }
.ml-display span { color: var(--muted); font-size: 1.125rem; }
.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.toggle {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--edge); border-radius: 12px; padding: 0 4px; min-height: 48px; color: var(--muted);
}
.toggle[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 650; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  border-radius: 12px; border: 1px solid var(--edge); background: var(--surface-2); color: var(--text);
  padding: 12px 18px; font-weight: 650; min-height: 50px;
}
.btn.primary { flex: 1; background: var(--bottle); color: var(--on-accent); border-color: var(--bottle); }
.btn.danger { color: var(--danger); background: none; }
.hint { color: var(--muted); font-size: 0.875rem; }

.feed-gap { display: flex; align-items: center; gap: 8px; }
.feed-gap select {
  flex: 1; min-height: 46px; background: var(--bg); color: var(--text); border: 1px solid var(--edge);
  border-radius: 10px; padding: 0 10px; font: inherit;
}
.field .hint { margin: 6px 0 0; }

/* Settings switch: whole row is the tap target. */
.field > label.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  color: var(--text); font-size: 1rem; margin: 0; min-height: 56px; cursor: pointer;
}
.switch-title { display: block; font-weight: 600; }
.switch-sub { display: block; color: var(--muted); font-size: 0.875rem; margin-top: 2px; }
input[role="switch"] {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 52px; height: 32px; border-radius: 999px; border: 1px solid var(--edge); background: var(--bg); position: relative;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted);
}
input[role="switch"]:checked { background: var(--text); border-color: var(--text); }
input[role="switch"]:checked::after { left: 23px; background: var(--bg); }
@media (prefers-reduced-motion: no-preference) { input[role="switch"]::after { transition: left 0.15s; } }

/* ---------- gate / boot ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: 100%; max-width: 340px; text-align: center; }
.gate-card h1 { margin: 10px 0 4px; }
.gate-card p { color: var(--muted); margin: 0 0 18px; }
.gate form { display: grid; gap: 10px; }
.gate .btn { width: 100%; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 0.875rem; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-b) + 16px); max-width: 528px; margin: 0 auto; z-index: 20;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 14px; font-weight: 600; font-size: 0.9375rem;
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
}
.toast button { background: none; border: 0; color: inherit; text-decoration: underline; min-height: 44px; min-width: 44px; padding: 0 6px; font-weight: 700; }
.toast-actions { display: flex; gap: 4px; flex: none; }

/* Weigh-ins */
.weight-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.weight-row input {
  width: 100%; min-width: 0; flex: 1; background: var(--bg); color: var(--text); border: 1px solid var(--edge);
  border-radius: 10px; padding: 0 12px; min-height: 50px; font-size: 1.375rem; font-weight: 700;
}
.weight-row span { color: var(--muted); }
#f-kind .seg button { padding: 0 2px; font-size: 0.9375rem; }
.chart .line-weight { fill: none; stroke: var(--c-neutral); stroke-width: 2; stroke-linejoin: round; }
.chart .dot-weight { fill: var(--c-neutral); stroke: var(--surface); stroke-width: 2; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-head .btn { min-height: 44px; padding: 0 14px; flex: none; }

.foot { text-align: center; color: var(--faint); font-size: 0.8125rem; margin-top: 24px; }

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: rise 0.18s ease-out; }
  @keyframes rise { from { transform: translateY(24px); opacity: 0.6; } }
}
