/* Night nursery: deep navy, moonlight text, warm low-glare accents. Day = cream + soft blue. */
:root, :root[data-theme="night"] {
  --bg: #0E1730;
  --bg2: #16213F;
  --card: rgba(207, 224, 255, 0.055);
  --card2: rgba(207, 224, 255, 0.09);
  --line: rgba(207, 224, 255, 0.11);
  --text: #CFE0FF;
  --strong: #EAF1FF;
  --muted: #8C9CC4;
  --accent: #A8C5FF;
  --feed: #F4B860;
  --pee: #7CC4F2;
  --poop: #C9A27A;
  --ok: #8FD6B0;
  --danger: #F28B82;
  --on-accent: #0E1730;
  --band: #0E1730;
  --tabbar: rgba(14, 23, 48, 0.86);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --sky: radial-gradient(1.2px 1.2px at 12% 8%, rgba(234,241,255,.75) 50%, transparent 51%),
         radial-gradient(1px 1px at 78% 4%, rgba(234,241,255,.6) 50%, transparent 51%),
         radial-gradient(1.4px 1.4px at 90% 14%, rgba(234,241,255,.55) 50%, transparent 51%),
         radial-gradient(1px 1px at 34% 16%, rgba(234,241,255,.5) 50%, transparent 51%),
         radial-gradient(1px 1px at 58% 11%, rgba(234,241,255,.45) 50%, transparent 51%),
         radial-gradient(120% 60% at 50% -10%, rgba(120,150,230,.18), transparent 60%);
  color-scheme: dark;
}
:root[data-theme="day"] {
  --bg: #FBF6EE;
  --bg2: #EEF3FB;
  --card: #FFFFFF;
  --card2: #F3F6FC;
  --line: rgba(34, 48, 79, 0.10);
  --text: #2B3A5C;
  --strong: #18233D;
  --muted: #6B7894;
  --accent: #4E78C9;
  --feed: #D8902B;
  --pee: #3A93CF;
  --poop: #9C7650;
  --ok: #2E9A6A;
  --danger: #C94A3F;
  --on-accent: #FFFFFF;
  --band: #24365F;
  --tabbar: rgba(251, 246, 238, 0.9);
  --shadow: 0 8px 24px rgba(34, 48, 79, 0.10);
  --sky: radial-gradient(120% 60% at 50% -10%, rgba(78,120,201,.14), transparent 60%);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--sky), linear-gradient(180deg, var(--bg2), var(--bg) 420px);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.4 ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior-y: none;
}
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
h1, h2, h3 { color: var(--strong); margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* status-bar strip so white iOS status text always shows */
.band { position: fixed; inset: 0 0 auto 0; height: env(safe-area-inset-top); background: var(--band); z-index: 30; }

#app {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

/* ---------- header ---------- */
.hero { display: flex; align-items: center; gap: 14px; padding: 6px 2px 16px; }
.avatar {
  width: 64px; height: 64px; border-radius: 50%; flex: none; overflow: hidden;
  background: var(--card2); border: 2px solid var(--line);
  display: grid; place-items: center; color: var(--muted); font-size: 22px; line-height: 1;
  box-shadow: 0 0 0 4px rgba(168, 197, 255, 0.08);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar small { display: block; font-size: 10px; margin-top: 2px; }
.hero .who { flex: 1; min-width: 0; }
.hero h1 { font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero .age { color: var(--muted); font-size: 14px; margin-top: 2px; }
.moon { width: 18px; height: 18px; vertical-align: -3px; margin-right: 4px; fill: var(--feed); opacity: .9; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.pending, .dot.syncing { background: var(--feed); } .dot.error, .dot.offline { background: var(--muted); }
.syncbtn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 8px; }

.pagehead { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 2px 14px; }
.pagehead h1 { font-size: 28px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 .link { font-size: 14px; font-weight: 600; color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.muted { color: var(--muted); }

/* feed ring */
.ringcard { display: flex; align-items: center; gap: 16px; }
.ringwrap { position: relative; width: 132px; height: 132px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--line); }
.ring .prog { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease, stroke .4s; }
.ring.due .prog, .ring.soon .prog { stroke: var(--feed); }
.ring.live .prog { stroke: var(--feed); }
.ringtext { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ringtext b { font-size: 26px; color: var(--strong); font-variant-numeric: tabular-nums; }
.ringtext span { font-size: 12px; color: var(--muted); }
.ringside { flex: 1; min-width: 0; }
.ringside .big { font-size: 17px; color: var(--strong); font-weight: 600; }
.ringside .due { color: var(--feed); font-weight: 700; }
.ringside p { margin: 4px 0; font-size: 14px; color: var(--muted); }
.timerbtns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* big tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 4px 0 14px; }
.tile {
  border-radius: 24px; padding: 18px 6px 14px; text-align: center;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: transform .12s ease;
}
.tile:active { transform: scale(.96); }
.tile .ico { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; }
.tile .ico svg { width: 28px; height: 28px; }
.tile b { font-size: 16px; color: var(--strong); }
.tile small { font-size: 11px; color: var(--muted); min-height: 14px; }
.tile.feed .ico { background: color-mix(in srgb, var(--feed) 22%, transparent); color: var(--feed); }
.tile.pee .ico  { background: color-mix(in srgb, var(--pee) 22%, transparent); color: var(--pee); }
.tile.poop .ico { background: color-mix(in srgb, var(--poop) 24%, transparent); color: var(--poop); }
.tile.live { border-color: color-mix(in srgb, var(--feed) 60%, transparent); }
.pulse { animation: pulse .5s ease; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); } 100% { box-shadow: 0 0 0 18px transparent; } }

/* counts */
.counts { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.counts div + div { border-left: 1px solid var(--line); }
.counts b { display: block; font-size: 26px; color: var(--strong); font-variant-numeric: tabular-nums; }
.counts span { font-size: 12px; color: var(--muted); }
.counts .f b { color: var(--feed); } .counts .w b { color: var(--pee); } .counts .d b { color: var(--poop); }
.guide { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); text-align: center; }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line); }
.tl li:first-child { border-top: 0; }
.tl .t { width: 66px; flex: none; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl .i { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.tl .i svg { width: 16px; height: 16px; }
.tl .i.feed { background: color-mix(in srgb, var(--feed) 20%, transparent); color: var(--feed); }
.tl .i.pee  { background: color-mix(in srgb, var(--pee) 20%, transparent); color: var(--pee); }
.tl .i.poop { background: color-mix(in srgb, var(--poop) 22%, transparent); color: var(--poop); }
.tl .d { flex: 1; min-width: 0; color: var(--strong); font-size: 15px; }
.tl .d small { display: block; color: var(--muted); font-size: 12px; }
.tl .by { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }

/* history */
.day { border-top: 1px solid var(--line); }
.day:first-of-type { border-top: 0; }
.dayhead { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 0; text-align: left; }
.dayhead .dn { flex: 1; }
.dayhead .dn b { color: var(--strong); display: block; }
.dayhead .dn small { color: var(--muted); font-size: 12px; }
.pills { display: flex; gap: 6px; }
.pill { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--card2); font-variant-numeric: tabular-nums; }
.pill.f { color: var(--feed); } .pill.w { color: var(--pee); } .pill.d { color: var(--poop); }

/* key-value rows */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--strong); text-align: right; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows .main { flex: 1; min-width: 0; }
.rows .main b { color: var(--strong); font-weight: 600; display: block; }
.rows .main small { color: var(--muted); font-size: 13px; }
.rows .side { color: var(--muted); font-size: 13px; text-align: right; }
.call { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); font-weight: 600; text-decoration: none; font-size: 14px; }

