/* Nestling. Layout: one narrow column built for a thumb, with status at the
   top, big actions in the middle, history below and a fixed tab bar at the
   bottom. Dark palette is low-glare for 3am feeds. */
:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #e3e8ed;
  --line: #d4dbe2;
  --ink: #17232c;
  --ink-2: #4b5a66;
  --ink-3: #7b8994;
  --sleep: #5a55c8;
  --sleep-soft: #e4e2fb;
  --feed: #13807a;
  --feed-soft: #d6efec;
  --nappy: #b0740c;
  --nappy-soft: #f6e8cc;
  --good: #2e7d4f;
  --warn: #a8670a;
  --bad: #b3372f;
  --focus: #5a55c8;
  --shadow: 0 1px 2px rgb(23 35 44 / 6%), 0 4px 16px rgb(23 35 44 / 6%);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", "Nunito", -apple-system, "Segoe UI", sans-serif;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1216; --surface: #161e24; --surface-2: #1f2a32; --line: #2a3640;
    --ink: #dfe7ec; --ink-2: #a3b1bb; --ink-3: #6f7e89;
    --sleep: #9f9bff; --sleep-soft: #26244a; --feed: #4fc4bb; --feed-soft: #133532;
    --nappy: #e2ac4a; --nappy-soft: #3a2c12; --good: #6cc48f; --warn: #e2ac4a; --bad: #f08a80;
    --focus: #9f9bff; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1216; --surface: #161e24; --surface-2: #1f2a32; --line: #2a3640;
  --ink: #dfe7ec; --ink-2: #a3b1bb; --ink-3: #6f7e89;
  --sleep: #9f9bff; --sleep-soft: #26244a; --feed: #4fc4bb; --feed-soft: #133532;
  --nappy: #e2ac4a; --nappy-soft: #3a2c12; --good: #6cc48f; --warn: #e2ac4a; --bad: #f08a80;
  --focus: #9f9bff; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.num, time, .tabular { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) max(16px, env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px) max(16px, env(safe-area-inset-left, 0px));
  display: grid;
  gap: 14px;
}
#app.no-tabs { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); }
.boot { padding: 40vh 0; text-align: center; color: var(--ink-3); }

/* ---- header ---------------------------------------------------------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { font: 700 26px/1.1 var(--font-display); margin: 0; letter-spacing: -0.01em; }
.top .age { color: var(--ink-2); font-size: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-2); font-size: 13px; white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.pill.good::before { background: var(--good); }
.pill.warn::before { background: var(--warn); }
.pill.bad::before { background: var(--bad); }

/* ---- cards ----------------------------------------------------------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2, .section-title {
  margin: 0 0 6px; font-size: 13px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3);
}
.section-title { margin: 6px 4px 0; }

.timer-card { border: 2px solid transparent; }
.timer-card.sleep { background: var(--sleep-soft); border-color: color-mix(in srgb, var(--sleep) 35%, transparent); }
.timer-card.feed { background: var(--feed-soft); border-color: color-mix(in srgb, var(--feed) 35%, transparent); }
.timer-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.timer-head .label { font-weight: 650; }
.timer-card.sleep .label { color: var(--sleep); }
.timer-card.feed .label { color: var(--feed); }
.big-time { font: 700 52px/1 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin: 6px 0 2px; }
.sub { color: var(--ink-2); font-size: 14px; }
.muted { color: var(--ink-3); }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }
.stack { display: grid; gap: 10px; }

/* ---- buttons --------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 10px 16px; border-radius: var(--radius-sm); border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 650; font-size: 17px; text-align: center;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn.small { min-height: 44px; font-size: 15px; padding: 8px 12px; }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.sleep { background: var(--sleep); color: var(--surface); }
.btn.feed { background: var(--feed); color: var(--surface); }
.btn.nappy { background: var(--nappy); color: var(--surface); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1.5px solid currentColor; }
.btn.link { background: none; min-height: 0; padding: 6px 0; color: var(--ink-2); font-weight: 600; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
.btn[aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: -3px; }
.btn:disabled { opacity: 0.5; }

.side-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.side-toggle .btn { min-height: 76px; flex-direction: column; gap: 2px; background: var(--surface); }
.side-toggle .btn .s { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.side-toggle .btn.on { background: var(--feed); color: var(--surface); }
.side-toggle .btn.on .s { color: inherit; opacity: 0.85; }

/* ---- quick actions --------------------------------------------------- */
.actions { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.actions .btn { min-height: 72px; flex-direction: column; gap: 2px; font-size: 16px; }
.actions .btn .s { font-size: 12px; font-weight: 500; opacity: 0.85; }
.actions .w2 { grid-column: span 2; }
.actions .w3 { grid-column: span 3; }
.actions .soft-sleep { background: var(--sleep-soft); color: var(--sleep); }
.actions .soft-feed { background: var(--feed-soft); color: var(--feed); }
.actions .soft-nappy { background: var(--nappy-soft); color: var(--nappy); }

/* ---- next sleep ------------------------------------------------------ */
.next .window { font: 700 30px/1.15 var(--font-display); letter-spacing: -0.01em; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.next .likely { color: var(--ink-2); font-size: 15px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 650; background: var(--surface-2); color: var(--ink-2); }
.chip.in { background: var(--sleep); color: var(--surface); }
.chip.after { background: var(--nappy-soft); color: var(--nappy); }
.track { position: relative; height: 10px; border-radius: 99px; background: var(--surface-2); margin: 14px 0 6px; overflow: hidden; }
.track .win { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--sleep) 35%, transparent); }
.track .now { position: absolute; top: -2px; bottom: -2px; width: 4px; border-radius: 2px; background: var(--ink); }
.track-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); }
.reasons { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.reasons li { padding-left: 16px; position: relative; color: var(--ink-2); font-size: 15px; }
.reasons li::before { content: ""; position: absolute; left: 2px; top: 0.6em; width: 6px; height: 6px; border-radius: 50%; background: var(--sleep); }
.cues { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink-2); font-size: 14px; }
.conf { font-size: 13px; color: var(--ink-3); margin-top: 8px; }
.why { margin-top: 10px; }
.why summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 650; color: var(--sleep); list-style: none; }
.why summary::-webkit-details-marker { display: none; }
.why summary::after { content: "›"; margin-left: 8px; transition: transform 0.15s; }
.why[open] summary::after { transform: rotate(90deg); }
.why .reasons { margin-top: 2px; }

