:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1f2329;
  --muted: #8a9099;
  --line: #eceef1;
  --green: #16a36a;
  --green-weak: #e3f5ec;
  --green-soft: #8fd3b4;
  --red: #d9534f;
  --red-weak: #fdecea;
  --chip: #f2f4f6;
  --grid: #eceef1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --card: #1b1e21;
    --text: #e8eaed;
    --muted: #8d939b;
    --line: #2a2e33;
    --green: #2fbf84;
    --green-weak: #173a2b;
    --green-soft: #1f7a55;
    --red: #ef6b66;
    --red-weak: #3a1f1e;
    --chip: #262a2e;
    --grid: #2a2e33;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  padding: env(safe-area-inset-top) 0 calc(24px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h2 { font-size: 17px; margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; color: var(--muted); font-size: 14px; }
.top .spacer { width: 48px; }
.link { color: var(--muted); font-size: 14px; }

.composer {
  margin: 0 12px;
  background: var(--card);
  border-radius: 18px;
  padding: 14px 14px 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .05);
}
.composer textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.5; min-height: 72px;
}
.composer textarea::placeholder { color: #b4b9c0; }
.preview { position: relative; display: inline-block; margin: 4px 0 6px; }
.preview img { max-height: 120px; max-width: 100%; border-radius: 10px; display: block; }
.preview .x { position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%; background: #000a; color: #fff; font-size: 16px; line-height: 24px; }
.tools { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.tool {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 999px;
  background: var(--chip); font-size: 13px; color: var(--text); cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.tool.on { background: var(--green); color: #fff; }
.send {
  margin-left: auto; padding: 8px 20px; border-radius: 999px; background: var(--green); color: #fff; font-size: 15px; font-weight: 500;
}
.send:disabled { opacity: .4; cursor: default; }
.send.busy { opacity: .6; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 18px 14px; }
.hint.center { text-align: center; }

.card { background: var(--card); border-radius: 16px; margin: 0 12px 12px; padding: 14px 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; cursor: pointer; }
.extra { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; text-align: center; }
.muted { color: var(--muted); }

.result { border: 1px solid var(--green-weak); }
.saved { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.undo { color: var(--red); font-size: 12px; padding-left: 12px; }

.stat { display: flex; align-items: baseline; gap: 4px; margin-bottom: 4px; }
.big { font-size: 28px; font-weight: 700; }
.unit { font-size: 12px; color: var(--muted); }
.delta { margin-left: 8px; font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.delta.up { background: var(--red-weak); color: var(--red); }
.delta.down { background: var(--green-weak); color: var(--green); }
.chart { width: 100%; height: 160px; display: block; }
.chart-sm { height: 130px; }

.row { display: flex; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.row:first-child { border-top: 0; }
.row .day { width: 44px; flex-shrink: 0; color: var(--muted); font-size: 12px; padding-top: 2px; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; margin-right: 6px; }
.row .meta, .row .detail { color: var(--muted); font-size: 12px; }

.nut { margin-bottom: 10px; }
.nut-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.nut-head .over { color: var(--red); }
.bar { height: 7px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 999px; }
.bar > i.over { background: #e67e5c; }
.meals:not(:empty) { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 4px; }
.meal { display: flex; align-items: center; padding: 5px 0; font-size: 13px; gap: 6px; }
.meal .tag { font-size: 11px; color: var(--green); background: var(--green-weak); padding: 0 6px; border-radius: 4px; }
.meal .name { flex: 1; }

.todo { display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.todo:first-child { border-top: 0; }
.todo .check { width: 18px; height: 18px; border: 2px solid #c9ced6; border-radius: 50%; flex-shrink: 0; margin-top: 2px; }
.todo .detail { color: var(--muted); font-size: 12px; }

.footer { display: block; margin: 4px auto 0; padding: 8px; }

.tabs {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 6px; padding: 8px 12px; background: var(--bg); overflow-x: auto;
}
.tabs button { flex: 1; white-space: nowrap; padding: 7px 10px; border-radius: 999px; background: var(--card); font-size: 13px; }
.tabs button.on { background: var(--green); color: #fff; font-weight: 600; }
.list { margin: 6px 12px; background: var(--card); border-radius: 16px; overflow: hidden; }
.item { display: flex; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--chip); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-size: 15px; font-weight: 500; }
.item .sub { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.item .date { font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 2px; }
.item.done .title { color: var(--muted); text-decoration: line-through; }
.more { display: block; margin: 8px auto; padding: 8px 18px; border-radius: 999px; background: var(--card); font-size: 13px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(40px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(30, 32, 36, .92); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; max-width: 86vw; z-index: 50;
}
