:root {
  --bg: #F8F4ED;
  --card: #FCFAF5;
  --ink: #3B3D3F;
  --ink-2: #6B6F73;
  --ink-3: #8E9196;
  --line: rgba(122,96,88,.18);
  --accent: #537D96;
  --accent-hover: #456A80;
  --accent-soft: rgba(83,125,150,.08);
  --green: #7BAE7F;
  --danger: #8B3A3A;
  --serif: 'EB Garamond','Noto Serif SC','Source Han Serif SC','Songti SC','STSong','SimSun',serif;
  --ui: system-ui,-apple-system,'PingFang SC',sans-serif;
  --mono: 'JetBrains Mono',ui-monospace,monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.7;
  min-height: 100vh;
}

h1, h2, h3 { font-weight: 500; letter-spacing: .01em; }

h2 {
  font-size: 1.25rem;
  border-left: 2px solid var(--accent);
  padding-left: 8px;
  border-radius: 0;
  margin: 1.6em 0 .6em;
}

h3 { font-size: 1.05rem; color: var(--ink); }

a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; text-decoration-color: rgba(83,125,150,.4); }
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }

:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* 顶部 */
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 26px; height: 26px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}
.brand-mark::after {
  content: '';
  position: absolute; inset: 5px;
  background: var(--accent-soft);
  border-radius: 50%;
}

.brand h1 { font-size: 1.15rem; line-height: 1.2; }
.brand-sub { font-size: .75rem; color: var(--ink-3); font-family: var(--ui); }

.nav { display: flex; gap: 2px; }

.nav-btn {
  font-family: var(--ui);
  font-size: .85rem;
  border: none;
  background: transparent;
  color: var(--ink-2);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--accent-soft); color: var(--accent-hover); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 500; }

/* 主容器 */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 8px 16px 60px;
}

.view { display: none; }
.view.active { display: block; }

.today-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; margin-top: .8em;
}
.today-head h2 { margin: 0; }

/* 指标 */
.metrics {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin: 1.2em 0 1.4em;
}
.metric {
  flex: 1 1 140px; min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .9rem 1.1rem .75rem;
}
.metric-label { font-size: .8rem; color: var(--ink-2); font-family: var(--ui); }
.metric-value {
  font-size: 1.7rem; font-weight: 500;
  color: var(--accent-hover);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.metric-value.positive { color: var(--green); }
.metric-value.negative { color: var(--danger); }
.metric-unit { font-size: .75rem; color: var(--ink-3); font-family: var(--ui); }

/* 面板 */
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin-bottom: 16px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; margin-bottom: .7rem;
}

/* 按钮 */
.btn {
  font-family: var(--ui);
  border: 1px solid rgba(122,96,88,.25);
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  padding: 6px 14px;
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s cubic-bezier(.16,1,.3,1), border-color .15s;
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: #FCFAF5; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { color: var(--ink-2); border-color: rgba(122,96,88,.18); }
.btn.ghost:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: rgba(139,58,58,.3); }
.btn.danger:hover { background: rgba(139,58,58,.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 列表 */
.record-list { display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--ink-3); font-size: .9rem; padding: .5rem 0; }

.record {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .5rem .8rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.record:hover { border-color: rgba(83,125,150,.35); }

.record-main { min-width: 0; flex: 1; }
.record-name { font-size: .95rem; color: var(--ink); }
.record-meta { font-size: .78rem; color: var(--ink-3); font-family: var(--ui); }

.record-kcal {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: .95rem;
  color: var(--accent-hover);
  white-space: nowrap;
}
.record-kcal.exercise { color: var(--green); }
.record-kcal::after { content: ' kcal'; font-family: var(--ui); font-size: .72rem; color: var(--ink-3); }

.record-del {
  border: none; background: transparent;
  color: var(--ink-3); cursor: pointer;
  font-size: .9rem; padding: 2px 6px; border-radius: 3px;
  font-family: var(--ui);
}
.record-del:hover { color: var(--danger); background: rgba(139,58,58,.06); }

.meal-tag {
  display: inline-flex; padding: 1px 7px; font-size: .72rem; font-weight: 500;
  border-radius: 4px; background: var(--accent-soft); color: var(--accent-hover);
  font-family: var(--ui); margin-right: 6px;
}

/* 历史 */
.month-picker { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink-2); font-family: var(--ui); }
.month-picker input {
  font-family: var(--ui); font-size: .85rem;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--card); color: var(--ink); padding: 4px 8px;
}

