:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-2: #f2ebe1;
  --text: #2d2a26;
  --muted: #776f65;
  --border: #e4d9cb;
  --primary: #d9774b;
  --on-primary: #ffffff;
  --danger: #c0403a;

  --meal: #d97a3c;   --meal-bg: #fcebdd;
  --sleep: #5f67c2;  --sleep-bg: #e9ebfa;
  --toilet: #2f9481; --toilet-bg: #ddf2ed;
  --tantrum: #cc5470; --tantrum-bg: #fae3e9;
  --school: #3b78b8;  --school-bg: #e2edf9;
  --teacher: #8460bd; --teacher-bg: #efe7fa;
  --home: #4a8f3f;    --home-bg: #e4f2df;
  --mom: #a65a8c;

  --accent: var(--primary);
  --radius: 16px;
  --shadow: 0 1px 3px rgba(70, 45, 20, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1c19;
    --surface: #2a2622;
    --surface-2: #35302b;
    --text: #f1ebe4;
    --muted: #b3a99d;
    --border: #463f38;
    --primary: #e88a5f;
    --on-primary: #1f1c19;
    --danger: #f07a72;
    --meal: #f0a26c;   --meal-bg: #3b2c20;
    --sleep: #9aa1f0;  --sleep-bg: #282a42;
    --toilet: #62c7b3; --toilet-bg: #1e3631;
    --tantrum: #ee8aa2; --tantrum-bg: #3d2229;
    --school: #8dbaf0;  --school-bg: #1f2e40;
    --teacher: #c2a6ee; --teacher-bg: #2f2640;
    --home: #93cf88;    --home-bg: #213320;
    --mom: #e29ac6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 560px; margin: 0 auto; }

a { color: inherit; }

button, input, textarea, select { font: inherit; color: inherit; }

button { cursor: pointer; }

.loading, .empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.page {
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

.top h1 { font-size: 22px; margin: 4px 0 8px; }

h2 { font-size: 17px; margin: 0 0 8px; }

/* ---------- 日付 ---------- */

.daynav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 24px;
  line-height: 1;
}
.icon-btn:disabled { opacity: 0.3; cursor: default; }

.daylabel {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  min-height: 44px;
}

.date-overlay {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  cursor: pointer;
}

.today-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
}

.link-btn {
  display: block;
  margin: 0 auto 4px;
  border: 0;
  background: none;
  color: var(--primary);
  font-weight: 600;
  padding: 6px 12px;
}

/* ---------- 記録ボタン ---------- */

.quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0 24px;
}

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 104px;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 700;
  font-size: 17px;
  box-shadow: var(--shadow);
  border: 1.5px solid transparent;
  user-select: none;
  -webkit-user-select: none;
}
.quick-btn:active { transform: scale(0.97); }
.quick-icon { font-size: 34px; line-height: 1.1; }

.c-meal    { background: var(--meal-bg);    color: var(--meal); }
.c-sleep   { background: var(--sleep-bg);   color: var(--sleep); }
.c-toilet  { background: var(--toilet-bg);  color: var(--toilet); }
.c-tantrum { background: var(--tantrum-bg); color: var(--tantrum); }

.t-meal    { --accent: var(--meal); }
.t-sleep   { --accent: var(--sleep); }
.t-toilet  { --accent: var(--toilet); }
.t-tantrum { --accent: var(--tantrum); }

/* ---------- タイムライン ---------- */

.timeline ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.tl-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-left: 5px solid currentColor;
}
.tl-item.c-meal    { border-left-color: var(--meal); }
.tl-item.c-sleep   { border-left-color: var(--sleep); }
.tl-item.c-toilet  { border-left-color: var(--toilet); }
.tl-item.c-tantrum { border-left-color: var(--tantrum); }

.tl-time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 44px; }
.tl-icon { font-size: 20px; line-height: 1.3; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tl-line, .tl-note { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.tl-note {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tl-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; flex-shrink: 0; }

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--tantrum-bg);
  color: var(--tantrum);
  border: 1px solid var(--tantrum);
}

/* ---------- 入力画面 ---------- */

.form-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.form-head h1 { font-size: 21px; margin: 0; }
.back { text-decoration: none; color: var(--accent); font-weight: 600; padding: 6px 0; align-self: flex-start; }

.field { margin: 18px 0; }
.field-label { font-weight: 700; font-size: 15px; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.hint { font-weight: 400; font-size: 13px; color: var(--muted); }
.hint-text { font-size: 14px; color: var(--muted); margin: 6px 0; }

.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input.short { max-width: 140px; }
textarea.input { resize: vertical; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 16px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-primary);
  font-weight: 600;
}
.more-chip { border-style: dashed; color: var(--muted); }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale .chip { padding: 8px 0; font-variant-numeric: tabular-nums; }

