:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #1b1a18;
  --muted: #79746b;
  --faint: #a9a49b;
  --line: #e9e5dd;
  --accent: #2f7d4f;
  --accent-soft: #e7f2ea;
  --warm: #c2761a;
  --warm-soft: #fbf0dd;
  --danger: #b4471f;
  --danger-soft: #fbeae2;
  --shadow: 0 1px 2px rgba(28, 26, 22, .04), 0 6px 20px -12px rgba(28, 26, 22, .18);
  --r: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --card: #1c1b19;
    --ink: #f2efe9;
    --muted: #9d968a;
    --faint: #6d675d;
    --line: #2c2a26;
    --accent: #6fbb8b;
    --accent-soft: #1f3328;
    --warm: #e0a355;
    --warm-soft: #33291a;
    --danger: #e8875f;
    --danger-soft: #35231b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -14px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }

.app { max-width: 560px; margin: 0 auto; padding: 0 14px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .inner { max-width: 560px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h1 { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: -.3px; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ---------- generic ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}
.card.flat { box-shadow: none; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-h .t { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 8px; }

.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mono { font-variant-numeric: tabular-nums; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- buttons ---------- */
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 11px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 14px; font-weight: 550;
  transition: transform .12s ease, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.icon-btn:active { transform: scale(.94); }

/* ---------- today head ---------- */
.today-hero {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 6px 4px 12px;
}
.today-hero .d { font-size: 28px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.today-hero .w { font-size: 13px; color: var(--muted); margin-top: 5px; }

/* ---------- training ---------- */
.train-line {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.train-line:last-child { border-bottom: none; padding-bottom: 2px; }
.train-line:first-child { padding-top: 2px; }
.tl-icon {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); font-size: 15px;
}
.tl-icon.rest { background: var(--line); }
.tl-icon.off { background: var(--line); opacity: .55; }
.tl-main .n { font-size: 14px; font-weight: 550; }
.tl-main .m { font-size: 12px; color: var(--muted); }
.tl-main .n.done { text-decoration: line-through; color: var(--faint); }

.check {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  border: 1.5px solid var(--line); background: transparent;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 14px;
  transition: all .15s;
}
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- meals ---------- */
.meal-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.meal-head .lbl { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.meal-head .cal { font-size: 12px; color: var(--faint); }

.dish {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed color-mix(in srgb, var(--line) 80%, transparent);
}
.dish:last-of-type { border-bottom: none; }
.dish .em { font-size: 19px; width: 24px; text-align: center; flex: none; }
.dish .body { flex: 1; min-width: 0; }
.dish .nm { font-size: 15px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.dish .meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.dish.missing .nm { color: var(--danger); }
.dish.missing .em { opacity: .45; }
.dish .amt { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }

.tag {
  font-size: 10px; padding: 1px 6px; border-radius: 5px;
  background: var(--line); color: var(--muted); font-weight: 500;
}
.tag.warn { background: var(--danger-soft); color: var(--danger); }
.tag.mild { background: var(--warm-soft); color: var(--warm); }

.vbtn {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px;
}
.vbtn:active { transform: scale(.92); }

.meal-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 8px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}

/* ---------- bars ---------- */
.gauge { margin: 12px 0 2px; }
.gauge:first-child { margin-top: 2px; }
.gauge-top { display: flex; align-items: baseline; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.gauge-top .k { color: var(--muted); font-weight: 550; }
.gauge-top .v { font-variant-numeric: tabular-nums; }
.bar { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar > i.over { background: var(--warm); }
.bar > i.under { background: var(--faint); }

/* ---------- panels / lists ---------- */
.list { border-radius: var(--r); overflow: hidden; background: var(--card); border: 1px solid var(--line); }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); width: 100%; text-align: left;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--bg); }

/* ---------- pantry ---------- */
.chip-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 8px 11px; border-radius: 10px; font-size: 13.5px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  display: inline-flex; align-items: center; gap: 5px;
  transition: all .15s;
}
.chip:active { transform: scale(.96); }
.chip .ce { font-size: 15px; line-height: 1; }
.chip .cs { font-size: 11px; font-weight: 600; padding: 1px 5px; border-radius: 5px; margin-left: 1px; }
.chip.st-ok .cs { display: none; }
.chip.st-low { background: var(--warm-soft); border-color: color-mix(in srgb, var(--warm) 28%, var(--line)); }
.chip.st-low .cs { background: color-mix(in srgb, var(--warm) 16%, transparent); color: var(--warm); }
.chip.st-none { background: transparent; border-style: dashed; color: var(--faint); }
.chip.st-none .cn { text-decoration: line-through; }
.chip.st-none .ce { opacity: .5; }
.chip.st-none .cs { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.pantry-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 2px 12px; }

/* ---------- segmented ---------- */
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 6px 4px; border-radius: 8px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.seg button .dot { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); margin-left: 3px; vertical-align: 3px; }
.caption { font-size: 12.5px; color: var(--muted); margin: 2px 2px 0; }

/* ---------- nav ---------- */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--line);
}
.nav .inner { max-width: 560px; margin: 0 auto; display: flex; }
.nav button {
  flex: 1; padding: 8px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--faint); font-weight: 550;
}
.nav button.on { color: var(--accent); }
.nav svg { width: 21px; height: 21px; }

