:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --card2: #eef0f3;
  --line: #e3e6eb;
  --text: #14161a;
  --sub: #6b7280;
  --accent: #12a866;
  --accent-ink: #ffffff;
  --accent-soft: rgba(18, 168, 102, .12);
  --danger: #e5484d;
  --warn: #e8890c;
  --c-p: #3b82f6;
  --c-c: #f2a516;
  --c-f: #ef6f6c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  --tab-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --card: #181b20;
    --card2: #23272e;
    --line: #2c3139;
    --text: #f1f3f6;
    --sub: #8d95a3;
    --accent: #34d399;
    --accent-ink: #04281a;
    --accent-soft: rgba(52, 211, 153, .14);
    --danger: #ff6b6b;
    --warn: #fbbf24;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea {
  font-size: 16px;
  background: var(--card2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--sub) 50%), linear-gradient(135deg, var(--sub) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
input::placeholder { color: var(--sub); opacity: .7; }
input[type=checkbox] { width: auto; }

#view {
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 640px;
  margin: 0 auto;
}
body.resting #view { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 120px); }

h1 { font-size: 28px; line-height: 1.2; margin: 4px 0 14px; letter-spacing: -.5px; }
h2 { font-size: 18px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--sub); font-size: 13px; }
.accent { color: var(--accent); }
.danger { color: var(--danger) !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.top { margin-bottom: 6px; }
.empty { text-align: center; color: var(--sub); padding: 22px 10px; font-size: 14px; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--card2); color: var(--sub); margin-right: 4px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 12px; }
.center { text-align: center; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; background: var(--card2); }
.list { padding: 0 14px; }
.li { display: flex; align-items: center; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--line); min-height: 50px; }
.li:last-child { border-bottom: 0; }
.li select, .li input { width: auto; max-width: 55%; }
.sec-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; }
.sec-head h2 { margin: 0; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border-radius: 12px;
  font-weight: 600; font-size: 15px;
  background: var(--card2); color: var(--text);
  transition: transform .1s, opacity .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1.5px dashed var(--line); color: var(--sub); }
.btn.text { background: none; height: auto; padding: 6px 4px; color: var(--accent); font-weight: 500; }
.btn.sm { height: 34px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; margin-bottom: 12px; }
.btn.danger-bg { background: var(--danger); color: #fff; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: var(--sub); font-size: 18px; flex-shrink: 0; }
.icon-btn:active { background: var(--card2); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* 分段 & 标签 */
.seg { display: flex; background: var(--card2); border-radius: 11px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; height: 34px; border-radius: 9px; font-size: 14px; color: var(--sub); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip { flex-shrink: 0; height: 32px; padding: 0 14px; border-radius: 99px; background: var(--card2); font-size: 14px; color: var(--sub); }
.chip.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* 表单 */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* 统计 */
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--sub); margin-left: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.macro { margin-top: 10px; }
.macro .between { font-size: 13px; margin-bottom: 4px; }
.ring-wrap { display: flex; align-items: center; gap: 16px; }
.ring { width: 108px; height: 108px; flex-shrink: 0; }
.ring text { fill: var(--text); }

/* 底部标签栏 */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
#tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--sub); }
#tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabbar button.on { color: var(--accent); }

/* 休息计时条 */
#rest {
  position: fixed; left: 12px; right: 12px; z-index: 21;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 10px);
  max-width: 616px; margin: 0 auto;
  background: var(--text); color: var(--bg);
  border-radius: 18px; overflow: hidden;
  transform: translateY(30px); opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .25s, opacity .25s, visibility .25s;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
#rest.show { transform: none; opacity: 1; visibility: visible; pointer-events: auto; }
.rest-track { height: 4px; background: rgba(127,127,127,.3); }
#rest-p { height: 100%; background: var(--accent); width: 0; transition: width .25s linear; }
.rest-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.rest-row button { height: 38px; min-width: 50px; border-radius: 10px; background: rgba(127,127,127,.22); color: inherit; font-weight: 600; }
.rest-row .rest-skip { background: var(--accent); color: var(--accent-ink); padding: 0 14px; }
.rest-mid { flex: 1; text-align: center; }
.rest-mid .sub { color: inherit; opacity: .6; font-size: 12px; }
.rest-mid b { font-size: 24px; font-variant-numeric: tabular-nums; }

/* 底部抽屉 */
#sheet {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#sheet.show { opacity: 1; pointer-events: auto; }
.sheet-panel {
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 18px);
  -webkit-overflow-scrolling: touch;
  animation: up .25s ease-out;
}
.sheet-panel::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; min-height: 36px; }
.sheet-head b { font-size: 18px; }

