:root {
  --bg: #fbf6f0;
  --bg-2: #f3e9df;
  --surface: #ffffff;
  --surface-2: #fbf2ea;
  --ink: #3a2230;
  --ink-2: #6b4858;
  --muted: #9b7e8a;
  --line: #ead9cf;
  --rose: #b35a73;
  --rose-soft: #e9b6c2;
  --sand: #d8b486;
  --green: #6b8e5a;
  --green-soft: #cfe1bf;
  --amber: #c98a3b;
  --amber-soft: #f1d8a8;
  --red: #b6584f;
  --red-soft: #efc7c1;
  --pink: #d99ab1;
  --blue: #5d7da6;
  --shadow: 0 4px 18px rgba(58, 34, 48, 0.08);
  --radius: 18px;
  --radius-s: 12px;
  --tap: 48px;
}
body.night {
  --bg: #1c1419;
  --bg-2: #261b21;
  --surface: #2a1f25;
  --surface-2: #34262d;
  --ink: #f3e2dc;
  --ink-2: #c9aeb6;
  --muted: #8d7381;
  --line: #463038;
  --rose: #d99ab1;
  --rose-soft: #4a2f37;
  --sand: #b89066;
  --green: #8fb37a;
  --green-soft: #34402e;
  --amber: #d8a35e;
  --amber-soft: #4a3825;
  --red: #d28279;
  --red-soft: #4a2e2c;
  --pink: #c987a3;
  --blue: #7e9ec5;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); padding-top: env(safe-area-inset-top); }
#root { display: flex; flex-direction: column; min-height: 100vh; max-width: 720px; margin: 0 auto; }
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--bg); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--line); }
#topbar .title { font-weight: 600; font-size: 18px; }
#topbar .child-switch { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--ink-2); min-height: 36px; }
#screen { flex: 1; padding: 18px; padding-bottom: 90px; }
#bottomnav { position: fixed; left: 0; right: 0; bottom: 0; max-width: 720px; margin: 0 auto; background: var(--surface); border-top: 1px solid var(--line); display: flex; z-index: 6; padding-bottom: env(safe-area-inset-bottom); }
#bottomnav button { flex: 1; background: none; border: 0; padding: 12px 4px; color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: var(--tap); }
#bottomnav button.active { color: var(--rose); }
#bottomnav button .ic { font-size: 22px; line-height: 1; }
h1, h2, h3 { margin: 0 0 10px; font-weight: 600; }
h1 { font-size: 26px; letter-spacing: -0.01em; }
h2 { font-size: 20px; margin-top: 18px; }
h3 { font-size: 16px; color: var(--ink-2); }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid var(--line); }
.card-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 12px; }
button { font: inherit; cursor: pointer; }
.btn { background: var(--rose); color: #fff; border: 0; border-radius: var(--radius-s); padding: 14px 18px; min-height: var(--tap); font-size: 16px; font-weight: 600; }
.btn:active { transform: scale(0.97); }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn-big { padding: 22px 18px; font-size: 20px; min-height: 64px; border-radius: var(--radius); width: 100%; }
.btn-green { background: var(--green); }
.btn-warn { background: var(--amber); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
input, textarea, select { font: inherit; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); color: var(--ink); width: 100%; min-height: var(--tap); }
textarea { resize: vertical; }
label { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 6px; }
.tag { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; min-height: 40px; display: inline-flex; align-items: center; font-size: 14px; color: var(--ink); }
.tag.on { background: var(--rose-soft); border-color: var(--rose); color: var(--ink); }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.metric { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.metric:last-child { border: 0; }
.metric .v { font-weight: 600; }
.metric .norm { color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.norm { background: var(--green); }
.dot.low { background: var(--amber); }
.dot.high { background: var(--red); }
#toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 999px; z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: flex-end; justify-content: center; z-index: 50; }
#modal.open { display: flex; }
#modal .sheet { background: var(--bg); width: 100%; max-width: 720px; border-radius: 24px 24px 0 0; padding: 22px 18px; max-height: 90vh; overflow: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.scale { position: relative; height: 14px; background: var(--line); border-radius: 999px; margin: 18px 0 8px; overflow: hidden; }
.scale .green { position: absolute; top: 0; bottom: 0; background: var(--green-soft); }
.scale .yellow { position: absolute; top: 0; bottom: 0; background: var(--amber-soft); }
.scale .red { position: absolute; top: 0; bottom: 0; background: var(--red-soft); }
.scale .marker { position: absolute; top: -4px; bottom: -4px; width: 4px; background: var(--ink); border-radius: 2px; }
.scale-ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.bigbtn { background: linear-gradient(180deg, var(--rose-soft), var(--bg-2)); border: 2px solid var(--rose); border-radius: 28px; padding: 32px 18px; text-align: center; font-size: 22px; font-weight: 600; color: var(--ink); min-height: 100px; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.bigbtn.sleep { background: linear-gradient(180deg, var(--green-soft), var(--bg-2)); border-color: var(--green); }
.timer { font-size: 36px; font-weight: 300; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.list-item { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.list-item:last-child { border: 0; }
.tabs { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; margin-bottom: 14px; }
.tabs button { flex: 1; background: none; border: 0; padding: 10px 8px; border-radius: 999px; color: var(--ink-2); min-height: 40px; font-size: 14px; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.reco { background: var(--surface); border-left: 4px solid var(--amber); padding: 14px 16px; border-radius: var(--radius-s); margin-bottom: 10px; }
.reco.good { border-color: var(--green); }
.reco h4 { margin: 0 0 4px; font-size: 15px; }
.reco p { margin: 0; font-size: 14px; color: var(--ink-2); }
.reco .why { font-size: 13px; color: var(--muted); margin-top: 6px; display: none; }
.reco.open .why { display: block; }
.disclaimer { font-size: 12px; color: var(--muted); padding: 12px; text-align: center; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; background: var(--surface-2); border-radius: 999px; font-size: 13px; margin: 0 6px 6px 0; }
.history-day { background: var(--surface-2); border-radius: var(--radius-s); padding: 14px; margin-bottom: 10px; }
.sleep-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.sleep-row:last-child { border: 0; }
.sleep-row .time { font-variant-numeric: tabular-nums; font-weight: 600; }
.sleep-row .dur { color: var(--ink-2); font-size: 14px; }
.sleep-row .ic { width: 30px; text-align: center; }
.heatmap { display: grid; grid-template-columns: 40px repeat(7, 1fr); gap: 3px; font-size: 11px; }
.heatmap .lbl { color: var(--muted); }
.heatmap .cell { aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); }
.heatmap .cell.l1 { background: var(--green-soft); }
.heatmap .cell.l2 { background: var(--amber-soft); }
.heatmap .cell.l3 { background: var(--red-soft); }
.svg-chart { width: 100%; height: auto; }
.toggle { display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface-2); border-radius: 999px; min-height: 40px; cursor: pointer; }
.toggle.on { background: var(--rose-soft); }
.iconbtn { background: var(--surface-2); border: 0; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.welcome { text-align: center; padding: 40px 20px; }
.welcome .logo { font-size: 48px; margin-bottom: 12px; }
.seg { display: flex; gap: 6px; background: var(--surface-2); border-radius: var(--radius-s); padding: 4px; }
.seg button { flex: 1; background: none; border: 0; padding: 10px; border-radius: 8px; color: var(--ink-2); min-height: 40px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.fade-in { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (min-width: 700px) { #screen { padding: 24px; } h1 { font-size: 30px; } }
