:root {
  --pink: #ff7a9c;
  --pink-dark: #f2567f;
  --pink-soft: #ffe3ec;
  --green: #34c98a;
  --red: #ff6b6b;
  --bg: #fff5f8;
  --card: #ffffff;
  --text: #2c2230;
  --muted: #6b5f6a;
  --line: #f0e4ea;
  --shadow: 0 4px 18px rgba(242, 86, 127, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 0; }
.page { animation: fade .25s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 8px 0 16px; flex-wrap: wrap;
}
.app-header h1 { font-size: 22px; margin: 0; }
.date-nav { display: flex; align-items: center; gap: 6px; }
.date-nav input[type=date] {
  border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px;
  font-size: 16px; background: #fff; color: var(--text);
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: #fff; box-shadow: var(--shadow); font-size: 20px; color: var(--pink-dark);
  cursor: pointer;
}

/* Hero card */
.hero-card {
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  color: #fff; border-radius: var(--radius); padding: 22px 20px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.hero-label { font-size: 14px; opacity: .9; }
.hero-value { font-size: 46px; font-weight: 800; line-height: 1.1; margin: 4px 0 12px; }
.hero-value small { font-size: 18px; font-weight: 600; opacity: .85; }
.progress-wrap { position: relative; height: 30px; margin-top: 6px; }
.progress-track { position: absolute; left: 0; right: 0; top: 16px; height: 12px; background: rgba(255,255,255,.30); border-radius: 99px; overflow: hidden; }
.progress-seg { position: absolute; top: 0; bottom: 0; left: 0; width: 0; transition: width .45s ease, left .45s ease; }
.progress-seg.diet { background: #ffffff; }
.progress-seg.ex { background: #ffd166; }
.progress-seg.over { background: repeating-linear-gradient(45deg, rgba(255,255,255,.65) 0 5px, rgba(255,209,102,.55) 5px 10px); }
.progress-seg.surplus { background: #c2185b; }
.progress-wrap.maxed .progress-track { box-shadow: 0 0 9px 1px rgba(255,209,102,.95); }
.bar-mark { position: absolute; top: 0; bottom: 0; width: 0; pointer-events: none; }
.bar-mark .lbl { position: absolute; top: 0; left: 0; transform: translateX(-50%); font-size: 10px; line-height: 14px; white-space: nowrap; }
.bar-mark .line { position: absolute; top: 13px; left: 0; width: 2px; height: 18px; transform: translateX(-50%); border-radius: 2px; }
.target-mark .lbl { color: #fff; background: rgba(0,0,0,.42); padding: 0 5px; border-radius: 6px; }
.target-mark .line { background: rgba(0,0,0,.6); }
.tdee-line .lbl { color: rgba(255,255,255,.95); font-weight: 600; }
.tdee-line .line { background: rgba(255,255,255,.95); }
.bar-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 11px; opacity: .95; }
.bar-legend span { display: inline-flex; align-items: center; gap: 5px; }
.bar-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.bar-legend i.diet { background: #fff; }
.bar-legend i.ex { background: #ffd166; }
.hero-sub { font-size: 13px; opacity: .92; margin-top: 12px; }

/* Stat row */
.stat-row { display: flex; gap: 10px; margin-bottom: 18px; }
.stat-box { flex: 1; background: var(--card); border-radius: 14px; padding: 12px 8px; text-align: center; box-shadow: var(--shadow); }
.stat-num { font-size: 22px; font-weight: 700; }
.stat-num .plus { font-size: 14px; font-weight: 700; color: var(--pink-dark); margin-left: 1px; }
.stat-cap { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Blocks */
.block { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.block-head h2 { font-size: 16px; margin: 0; }
.add-btn {
  border: none; background: var(--pink); color: #fff; font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-radius: 12px; cursor: pointer;
}
.add-btn:active { transform: scale(.96); }
.add-btn.ghost { background: var(--pink-soft); color: var(--pink-dark); }
.block-foot { text-align: right; color: var(--muted); font-size: 13px; margin-top: 6px; }

/* Entry list */
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.entry-list li:last-child { border-bottom: none; }
.entry-left { min-width: 0; flex: 1 1 auto; }
.entry-left.tappable { cursor: pointer; }
.entry-left.tappable:active { opacity: .6; }
.entry-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { font-size: 12px; color: var(--muted); }
.entry-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.entry-kcal { font-weight: 700; }
.del-btn {
  border: none; background: none; color: var(--red); font-size: 18px; cursor: pointer;
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0;
}
.del-btn:active { background: var(--pink-soft); }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 10px 0; }

/* Weight row */
.weight-row { display: flex; gap: 10px; }
.weight-row input { flex: 1; }

/* Inputs */
input, select {
  font-family: inherit; font-size: 16px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--pink); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 5px; }

/* Hint */
.hint { font-size: 13px; color: var(--muted); margin: 0 0 14px; }

/* Food library */
.food-lib-list { list-style: none; margin: 0; padding: 0; }
.food-lib-list li {
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between;
}
.lib-info { min-width: 0; flex: 1 1 auto; }
.lib-info b { font-size: 15px; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.lib-info .entry-meta { display: block; }
.lib-actions { display: flex; gap: 8px; flex-shrink: 0; }
.lib-actions button { border: none; background: var(--pink-soft); color: var(--pink-dark); border-radius: 10px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.lib-actions .del { background: #ffe1e1; color: var(--red); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--pink-soft); color: var(--pink-dark); margin-left: 6px; }

/* Forms */
.form-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.form-card h2 { font-size: 16px; margin: 0 0 12px; }
.calc-preview { background: var(--pink-soft); color: var(--pink-dark); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 600; }
.btn-row { display: flex; gap: 10px; }
.btn-row .add-btn { flex: 1; }
.save-big { width: 100%; border: none; background: var(--pink); color: #fff; font-size: 17px; font-weight: 700; padding: 14px; border-radius: 14px; cursor: pointer; margin-bottom: 10px; }

/* Charts */
.chart-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.chart-card h2 { font-size: 15px; margin: 0 0 10px; }
.chart-box { position: relative; width: 100%; height: 240px; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.summary-card { font-size: 14px; line-height: 1.9; }
.summary-card b { color: var(--pink-dark); }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 50;
  max-width: 560px; margin: 0 auto;
}
.tab {
  flex: 1; border: none; background: none; padding: 8px 0 10px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tab span { font-size: 21px; }
.tab.active { color: var(--pink-dark); font-weight: 600; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(40,20,30,.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); animation: slideup .25s ease;
  max-height: 88vh; overflow-y: auto;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal-foot { display: flex; gap: 10px; margin-top: 8px; }
.modal-foot .add-btn { flex: 1; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }

/* Segmented control */
.seg { display: flex; background: var(--pink-soft); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg-btn { flex: 1; border: none; background: none; padding: 8px; border-radius: 9px; font-size: 14px; color: var(--pink-dark); cursor: pointer; }
.seg-btn.active { background: #fff; font-weight: 700; box-shadow: var(--shadow); }

/* Toast */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(44,34,48,.92); color: #fff; padding: 10px 18px; border-radius: 99px;
  font-size: 14px; z-index: 200; animation: fade .2s ease;
}

/* Hero color states */
.hero-card.good { background: linear-gradient(135deg, #4fd1a0, #2bb07f); }
.hero-card.bad { background: linear-gradient(135deg, #ff9a7a, #f2567f); }