.day-group { margin-bottom: 14px; }
.day-group-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 4px; border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.day-group-head .date { font-weight: 500; font-size: .95rem; }
.day-group-head .day-sum { font-size: .8rem; color: var(--ink-2); font-family: var(--ui); font-variant-numeric: tabular-nums; }
.day-group-head .day-sum .burn { color: var(--green); }

/* 统计图表 */
#chart-wrap { overflow-x: auto; }
.chart-legend { display: flex; gap: 16px; font-size: .8rem; color: var(--ink-2); margin-top: 8px; font-family: var(--ui); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }
.legend-dot.intake { background: var(--accent); }
.legend-dot.burn { background: var(--green); }

.stat-notes { font-size: .9rem; color: var(--ink-2); }

/* 设置表单 */
.form-panel { display: flex; flex-direction: column; gap: 12px; }
.form-panel label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: .85rem; color: var(--ink-2); font-family: var(--ui);
}
.form-panel input, .form-panel select {
  font-family: var(--ui); font-size: .9rem;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); color: var(--ink);
  padding: 8px 10px;
  width: 100%;
}
.form-panel input:focus, .form-panel select:focus { outline: 1px solid var(--accent); }
.form-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.form-hint { font-size: .78rem; color: var(--ink-3); font-family: var(--ui); line-height: 1.5; }

/* 弹层 */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(59,61,63,.4);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.overlay.hidden { display: none; }

.sheet {
  background: var(--card);
  border-radius: 8px 8px 0 0;
  width: 100%; max-width: 560px;
  max-height: 82vh;
  display: flex; flex-direction: column;
  box-shadow: 0 -2px 16px rgba(59,61,63,.12);
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.sheet-head h3 { margin: 0; }
.sheet-body { padding: 16px 20px; overflow-y: auto; }
.sheet-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line);
}

@media (min-width: 640px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 8px; max-height: 84vh; }
}

/* 识别结果 */
.ai-item {
  border: 1px solid var(--line); border-radius: 4px;
  padding: .5rem .8rem; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px;
}
.ai-item input[type=number] {
  width: 90px; font-family: var(--mono); font-size: .9rem;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); color: var(--ink); padding: 4px 6px;
}
.ai-item .ai-name { flex: 1; min-width: 0; }
.ai-item .ai-name .nm { font-size: .92rem; }
.ai-item .ai-name .pt { font-size: .78rem; color: var(--ink-3); font-family: var(--ui); }
.ai-item .ai-kcal-label { font-size: .78rem; color: var(--ink-3); font-family: var(--ui); }
.ai-loading { padding: 1rem 0; text-align: center; color: var(--ink-2); }

.calc-preview {
  background: var(--accent-soft);
  border-radius: 4px; padding: 10px 14px;
  font-size: .9rem; color: var(--accent-hover);
}

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--card);
  font-size: .85rem; font-family: var(--ui);
  padding: 8px 18px; border-radius: 4px;
  z-index: 100; opacity: 1;
  transition: opacity .3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.account-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.account-line .email { font-family: var(--mono); font-size: .9rem; color: var(--ink-2); }

@media (max-width: 520px) {
  .header-inner { justify-content: center; }
  .nav { width: 100%; justify-content: space-around; }
  .metric-value { font-size: 1.4rem; }
}