/* growth chart */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.chart circle { fill: var(--bg); stroke: var(--accent); stroke-width: 2.5; }
.chart text { fill: var(--muted); font-size: 10px; }
.stat { display: flex; gap: 10px; margin-bottom: 10px; }
.stat div { flex: 1; background: var(--card2); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; color: var(--strong); font-size: 18px; }
.stat span { font-size: 12px; color: var(--muted); }

/* milestones */
.mgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.mcard {
  position: relative; aspect-ratio: 4 / 5; border-radius: 20px; overflow: hidden; text-align: left;
  background: linear-gradient(160deg, #2B3F78, #1A2550 60%, #3A2F5E);
  border: 1px solid var(--line); box-shadow: var(--shadow); color: #EAF1FF;
}
.mcard img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mcard .noimg { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; opacity: .85; }
.mcard .cap { position: absolute; inset: auto 0 0 0; padding: 30px 12px 12px; background: linear-gradient(transparent, rgba(8, 12, 28, .82)); }
.mcard .cap b { display: block; font-size: 15px; }
.mcard .cap small { font-size: 12px; opacity: .8; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 16px; font-weight: 700; font-size: 16px;
  background: var(--accent); color: var(--on-accent); min-height: 48px;
}
.btn.wide { width: 100%; }
.btn.soft { background: var(--card2); color: var(--strong); }
.btn.warm { background: var(--feed); color: #2A1B05; }
.btn.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: 14px; border-radius: 12px; }
.btn:active { transform: scale(.98); }
.btnrow { display: flex; gap: 10px; margin-top: 14px; }
.btnrow > * { flex: 1; }
.add { width: 100%; padding: 13px; border-radius: 16px; border: 1.5px dashed var(--line); color: var(--accent); font-weight: 600; margin-top: 8px; }

/* chips & segments */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 14px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.chip .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); }
.seg { display: flex; background: var(--card2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 10px 8px; border-radius: 11px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--on-accent); }
.tog { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--card2); flex: 1; font-weight: 600; }
.tog .box { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--muted); display: grid; place-items: center; }
.tog[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); }
.tog[aria-pressed="true"] .box::after { content: ""; width: 10px; height: 6px; border: 2.5px solid var(--on-accent); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }

