:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2dd4bf;
  --brand-2: #34d399;
  --brand-deep: #0d9488;
  --accent: #f59e0b;
  --danger: #ef4444;
  --good: #16a34a;
  --shadow: 0 6px 24px rgba(15, 23, 42, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
a { color: var(--brand-deep); }

/* ---------- 顶部 ---------- */
.topbar {
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  padding: 22px 20px;
  box-shadow: var(--shadow);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: .5px; }
.topbar p { margin: 4px 0 0; opacity: .92; font-size: 13px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar-user #user-email { opacity: .95; }

/* ---------- 登录 / 注册 ---------- */
.auth-mask {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #0d9488 0%, #34d399 100%);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-card {
  background: #fff; border-radius: 20px; padding: 30px 26px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-card h1 { margin: 0 0 6px; font-size: 26px; color: var(--brand-deep); text-align: center; }
.auth-sub { font-size: 13px; color: var(--muted); text-align: center; margin: 0 0 18px; }
.auth-tabs { display: flex; gap: 6px; background: #f1f5f9; padding: 4px; border-radius: 999px; margin-bottom: 16px; }
.auth-tabs button {
  flex: 1; border: none; background: transparent; padding: 8px; border-radius: 999px;
  font-size: 14px; color: var(--muted); cursor: pointer;
}
.auth-tabs button.active { background: #fff; color: var(--brand-deep); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.auth-msg { margin-top: 12px; font-size: 13px; text-align: center; min-height: 18px; }
.auth-msg.ok { color: var(--good); }
.auth-msg.err { color: var(--danger); }

/* ---------- 导航 ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0,0,0,.04);
  overflow-x: auto;
}
.tab {
  border: none;
  background: transparent;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: .2s;
}
.tab.active { background: var(--brand); color: #fff; font-weight: 600; }

/* ---------- 容器 ---------- */
.wrap { max-width: 860px; margin: 0 auto; padding: 18px 16px 60px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to {opacity:1;transform:none;} }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 14px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card h2 .ico { font-size: 20px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  background: #fff;
  color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); border-color: transparent; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; }

.btn {
  display: inline-block;
  border: none;
  background: var(--brand);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: #fff; color: var(--brand-deep); border: 1px solid var(--brand); }
.btn.small { padding: 7px 13px; font-size: 13px; }
.btn.block { width: 100%; }

/* ---------- 仪表盘指标 ---------- */
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.metric {
  background: linear-gradient(135deg, #f0fdfa, #ecfeff);
  border: 1px solid #d1fae5;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.metric .v { font-size: 24px; font-weight: 700; color: var(--brand-deep); }
.metric .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.metric .sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.badge-line { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.badge {
  background: #fff7ed; color: #c2410c;
  border: 1px solid #fed7aa;
  padding: 5px 10px; border-radius: 999px; font-size: 12px;
}

/* ---------- 餐次 ---------- */
.meal { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.meal .head { display: flex; justify-content: space-between; align-items: center; }
.meal .title { font-weight: 600; font-size: 15px; }
.meal .kcal { color: var(--accent); font-weight: 700; font-size: 14px; }
.meal .macros { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 8px 0; }
.meal .acts { display: flex; gap: 8px; }

/* ---------- 运动 ---------- */
.ex-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ex {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.ex .name { font-weight: 600; }
.ex .meta { font-size: 12px; color: var(--muted); }
.ex .desc { font-size: 12px; color: #4b5563; }
.ex .done { color: var(--good); font-weight: 600; }

/* ---------- 体重追踪 ---------- */
.weight-input { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.chart-box { width: 100%; overflow-x: auto; margin-top: 10px; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
table.log th, table.log td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.log th { color: var(--muted); font-weight: 600; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; max-width: 440px; width: 100%;
  padding: 22px; box-shadow: var(--shadow); max-height: 86vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 10px; }
.modal .recipe { font-size: 14px; color: #374151; background: #f8fafc; padding: 12px; border-radius: 10px; }
.modal .close { float: right; cursor: pointer; color: var(--muted); font-size: 20px; border: none; background: none; }

/* ---------- 鼓励弹窗 ---------- */
.cheer-mask {
  position: fixed; inset: 0; background: rgba(13,148,136,.35);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 16px;
}
.cheer-mask.show { display: flex; animation: fade .3s; }
.cheer {
  background: #fff; border-radius: 20px; padding: 30px 26px; text-align: center;
  max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.cheer .emoji { font-size: 54px; }
.cheer .title { font-size: 20px; font-weight: 700; margin: 10px 0 6px; color: var(--brand-deep); }
.cheer .msg { font-size: 15px; color: #374151; }
.cheer .reward { margin-top: 14px; font-size: 13px; color: #c2410c; background: #fff7ed; padding: 8px 12px; border-radius: 10px; display: inline-block; }

.empty { text-align: center; color: var(--muted); padding: 26px 0; font-size: 14px; }

.tag { display:inline-block; font-size:11px; padding:2px 8px; border-radius:999px; background:#ecfeff; color:#0e7490; margin-left:6px;}

@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .ex-list { grid-template-columns: 1fr; }
  .row { flex-direction: column; gap: 0; }
}
