:root {
  --bg: #fff7f3;
  --card: #ffffff;
  --text: #3b3340;
  --sub: #8a7f8f;
  --line: #f1e4df;
  --primary: #ee7b7b;
  --primary-ink: #ffffff;
  --soft: #fdeceb;
  --ok: #4daa8a;
  --warn: #e0a030;
  --danger: #d9534f;
  --shadow: 0 2px 10px rgba(120, 70, 70, 0.08);
  --radius: 18px;
  --tab-h: 64px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #13111a;
  --card: #1e1b27;
  --text: #ebe7f1;
  --sub: #9d96aa;
  --line: #2e2a3a;
  --primary: #e58a8a;
  --primary-ink: #1a1220;
  --soft: #2a2230;
  --ok: #5cc2a0;
  --warn: #e3b04e;
  --danger: #ea7b77;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
body.sheet-open { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); }

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
}
.child-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; text-align: left; box-shadow: var(--shadow);
}
.child-chip .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--soft); color: var(--primary); display: grid; place-items: center; flex: none; }
.child-chip .names { min-width: 0; line-height: 1.25; }
.child-chip .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.child-chip .age { font-size: 12.5px; color: var(--sub); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; flex: none; box-shadow: var(--shadow); }
.icon-btn:active { transform: scale(0.94); }

main#view { padding: 4px 14px 0; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h2, .section-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section-title small { font-weight: 400; color: var(--sub); }
.muted { color: var(--sub); font-size: 13.5px; }
.empty { text-align: center; color: var(--sub); padding: 18px 8px; font-size: 14px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 30;
  width: 100%; max-width: 560px; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--sub); font-size: 11.5px; }
.tabbar button i { font-size: 20px; }
.tabbar button[aria-current='page'] { color: var(--primary); font-weight: 700; }