/* ---- tiles ----------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--surface); border-radius: var(--radius-sm); padding: 12px; box-shadow: var(--shadow); min-width: 0; }
.tile .k { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); }
.tile .v { font: 700 21px/1.2 var(--font-display); white-space: nowrap; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.tile .d { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }

/* ---- entries list ---------------------------------------------------- */
.list { display: grid; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.entry { display: grid; grid-template-columns: 12px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; width: 100%; min-height: 60px; }
.entry:last-child { border-bottom: 0; }
.entry .dot { width: 12px; height: 12px; border-radius: 50%; }
.entry.sleep .dot { background: var(--sleep); }
.entry.feed .dot { background: var(--feed); }
.entry.nappy .dot { background: var(--nappy); }
.entry .t { font-weight: 650; }
.entry .m { font-size: 13px; color: var(--ink-2); }
.entry .when { font-size: 14px; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 18px; color: var(--ink-3); text-align: center; }

/* ---- day view -------------------------------------------------------- */
.daynav { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 8px; }
.daynav h2 { margin: 0; text-align: center; font: 700 20px var(--font-display); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border-radius: var(--radius-sm); padding: 12px; box-shadow: var(--shadow); }
.stat .k { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.stat .v { font: 700 22px/1.2 var(--font-display); font-variant-numeric: tabular-nums; }
.stat .d { font-size: 13px; color: var(--ink-3); }
.timeline { width: 100%; height: auto; display: block; }
.timeline text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--c); }

/* ---- forms ----------------------------------------------------------- */
label.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  width: 100%; min-height: 50px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--surface); font-size: 17px; font-weight: 500;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: var(--radius-sm); background: var(--surface-2); }
.seg button { min-height: 46px; border: 0; border-radius: 9px; background: transparent; font-weight: 650; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { min-height: 40px; padding: 6px 14px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: 15px; }
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.amounts .btn { min-height: 48px; }
.err { color: var(--bad); font-size: 14px; }
.note { font-size: 14px; color: var(--ink-2); }
.waking { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px; align-items: end; }

/* ---- sheet ----------------------------------------------------------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 40; animation: fade 0.15s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 20px) max(16px, env(safe-area-inset-left, 0px));
  animation: up 0.2s ease-out;
}
.sheet-inner { max-width: 560px; margin: 0 auto; display: grid; gap: 14px; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.sheet h3 { margin: 0; font: 700 22px var(--font-display); }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---- toast ----------------------------------------------------------- */
.toast {
  position: fixed; left: 0; right: 0; margin: 0 auto; z-index: 50;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
  width: min(528px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--ink); color: var(--bg); padding: 8px 8px 8px 16px; border-radius: 14px; animation: up 0.2s ease-out;
}
.toast .btn { min-height: 44px; background: transparent; color: var(--bg); border: 1.5px solid currentColor; }
.toast .acts { display: flex; gap: 6px; }

/* ---- tab bar --------------------------------------------------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 0 max(8px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(8px, env(safe-area-inset-left, 0px));
}
.tabbar nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); height: var(--tabbar-h); }
.tabbar a { display: grid; place-items: center; align-content: center; gap: 2px; text-decoration: none; color: var(--ink-3); font-size: 13px; font-weight: 650; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--ink); }

/* ---- auth / setup ---------------------------------------------------- */
.hero { text-align: center; padding: 8vh 0 8px; display: grid; gap: 10px; justify-items: center; }
.hero img { width: 84px; height: 84px; border-radius: 22px; }
.hero h1 { margin: 0; font: 800 34px var(--font-display); }
.hero p { margin: 0; color: var(--ink-2); max-width: 34ch; }
code, .code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 14px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.bigcode { font: 700 32px ui-monospace, Consolas, monospace; letter-spacing: 0.12em; text-align: center; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); }
.ww { display: grid; grid-template-columns: 1.3fr 1fr 1fr 0.8fr; gap: 6px; align-items: center; font-size: 14px; }
.ww input { min-height: 42px; padding: 6px 8px; font-size: 15px; }
.ww .h { font-size: 12px; color: var(--ink-3); font-weight: 650; }

@media (max-width: 380px) {
  .tile { padding: 10px; }
  .tile .v { font-size: 18px; }
  .big-time { font-size: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