.time-row { display: flex; gap: 8px; align-items: center; }

.durations {
  margin: 18px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 15px;
}
.durations strong { color: var(--accent); }

.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row .input { flex: 1; min-width: 0; }

.btn {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-weight: 600;
}
.btn.small { flex-shrink: 0; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-primary);
}
.btn.big { width: 100%; min-height: 54px; font-size: 18px; }
.btn:disabled { opacity: 0.5; }
.btn.danger-outline {
  display: block;
  margin: 24px auto 0;
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.later {
  margin: 24px 0;
  padding: 4px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.later h3 { font-size: 16px; margin: 12px 0 0; }

details.more {
  margin: 20px 0;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--border);
}
details.more summary {
  padding: 14px 0;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

.savebar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.savebar .btn { display: block; max-width: 528px; margin: 0 auto; }

.meta { font-size: 13px; color: var(--muted); margin-top: 24px; }
.center { text-align: center; }

/* 写真 */
.photos { display: flex; flex-wrap: wrap; gap: 10px; }
.photo { position: relative; width: 104px; height: 104px; }
.photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.photo-del {
  position: absolute; top: -8px; right: -8px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--text);
  color: var(--bg);
  font-size: 18px; line-height: 1;
}
.photo-add {
  width: 104px; height: 104px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  border-radius: 12px;
  border: 1.5px dashed var(--accent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.photo-add-icon { font-size: 28px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

/* 睡眠 */
.sleep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.sleep-btn {
  min-height: 96px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  background: var(--sleep-bg);
  color: var(--sleep);
  font-size: 16px;
  font-weight: 700;
}
.sleep-btn:active { transform: scale(0.97); }

/* ---------- 共通部品 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin: 12px 0;
}
.card h2 { margin-top: 14px; }

.navbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  max-width: 187px;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 6px;
  font-size: 12px;
  text-decoration: none;
  color: var(--muted);
}
.nav-item.on { color: var(--primary); font-weight: 700; }
.nav-icon { font-size: 22px; line-height: 1.2; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  z-index: 20;
}
.toast button {
  border: 0;
  background: none;
  color: var(--primary);
  font-weight: 700;
  padding: 4px;
}

.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 30;
}
.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: grid;
  gap: 8px;
}
.sheet-title { text-align: center; font-weight: 700; margin: 4px 0; }
.sheet-btn {
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 17px;
}
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { background: transparent; }

.error { color: var(--danger); }

/* ---------- 子ども ---------- */

.child-switch {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.child-btn {
  min-height: 52px;
  padding: 6px 8px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.3;
}
.child-btn.on {
  border-color: var(--child);
  background: color-mix(in srgb, var(--child) 14%, var(--surface));
}
.child-btn.on .child-name { color: var(--child); }
.child-name { font-weight: 700; font-size: 16px; }
.child-age { font-size: 12px; color: var(--muted); font-weight: 400; }

.child-single { margin-bottom: 8px; }
.child-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
}
.child-tag .child-age { margin-left: 2px; }
.child-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--child); flex-shrink: 0; }

.child-list { list-style: none; margin: 0; padding: 0; }
.child-list a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.child-mode {
  margin-left: auto;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.chev { color: var(--muted); font-size: 20px; }
.btn.add-child { display: block; text-align: center; text-decoration: none; margin: 12px 0 14px; line-height: 26px; }

.welcome { padding: 8px 16px 16px; }
.welcome .btn { display: block; text-align: center; text-decoration: none; line-height: 34px; margin-top: 12px; }

.mode-choices { display: grid; gap: 8px; }
.mode-choice {
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface);
  display: grid;
  gap: 2px;
}
.mode-choice span { font-size: 14px; color: var(--muted); }
.mode-choice.on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }

/* ---------- 就学の記録 ---------- */

.quick.three { grid-template-columns: 1fr 1fr 1fr; }
.quick.three .quick-label { font-size: 15px; text-align: center; line-height: 1.3; }

.c-schoolDay { background: var(--school-bg);  color: var(--school); }
.c-issue     { background: var(--tantrum-bg); color: var(--tantrum); }
.c-teacher   { background: var(--teacher-bg); color: var(--teacher); }
.tl-item.c-schoolDay { border-left-color: var(--school); }
.tl-item.c-issue     { border-left-color: var(--tantrum); }
.tl-item.c-teacher   { border-left-color: var(--teacher); }
.t-schoolDay { --accent: var(--school); }
.t-issue     { --accent: var(--tantrum); }
.t-teacher   { --accent: var(--teacher); }

.scale .chip.face { display: flex; flex-direction: column; align-items: center; line-height: 1.2; padding: 6px 0; }
.face-icon { font-size: 22px; }

.tl-line {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.c-school { background: var(--school-bg); color: var(--school); }
.c-home   { background: var(--home-bg);   color: var(--home); }
.tl-item.c-school { border-left-color: var(--school); }
.tl-item.c-home   { border-left-color: var(--home); }
.t-school { --accent: var(--school); }
.t-home   { --accent: var(--home); }

.scale-words { display: grid; gap: 8px; }
.scale-words .chip { display: flex; align-items: center; gap: 12px; border-radius: 12px; text-align: left; }
.scale-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}

/* ---------- トラブル・宿題 ---------- */

.calm-btn {
  display: block;
  width: 100%;
  margin: -12px 0 20px;
  color: var(--school);
  border-color: var(--school);
  border-style: dashed;
  background: transparent;
}

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.small-link { font-size: 14px; color: var(--primary); font-weight: 600; text-decoration: none; }
.troubles { margin-bottom: 24px; }
.trouble-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.trouble-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1.5px solid var(--tantrum);
  text-decoration: none;
}
.trouble-name { font-weight: 700; }
.trouble-meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.status { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status.s-0 { background: var(--tantrum-bg); color: var(--tantrum); }
.status.s-1 { background: var(--meal-bg); color: var(--meal); }
.status.s-2 { background: var(--home-bg); color: var(--home); }

.tl-trouble { font-size: 13px; color: var(--tantrum); font-weight: 600; margin-top: 2px; }
.tl-day { font-weight: 700; font-size: 14px; color: var(--muted); margin-top: 8px; }
.trouble-actions { margin: 4px 0 20px; }
.trouble-actions .btn { flex: 1; }
h2.spaced { margin-top: 24px; }

.new-trouble-btn { margin-top: 10px; }
.new-trouble {
  padding: 4px 14px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--tantrum);
  background: var(--surface);
}

