/* ===========================================================
   吃准 · 设计令牌与组件样式
   深色优先，跟随系统；无任何 UI 框架，全手写。
   =========================================================== */

:root {
  --bg: #07100d;
  --bg-elev: #0c1713;
  --card: #11201b;
  --card-2: #16281f;
  --line: #20352c;
  --line-soft: #1a2c24;
  --text: #eaf5ef;
  --muted: #90a99d;
  --dim: #5e7a6d;
  --primary: #3ddc84;
  --primary-ink: #062015;
  --primary-soft: #163d2a;
  --amber: #ffb454;
  --blue: #5aa9ff;
  --pink: #ff7eb6;
  --red: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 11px;
  --pad: 18px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "MiSans", "HarmonyOS Sans SC", "PingFang SC", "Noto Sans SC", -apple-system,
    BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html[data-theme="light"] {
  --bg: #f4f7f4;
  --bg-elev: #ffffff;
  --card: #ffffff;
  --card-2: #f0f4f0;
  --line: #dfe8e1;
  --line-soft: #e8efe9;
  --text: #0d1a14;
  --muted: #5b7268;
  --dim: #8a9d94;
  --primary: #0f9d58;
  --primary-ink: #ffffff;
  --primary-soft: #d8f2e2;
  --shadow: 0 8px 24px rgba(12, 40, 26, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
}

#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--dim);
  letter-spacing: 0.12em;
  font-weight: 500;
  background: var(--bg);
  transition: opacity 0.3s;
}

#app {
  min-height: 100dvh;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}

/* ---------- 布局 ---------- */
.screen {
  padding: calc(var(--safe-t) + 14px) var(--pad) 8px;
  animation: fade 0.22s ease;
  max-width: 620px;
  margin: 0 auto;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 40px;
}
.topbar h1 {
  font-size: 22px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar .sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.topbar .actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.card.tight {
  padding: 12px 14px;
}
.card.flat {
  background: transparent;
  border: 1px dashed var(--line);
}
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin-bottom: 10px;
  gap: 8px;
}
.card-title b {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.row.between {
  justify-content: space-between;
}
.col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.grow {
  flex: 1;
  min-width: 0;
}
.muted {
  color: var(--muted);
}
.dim {
  color: var(--dim);
}
.tiny {
  font-size: 12px;
}
.big-num {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.num {
  font-variant-numeric: tabular-nums;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 环形进度 ---------- */
.ring-wrap {
  position: relative;
  display: grid;
  place-items: center;
  margin: 4px auto 6px;
}
.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 2px;
}
.ring-center .v {
  font-size: 42px;
  font-weight: 720;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ring-center .u {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.ring-center .s {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  transition: transform 0.12s ease, opacity 0.12s;
}
.btn:active {
  transform: scale(0.97);
}
.btn.primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
}
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.btn.block {
  display: flex;
  width: 100%;
}
.btn.sm {
  height: 36px;
  padding: 0 14px;
  font-size: 13.5px;
  border-radius: 11px;
}
.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line-soft);
  color: var(--muted);
}

/* ---------- 表单 ---------- */
.field {
  margin-bottom: 14px;
}
.field > label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 7px;
  letter-spacing: 0.02em;
}
.input,
.selectbox {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus,
.selectbox:focus {
  border-color: var(--primary);
}
.hint {
  font-size: 12px;
  color: var(--dim);
  margin-top: 6px;
  line-height: 1.45;
}

.stepper {
  display: flex;
  align-items: center;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  height: 54px;
}
.stepper button {
  width: 54px;
  height: 100%;
  font-size: 24px;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.stepper button:active {
  background: var(--line-soft);
}
.stepper .val {
  flex: 1;
  text-align: center;
  font-size: 22px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  border: 0;
  background: transparent;
  outline: none;
  min-width: 0;
}
.stepper .val.small {
  font-size: 17px;
}
.stepper .unit {
  font-size: 13px;
  color: var(--dim);
  padding-right: 10px;
}
.stepper.sm {
  height: 44px;
  border-radius: 12px;
}
.stepper.sm button {
  width: 42px;
  font-size: 19px;
}
.stepper.sm .val {
  font-size: 17px;
  font-weight: 600;
}
.stepper.sm .unit {
  font-size: 12px;
}

.seg {
  display: flex;
  gap: 4px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px;
}
.seg button {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.seg button.on {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.seg.wrap {
  flex-wrap: wrap;
}
.seg.wrap button {
  flex: 1 1 44%;
}

/* ---------- 列表 ---------- */
.list {
  display: flex;
  flex-direction: column;
}
.li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.li:last-child {
  border-bottom: 0;
}
.li .avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 16px;
  flex: none;
}
.li .arrow {
  color: var(--dim);
  font-size: 18px;
  margin-left: 4px;
}
.li .kcal {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ---------- 标签 ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.chip.on {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  background: var(--card-2);
  color: var(--muted);
}
.pill.warn {
  background: rgba(255, 180, 84, 0.14);
  color: var(--amber);
}
.pill.good {
  background: var(--primary-soft);
  color: var(--primary);
}

/* ---------- 宏量营养素条 ---------- */
.macros {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}
.macro {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}
.macro .bar {
  height: 7px;
  border-radius: 99px;
  background: var(--line-soft);
  overflow: hidden;
}
.macro .bar > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}
.macro .bar > i.p {
  background: var(--blue);
}
.macro .bar > i.c {
  background: var(--amber);
}
.macro .bar > i.f {
  background: var(--pink);
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-top: 1px solid var(--line-soft);
  display: flex;
  z-index: 30;
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--dim);
  padding-top: 6px;
  transition: color 0.15s;
}
.tabbar button.on {
  color: var(--primary);
}
.tabbar svg {
  width: 23px;
  height: 23px;
}

/* 右下角相机大按钮 */
.cam-fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(61, 220, 132, 0.28);
  z-index: 31;
  border: 4px solid var(--bg);
}
.cam-fab:active {
  transform: scale(0.94);
}

/* ---------- 弹层 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  animation: fadein 0.18s ease;
  backdrop-filter: blur(2px);
}
@keyframes fadein {
  from {
    opacity: 0;
  }
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: var(--bg-elev);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line);
  padding: 8px var(--pad) calc(20px + var(--safe-b));
  max-height: 88dvh;
  overflow-y: auto;
  animation: up 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes up {
  from {
    transform: translateY(100%);
  }
}
.sheet .grab {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin: 6px auto 14px;
}
.sheet h2 {
  font-size: 19px;
  margin: 0 0 4px;
  font-weight: 650;
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-b) + 24px);
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 60;
  box-shadow: var(--shadow);
  animation: up 0.2s ease;
  max-width: 86vw;
  text-align: center;
}

.banner {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 12px;
}
.banner.warn {
  background: rgba(255, 180, 84, 0.1);
  color: #ffcf9a;
  border: 1px solid rgba(255, 180, 84, 0.22);
}
.banner.info {
  background: var(--card-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.banner.danger {
  background: rgba(255, 107, 107, 0.1);
  color: #ffb1b1;
  border: 1px solid rgba(255, 107, 107, 0.22);
}

/* ---------- 首页餐次 ---------- */
.meal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line-soft);
}
.meal-row:last-child {
  border-bottom: 0;
}
.meal-ico {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--card-2);
  font-size: 19px;
  flex: none;
}
.meal-row .empty-hint {
  color: var(--dim);
  font-size: 13px;
}
.add-mini {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--card-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 19px;
  border: 1px solid var(--line);
}

