/* Layout: one phone-width app column, sticky header, fixed bottom tab bar */
:root {
  --bg: #F2F3EF;
  --surface: #FFFFFF;
  --fg: #1A1C19;
  --muted: #676C64;
  --line: #E1E3DC;
  --p: #E0513A;
  --f: #D99A0F;
  --c: #23917F;
  --good: #2E8A4A;
  --warn: #C9541A;
  --accent: #C96E10;
  --accent-ink: #FFFFFF;
  --display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", sans-serif;
  --body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111311; --surface: #1B1E1A; --fg: #ECEEE8; --muted: #9DA297; --line: #2B2F29;
    --p: #F26A52; --f: #EDB234; --c: #3DB59F; --good: #57B870; --warn: #EE7A40;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111311; --surface: #1B1E1A; --fg: #ECEEE8; --muted: #9DA297; --line: #2B2F29;
  --p: #F26A52; --f: #EDB234; --c: #3DB59F; --good: #57B870; --warn: #EE7A40;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 15px; line-height: 1.6; padding-inline: 16px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }


.app { max-width: 420px; margin: 0 auto; padding-block: 8px 110px; }
.app { padding-top: 6px; }
header.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); display: flex; align-items: center; justify-content: space-between; padding-block: 10px; }
.logo { font-family: var(--display); font-size: 24px; letter-spacing: .02em; line-height: 1; }
.logo span { color: var(--accent); }
.chips { display: flex; gap: 6px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.view { display: grid; gap: 14px; }
.panel { background: var(--surface); border-radius: 18px; padding: 16px; border: 1px solid var(--line); }
.eyebrow { font-size: 11px; letter-spacing: .12em; color: var(--muted); font-weight: 700; }
.date { font-size: 13px; color: var(--muted); }

/* home hero */
.hero { display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 140px; height: 140px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-family: var(--display); font-size: 28px; line-height: 1.1; }
.ring .sub { font-size: 11px; color: var(--muted); }
.score { display: grid; gap: 2px; min-width: 0; }
.score .val { font-family: var(--display); font-size: 44px; line-height: 1; }
.score .val small { font-size: 16px; margin-left: 2px; }
.score .state { font-size: 13px; font-weight: 700; }
.remain { font-size: 13px; color: var(--muted); }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-row b { font-family: var(--display); font-weight: 400; font-size: 15px; }
.track { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.bar-row .amt { color: var(--muted); min-width: 92px; text-align: right; }
.bar-row .amt strong { color: var(--fg); }

.coach { display: grid; grid-template-columns: 36px 1fr; gap: 12px; align-items: start; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.coach .face { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-content: center; font-family: var(--display); font-size: 14px; }
.coach p { margin: 0; font-size: 14px; }
.coach .who { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .08em; }

.meals { display: grid; }
.meal { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding-block: 10px; border-top: 1px solid var(--line); }
.meal:first-of-type { border-top: 0; }
.slot { font-size: 12px; font-weight: 700; color: var(--accent); }
.meal .name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.meal .pfc { font-size: 12px; color: var(--muted); }
.meal .kcal { font-family: var(--display); font-size: 15px; }
.health-tag { font-size: 10px; color: var(--good); font-weight: 700; }

.fab { position: fixed; right: max(16px, calc(50% - 194px)); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 6; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px; padding: 14px 22px; font-weight: 700; font-size: 15px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); }

/* tab bar */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
nav.tabs .in { max-width: 420px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
nav.tabs button { background: none; border: 0; padding: 8px 0 10px; display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); }
nav.tabs button svg { width: 22px; height: 22px; }
nav.tabs button[aria-current="page"] { color: var(--accent); font-weight: 700; }

/* record */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; border-radius: 9px; padding: 7px 0; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--surface); font-weight: 700; }
.drop { position: relative; display: grid; place-items: center; gap: 6px; border: 2px dashed var(--line); border-radius: 16px; min-height: 170px; text-align: center; color: var(--muted); font-size: 14px; cursor: pointer; overflow: hidden; }
.drop img { width: 100%; max-height: 240px; object-fit: cover; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.text-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.field { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.btn { border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700; background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; }
.examples button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { transform: scale(.5); opacity: .4; } }
.result h3 { margin: 0; font-size: 20px; font-weight: 700; }
.result .kcal-big { font-family: var(--display); font-size: 34px; line-height: 1.1; }
.result .kcal-big small { font-size: 14px; color: var(--muted); font-family: var(--body); }
.pfc-trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pfc-trio div { border-radius: 12px; padding: 8px 10px; background: var(--bg); }
.pfc-trio span { font-size: 11px; font-weight: 700; }
.pfc-trio b { display: block; font-family: var(--display); font-weight: 400; font-size: 18px; }
.items { width: 100%; border-collapse: collapse; font-size: 13px; }
.items td { padding: 5px 0; border-top: 1px solid var(--line); }
.items td:last-child { text-align: right; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 label { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.actions { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
.conf { font-size: 11px; color: var(--muted); }

/* detail mode */
textarea.field { resize: vertical; line-height: 1.7; }
.drows { display: grid; }
.drow { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding-block: 8px; border-top: 1px solid var(--line); }
.drow:first-child { border-top: 0; }
.drow .dn { min-width: 0; }
.drow .name { font-weight: 500; overflow-wrap: anywhere; }
.drow .pfc { font-size: 12px; color: var(--muted); }
.guess { font-size: 10px; font-weight: 700; color: var(--warn); border: 1px solid currentColor; border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: 2px; }
.stepper.sm button { width: 28px; height: 28px; }
.stepper.sm b { min-width: 52px; font-size: 14px; }
.del { width: 28px; height: 28px; border-radius: 50%; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; }

/* report */
.chart-wrap svg { width: 100%; height: auto; display: block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { text-align: center; padding: 8px 4px; border-radius: 12px; background: var(--bg); }
.stat b { display: block; font-family: var(--display); font-weight: 400; font-size: 20px; }
.stat span { font-size: 11px; color: var(--muted); }

/* settings */
.setting { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding-block: 10px; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting .k { font-weight: 500; }
.setting .d { font-size: 12px; color: var(--muted); }
.switch { width: 48px; height: 28px; border-radius: 999px; border: 0; background: var(--line); position: relative; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); }
.stepper b { font-family: var(--display); font-weight: 400; min-width: 64px; text-align: center; }
.targets { width: 100%; border-collapse: collapse; font-size: 14px; }
.targets td { padding: 7px 0; border-top: 1px solid var(--line); }
.targets td:nth-child(2) { text-align: right; font-family: var(--display); }
.targets td:last-child { text-align: right; font-size: 11px; color: var(--muted); padding-left: 10px; }
.linked { color: var(--good); font-weight: 700; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 9; background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 13px; width: max-content; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }

@media (max-width: 360px) { .hero { grid-template-columns: 1fr; justify-items: center; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ===== フェーズ2b 追加 ===== */
.p { color: var(--p); } .f { color: var(--f); } .c { color: var(--c); }
.p-bg { background: var(--p); } .f-bg { background: var(--f); } .c-bg { background: var(--c); }
.loading-line { color: var(--muted); text-align: center; padding-block: 40px; }
.error-panel { display: grid; gap: 10px; border-color: var(--warn); }
.empty { color: var(--muted); font-size: 14px; padding-block: 8px; }
.partial { font-size: 11px; color: var(--muted); }
.tag { font-size: 10px; font-weight: 700; border: 1px solid currentColor; border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: 2px; color: var(--muted); }
.tag.warn { color: var(--warn); }
.tag.ok { color: var(--good); }
.amb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.amb-chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.amb-chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.search-results { display: grid; gap: 4px; }
.search-results button { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.search-results small { color: var(--muted); }
.form-grid { display: grid; gap: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.note { font-size: 12px; color: var(--warn); margin: 0; }
.done { display: grid; gap: 12px; text-align: center; }
.done .big-check { font-family: var(--display); font-size: 28px; color: var(--good); }
.btn.danger { background: var(--warn); }
.btn[disabled] { opacity: .5; }
.key-box { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; background: var(--bg); border-radius: 10px; padding: 10px; user-select: all; }
.key-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding-block: 8px; border-top: 1px solid var(--line); font-size: 13px; }
.key-row:first-child { border-top: 0; }
.key-row small { color: var(--muted); display: block; }
.auth-page { min-height: 100%; display: grid; place-items: center; padding-block: 40px; }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 16px; }
.auth-card .logo { font-size: 40px; text-align: center; }
.auth-card .lead { text-align: center; color: var(--muted); font-size: 14px; margin: 0; }
.msg { border-radius: 12px; padding: 10px 12px; font-size: 13px; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.msg.error { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); color: var(--fg); }
.google-btn { display: block; text-align: center; text-decoration: none; }