.sub-label { font-weight: 700; font-size: 14px; margin: 14px 0 6px; display: flex; gap: 8px; align-items: baseline; }
.hw-list { display: grid; gap: 12px; }
.hw-item {
  padding: 4px 14px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.hw-head { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; }
.hw-custom { margin-top: 8px; }
.danger-text { color: var(--danger); margin: 0; }
.btn.add-hw { border-style: dashed; color: var(--accent); }

/* ---------- わたしの記録 ---------- */

.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.me-btn {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  text-decoration: none;
}
.t-mom { --accent: var(--mom); }
.head-row { display: flex; justify-content: space-between; align-items: center; }
.lock-now { margin: 0; color: var(--mom); }
.forgot { margin-top: 24px; color: var(--muted); }
.plain-list { padding-left: 20px; margin: 0 0 12px; }
.plain-list li { margin: 4px 0; }
.cycle { display: grid; gap: 4px; padding: 12px 16px; }
.cycle-day { font-size: 16px; }
.cycle-day strong { font-size: 22px; color: var(--mom); }
.cycle .btn { justify-self: start; }
.med-row {
  padding: 8px 12px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.med-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.med-head .danger-text { margin-left: auto; }
.add-med { margin-top: 8px; }
.gap { height: 8px; }
.mom-snap { border-color: var(--mom); }
.mom-snap summary { color: var(--mom); }
.unlock-snap { margin-bottom: 14px; }
.tl-item.c-mom { border-left-color: var(--mom); }

.c-nursery { background: var(--school-bg); color: var(--school); }
.tl-item.c-nursery { border-left-color: var(--school); }
.t-nursery { --accent: var(--school); }
/* ボタンが奇数のときは、最後のボタンを横いっぱいにする */
.quick:not(.three) .quick-btn:last-child:nth-child(odd) {
  grid-column: span 2;
  flex-direction: row;
  gap: 10px;
  min-height: 72px;
}
.change-pass { margin-top: 24px; color: var(--muted); }

.snap-axis { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 8px; margin: 8px 0; }
.snap-label { font-weight: 700; font-size: 14px; }
.tl-mom { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tl-mom.has { color: var(--mom); font-weight: 600; }

/* ---------- バックアップ ---------- */
.backup { display: grid; gap: 8px; padding: 4px 16px 16px; }
.backup .btn { width: 100%; }
.restore-btn { display: block; text-align: center; cursor: pointer; line-height: 26px; margin-top: 8px; }
.backup-reminder {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: -8px 0 20px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--meal-bg);
  color: var(--meal);
  font-weight: 600;
  text-decoration: none;
}
.backup-reminder .chev { margin-left: auto; color: inherit; }