/* ---------- 进度小条 ---------- */
.progress {
  height: 8px;
  background: var(--line-soft);
  border-radius: 99px;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.45s ease;
}

/* ---------- 表格 ---------- */
.week-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.week-table th {
  text-align: left;
  font-weight: 500;
  color: var(--dim);
  font-size: 11.5px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line-soft);
}
.week-table td {
  padding: 9px 4px;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
}
.week-table tr:last-child td {
  border-bottom: 0;
}
.week-table tr.now td {
  color: var(--primary);
}

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  color: var(--dim);
  font-size: 13.5px;
  padding: 28px 10px;
  line-height: 1.7;
}

/* ---------- 统计格 ---------- */
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--card-2);
  border-radius: var(--r-md);
  padding: 13px 14px;
}
.stat .k {
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.02em;
}
.stat .v {
  font-size: 22px;
  font-weight: 680;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.stat .v small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 3px;
}

/* ---------- 引导页 ---------- */
.onboard {
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 26px) 22px calc(30px + var(--safe-b));
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}
.onboard .steps {
  display: flex;
  gap: 6px;
  margin-bottom: 26px;
}
.onboard .steps i {
  flex: 1;
  height: 3px;
  border-radius: 99px;
  background: var(--line);
  transition: background 0.3s;
}
.onboard .steps i.on {
  background: var(--primary);
}
.onboard h1 {
  font-size: 27px;
  line-height: 1.28;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.onboard p.lead {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 26px;
  line-height: 1.6;
}
.onboard .body {
  flex: 1;
}
.onboard .foot {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- 图表 ---------- */
.chart {
  width: 100%;
  display: block;
  overflow: visible;
}
.chart .axis {
  stroke: var(--line);
  stroke-width: 1;
}
.chart .grid {
  stroke: var(--line-soft);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}
.chart text {
  fill: var(--dim);
  font-size: 9.5px;
  font-family: var(--font);
}

/* ---------- 屏幕阅读器 ---------- */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