/* ---------- buttons / forms ---------- */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 16px; min-height: 48px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.soft { background: var(--soft); border-color: transparent; color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 600; padding: 6px 4px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; font-weight: 600; }
.input, input[type='text'], input[type='number'], input[type='date'], input[type='datetime-local'], textarea, select {
  width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 14px; min-height: 48px; outline: none;
}
.input:focus, input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 72px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 64px; min-height: 48px; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px; padding: 8px 10px; font-weight: 600; }
.seg button[aria-pressed='true'] { background: var(--soft); border-color: var(--primary); color: var(--primary); }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 54px; height: 54px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--bg); font-size: 22px; font-weight: 700; flex: none; }
.stepper .val { flex: 1; text-align: center; font-size: 34px; font-weight: 800; line-height: 1.1; }
.stepper .val small { font-size: 15px; font-weight: 600; color: var(--sub); margin-left: 4px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chips button { border: 1.5px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 14px; min-height: 40px; font-weight: 600; }
.chips button:active { background: var(--soft); }

.notice { border-radius: 12px; padding: 10px 12px; font-size: 13.5px; background: var(--soft); margin-bottom: 14px; }
.notice.warn { background: color-mix(in srgb, var(--warn) 18%, var(--card)); }
.notice.danger { background: color-mix(in srgb, var(--danger) 16%, var(--card)); }
.error-text { color: var(--danger); font-size: 13.5px; margin: 6px 0 10px; min-height: 1px; }

/* ---------- home ---------- */
.hero { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.since-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.since { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.since .lbl { font-size: 12.5px; color: var(--sub); display: flex; align-items: center; gap: 6px; }
.since .big { font-size: 22px; font-weight: 800; margin-top: 2px; line-height: 1.25; }
.since .sub { font-size: 12.5px; color: var(--sub); }

.timer-card { display: flex; align-items: center; gap: 12px; border: 2px solid var(--primary); background: var(--soft); border-radius: 16px; padding: 12px; }
.timer-card + .timer-card { margin-top: 8px; }
.timer-card .tc-body { flex: 1; min-width: 0; }
.timer-card .tc-title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.timer-card .tc-time { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.timer-card .btn { min-height: 52px; }

.quick-main { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick-sub { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 10px; }
.qbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 92px; font-weight: 700; font-size: 14.5px; padding: 8px 4px;
}
.qbtn:active { transform: scale(0.96); }
.qbtn .qi { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 20px; }
.quick-sub .qbtn { min-height: 74px; font-size: 12.5px; }
.quick-sub .qbtn .qi { width: 34px; height: 34px; font-size: 15px; }
.qbtn[data-active='true'] { border: 2px solid var(--primary); background: var(--soft); }

.today-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; }
.today-stats .n { font-size: 20px; font-weight: 800; line-height: 1.2; }
.today-stats .n small { font-size: 11px; font-weight: 600; color: var(--sub); }
.today-stats .l { font-size: 11.5px; color: var(--sub); }

/* ---------- log rows ---------- */
.log-list { display: flex; flex-direction: column; }
.log-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; width: 100%; min-height: 56px; }
.log-row:last-child { border-bottom: 0; }
.log-ic { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; font-size: 16px; }
.log-main { flex: 1; min-width: 0; }
.log-title { font-weight: 700; }
.log-sub { font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-time { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }

.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-nav .day-label { font-weight: 800; font-size: 17px; text-align: center; flex: 1; }
.day-nav .icon-btn { box-shadow: none; }

.fab { position: fixed; right: max(16px, calc(50% - 280px + 16px)); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 25; height: 56px; border-radius: 999px; padding: 0 22px; border: 0; background: var(--primary); color: var(--primary-ink); font-weight: 700; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); display: flex; align-items: center; gap: 8px; }

/* ---------- stats / charts ---------- */
.chart-box { position: relative; height: 190px; }
.avg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.avg-grid .n { font-size: 20px; font-weight: 800; }
.avg-grid .l { font-size: 12px; color: var(--sub); }

/* ---------- vaccines ---------- */
.vac-row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; text-align: left; min-height: 60px; }
.vac-row:last-child { border-bottom: 0; }
.vac-check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; color: transparent; }
.vac-row[data-done='true'] .vac-check { background: var(--ok); border-color: var(--ok); color: #fff; }
.vac-main { flex: 1; min-width: 0; }
.vac-name { font-weight: 700; }
.vac-sub { font-size: 12.5px; color: var(--sub); }
.badge { font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 3px 10px; background: var(--soft); color: var(--primary); white-space: nowrap; flex: none; }
.badge.now { background: color-mix(in srgb, var(--ok) 20%, var(--card)); color: var(--ok); }
.badge.late { background: color-mix(in srgb, var(--danger) 18%, var(--card)); color: var(--danger); }
.badge.opt { background: var(--bg); color: var(--sub); border: 1px solid var(--line); }
details.fold > summary { cursor: pointer; font-weight: 700; padding: 4px 0; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 6, 16, 0.5); z-index: 50; animation: fade 0.15s ease-out; }
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 51;
  width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--card); border-radius: 24px 24px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  animation: up 0.2s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.sheet-head h2 { font-size: 18px; display: flex; align-items: center; gap: 10px; }
.sheet-head .icon-btn { box-shadow: none; }
.sheet-body { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; top: calc(10px + env(safe-area-inset-top)); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 14px; }
.toast { pointer-events: auto; background: #3b3340; color: #fff; border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); max-width: 520px; animation: fade 0.15s ease-out; }
:root[data-theme='dark'] .toast { background: #ebe7f1; color: #1a1220; }
.toast button { border: 0; background: none; color: #ffb4b4; font-weight: 800; padding: 4px 6px; }
:root[data-theme='dark'] .toast button { color: #b3392f; }

/* ---------- onboarding ---------- */
.onboard { max-width: 520px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top)) 20px 40px; display: flex; flex-direction: column; gap: 18px; }
.onboard .logo { width: 84px; height: 84px; border-radius: 26px; background: var(--soft); color: var(--primary); display: grid; place-items: center; font-size: 40px; margin: 0 auto; }
.onboard h1 { text-align: center; font-size: 26px; }
.onboard .lead { text-align: center; color: var(--sub); }
.feature-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.feature-list li { display: flex; gap: 10px; align-items: flex-start; font-size: 14.5px; }
.feature-list i { color: var(--primary); margin-top: 4px; width: 18px; text-align: center; }
.code-box { font-size: 30px; font-weight: 800; letter-spacing: 0.18em; text-align: center; background: var(--soft); border-radius: 14px; padding: 14px 8px; font-variant-numeric: tabular-nums; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.member-list li:last-child { border-bottom: 0; }
.disclaimer { font-size: 12px; color: var(--sub); line-height: 1.6; }

.skeleton { height: 90px; border-radius: 16px; background: linear-gradient(90deg, var(--line), var(--card), var(--line)); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
