/* Cradle Clock — dark-first, calm night palette. Light mode overrides under [data-theme="light"]. */
/* Six color schemes. :root = Midnight (default). The others override via [data-theme]. */
:root, :root[data-theme="midnight"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f242d; --surface-3: #262c37;
  --text: #e7ecf3; --muted: #9aa4b2; --border: #2a3038;
  --accent: #8aa1ff; --accent-text: #0f1115; --link: #8aa1ff;
  --good: #6fcf97; --warn: #f2c14e; --bad: #eb6f6f; --danger: #eb6f6f;
}
:root { --radius: 14px; --radius-lg: 22px; --deco: color-mix(in srgb, var(--accent) 34%, transparent); }

:root[data-theme="daylight"] {
  --bg: #f5f6fb; --surface: #ffffff; --surface-2: #eef0f7; --surface-3: #e4e7f1;
  --text: #1c2230; --muted: #5b6473; --border: #d9dce6;
  --accent: #5566e6; --accent-text: #ffffff; --link: #3f51d6;
  --good: #2f9e63; --warn: #c98a14; --bad: #cf4b4b; --danger: #cf4b4b;
}
:root[data-theme="nursery"] {
  --bg: #faf7f0; --surface: #ffffff; --surface-2: #f1ece1; --surface-3: #e7e0d2;
  --text: #2c2a24; --muted: #6f6a5d; --border: #e0d8c8;
  --accent: #7faf86; --accent-text: #ffffff; --link: #4f8f6a;
  --good: #5aa777; --warn: #c79a3e; --bad: #cf6f5f; --danger: #cf6f5f;
}
:root[data-theme="blush"] {
  --bg: #fdf4f6; --surface: #ffffff; --surface-2: #f8e9ee; --surface-3: #f1dbe3;
  --text: #2e2329; --muted: #7a6770; --border: #eed3dc;
  --accent: #e07a99; --accent-text: #ffffff; --link: #c45a7e;
  --good: #4caf7d; --warn: #d39a3c; --bad: #d9536b; --danger: #d9536b;
}
:root[data-theme="forest"] {
  --bg: #0d1512; --surface: #141d18; --surface-2: #1b2620; --surface-3: #233029;
  --text: #e3efe8; --muted: #8fa89a; --border: #26352d;
  --accent: #5fd0a3; --accent-text: #0d1512; --link: #5fd0a3;
  --good: #6fcf97; --warn: #e9c45f; --bad: #e88a7a; --danger: #e88a7a;
}
:root[data-theme="amber"] {
  --bg: #15110b; --surface: #1d1810; --surface-2: #261f15; --surface-3: #30271a;
  --text: #f0e7d8; --muted: #b09a7e; --border: #34291b;
  --accent: #f0a85a; --accent-text: #15110b; --link: #f0a85a;
  --good: #9bc46a; --warn: #e8b54e; --bad: #e07a5a; --danger: #e07a5a;
}
:root[data-theme="lavender"] {
  --bg: #f6f5fc; --surface: #ffffff; --surface-2: #efecf8; --surface-3: #e6e1f2;
  --text: #2a2440; --muted: #6b6480; --border: #e2dcf0;
  --accent: #7c5fd3; --accent-text: #ffffff; --link: #6a4fc0;
  --good: #4caf7d; --warn: #c98a14; --bad: #d9536b; --danger: #d9536b;
}
:root[data-theme="ocean"] {
  --bg: #0c1418; --surface: #121c22; --surface-2: #17242c; --surface-3: #1f2f39;
  --text: #e2eef2; --muted: #8aa3ac; --border: #223038;
  --accent: #3fc2d4; --accent-text: #06232a; --link: #6fd6e4;
  --good: #6fcf97; --warn: #e9c45f; --bad: #e88a7a; --danger: #e88a7a;
}
:root[data-theme="sunshine"] {
  --bg: #fffdf3; --surface: #ffffff; --surface-2: #fbf4dc; --surface-3: #f6ecc8;
  --text: #3a3320; --muted: #7a6f4d; --border: #efe3c0;
  --accent: #eab308; --accent-text: #2a2200; --link: #b88a06;
  --good: #4caf7d; --warn: #cf8a14; --bad: #d9536b; --danger: #d9536b;
}
:root[data-theme="bubblegum"] {
  --bg: #fff1f7; --surface: #ffffff; --surface-2: #fde3ef; --surface-3: #fbd3e5;
  --text: #3a1f2c; --muted: #86616f; --border: #f6cfe0;
  --accent: #ec4899; --accent-text: #ffffff; --link: #d02d80;
  --good: #4caf7d; --warn: #cf9a3c; --bad: #d9536b; --danger: #d9536b;
}
:root[data-theme="cottoncandy"] {
  --bg: #fbf3fb; --surface: #ffffff; --surface-2: #f4e8f6; --surface-3: #ecdcf0;
  --text: #33263a; --muted: #756880; --border: #ecd8f0;
  --accent: #c563cf; --accent-text: #ffffff; --link: #a94fc0;
  --good: #4caf7d; --warn: #cf9a3c; --bad: #d9536b; --danger: #d9536b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--bg);
  /* Soft multi-hue gradient washes (recolor per scheme via accent/good/warn). */
  background-image:
    radial-gradient(42rem 42rem at 6% -8%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 60%),
    radial-gradient(36rem 36rem at 106% 4%, color-mix(in srgb, var(--good) 26%, transparent), transparent 60%),
    radial-gradient(40rem 40rem at 50% 114%, color-mix(in srgb, var(--warn) 22%, transparent), transparent 62%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }

/* Decorative baby-motif pattern layer — behind all content, drifts gently. */
.bg-deco { position: fixed; top: -6%; left: -6%; width: 112%; height: 112%; z-index: -1; pointer-events: none; opacity: 0.9; animation: bw-drift 26s ease-in-out infinite alternate; }
.bg-deco .deco-motif { fill: var(--deco); }
@keyframes bw-drift { from { transform: translate(0, 0); } to { transform: translate(2.2%, 1.8%); } }
@media (prefers-reduced-motion: reduce) { .bg-deco { animation: none; } }

/* Counting sheep — a few that hop gently in the background. Transform-only (GPU), 4 elements, so it's
   basically free. Recolors per scheme; sits behind all content. */
.sheep-layer { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.sheep { position: absolute; width: 54px; height: 40px; opacity: 0.8; will-change: transform; animation: sheep-hop 8s ease-in-out infinite; }
.sheep .sheep-wool { fill: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
.sheep .sheep-face { fill: color-mix(in srgb, var(--text) 55%, transparent); }
.sheep .sheep-eye  { fill: var(--surface); }
.sheep .sheep-legs { fill: color-mix(in srgb, var(--text) 45%, transparent); }
.sheep-1 { left: 7%;  top: 20%; }
.sheep-2 { left: 70%; top: 37%; width: 42px; height: 31px; animation-delay: 2s; }
.sheep-3 { left: 24%; top: 70%; width: 48px; height: 35px; animation-delay: 4.2s; }
.sheep-4 { left: 78%; top: 77%; width: 38px; height: 28px; animation-delay: 6s; }
.sheep-5 { left: 84%; top: 13%; width: 40px; height: 29px; animation-delay: 1s; }
.sheep-6 { left: 4%;  top: 48%; width: 46px; height: 34px; animation-delay: 3s; }
.sheep-7 { left: 45%; top: 85%; width: 44px; height: 32px; animation-delay: 5.2s; }
.sheep-8 { left: 88%; top: 60%; width: 34px; height: 25px; animation-delay: 7.2s; }
@keyframes sheep-hop {
  0%, 68%, 100% { transform: translateY(0); }
  74% { transform: translateY(-15px); }
  80% { transform: translateY(0); }
  84% { transform: translateY(-7px); }
  88% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .sheep { animation: none; } }

/* Screen-flash when a feeding is due (respects reduced-motion). */
@keyframes cc-flash { 0%,100% { background: var(--bg); } 50% { background: color-mix(in srgb, var(--warn) 28%, var(--bg)); } }
body.cc-flash { animation: cc-flash 0.9s ease-in-out 4; }
@media (prefers-reduced-motion: reduce) { body.cc-flash { animation: none; } }

/* Layout shell */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.app-header .brandrow { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-header .app-logo { width: 28px; height: 28px; border-radius: 7px; flex: none; }
.app-header .baby { display: flex; align-items: center; gap: 8px; min-width: 0; }
.app-header h1 { font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .baby select { max-width: 46vw; }
main { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 16px 16px 96px; }

/* Bottom tab nav — one-handed */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: 0; color: var(--muted); padding: 10px 4px 12px;
  font-size: 0.72rem; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 56px;
}
.tabbar button .ico { font-size: 1.25rem; line-height: 1; }
.tabbar button.active { color: var(--accent); }

/* Buttons */
button { font: inherit; cursor: pointer; }
.btn {
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); padding: 12px 16px; min-height: 48px; width: 100%;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; }
.btn.sm { min-height: 40px; padding: 8px 12px; width: auto; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; min-height: 40px; min-width: 40px; padding: 6px 10px; font-size: 1.1rem; line-height: 1; }
.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Inputs */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { min-height: 64px; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; font-size: 0.82rem; color: var(--muted); margin: 0 0 4px 2px; }

/* Home — hero feeding button + countdown */
.hero { text-align: center; padding: 8px 0 4px; }
.bigbtn {
  width: 220px; height: 220px; max-width: 64vw; max-height: 64vw; aspect-ratio: 1;
  border-radius: 50%; border: 0; margin: 8px auto; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.bigbtn .lbl { font-size: 1.35rem; font-weight: 800; letter-spacing: 0.3px; }
.bigbtn .sub { font-size: 0.85rem; opacity: 0.8; margin-top: 4px; }
.bigbtn.feeding { background: var(--good); }
.bigbtn.sleeping { background: var(--surface-2); color: var(--text); border: 2px solid var(--border); }

.stopwatch { font-variant-numeric: tabular-nums; font-size: 3rem; font-weight: 800; letter-spacing: 1px; }
.stopwatch.paused { color: var(--warn); }

/* Countdown card */
.count {
  margin: 14px 0; padding: 16px; border-radius: var(--radius-lg); border: 1px solid var(--border);
  background: var(--surface); text-align: center;
}
.count .due { font-size: 1.05rem; }
.count .big { font-size: 2.1rem; font-weight: 800; font-variant-numeric: tabular-nums; margin: 2px 0; }
.count.early .big { color: var(--text); }
.count.window .big { color: var(--warn); }
.count.overdue .big { color: var(--bad); }
.count .win { font-size: 0.85rem; color: var(--muted); }

/* Today's rhythm (day plan) */
.plan { margin: 14px 0; }
.plan .planhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.planlist { display: flex; flex-direction: column; }
.planrow { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.planrow:last-child { border-bottom: 0; }
.planrow .pi { width: 18px; text-align: center; color: var(--muted); font-weight: 700; }
.planrow .pt { font-variant-numeric: tabular-nums; font-weight: 600; }
.planrow .pl { color: var(--muted); font-size: 0.82rem; margin-left: auto; }
.planrow .pedit-btn { background: none; border: 0; padding: 2px 6px; margin-left: 8px; display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer; min-height: auto; }
.planrow .pedit-btn .pico { font-size: 1.15rem; line-height: 1; color: var(--accent); }
.planrow .pedit-btn .plbl { font-size: 0.62rem; color: var(--muted); }
.planrow .plog-btn .pico { color: #b08bd8; }
.planrow.done .pt { color: var(--muted); }
.planrow.done .pi { color: var(--good); }
.planrow.past { opacity: 0.5; }
.planrow.next { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 10px; border-bottom-color: transparent; padding-left: 8px; padding-right: 8px; }
.planrow.next .pi, .planrow.next .pt { color: var(--accent); }
.planrow.next .pl { color: var(--accent); font-weight: 600; }
.planrow.dream .pi, .planrow.dream .pl { color: #b08bd8; }
.planrow.dream .pt { color: var(--text); }
.planfoot { font-size: 0.75rem; margin-top: 8px; }

/* Warning banner */
.warnbar {
  position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 15;
  background: color-mix(in srgb, var(--warn) 22%, var(--surface)); border: 1px solid var(--warn);
  border-radius: 12px; padding: 12px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px;
}
.warnbar .msg { flex: 1; font-weight: 600; }

/* Cards / timeline */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.tl-card { display: flex; gap: 12px; align-items: flex-start; }
.tl-card .when { width: 64px; flex: none; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; padding-top: 2px; }
.tl-card .body { flex: 1; min-width: 0; }
.tl-card .head { display: flex; align-items: center; gap: 8px; }
.tl-card .title { font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.good { background: var(--good); } .dot.bad { background: var(--bad); } .dot.none { background: var(--muted); }
.kind-feeding { border-left: 3px solid var(--accent); }
.kind-sleep { border-left: 3px solid #b08bd8; }
.kind-note { border-left: 3px solid var(--muted); }
.detailline { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }
.cardactions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* Side toggle + steppers */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--surface-2); border: 0; color: var(--text); padding: 8px 14px; min-height: 40px; }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.seg.seg-wrap { display: flex; flex-wrap: wrap; gap: 6px; border: 0; overflow: visible; }
.seg.seg-wrap button { border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; }
.seg.seg-wrap button.on { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.seg.seg-wrap .chip-other { border-style: dashed; color: var(--muted); }

/* The post-feeding fill-in form (and the feeding editor): tint the boxes toward the scheme's accent
   with a stronger border so the fields stand out on every background — the plain surface-2 fill was
   nearly invisible on the light schemes. Selected toggles keep the solid-accent look. */
.logform input, .logform select, .logform textarea {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface-2));
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  border-width: 1.5px;
}
.logform input::placeholder, .logform textarea::placeholder { color: color-mix(in srgb, var(--text) 55%, transparent); }
.logform .seg { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); border-width: 1.5px; }
.logform .seg button:not(.on) { background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); }
.logform .seg.seg-wrap button:not(.on) {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-2));
}
/* "Write today's summary" + "Done" get the same accent tint as the fields so they don't disappear. */
.logform .btn.hilite {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface-2));
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  border-width: 1.5px;
}
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 1.2rem; }
.stepper .val { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }

