:root {
  --bg: #fff7f8;
  --card: #ffffff;
  --text: #2b2228;
  --muted: #7b6b72;
  --line: #efdfe3;
  --accent: #e8798f;
  --accent-soft: #fde4ea;
  --accent-text: #ffffff;
  --night: #6c63c9;
  --nap: #f3b95f;
  --band1: rgba(232, 121, 143, 0.12);
  --band2: rgba(232, 121, 143, 0.22);
  --median: #c95b73;
  --grid: #eadde1;
  --ok: #3a9d6a;
  --warn: #d9822b;
  --danger: #c84a4a;
  --radius: 16px;
  --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a1f;
    --card: #27242b;
    --text: #f3eef0;
    --muted: #a8989f;
    --line: #3a343d;
    --accent: #f28ba0;
    --accent-soft: #3b2b31;
    --accent-text: #2b1a20;
    --night: #8f87e8;
    --nap: #f1c270;
    --band1: rgba(242, 139, 160, 0.14);
    --band2: rgba(242, 139, 160, 0.26);
    --median: #f28ba0;
    --grid: #3a343d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
.top-inner { padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; }
.name { font-weight: 700; font-size: 20px; }
.age { color: var(--muted); font-size: 13px; }

.screen { padding: 14px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px); max-width: 640px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; min-height: var(--tab-h);
}
.tabs a .ico { font-size: 20px; line-height: 1; }
.tabs a.active { color: var(--accent); font-weight: 600; }