/* 提示 */
#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); z-index: 40;
  transform: translate(-50%, -30px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 99px; font-size: 14px; font-weight: 500;
  transition: all .25s; width: max-content; max-width: 90vw; text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* 训练 */
.tpl { display: flex; align-items: center; gap: 12px; }
.wk-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.wk-name { font-size: 22px; font-weight: 700; background: none; padding: 0; border-radius: 0; border: 0; }
.ex-top { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.ex-top b { font-size: 16px; }
.set-grid { display: grid; grid-template-columns: 28px 1fr 1fr 44px; gap: 8px; align-items: center; margin-bottom: 6px; }
.set-grid.head { font-size: 12px; color: var(--sub); text-align: center; margin-bottom: 4px; }
.set-grid .n { text-align: center; color: var(--sub); font-weight: 600; }
.set-grid input { text-align: center; padding: 9px 4px; font-variant-numeric: tabular-nums; }
.chk { height: 40px; border-radius: 10px; background: var(--card2); color: var(--sub); font-weight: 700; font-size: 17px; }
.set-grid.done input { background: var(--accent-soft); }
.set-grid.done .chk { background: var(--accent); color: var(--accent-ink); }
.ex-actions { display: flex; justify-content: space-between; margin-top: 2px; }
.stepper { display: inline-flex; align-items: center; background: var(--card2); border-radius: 10px; }
.stepper button { width: 32px; height: 32px; font-size: 18px; color: var(--accent); }
.stepper span { min-width: 40px; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.mini-input { width: 58px !important; padding: 6px 4px !important; text-align: center; font-size: 16px; }

.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 3px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--card2); }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 55%, var(--card2)); }
.heat i.l2 { background: var(--accent); }
.heat i.today { outline: 1.5px solid var(--text); outline-offset: -1.5px; }
.heat i.fut { opacity: .3; }
.wk-detail { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.wk-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 4px 0; font-size: 14px; }
.wk-line > span:first-child { min-width: 0; }
.burn-tag { flex-shrink: 0; font-size: 13px; padding: 3px 8px; border-radius: 99px; background: var(--card2); color: var(--warn); font-weight: 600; margin-top: 2px; }
.pr { color: var(--warn); font-weight: 600; font-size: 12px; }

/* 图表 */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--sub); font-size: 10px; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); }
.chart .dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }

/* 饮食 */
.date-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.date-nav b { font-size: 17px; }
.meal-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.food-row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.food-row:active { background: var(--card2); }
.nut4 { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; background: var(--card); border-radius: 12px; padding: 10px 4px; }
.nut4 b { display: block; font-size: 17px; }
.dot-p, .dot-c, .dot-f { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot-p { background: var(--c-p); } .dot-c { background: var(--c-c); } .dot-f { background: var(--c-f); }

/* 照片 */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--card2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo span { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; color: #fff; padding: 12px 6px 4px; background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.photo.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.photo .badge { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.add-photo { display: flex; align-items: center; justify-content: center; flex-direction: column; color: var(--sub); border: 1.5px dashed var(--line); background: none; font-size: 13px; }
.add-photo b { font-size: 26px; font-weight: 300; }
.big-photo { width: 100%; border-radius: 12px; display: block; }
.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cmp img { width: 100%; border-radius: 10px; display: block; }

/* 首页 */
.hello { display: flex; justify-content: space-between; align-items: flex-end; }
.today-card { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #0b6b44)); color: #fff; }
.today-card .sub { color: rgba(255,255,255,.8); }
.today-card .btn { background: #fff; color: #0b5c3a; }
.tip { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.tip:last-child { border-bottom: 0; }
.tip .ic { font-size: 18px; line-height: 1.3; flex-shrink: 0; }
.sum-line { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.sum-line:last-child { border-bottom: 0; }
.up { color: var(--accent); } .down { color: var(--danger); }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* AI 教练 */
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.msg { max-width: 92%; border-radius: 16px; padding: 10px 14px; font-size: 15px; line-height: 1.6; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 6px; max-width: 100%; }
.msg.ai p { margin: 0 0 6px; }
.msg.ai h4 { margin: 10px 0 4px; font-size: 15px; }
.msg.ai h4:first-child { margin-top: 0; }
.msg.ai ul, .msg.ai ol { margin: 2px 0 8px; padding-left: 20px; }
.msg.ai li { margin: 2px 0; }
.msg.ai hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.msg.ai code { background: var(--card2); border-radius: 4px; padding: 0 4px; font-size: 13px; }
.msg.ai pre { background: var(--card2); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font-size: 12px; }
.msg.ai > :last-child { margin-bottom: 0; }
.ai-table { overflow-x: auto; margin: 4px 0 8px; }
.ai-table table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.ai-table th, .ai-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; white-space: nowrap; }
.ai-table th { background: var(--card2); }
.ai-act { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--sub); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px); display: flex; gap: 8px; align-items: flex-end; background: var(--bg); padding: 8px 0 0; }
.composer textarea { resize: none; min-height: 44px; max-height: 140px; line-height: 1.4; }
.composer .btn { flex-shrink: 0; height: 44px; }
.chip[disabled] { opacity: .5; }
.exp-preview { background: var(--card2); border-radius: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; max-height: 220px; overflow-y: auto; margin: 0; }
