:root {
  --bg:#111418; --card:#1b2027; --raised:#232931; --line:#2a313a;
  --text:#eef1f4; --muted:#8b95a1;
  --go:#22835a; --go-ink:#5fd19b; --go-tint:rgba(95,209,155,.10);
  --stop:#e0605c; --stop-tint:rgba(224,96,92,.10);
  --warn:#e0a53a; --warn-tint:rgba(224,165,58,.10);
  --r-lg:28px; --r-md:16px; --r-sm:10px;
  --ease:cubic-bezier(.16,1,.3,1);
  color-scheme:dark;
}
* { box-sizing:border-box; }
html, body { margin:0; background:var(--bg); color:var(--text); }
body { font:16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing:antialiased; -webkit-tap-highlight-color:transparent; text-rendering:optimizeLegibility; }
::selection { background:rgba(95,209,155,.32); color:var(--text); }
button { font:inherit; color:inherit; cursor:pointer; touch-action:manipulation; -webkit-user-select:none; user-select:none; }
button:disabled { cursor:default; }
:focus-visible { outline:2px solid var(--go-ink); outline-offset:3px; border-radius:var(--r-sm); }
p { margin:0; }
.sr { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.icon { width:18px; height:18px; flex:none; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }

main { max-width:520px; margin:0 auto; padding:max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(48px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

/* ---- Hero ---- */
.hero { text-align:center; padding-top:4px; }
.status { color:var(--muted); font-size:15px; min-height:21px; transition:color .3s; }
.timer { font-family:ui-rounded, -apple-system, system-ui, sans-serif; font-size:72px; line-height:1.05; font-weight:600; font-variant-numeric:tabular-nums; letter-spacing:-.03em; margin:4px 0 18px; transition:color .3s; }
body.live .timer, body.live .status { color:var(--stop); }

/* ---- Ritmo ---- */
.rhythm { display:flex; align-items:center; gap:12px; border-radius:var(--r-md); padding:12px 14px; margin:14px 0 10px; background:var(--card); transition:background-color .3s; }
.ricon { width:36px; height:36px; border-radius:50%; display:grid; place-items:center; background:var(--raised); color:var(--muted); flex:none; }
.ricon svg { width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; display:none; }
.rhythm .i-idle { display:block; }
.rhythm.ok, .rhythm.mid { --tint:var(--go-tint); --ink:var(--go-ink); background:linear-gradient(var(--tint), var(--tint)), var(--card); }
.rhythm.mid { --tint:var(--warn-tint); --ink:var(--warn); }
.rhythm.ok .ricon, .rhythm.mid .ricon { color:var(--ink); background:var(--tint); }
.rhythm.ok .i-idle, .rhythm.mid .i-idle, .rhythm.irr .i-idle { display:none; }
.rhythm.ok .i-ok, .rhythm.mid .i-irr, .rhythm.irr .i-irr { display:block; }
.rtext { min-width:0; }
.rtext b { display:block; font-size:17px; font-weight:650; font-variant-numeric:tabular-nums; }
.rhythm.ok b, .rhythm.mid b { color:var(--ink); }
.rtext span { display:block; font-size:13px; color:var(--muted); font-variant-numeric:tabular-nums; }

/* ---- Tasti principali ---- */
.start { position:relative; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px; width:100%; aspect-ratio:1.6; max-height:240px; border:0; border-radius:var(--r-lg); color:#fff; background:var(--go); box-shadow:0 1px 0 rgba(255,255,255,.08) inset, 0 8px 20px -10px rgba(0,0,0,.6); transition:transform .12s var(--ease), filter .2s, background-color .25s; }
.start.stop { --ring:#ff9a96; background:#b8423f; }
.bcheck { display:none; width:46px; height:46px; fill:none; stroke:#fff; stroke-width:2.6; stroke-linecap:round; stroke-linejoin:round; stroke-dasharray:24; stroke-dashoffset:24; }
.start.done .bcheck { display:block; animation:draw .35s var(--ease) forwards; }
.start.done .start-label { font-size:24px; letter-spacing:.02em; text-transform:none; }
.start.done .start-sub { font-variant-numeric:tabular-nums; }
@keyframes draw { to { stroke-dashoffset:0; } }
.lockbar { position:absolute; left:18px; right:18px; bottom:14px; height:4px; border-radius:2px; background:rgba(255,255,255,.22); overflow:hidden; opacity:0; }
.lockbar::after { content:""; position:absolute; inset:0; background:#fff; transform-origin:left; transform:scaleX(0); }
.start.done .lockbar { opacity:1; }
.start.done .lockbar::after { animation:drain 3s linear forwards; }
@keyframes drain { from { transform:scaleX(1); } to { transform:scaleX(0); } }
.start.done { cursor:default; }
.start-label { font-size:36px; font-weight:750; letter-spacing:.06em; text-transform:uppercase; }
.start-sub { font-size:14px; font-weight:500; }
.start:active { transform:scale(.975); }
.start::after { content:""; position:absolute; inset:-2px; border-radius:30px; pointer-events:none; border:2px solid var(--ring, var(--go-ink)); opacity:0; }
.start.pulse::after { animation:pulse .7s var(--ease); }
@keyframes pulse { from { opacity:.9; transform:scale(1); } to { opacity:0; transform:scale(1.06); } }
.start:disabled { filter:saturate(.6) brightness(.85); }
.err { color:var(--stop); text-align:center; font-size:13px; min-height:18px; margin-top:6px; }
.err:empty { min-height:0; margin:0; }

/* ---- Statistiche ---- */
.stats { display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin:10px 0 8px; }
.stat { background:var(--card); border-radius:var(--r-md); padding:14px 6px 12px; text-align:center; }
.stat b { display:block; font-size:24px; font-weight:650; font-variant-numeric:tabular-nums; letter-spacing:-.01em; }
.stat span { display:block; margin-top:2px; font-size:12px; color:var(--muted); }
.hint { font-size:12px; color:var(--muted); text-align:center; text-wrap:balance; }
.hint.left { text-align:left; }
.hint.below { margin-top:10px; }

/* ---- Bottoni secondari ---- */
.ghost { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:13px 14px; border-radius:var(--r-md); border:1px solid var(--line); background:var(--card); font-size:15px; font-weight:600; transition:background-color .15s, border-color .15s, opacity .15s; }
.ghost:active { background:var(--raised); }
.ghost.small { padding:9px 14px; border-radius:var(--r-sm); font-size:14px; font-weight:500; color:var(--text); }
.ghost:disabled { opacity:.4; }
.link { background:none; border:0; padding:8px 12px; color:var(--muted); font-size:13px; text-decoration:underline; text-underline-offset:3px; text-decoration-color:var(--line); }

/* ---- Sezioni ---- */
section + section { margin-top:32px; }
.sechead { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:10px; min-height:34px; }
h2 { margin:0; font-size:13px; font-weight:650; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); }
.seg { display:flex; background:var(--card); border-radius:var(--r-sm); padding:3px; }
.seg button { background:none; border:0; color:var(--muted); font-size:13px; font-weight:500; padding:6px 11px; border-radius:7px; transition:background-color .15s, color .15s; }
.seg button[aria-pressed="true"] { background:var(--raised); color:var(--text); font-weight:600; box-shadow:0 1px 2px rgba(0,0,0,.35); }

/* ---- Grafici ---- */
.chart { position:relative; margin:0 0 8px; background:var(--card); border-radius:var(--r-md); padding:12px 12px 8px; touch-action:pan-y; }
.chart svg { display:block; overflow:visible; }
.chart svg text { font-family:-apple-system, system-ui, sans-serif; font-variant-numeric:tabular-nums; }
.ctitle { display:flex; justify-content:space-between; gap:8px; font-size:13px; font-weight:600; margin:0 2px 8px; }
.ctitle small { font-size:12px; font-weight:400; color:var(--muted); }
.cempty { font-size:13px; color:var(--muted); text-align:center; padding:26px 12px 22px; text-wrap:balance; }
.tip { position:absolute; left:0; top:0; pointer-events:none; background:var(--raised); color:var(--text); font-size:12px; font-weight:500; padding:6px 9px; border-radius:8px; white-space:nowrap; box-shadow:0 6px 18px -6px rgba(0,0,0,.6); transform:translate(-50%, calc(-100% - 10px)); opacity:0; transition:opacity .12s; font-variant-numeric:tabular-nums; }
.tip.show { opacity:1; }
.tip b { font-weight:650; }

/* ---- Storico ---- */
table { width:100%; border-collapse:collapse; font-variant-numeric:tabular-nums; }
th { text-align:left; font-size:12px; color:var(--muted); font-weight:500; padding:6px 6px 8px; border-bottom:1px solid var(--line); }
td { padding:12px 6px; border-bottom:1px solid var(--line); font-size:17px; }
.num { text-align:right; }
th.x, td.x { width:40px; text-align:right; padding-right:2px; color:var(--muted); }
td.x .icon { width:17px; height:17px; vertical-align:-3px; }
tbody tr:not(.day):not(.none) { cursor:pointer; transition:background-color .12s; }
tbody tr:not(.day):not(.none):active { background:var(--card); }
td.dim { color:var(--muted); }
tr.day td { font-size:12px; font-weight:600; color:var(--muted); padding:18px 6px 6px; border-bottom:0; text-transform:capitalize; }
tr.running td { color:var(--stop); }
tr.none td { color:var(--muted); text-align:center; padding:28px 0; font-size:15px; border-bottom:0; }

.foot { display:flex; flex-direction:column; align-items:center; gap:6px; margin-top:32px; }

/* ---- Toast ---- */
.toast { position:fixed; left:50%; bottom:max(24px, calc(env(safe-area-inset-bottom) + 12px)); transform:translate(-50%, 12px); display:flex; align-items:center; gap:14px; background:var(--raised); color:var(--text); padding:11px 12px 11px 16px; border-radius:14px; font-size:14px; box-shadow:0 10px 30px -10px rgba(0,0,0,.7); opacity:0; pointer-events:none; transition:opacity .2s, transform .3s var(--ease); z-index:10; }
.toast.show { opacity:1; transform:translate(-50%, 0); pointer-events:auto; }
.toast span { white-space:nowrap; }
.toast button { background:none; border:0; color:var(--go-ink); font-weight:700; font-size:14px; padding:4px 6px; }
.toast button[hidden] { display:none; }

/* ---- Dialoghi ---- */
dialog { background:var(--card); color:var(--text); border:0; border-radius:22px; padding:22px 20px 14px; width:min(92vw, 420px); box-shadow:0 30px 80px -20px rgba(0,0,0,.8); }
dialog::backdrop { background:rgba(5,7,9,.65); }
dialog h3 { margin:0 0 6px; font-size:19px; font-weight:650; }
dialog label { display:block; font-size:13px; color:var(--muted); margin:16px 0 6px; }
.opt { font-weight:400; }
dialog input[type=time] { width:100%; font:inherit; font-size:24px; font-variant-numeric:tabular-nums; padding:10px 12px; border-radius:12px; border:1px solid var(--line); background:var(--bg); color:var(--text); }
dialog input[type=time]:focus { outline:none; border-color:var(--go-ink); }
.nudge { display:flex; gap:6px; margin-top:8px; }
.nudge button { flex:1; padding:9px 4px; border-radius:var(--r-sm); border:1px solid var(--line); background:var(--bg); font-size:14px; font-variant-numeric:tabular-nums; }
.nudge button:active { background:var(--raised); }
dialog .err { text-align:left; margin-top:10px; }
.actions { display:flex; gap:8px; margin-top:20px; }
.actions button { flex:1; padding:14px; border-radius:12px; border:0; font-size:16px; font-weight:600; }
.actions .save { background:var(--go); color:#fff; }
.actions .cancel { background:var(--raised); }
.del { display:block; width:100%; margin-top:8px; padding:12px; background:none; border:0; color:var(--stop); font-size:14px; font-weight:500; }

@media (hover:hover) {
  .start:hover { filter:brightness(1.07); }
  .ghost:not(:disabled):hover { border-color:#3a434e; background:var(--raised); }
  .seg button:not([aria-pressed="true"]):hover { color:var(--text); }
  .link:hover { color:var(--text); }
  tbody tr:not(.day):not(.none):hover { background:var(--card); }
  .nudge button:hover, .actions .cancel:hover { background:var(--raised); }
  .actions .save:hover { filter:brightness(1.08); }
}
@media (max-width:360px) {
  .timer { font-size:60px; }
  .start-label { font-size:30px; }
  td { font-size:16px; }
}
@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { transition-duration:.01ms !important; animation:none !important; }
  .bcheck { stroke-dashoffset:0; }
  .start.done .lockbar::after { transform:scaleX(1); }
}

/* ---- Collegamento ai grafici ---- */
.tocharts { display:flex; align-items:center; gap:14px; margin-top:20px; padding:14px 14px 14px 16px; border-radius:var(--r-md); background:var(--card); color:var(--text); text-decoration:none; transition:background-color .15s; }
.tocharts > .icon:first-child { width:22px; height:22px; color:var(--go-ink); }
.tocharts span { flex:1; min-width:0; }
.tocharts b { display:block; font-size:16px; font-weight:600; }
.tocharts small { display:block; font-size:13px; color:var(--muted); }
.tocharts .chev { color:var(--muted); }
.tocharts:active { background:var(--raised); }
.tocharts + section { margin-top:32px; }

/* ---- Pagina grafici ---- */
.pagehead { display:grid; grid-template-columns:1fr auto 1fr; align-items:center; margin:0 0 18px; min-height:40px; }
.pagehead h1 { grid-column:2; margin:0; font-size:17px; font-weight:650; }
.back { grid-column:1; grid-row:1; justify-self:start; display:inline-flex; align-items:center; gap:2px; margin-left:-6px; padding:8px 8px 8px 2px; border-radius:var(--r-sm); color:var(--go-ink); text-decoration:none; font-size:16px; }
.back .icon { width:22px; height:22px; }
.seg button { padding:6px 10px; }
@media (hover:hover) {
  .tocharts:hover { background:var(--raised); }
  .back:hover { background:var(--card); }
}

/* ---- Regola 5-1-1 ---- */
.r511 { background:var(--card); border-radius:var(--r-md); padding:14px 14px 12px; margin-bottom:0; transition:background-color .3s; }
.r511head { display:flex; justify-content:space-between; align-items:baseline; margin-bottom:8px; }
.r511head b { font-size:15px; font-weight:650; }
.r511head span { font-size:13px; color:var(--muted); }
.checks { list-style:none; margin:0; padding:0; display:grid; gap:2px; }
.checks li { display:flex; align-items:center; gap:10px; min-height:30px; font-size:15px; }
.ck svg { display:block; width:20px; height:20px; fill:none; stroke:var(--muted); stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.checks li[data-state="yes"] .ck svg { stroke:var(--go-ink); }
.checks li[data-state="yes"] .cl { color:var(--text); }
.cl { flex:1; color:var(--muted); }
.cv { font-size:13px; color:var(--muted); font-variant-numeric:tabular-nums; text-align:right; }
.r511msg { font-size:15px; font-weight:600; color:var(--go-ink); margin-top:8px; }
.r511msg:empty { display:none; }
.r511.met { background:linear-gradient(var(--go-tint), var(--go-tint)), var(--card); }
.r511.met .r511head span { color:var(--go-ink); font-weight:600; }
.redflags { font-size:12px; line-height:1.45; color:var(--muted); margin-top:10px; padding-top:10px; border-top:1px solid var(--line); }
.redflags b { color:var(--text); font-weight:600; }

/* ---- Neonato ---- */
:root { --wet:#2a68ab; --wet-ink:#7db3ea; --wet-tint:rgba(125,179,234,.12); }
.feedhero .timer { margin-bottom:4px; }
.fsub { color:var(--muted); font-size:14px; font-variant-numeric:tabular-nums; min-height:20px; margin-bottom:18px; text-wrap:balance; }
body.soon .feedhero .timer, body.soon .feedhero .status { color:var(--warn); }
body.late .feedhero .timer, body.late .feedhero .status { color:var(--stop); }
.duo { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.start.half { aspect-ratio:auto; min-height:168px; gap:4px; padding:16px 8px 24px; }
.start.half .start-label { font-size:24px; letter-spacing:.04em; }
.start.half .start-sub { font-size:13px; text-wrap:balance; text-align:center; }
.start.half.done .start-label { font-size:20px; }
.bicon { width:36px; height:36px; margin-bottom:4px; fill:none; stroke:#fff; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.start.done .bicon { display:none; }
.start.half .bcheck { width:36px; height:36px; margin-bottom:4px; }
.start.wet { --ring:var(--wet-ink); background:var(--wet); }
.start.half::after { border-radius:var(--r-lg); }

.wetcard { background:var(--card); border-radius:var(--r-md); padding:14px 14px 12px; margin-top:14px; transition:background-color .3s; }
.wetrow { display:flex; align-items:center; justify-content:space-between; gap:12px; margin:2px 0 6px; }
.wetnum { display:flex; align-items:baseline; gap:6px; font-variant-numeric:tabular-nums; }
.wetnum b { font-size:44px; line-height:1; font-weight:650; letter-spacing:-.02em; }
.wetnum span { font-size:18px; color:var(--muted); }
.pips { display:flex; flex-wrap:wrap; justify-content:flex-end; gap:6px; max-width:60%; }
.pips span { width:16px; height:16px; border-radius:50%; border:2px solid var(--line); transition:background-color .3s, border-color .3s; }
.pips span.on { background:var(--wet-ink); border-color:var(--wet-ink); }
.wetmsg { font-size:14px; font-variant-numeric:tabular-nums; }
.wetcard.ok { background:linear-gradient(var(--go-tint), var(--go-tint)), var(--card); }
.wetcard.ok .wetmsg { color:var(--go-ink); }
.wetcard.low { background:linear-gradient(var(--warn-tint), var(--warn-tint)), var(--card); }
.wetcard.low .wetmsg { color:var(--warn); }
.wetnote { font-size:12px; line-height:1.45; color:var(--muted); margin-top:10px; padding-top:10px; border-top:1px solid var(--line); }
body.baby .stats { margin-top:10px; }
.kind { display:inline-flex; align-items:center; gap:8px; }
.kind::before { content:""; width:9px; height:9px; border-radius:50%; background:var(--go-ink); }
.kind.wet::before { background:var(--wet-ink); }
.btable th.num { white-space:nowrap; }
.kindseg { margin-top:14px; }
.kindseg button { flex:1; padding:9px 10px; font-size:15px; }

/* ---- Home ---- */
.homehead { padding:28px 4px 22px; }
.homehead h1 { margin:0; font-size:34px; font-weight:700; letter-spacing:-.02em; }
.homehead p { color:var(--muted); font-size:15px; margin-top:2px; }
.tiles { display:grid; gap:12px; }
.tile { display:flex; align-items:center; gap:14px; padding:18px 14px 18px 16px; border-radius:var(--r-lg); background:var(--card); color:var(--text); text-decoration:none; transition:background-color .15s, transform .12s var(--ease); }
.tile:active { background:var(--raised); transform:scale(.985); }
.tileicon { width:48px; height:48px; border-radius:50%; display:grid; place-items:center; flex:none; background:var(--go-tint); color:var(--go-ink); }
.tile.contr .tileicon { background:var(--stop-tint); color:var(--stop); }
.tileicon svg { width:26px; height:26px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.tiletext { flex:1; min-width:0; }
.tiletext b { display:block; font-size:19px; font-weight:650; }
.tiletext small { display:block; font-size:14px; color:var(--muted); }
.tiletext em { display:block; font-style:normal; font-size:14px; font-weight:500; margin-top:8px; font-variant-numeric:tabular-nums; }
.tiletext em + em { margin-top:2px; }
.tiletext em.dim { color:var(--muted); font-weight:400; }
.tiletext em.soon { color:var(--warn); }
.tiletext em.late { color:var(--stop); }
.tile .chev { color:var(--muted); }
@media (hover:hover) { .tile:hover { background:var(--raised); } }