h2 { font-size: 18px; margin: 18px 0 8px; }
h2:first-child { margin-top: 2px; }
.hint { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card.accent { background: var(--accent-soft); border-color: transparent; }
.card .title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.big { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

.btn {
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 12px 16px; font-weight: 600; min-height: 46px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.night { background: var(--night); border-color: var(--night); color: #fff; }
.btn.block { width: 100%; }
.btn.huge { min-height: 72px; font-size: 20px; border-radius: 20px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--accent-soft); color: var(--text); }

form.form { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 11px 12px; min-height: 46px; font-size: 16px;
}
.field textarea { min-height: 90px; resize: vertical; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.list { display: grid; gap: 8px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
}
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .s { font-size: 13px; color: var(--muted); }
.item .x { border: 0; background: transparent; color: var(--muted); font-size: 18px; padding: 6px; }
.day-head { font-size: 13px; color: var(--muted); margin: 10px 0 4px; display: flex; justify-content: space-between; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.night { background: var(--night); }
.dot.nap { background: var(--nap); }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 10px; fill: var(--muted); }
.chart .axis { stroke: var(--grid); stroke-width: 1; }
.chart .band1 { fill: var(--band1); }
.chart .band2 { fill: var(--band2); }
.chart .median { stroke: var(--median); stroke-width: 1; fill: none; stroke-dasharray: 3 3; }
.chart .pline { stroke: var(--text); stroke-width: 1.5; fill: none; }
.chart .pt { fill: var(--accent); stroke: var(--card); stroke-width: 1.5; }
.chart .plabel { fill: var(--text); font-weight: 600; }
.chart .bar-night { fill: var(--night); }
.chart .bar-nap { fill: var(--nap); }
.chart .norm { fill: var(--ok); opacity: 0.12; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

.diary-entry { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.diary-entry .d { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.diary-entry p { margin: 6px 0 0; white-space: pre-wrap; }
.diary-entry img { width: 100%; border-radius: 12px; margin-top: 8px; display: block; max-height: 320px; object-fit: cover; }
.photo-pick { position: relative; }
.photo-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.photo-prev { width: 100%; max-height: 200px; object-fit: cover; border-radius: 12px; display: block; margin-top: 6px; }

.sleeping-pulse { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--night); animation: pulse 1.6s infinite; margin-right: 6px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: all 0.2s; z-index: 20; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.lightbox[hidden] { display: none; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 30; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; }
.lb-close { position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 14px; border: 0; background: rgba(255,255,255,0.15); color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 18px; }

.empty { text-align: center; color: var(--muted); padding: 24px 10px; font-size: 14px; }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; padding: 6px 0; }
details.more > summary::-webkit-details-marker { display: none; }
.sep { height: 1px; background: var(--line); margin: 10px 0; }

/* ---- stage 2: hub, checklists, teeth, dosing ---- */
.link-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.link-card > div { flex: 1; min-width: 0; }
.link-card .title { margin-bottom: 2px; }
.hub-ico { font-size: 26px; line-height: 1; width: 36px; text-align: center; flex: none; }
.chev { color: var(--muted); font-size: 22px; line-height: 1; flex: none; }
.warn-card { border-color: var(--warn); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.full:not(.on) { color: var(--ok); border-color: var(--ok); }
.chip.future:not(.on) { color: var(--muted); }

.item.check { cursor: pointer; align-items: flex-start; }
.item.check input[type="checkbox"] { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.item.check.done .t { color: var(--muted); font-weight: 500; }
.item.check.done.reminder .t { text-decoration: line-through; }
.inline-date { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 13px; padding: 0; width: 7.5em; }
.inline-num { width: 5.5em; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 8px; font-size: 16px; margin-left: 6px; }
.tips { margin: 0; padding-left: 18px; display: grid; gap: 8px; }

.item.tap { width: 100%; text-align: left; border-color: var(--line); }
.item.tap .main, .item.tap .t, .item.tap .s { display: block; }
.item.tap.dim .t { color: var(--muted); font-weight: 500; }
.st { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid var(--line); background: transparent; }
.st.ok { background: var(--ok); border-color: var(--ok); }
.st.reaction { background: var(--warn); border-color: var(--warn); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; color: var(--warn); border: 1px solid var(--warn); border-radius: 6px; padding: 0 5px; vertical-align: 1px; }
.item .ico { font-size: 20px; flex: none; }

.jaw { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.jaw-l { width: 34px; font-size: 11px; color: var(--muted); text-align: right; flex: none; }
.teeth { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; flex: 1; }
.tooth { aspect-ratio: 1 / 1.3; border: 1px solid var(--line); background: var(--bg); border-radius: 6px 6px 9px 9px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 0; min-width: 0; }
.jaw:first-child .tooth { border-radius: 9px 9px 6px 6px; }
.tooth.due { border-style: dashed; border-color: var(--accent); }
.tooth.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tooth.sel { outline: 2px solid var(--night); outline-offset: 1px; }
.dose-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.item.col { flex-direction: column; align-items: stretch; }

/* ---- stage 3: guide, reminders, report ---- */
details.topic { padding: 0; overflow: hidden; }
details.topic > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; }
details.topic > summary::-webkit-details-marker { display: none; }
details.topic > summary strong { flex: 1; }
details.topic[open] > summary .chev { transform: rotate(90deg); }
details.topic .tips { padding: 0 14px 12px 32px; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 12px; }
.sources a { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; text-decoration: none; }
.item.overdue .s { color: var(--warn); }
.item.today .t { color: var(--accent); }
.report { background: #fff; color: #111; border-radius: var(--radius); padding: 16px; font-size: 14px; line-height: 1.45; }
.report h1 { font-size: 20px; margin: 0 0 4px; }
.report h2 { font-size: 15px; margin: 16px 0 6px; border-bottom: 1px solid #ddd; padding-bottom: 3px; }
.report .meta, .report .small, .report small { color: #666; font-size: 12px; }
.report table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report td, .report th { text-align: left; padding: 4px 6px; border-bottom: 1px solid #eee; vertical-align: top; }
.report th { font-weight: 600; color: #555; }
.report ul { margin: 4px 0; padding-left: 18px; }
.report .questions { min-height: 60px; border: 1px dashed #bbb; border-radius: 8px; padding: 8px; white-space: pre-wrap; }
.report .questions:empty::before { content: attr(data-placeholder); color: #999; }
@media print {
  .top, .tabs, .no-print, #toast { display: none !important; }
  body { background: #fff; }
  .screen { padding: 0; max-width: none; }
  .report { border-radius: 0; padding: 0; }
  .report .questions { border: 0; padding: 0; }
  .report .questions:empty { display: none; }
}
