:root {
  --bg: #f6efe7;
  --surface: #fffaf5;
  --surface-2: #f0e6db;
  --line: #e6d9cb;
  --text: #2f2723;
  --muted: #85776d;
  --accent: #c97b56;
  --accent-ink: #fff;
  --danger: #c4543f;
  --shadow: 0 1px 2px rgba(60, 40, 25, .06), 0 6px 20px rgba(60, 40, 25, .06);
  --radius: 18px;

  --feed: #e38b5d;
  --sleep: #7579d1;
  --diaper: #3ea999;
  --pump: #cf6f98;
  --med: #cf5f5f;
  --temp: #d39b2f;
  --growth: #6f9f4f;
  --note: #a77bc9;

  --tabbar-h: 68px;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a1f;
    --surface: #25242b;
    --surface-2: #2f2e36;
    --line: #3a3842;
    --text: #f1ece7;
    --muted: #a39d98;
    --accent: #e39a74;
    --accent-ink: #22160f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Boot */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.shell {
  max-width: 640px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.baby-switch {
  display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; text-align: left;
}
.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 800; font-size: 18px; color: var(--accent); flex: none;
}
.baby-name { font-size: 22px; font-weight: 800; }
.baby-age { font-size: 13px; color: var(--muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--growth); display: inline-block; margin-left: 6px; vertical-align: middle; }
.sync-dot.off { background: var(--muted); }

.section-title { font-size: 13px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 4px 10px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}

/* Quick actions */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.qbtn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 4px 10px; font-weight: 700; font-size: 13px; box-shadow: var(--shadow);
  transition: transform .08s ease;
}
.qbtn:active { transform: scale(.96); }
.qicon {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 21px;
  background: color-mix(in srgb, var(--c) 16%, transparent);
}

/* Active timers */
.timer-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--c) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 35%, var(--line));
  margin-bottom: 10px;
}
.timer-card .t-main { flex: 1; min-width: 0; }
.timer-card .t-label { font-weight: 800; }
.timer-card .t-clock { font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 800; color: var(--c); }
.timer-card .t-actions { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; }
.timer-card .t-actions .btn { flex: 1; }

