:root {
  --bg: #f6f8f5;
  --card: #ffffff;
  --ink: #1d2420;
  --muted: #78837c;
  --line: #e7ebe7;
  --brand: #2f8f5b;
  --brand-soft: #e7f3eb;
  --accent: #d9763c;
  --accent-soft: #fbeee6;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(24, 40, 30, .05), 0 8px 24px rgba(24, 40, 30, .05);
}

* { 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, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 248, 245, .92);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: .01em;
  font-weight: 650;
}
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.goal-chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- 主体 ---------- */
main {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 18px 8px;
}
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 热量环 ---------- */
.ring-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  gap: 18px;
  align-items: center;
}
.ring { position: relative; width: 118px; height: 118px; flex: 0 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring-bg { stroke: #edf1ed; }
.ring-fg { stroke: var(--brand); stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .6s ease, stroke .3s; }
.ring-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1px;
}
.ring-text strong { font-size: 24px; font-weight: 680; letter-spacing: -.02em; }
.ring-text span { font-size: 11px; color: var(--muted); }
.ring-side { flex: 1; display: flex; flex-direction: column; gap: 9px; }
.metric { display: flex; align-items: baseline; gap: 6px; }
.metric b { font-size: 16px; font-weight: 650; }
.metric span { font-size: 12px; color: var(--muted); }

/* ---------- 标题行 ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 10px;
}
.section-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.text-btn {
  border: 0; background: none; color: var(--brand);
  font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 0;
}
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.hint.center { text-align: center; margin-top: 14px; }

/* ---------- 今日记录 ---------- */
.day-list { display: flex; flex-direction: column; gap: 10px; }
.empty {
  background: var(--card); border-radius: var(--radius);
  border: 1px dashed var(--line); padding: 26px 18px;
  text-align: center; color: var(--muted); font-size: 13.5px;
}
.meal-block {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.meal-block-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px 8px;
}
.meal-block-head strong { font-size: 14px; }
.meal-block-head em { font-style: normal; font-size: 12px; color: var(--muted); }
.meal-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-top: 1px solid var(--line);
}
.meal-row .nm { flex: 1; font-size: 14px; }
.meal-row .meta { font-size: 11.5px; color: var(--muted); display: block; }
.meal-row .kc { font-size: 12.5px; color: var(--brand); font-variant-numeric: tabular-nums; }
.del {
  border: 0; background: none; color: #c0c7c1;
  font-size: 18px; line-height: 1; padding: 2px 4px; cursor: pointer;
}

/* ---------- 推荐 ---------- */
.plan-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 15px; margin-bottom: 11px;
}
.plan-card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 9px;
}
.plan-card-head strong { font-size: 14.5px; }
.plan-card-head span { font-size: 12px; color: var(--muted); }
.plan-item {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.plan-item:first-of-type { border-top: 0; }
.plan-item .nm small { color: var(--muted); font-size: 11.5px; margin-left: 6px; }
.plan-item .kc { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.plan-total {
  margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted);
}
.plan-total b { color: var(--ink); font-size: 13.5px; }

/* ---------- 食物库 ---------- */
.search-wrap { margin-bottom: 12px; }
.search-wrap input {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--ink);
  outline: none;
}
.search-wrap input:focus { border-color: var(--brand); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 6px 13px; font-size: 12.5px;
  white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--brand-soft); border-color: #c9e6d5; color: var(--brand); font-weight: 600; }

.food-list { display: flex; flex-direction: column; gap: 8px; }
.food-card {
  background: var(--card); border-radius: 13px; box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.food-card .info { flex: 1; min-width: 0; }
.food-card .info strong { font-size: 14px; font-weight: 600; display: block; }
.food-card .info span { font-size: 11.5px; color: var(--muted); }
.food-card .num { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.food-card .num b { display: block; color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }
.add-btn {
  border: 1px solid #cfe7da; background: var(--brand-soft); color: var(--brand);
  width: 30px; height: 30px; border-radius: 50%; font-size: 18px; line-height: 1;
  cursor: pointer; flex: 0 0 auto;
}
.food-list.compact .food-card { box-shadow: none; border: 1px solid var(--line); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  gap: 4px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; max-width: 160px; border: 0; background: none;
  color: var(--muted); font-size: 13px; padding: 8px 0;
  border-radius: 10px; cursor: pointer;
}
.tab.active { color: var(--brand); font-weight: 650; background: var(--brand-soft); }

/* ---------- 弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(18, 26, 21, .38);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: up .24s ease;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.sheet-head h3 { margin: 0; font-size: 16px; font-weight: 650; }

.field { margin-bottom: 14px; }
.field.two { display: flex; gap: 12px; }
.field.two > div { flex: 1; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; color: var(--ink);
  background: #fbfcfb; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--brand); }

.segmented {
  display: flex; gap: 6px; background: #f1f4f1;
  padding: 4px; border-radius: 11px;
}
.segmented button {
  flex: 1; border: 0; background: none; border-radius: 8px;
  padding: 9px 4px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.segmented button.on {
  background: var(--card); color: var(--brand);
  font-weight: 650; box-shadow: 0 1px 3px rgba(20, 40, 28, .1);
}

.primary {
  width: 100%; border: 0; border-radius: 12px;
  background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 600; padding: 13px;
  cursor: pointer; margin-top: 4px;
}
.primary:active { opacity: .88; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: rgba(29, 36, 32, .92); color: #fff;
  font-size: 13px; padding: 9px 16px; border-radius: 999px;
  z-index: 80; pointer-events: none;
}