/* forms */
label.f { display: block; margin-top: 14px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.in, textarea.in, select.in {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card2); color: var(--strong); font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.in:focus { border-color: var(--accent); }
textarea.in { min-height: 110px; resize: vertical; }
.two { display: flex; gap: 10px; } .two > * { flex: 1; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 8px; }
.stepper button { width: 54px; height: 54px; border-radius: 50%; background: var(--card2); font-size: 26px; color: var(--strong); }
.stepper b { font-size: 38px; color: var(--strong); min-width: 120px; text-align: center; font-variant-numeric: tabular-nums; }
.stepper b small { font-size: 16px; color: var(--muted); }
.sec { font-size: 13px; color: var(--muted); margin: 16px 0 8px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.warn { font-size: 13px; color: var(--feed); margin-top: 10px; }

/* ---------- tab bar ---------- */
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--tabbar); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 600; }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs button[data-tab="today"] svg { fill: currentColor; stroke: none; }
#tabs button.on { color: var(--accent); }

/* ---------- sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
#sheet .scrim { position: absolute; inset: 0; background: rgba(4, 8, 20, .55); opacity: 0; transition: opacity .2s; }
#sheet .panel {
  position: absolute; inset: auto 0 0 0; max-width: 560px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: var(--bg2); border-radius: 26px 26px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 22px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
  -webkit-overflow-scrolling: touch;
}
#sheet.open { pointer-events: auto; }
#sheet.open .scrim { opacity: 1; }
#sheet.open .panel { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.panel h2 { font-size: 21px; margin-bottom: 12px; }
.sheethead { display: flex; justify-content: space-between; align-items: center; }
.x { padding: 8px; color: var(--muted); font-size: 15px; font-weight: 600; }

/* scanner + qr */
.scanbox { position: relative; border-radius: 20px; overflow: hidden; background: #000; aspect-ratio: 1; margin-top: 10px; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; }
.scanbox::after { content: ""; position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.8); border-radius: 18px; }
.qr { background: #fff; border-radius: 20px; padding: 14px; width: min(78vw, 300px); margin: 6px auto 12px; }
.qr svg { width: 100%; height: auto; display: block; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; background: var(--card2); padding: 10px 12px; border-radius: 12px; color: var(--strong); -webkit-user-select: all; user-select: all; }

/* ---------- welcome ---------- */
.welcome { min-height: calc(100vh - 140px); display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 12px; }
.welcome .art svg { width: 120px; height: 120px; }
.welcome h1 { font-size: 30px; }
.welcome p { color: var(--muted); margin: 0 auto; max-width: 340px; }
.welcome .btn { margin-top: 6px; }
.lock { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 14px; justify-content: center; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .22s ease;
  background: var(--strong); color: var(--bg); padding: 11px 14px 11px 18px; border-radius: 16px;
  display: flex; gap: 14px; align-items: center; font-weight: 600; font-size: 15px; box-shadow: var(--shadow); white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: var(--accent); font-weight: 700; padding: 4px 6px; }
:root[data-theme="night"] #toast button { color: #3B5FA8; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* v1.1: sleep, medicine, first-weeks check, doctor visit */
.tl .i.sleep, .sleepbar .i.sleep { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.tl .i.med { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.sleepbar { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 10px 14px; margin: 0 0 14px; box-shadow: var(--shadow); }
.sleepbar.on { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.sleepbar .sb { flex: 1; display: flex; align-items: center; gap: 12px; text-align: left; min-height: 44px; }
.sleepbar .i { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.sleepbar .i svg { width: 20px; height: 20px; }
.sleepbar b { display: block; color: var(--strong); font-size: 16px; }
.sleepbar small { color: var(--muted); font-size: 12px; }
.sleepbar .link { color: var(--accent); font-size: 14px; font-weight: 600; padding: 8px 4px; }
.sleepbar .sb:active { transform: scale(.98); }
.guide.checks { text-align: left; }
.ghead { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.chk { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px; margin: 6px 0; }
.chk .lbl { font-size: 13px; color: var(--strong); }
.chk .bar { height: 8px; border-radius: 999px; background: var(--card2); overflow: hidden; }
.chk .bar i { display: block; height: 100%; border-radius: 999px; opacity: .55; transition: width .4s; }
.chk.ok .bar i { opacity: 1; }
.chk .bar i.w { background: var(--pee); } .chk .bar i.d { background: var(--poop); } .chk .bar i.f { background: var(--feed); }
.chk b { font-size: 14px; color: var(--strong); font-variant-numeric: tabular-nums; min-width: 58px; text-align: right; }
.chk b small { color: var(--muted); font-weight: 400; font-size: 12px; }
.chk.ok b::after { content: " ✓"; color: var(--ok); }
.gfoot { font-size: 11px; color: var(--muted); margin: 8px 0 0; }
.visit { margin-top: 12px; }
.visit .vh { margin: 0 0 8px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.visit .vh b { color: var(--strong); font-size: 16px; }
.visit .rows .side { max-width: 48%; }