/* Day header */
.dayhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.dayhead .date { font-weight: 700; }

/* Summary card */
.summary { margin-top: 16px; border: 1px dashed var(--border); }
.summary .metrics { color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }
.summary .final { font-size: 1.02rem; }

/* History */
.hist-day { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.hist-day .d { font-weight: 700; }
.hist-day .s { color: var(--muted); font-size: 0.9rem; }

/* Sheet / modal */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0; width: 100%; max-width: 640px; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h3 { margin: 0 0 12px; }
@media (min-width: 560px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; border-bottom: 1px solid var(--border); } }
/* The daily-summary sheet is meant to be read at a glance — give it room so the whole recap shows
   without scrolling. The editor textarea auto-grows to its content (capped at 60vh) in app.js. */
.summary-sheet { max-width: 720px; max-height: 92vh; overflow-y: auto; }
.summary-sheet .summary { border: 0; margin-top: 0; }
.summary-sheet .summary .final { font-size: 1.1rem; line-height: 1.62; }
.summary-sheet .summary .metrics { font-size: 0.95rem; }
.summary-sheet textarea.sum-ta { min-height: 220px; font-size: 1.06rem; line-height: 1.55; }

/* Disclaimer */
.disclaimer { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 78px; background: var(--surface-3); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 8px 16px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
.pending { font-size: 0.78rem; color: var(--warn); }
.app-footer { text-align: center; color: var(--muted); font-size: 0.78rem; padding: 8px 0 2px; }
h2.screen-title { font-size: 1.2rem; margin: 4px 0 14px; }

/* Color-scheme swatch picker */
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { background: none; border: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 5px; width: 62px; min-height: auto; cursor: pointer; }
.swatch .chip { width: 46px; height: 46px; border-radius: 50%; border: 2px solid; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,0.25); }
.swatch .chip .acc { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,0.18); }
.swatch.on .chip { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch .nm { font-size: 0.72rem; color: var(--muted); }
.swatch.on .nm { color: var(--text); font-weight: 700; }

/* Install prompt bar */
.installbar { display: flex; align-items: center; gap: 10px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 12px; }
.installbar .msg { flex: 1; font-weight: 600; font-size: 0.92rem; }

/* Loading indicator */
.loadingbox { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 72vh; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
