:root {
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #e4e3df;
  --accent: #2563eb;
  --accent-soft: #e6edfd;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --card: #1e1e1c;
    --text: #ecebe6;
    --muted: #9c9b95;
    --line: #33332f;
    --accent: #6b9bff;
    --accent-soft: #1f2a44;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
main { max-width: 640px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; overflow: hidden; }
label { display: block; font-size: 13px; color: var(--muted); }
input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
label input, label select, label textarea { margin-top: 4px; }
/* iOS Safari 的日期框有固有最小宽度、高度也不同，会撑出格子和旁边的框叠在一起 */
input[type="date"] {
  -webkit-appearance: none; appearance: none;
  display: block; min-width: 0; max-width: 100%; height: 40px; line-height: 22px;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
select { height: 40px; }
button { cursor: pointer; width: auto; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }
.full { width: 100%; }

/* 底部导航 */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 10;
}
nav.tabs button {
  flex: 1; border: 0; border-radius: 0; padding: 14px 0; background: transparent; color: var(--muted);
}
nav.tabs button.active { color: var(--accent); font-weight: 600; }

/* 训练 */
.exercise h3 { margin-bottom: 2px; }
.ex-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ex-head h3 { margin: 0; min-width: 0; }
.seg.unit { flex: none; }
.seg.unit button { padding: 4px 12px; font-size: 13px; }
.sets { display: grid; grid-template-columns: 28px 1fr 1fr 44px; gap: 6px 8px; align-items: center; margin-top: 8px; }
.sets .done {
  width: 44px; height: 40px; padding: 0; font-size: 18px; color: var(--muted);
}
.sets .done.on { background: var(--good); border-color: var(--good); color: #fff; }

/* 组间休息计时条 */
#rest {
  position: fixed; left: 0; right: 0; bottom: calc(52px + env(safe-area-inset-bottom)); z-index: 15;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0,0,0,.15);
}
#rest[hidden] { display: none; }
.rest-track { height: 4px; background: var(--line); }
#rest-bar { height: 100%; background: var(--accent); transition: width .25s linear; }
.rest-body { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; align-items: center; padding: 10px 16px; }
.rest-body > div { flex: 1; min-width: 0; }
#rest-time { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
#rest-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rest-body button { padding: 8px 10px; flex: none; }
#rest.over #rest-time { color: var(--good); }
.sets .n { color: var(--muted); font-size: 13px; text-align: center; }
.sets input { padding: 8px; text-align: center; }
.last { font-size: 12px; color: var(--muted); margin-top: 6px; }
.sticky-save {
  position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 5;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }

/* 饮食 */
.bar { margin: 8px 0; }
.bar .label { display: flex; justify-content: space-between; font-size: 13px; }
.bar .track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar .fill { height: 100%; background: var(--accent); }
.bar.over .fill { background: var(--bad); }
.meal { display: flex; gap: 12px; }
.meal img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; flex: none; }
.meal .body { flex: 1; min-width: 0; }
.meal ul { margin: 4px 0; padding-left: 18px; font-size: 13px; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.verdict-合适 { color: var(--good); }
.verdict-偏高 { color: var(--bad); }
.verdict-偏低 { color: var(--warn); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; }
.seg button.on { background: var(--accent); color: #fff; }
.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px; z-index: 20;
}

/* 身体 */
svg text { fill: var(--muted); font-size: 11px; }

/* 登录 */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; }
.login-card label, .login-card button { margin-top: 12px; width: 100%; }
