:root {
  --bg: #fbf6f1;
  --surface: #ffffff;
  --ink: #4a3f3b;
  --muted: #84756e;
  --line: #f0e6dd;
  --accent: #db5f7c;
  --accent-ink: #ffffff;
  --accent-soft: #fde6ea;
  --band: #f3ebe4;
  /* グラフの線: 体重はピンク系、体脂肪率はミント系。朝は明るく、晩は濃く */
  --s-wm: #f29bb0;
  --s-we: #c2456a;
  --s-fm: #7cc6c0;
  --s-fe: #3f8f8a;
  --sun: #f0b95a;
  --moon: #9d93d6;
  --up: #c2456a;
  --down: #2f8f8a;
  --radius: 18px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1718;
    --surface: #272021;
    --ink: #f3e9e6;
    --muted: #a8989a;
    --line: #3a2f31;
    --accent: #f08fa5;
    --accent-ink: #2a1218;
    --accent-soft: rgba(240, 143, 165, .18);
    --band: #332a2c;
    --s-wm: #f7b3c3;
    --s-we: #d86a8b;
    --s-fm: #9fded8;
    --s-fe: #4fa7a1;
    --up: #f08fa5;
    --down: #7fd3cc;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* iPhoneでは丸ゴシック(ヒラギノ丸ゴ)で表示される */
  font-family: "Hiragino Maru Gothic ProN", "Zen Maru Gothic", "M PLUS Rounded 1c", "Yu Gothic UI", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* 全体を小さめに詰めて、1画面に収める */
.app {
  max-width: 430px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 14px calc(env(safe-area-inset-bottom) + 68px);
}

h1, h2, p, dl, dd, ul { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; }
i { font-style: normal; }

.title { font-size: 18px; font-weight: 600; letter-spacing: .02em; margin: 2px 2px 10px; }
h2 { font-size: 12px; font-weight: 600; letter-spacing: .08em; color: var(--muted); }
.fine { font-size: 11px; color: var(--muted); line-height: 1.6; }

/* ---------- カード・入力 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: grid;
  gap: 10px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1.25fr; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span:first-child { font-size: 11px; color: var(--muted); letter-spacing: .04em; }

input::-webkit-date-and-time-value { text-align: left; }

/* 文字サイズ16px未満だとiPhoneが入力時に勝手に拡大するので、入力欄は16pxを保つ */
input[type="text"],
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

input::placeholder { color: var(--muted); opacity: .55; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn:active { opacity: .7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.wide { width: 100%; min-height: 46px; font-size: 15px; }

/* ---------- マスコット ---------- */
.mascot { display: block; width: 76px; flex: none; }
.mascot svg { display: block; width: 100%; height: auto; }
.buddy { display: flex; align-items: center; gap: 8px; margin: 0 2px 4px; }
.buddy.in-card { margin: 0; }
.buddy.in-card .mascot { width: 48px; }

.bubble {
  position: relative;
  padding: 7px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
}

.bubble::before {
  content: "";
  position: absolute;
  left: -5px; top: 50%;
  width: 8px; height: 8px;
  margin-top: -4px;
  background: inherit;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}

.in-card .bubble { background: var(--bg); }

/* ---------- 1. 記録 ---------- */
.datebar { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; text-align: center; margin-bottom: 6px; }
.date { font-size: 17px; font-weight: 600; letter-spacing: .02em; }
.date small { font-size: 12px; font-weight: 400; color: var(--muted); margin-right: 8px; }

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:disabled { opacity: .3; cursor: default; }

/* 朝・晩 × 体重・体脂肪率 を1枚の表にまとめる */
.ge { display: grid; grid-template-columns: 50px 1fr 1fr; gap: 6px 10px; align-items: center; }
.ge .col { font-size: 11px; color: var(--muted); text-align: center; letter-spacing: .04em; }
.ge input { min-height: 48px; padding: 0 6px; font-size: 22px; font-weight: 300; text-align: center; }
.when { display: flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 600; }
.when svg { width: 18px; height: 18px; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.when .sun { stroke: var(--sun); }
.when .moon { stroke: var(--moon); }

/* ---------- 目標 ---------- */
.goal-main { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.goal-main b { font-size: 24px; font-weight: 300; line-height: 1.1; color: var(--ink); }
.goal-main .left { margin-left: 8px; }
.goal-main .left b { color: var(--accent); }
.progress { height: 8px; border-radius: 4px; background: var(--band); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.goal-foot { display: flex; justify-content: space-between; gap: 10px; }
.result-row { display: flex; align-items: center; gap: 12px; }
.result-row .mascot { width: 64px; }
.result-row .badge { display: inline-block; margin-bottom: 4px; }
.result-title { font-size: 15px; font-weight: 600; }

.badge {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.badge.neutral { background: var(--band); color: var(--muted); }

/* ---------- 2. グラフ ---------- */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }

.chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}

.chip[aria-pressed="true"] { color: var(--ink); background: var(--bg); }
.sw { width: 9px; height: 9px; flex: none; border-radius: 50%; border: 2px solid currentColor; opacity: .5; }
.chip[aria-pressed="true"] .sw { opacity: 1; }
.chip[aria-pressed="true"] .sw-wm { background: var(--s-wm); border-color: var(--s-wm); }
.chip[aria-pressed="true"] .sw-we { background: var(--s-we); border-color: var(--s-we); }
.chip[aria-pressed="true"] .sw-fm { background: var(--s-fm); border-color: var(--s-fm); }
.chip[aria-pressed="true"] .sw-fe { background: var(--s-fe); border-color: var(--s-fe); }

.readout { display: flex; flex-wrap: wrap; gap: 0 10px; min-height: 1.5em; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.readout b { font-weight: 500; color: var(--ink); }
.readout .k { display: inline-flex; align-items: center; gap: 4px; }
.readout .k::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.k-wm { color: var(--s-wm); } .k-we { color: var(--s-we); } .k-fm { color: var(--s-fm); } .k-fe { color: var(--s-fe); }

.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .ln { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart .ln.fat { stroke-width: 1.6; stroke-dasharray: 1 4; }
.chart .wm { stroke: var(--s-wm); } .chart .we { stroke: var(--s-we); }
.chart .fm { stroke: var(--s-fm); } .chart .fe { stroke: var(--s-fe); }
.chart circle { fill: var(--surface); stroke-width: 1.5; }
.chart .cursor line { stroke: var(--muted); stroke-width: 1; }
.chart .goal { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .goal-tag { fill: var(--accent); font-size: 10px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 0; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 12px; padding: 3px; }
.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg.four { grid-template-columns: repeat(4, 1fr); }

.seg button {
  min-height: 32px;
  padding: 0 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.field .seg { min-height: 42px; }
.field .seg button { min-height: 36px; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.facts.four { grid-template-columns: repeat(4, 1fr); }
.facts.ruled { border-top: 1px solid var(--line); padding-top: 10px; }
.facts dt { font-size: 10px; color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.facts dd { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.facts dd small { font-size: 10px; color: var(--muted); margin-left: 2px; }

/* ---------- 3. からだの現在地 ---------- */
.locked { justify-items: center; text-align: center; padding: 22px 20px; }
.locked .mascot { width: 84px; }
.dots { display: flex; gap: 8px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--line); }
.dots i.on { background: var(--accent); border-color: var(--accent); }

.big-num { display: flex; align-items: center; gap: 8px; font-size: 34px; font-weight: 300; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big-num small { font-size: 12px; font-weight: 600; letter-spacing: .08em; color: var(--muted); }
.big-num span small { font-size: 14px; font-weight: 400; letter-spacing: 0; }

.scale { position: relative; padding-top: 26px; }
.bar { display: grid; gap: 2px; height: 8px; }
.bar span { background: var(--band); }
.bar span:first-child { border-radius: 4px 0 0 4px; }
.bar span:last-child { border-radius: 0 4px 4px 0; }
.bar span.ok { background: var(--accent-soft); }
.bar.bmi, .bar-labels.bmi { grid-template-columns: 17.5fr 32.5fr 25fr 25fr; }
.bar.fat, .bar-labels.fat { grid-template-columns: 6fr 14fr 5fr 5fr; }
.bar-labels { display: grid; gap: 2px; margin-top: 8px; font-size: 10px; color: var(--muted); text-align: center; line-height: 1.3; }

.pin, .avg { position: absolute; transform: translateX(-50%); }
.pin { top: 0; z-index: 1; display: grid; justify-items: center; font-size: 10px; white-space: nowrap; }
.pin b { font-weight: 600; }
.pin::after { content: ""; width: 12px; height: 12px; margin-top: 5px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--accent); }
/* 同年代の平均は、バーを横切る縦線で示す(ラベルは下の凡例に出す) */
.avg { top: 20px; width: 2px; height: 20px; border-radius: 1px; background: var(--ink); }

.legend { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-you::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.lg-avg::before { content: ""; width: 2px; height: 12px; border-radius: 1px; background: var(--ink); }
.source { margin: 4px 4px 0; }

/* ---------- おすすめ(PR) ---------- */
.reco { margin-top: 20px; padding: 0 4px; }
.reco-head { display: flex; align-items: center; gap: 8px; }
.pr { font-size: 10px; letter-spacing: .1em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; line-height: 1.6; }
.reco li { border-bottom: 1px solid var(--line); }
.reco-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 12px; padding: 9px 0; text-decoration: none; }
.reco-item strong { font-size: 14px; font-weight: 500; }
.reco-item small { grid-column: 1; font-size: 11px; color: var(--muted); }
.reco-item .shop { grid-row: 1 / span 2; grid-column: 2; font-size: 11px; color: var(--muted); white-space: nowrap; }
.reco .fine { margin-top: 8px; }

/* ---------- 4. 一覧 ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.log { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.log th, .log td { padding: 7px 6px; text-align: right; font-weight: 400; }
.log thead th { font-size: 10px; color: var(--muted); letter-spacing: .06em; padding: 6px 8px 0; }
.log thead tr:last-child th { padding: 0 8px 5px; border-bottom: 1px solid var(--line); }
.log thead th[colspan] { text-align: center; }
.log .l { text-align: left; padding-left: 14px; }
.log td:last-child, .log thead tr:last-child th:last-child { padding-right: 14px; }
.log .grp { border-left: 1px solid var(--line); }
.log tbody td { border-bottom: 1px solid var(--line); font-size: 14px; }
.log tbody tr:last-child td { border-bottom: 0; }
.log td.l { font-size: 12px; color: var(--muted); white-space: nowrap; }
.log td.f { color: var(--muted); font-size: 13px; }
.log thead th[rowspan] { vertical-align: bottom; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.log thead th small { display: block; font-size: 9px; letter-spacing: 0; white-space: nowrap; }
/* 前日比: 増えたらピンク、減ったらミント。符号(+ −)も必ず付ける */
.log td.diff { font-size: 13px; color: var(--muted); }
.log td.diff.up { color: var(--up); }
.log td.diff.down { color: var(--down); }
.log .month th { text-align: left; padding: 8px 14px 4px; font-size: 11px; font-weight: 600; letter-spacing: .08em; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); }

/* ---------- モックアップ用の切り替え ---------- */
.mock-switch {
  display: grid;
  gap: 6px;
  padding: 12px;
  margin-top: 16px;
  border: 1px dashed var(--muted);
  border-radius: 14px;
  font-size: 11px;
  color: var(--muted);
}

.mock-switch strong { font-size: 12px; }
.mock-switch > span { margin-top: 6px; }
.mock-switch .seg { background: var(--band); }
.lineup { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.lineup button {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.lineup .mascot { width: 100%; max-width: 84px; }
.card .lineup button { background: var(--bg); }
.lineup button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ---------- タブ ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 4px max(6px, calc(50% - 215px)) calc(env(safe-area-inset-bottom) + 4px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

.tabs button {
  display: grid;
  justify-items: center;
  gap: 0;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  letter-spacing: .04em;
  cursor: pointer;
}

.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--accent); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 66px);
  transform: translate(-50%, 8px);
  max-width: 86vw;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 「記録はこのスマホの中だけ」の案内 ---------- */
.safe { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 12px; font-size: 11px; color: var(--muted); }
.safe svg, .safe-card svg { flex: none; fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.safe svg { width: 14px; height: 14px; }
.safe-card { grid-template-columns: auto 1fr; align-items: start; background: var(--accent-soft); border-color: transparent; }
.safe-card svg { width: 26px; height: 26px; margin-top: 2px; }
.safe-card h2 { font-size: 14px; letter-spacing: .02em; color: var(--ink); margin-bottom: 2px; }
.safe-card p { font-size: 12px; line-height: 1.7; }

/* ---------- はじめての案内 ---------- */
dialog {
  width: min(88vw, 340px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 20px 18px;
  background: var(--surface);
  color: var(--ink);
  text-align: center;
}

dialog::backdrop { background: rgba(60, 40, 40, .4); }
dialog .mascot { width: 96px; margin: 0 auto 4px; }
dialog h2 { font-size: 17px; letter-spacing: .02em; color: var(--ink); margin-bottom: 6px; }
dialog p { font-size: 13px; }
.welcome-safe { margin: 12px 0 14px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 12px; line-height: 1.7; text-align: left; }

/* ---------- そのほか ---------- */
.btn.danger { border-color: transparent; color: var(--muted); font-size: 12px; min-height: 36px; text-decoration: underline; }
.locked .btn { width: 100%; }
.log tr.day { cursor: pointer; }
.log tr.day:active td { background: var(--bg); }
.log tr.memo-row td { padding-top: 0; font-size: 11px; color: var(--muted); text-align: left; white-space: normal; }
/* メモの行があるとき、その上の行の下線は消してひとまとまりに見せる */
.log tr.day:has(+ tr.memo-row) td { border-bottom: 0; }

@media (max-width: 360px) {
  .ge input { font-size: 20px; }
  .big-num { font-size: 30px; }
  .facts.four { grid-template-columns: repeat(2, 1fr); }
  .row.three { grid-template-columns: 1fr 1fr; }
  .row.three > :last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
