:root {
  --bg: #fdf6f0;
  --surface: #ffffff;
  --text: #2a2630;
  --muted: #6f6878;
  --line: #ece4dc;
  --primary: #6b5bd2;
  --primary-text: #ffffff;
  --feed: #ffe3c2;
  --diaper: #d6ecff;
  --pee: #fff4b8;
  --poop: #e8d6c4;
  --danger: #c43d4b;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a1f;
    --surface: #26242c;
    --text: #f1edf5;
    --muted: #a49cae;
    --line: #38353f;
    --primary: #9d8ff0;
    --primary-text: #17151c;
    --feed: #5a4127;
    --diaper: #23405a;
    --pee: #55501f;
    --poop: #4a3a2c;
    --danger: #ff7a86;
    color-scheme: dark;
  }
}

* { 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;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0 0; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* Sign-in */
#signin { min-height: 100dvh; display: grid; place-items: center; }
.signin-card { text-align: center; display: grid; gap: 12px; justify-items: center; }
.big-emoji { font-size: 64px; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.topbar h1 { font-size: 22px; }
.link { background: none; border: 0; color: var(--muted); padding: 8px; }

/* Summary */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; display: grid; gap: 2px; min-width: 0;
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }

/* Action buttons */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.act {
  border: 0; border-radius: var(--radius); padding: 18px 8px; min-height: 92px;
  display: grid; justify-items: center; gap: 4px; font-size: 18px; font-weight: 600;
  transition: transform .08s ease;
}
.act span { font-size: 32px; line-height: 1; }
.act:active { transform: scale(.97); }
.act-feed { background: var(--feed); }
.act-diaper { background: var(--diaper); }
.act-pee { background: var(--pee); }
.act-poop { background: var(--poop); }

/* Timeline */
.day { margin: 0 0 16px; }
.day h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 6px 4px; }
.day ul { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day li + li { border-top: 1px solid var(--line); }
.item {
  width: 100%; background: none; border: 0; text-align: left; padding: 12px 14px;
  display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center;
}
.item .ico { font-size: 24px; text-align: center; }
.item .what { font-weight: 600; }
.item .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.item .when { font-size: 14px; color: var(--muted); white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* Buttons */
.primary, .secondary, .danger {
  border-radius: 12px; padding: 12px 18px; border: 1px solid transparent; font-weight: 600;
}
.primary { background: var(--primary); color: var(--primary-text); }
.secondary { background: var(--surface); border-color: var(--line); }
.danger { background: none; color: var(--danger); border-color: var(--danger); }
.wide { width: 100%; }
button:disabled { opacity: .6; }

/* Sheet */
dialog {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, 100%); max-width: 100%; margin: auto auto 0; border-radius: 20px 20px 0 0;
  max-height: 92dvh;
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
#form { padding: 20px 16px max(20px, env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.field input[type="datetime-local"], .field input[type="number"], .field input[type="text"] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; min-width: 0;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg label { flex: 1; min-width: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 12px 8px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px;
}
.seg input:checked + span { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.buttons { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 15px;
  max-width: calc(100% - 32px);
}