/* Status cards */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { padding: 14px; }
.stat .s-label { font-size: 13px; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.stat .s-value { font-size: 22px; font-weight: 800; margin-top: 4px; }
.stat .s-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.total { text-align: center; padding: 10px 4px; border-radius: 14px; background: var(--surface-2); }
.total b { display: block; font-size: 20px; }
.total span { font-size: 12px; color: var(--muted); font-weight: 700; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.tl-item:last-child { border-bottom: 0; }
.tl-time { width: 74px; white-space: nowrap; flex: none; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.tl-icon {
  width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; font-size: 17px;
  background: color-mix(in srgb, var(--c) 16%, transparent);
}
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-weight: 700; }
.tl-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.tl-by { font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 3px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }

/* Day nav */
.daynav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.daynav h2 { font-size: 20px; text-align: center; flex: 1; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 18px; font-weight: 800;
}
.icon-btn:disabled { opacity: .35; }

/* Filter chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-weight: 700; font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Charts */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 18px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 38px; border-radius: 8px 8px 4px 4px; background: var(--c); min-height: 3px; position: relative;
}
.bar-val { font-size: 11px; font-weight: 800; color: var(--muted); }
.bar-day { font-size: 11px; font-weight: 700; color: var(--muted); }
.bar-col.today .bar-day { color: var(--text); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; }
.chart-head h3 { font-size: 16px; }
.stack { display: grid; gap: 12px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.grid td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.grid th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tabbar-h); }
.tab {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.tab .ti { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tab.on { color: var(--text); }
.tab.on .ti { filter: none; opacity: 1; }

/* Buttons & forms */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 11px 16px;
  font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 7px 12px; border-radius: 11px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.tinted { background: var(--c); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .5; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .label, .label-row > label { font-size: 13px; font-weight: 800; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 12px;
  font-size: 16px; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
textarea.input { min-height: 70px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.seg { display: flex; background: var(--surface-2); border-radius: 13px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button {
  flex: 1; border: 0; background: none; border-radius: 10px; padding: 9px 6px; font-weight: 800; font-size: 14px; color: var(--muted);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; margin-bottom: 14px; }
.pick button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 13px; padding: 12px 6px; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 14px;
}
.pick button .pe { font-size: 22px; }
.pick button.on { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 14%, var(--surface)); }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .input { text-align: center; font-weight: 800; font-size: 20px; }
.stepper button { width: 46px; height: 46px; flex: none; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 22px; font-weight: 800; }

.timer-start { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.timer-start .btn { padding: 18px 10px; flex-direction: column; font-size: 15px; }
.timer-start .btn .big { font-size: 26px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Sheet (bottom modal) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 12, 8, .38); z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--surface);
  border-radius: 24px 24px 0 0; padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  animation: up .2s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 24px; }
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.sheet-head h2 { flex: 1; font-size: 21px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }

/* Auth / onboarding */
.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 48px) 20px 40px; }
.auth .logo { width: 84px; height: 84px; margin: 0 auto 14px; display: block; border-radius: 22px; box-shadow: var(--shadow); }
.auth h1 { text-align: center; font-size: 28px; font-weight: 800; }
.auth .lead { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.error { color: var(--danger); font-weight: 700; font-size: 14px; margin: 4px 0 12px; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 800; padding: 4px; }

.settings-list { display: grid; gap: 2px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 24px; font-weight: 800; letter-spacing: .18em;
  background: var(--surface-2); padding: 8px 14px; border-radius: 12px;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 80; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .undo { color: var(--accent); background: none; border: 0; font-weight: 800; margin-left: 10px; pointer-events: auto; }

/* Time wheels */
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.label-row .chip { padding: 4px 12px; }
.wheels {
  position: relative; display: flex; justify-content: center; align-items: center; gap: 2px;
  height: 152px; margin-top: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
.wheels::before {
  content: ""; position: absolute; left: 10px; right: 10px; top: 50%; height: 38px; transform: translateY(-50%);
  background: var(--surface-2); border-radius: 10px; pointer-events: none;
}
.wheel {
  position: relative; z-index: 1; height: 152px; width: 70px; overflow-y: scroll; padding: 57px 0;
  scroll-snap-type: y mandatory; scrollbar-width: none; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(transparent, #000 32%, #000 68%, transparent);
  mask-image: linear-gradient(transparent, #000 32%, #000 68%, transparent);
}
.wheel::-webkit-scrollbar { display: none; }
.wheel-item {
  height: 38px; line-height: 38px; text-align: center; scroll-snap-align: center; scroll-snap-stop: always; cursor: pointer;
  font-size: 20px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; transition: color .1s;
}
.wheel-item.sel { color: var(--text); font-weight: 800; font-size: 22px; }
.wheel-colon { position: relative; z-index: 1; font-size: 22px; font-weight: 800; padding-bottom: 3px; }
.dt-pair { display: grid; gap: 4px; }

/* Range history */
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.day-head .day-sum { text-transform: none; letter-spacing: 0; font-weight: 700; font-size: 12px; }

/* History calendar */
.range-label { flex: 1; background: none; border: 0; padding: 4px; text-align: center; border-radius: 12px; }
.range-label h2 { font-size: 20px; }
.range-label:active { background: var(--surface-2); }
.cal-caret { font-size: 15px; vertical-align: 2px; }
.cal { padding: 12px; margin-bottom: 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head .icon-btn { width: 36px; height: 36px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 4px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 800; color: var(--muted); padding: 4px 0; }
.cal-day {
  height: 40px; border: 0; background: none; font-weight: 700; font-size: 15px; border-radius: 0;
  font-variant-numeric: tabular-nums;
}
.cal-day.in { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.cal-day.start { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
.cal-day.end { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
.cal-day.start, .cal-day.end { background: var(--accent); color: var(--accent-ink); }
.cal-day.today:not(.start):not(.end) { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.cal-day:disabled { opacity: .3; }
.cal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