/* ---------- sheet ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(20,18,15,.42);
  backdrop-filter: blur(2px); animation: fade .18s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto;
  animation: up .24s cubic-bezier(.2,.9,.25,1);
  box-shadow: 0 -8px 40px -12px rgba(0,0,0,.3);
}
.sheet .grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 17px; font-weight: 650; letter-spacing: -.2px; }
.sheet .desc { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

@keyframes up { from { transform: translateY(30px); opacity: .6 } to { transform: none; opacity: 1 } }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--line); margin: 12px 0; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.badge.mild { background: var(--warm-soft); color: var(--warm); }

.alert {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--danger-soft); color: var(--danger);
  border-radius: 12px; padding: 11px 13px; font-size: 13px; margin-bottom: 12px;
}
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert .ic { flex: none; }

/* 今日提示 */
.card.notes { padding: 10px 13px; display: flex; flex-direction: column; gap: 7px; }
.note { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; line-height: 1.45; }
.note .ni { flex: none; font-size: 14px; line-height: 1.35; }
.note .nh { color: var(--ink); }
.note .nh b { font-weight: 650; }
.note .ns { color: var(--muted); font-size: 12px; margin-top: 1px; }
.note.bad .nh b { color: var(--danger); }
.note.warm .nh b { color: var(--warm); }
.note + .note { border-top: 1px solid var(--line); padding-top: 7px; }

/* 力量动作行 */
.ex-h { font-size: 11px; font-weight: 600; color: var(--faint); letter-spacing: .06em; margin: 12px 0 2px; }
.ex { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.ex:last-child { border-bottom: none; }
.ex-n { font-size: 14px; font-weight: 550; }
.ex-m { font-size: 12px; color: var(--muted); flex: none; }
.check.sm { width: 22px; height: 22px; border-radius: 6px; font-size: 12px; }

textarea, input[type=text], input[type=number], input[type=password], input:not([type]) {
  width: 100%; font: inherit; font-size: 15px;
  padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  outline: none;
}
textarea:focus, input:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 76px; }

.skeleton { color: var(--faint); font-size: 13px; padding: 10px 0; }
.spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg) } }

.week-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.week-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 4px; font-size: 11.5px; }
.week-table td { padding: 7px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.week-table tr.today td { background: var(--accent-soft); }

/* 记录里的选择器 */
.q { padding: 10px 0; border-top: 1px solid var(--line); }
.q:first-of-type { margin-top: 6px; }
.q-l { font-size: 13.5px; margin-bottom: 8px; }
.pills { display: flex; gap: 6px; }
.pill {
  flex: 1; padding: 8px 0; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.pill.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); color: var(--accent); font-weight: 600; }

/* 帮助 */
.help-step { font-size: 13.5px; line-height: 1.6; color: var(--muted); margin: 12px 0; }
.help-step b { display: block; color: var(--ink); font-size: 14px; margin-bottom: 2px; }

/* 轻提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px); z-index: 60;
  background: color-mix(in srgb, var(--ink) 88%, transparent); color: var(--bg);
  font-size: 13px; padding: 9px 15px; border-radius: 11px;
  opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none;
  max-width: 82vw; text-align: center; line-height: 1.4;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 表单字段 */
.fld { margin: 14px 0; }
.fld label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; }
