:root {
  --bg: #f5f6f1;
  --surface: #ffffff;
  --surface-soft: #eef0e9;
  --ink: #20231f;
  --muted: #6f756c;
  --line: #dfe3da;
  --green: #276749;
  --green-soft: #dcecdf;
  --coral: #d9674a;
  --gold: #c58a22;
  --blue: #477c9c;
  --danger: #a94438;
  --shadow: 0 18px 50px rgba(46, 52, 43, .11);
}

* { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-width: 320px; min-height: 100svh; background: var(--bg); color: var(--ink); font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif; letter-spacing: 0; overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.topbar { height: calc(72px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(24px, calc((100vw - 1160px) / 2)) 0; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(245,246,241,.94); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--ink); color: white; font-family: Georgia, serif; font-size: 21px; }
.brand div { display: grid; line-height: 1.2; }
.brand strong { font-size: 15px; }
.brand span:last-child { color: var(--muted); font-size: 11px; margin-top: 3px; }

.app-shell { max-width: 1160px; margin: 0 auto; padding: 28px 24px calc(64px + env(safe-area-inset-bottom)); }
.date-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 24px; position: relative; }
.date-button { border: 0; background: transparent; min-width: 180px; color: var(--ink); padding: 4px 12px; display: grid; gap: 2px; }
.date-button span { font-size: 18px; font-weight: 700; }
.date-button small { font-size: 12px; color: var(--muted); }
#datePicker { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 6px; font-size: 25px; line-height: 1; }
.icon-button:hover { border-color: #abb2a7; }
.icon-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.quiet-button, .secondary-button, .primary-button { min-height: 40px; border-radius: 6px; padding: 0 16px; border: 1px solid transparent; font-weight: 650; font-size: 13px; }
.quiet-button { background: transparent; color: var(--green); position: absolute; right: 0; }
.secondary-button { background: var(--surface); border-color: var(--line); color: var(--ink); }
.primary-button { background: var(--green); color: white; }
.full { width: 100%; }

.summary-band { background: var(--ink); color: white; padding: 32px; border-radius: 8px; box-shadow: var(--shadow); }
.summary-heading { display: flex; justify-content: space-between; align-items: end; padding-bottom: 28px; border-bottom: 1px solid rgba(255,255,255,.15); }
.eyebrow { display: block; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; margin-bottom: 6px; }
.summary-band .eyebrow { color: #aeb6a9; }
h1, h2, p { margin: 0; }
h1 { font-family: Georgia, "Songti SC", serif; font-size: 44px; font-weight: 500; line-height: 1; }
h1 small { font: 500 14px Inter, sans-serif; color: #b9c0b4; }
h2 { font-size: 22px; line-height: 1.2; }
.profile-summary { font-size: 13px; color: #cbd0c7; }
.macro-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; padding-top: 27px; }
.macro-card { min-width: 0; }
.macro-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.macro-name { font-size: 13px; color: #d9ded5; }
.macro-value { font-size: 18px; font-weight: 750; white-space: nowrap; }
.macro-value small { color: #959e91; font-size: 11px; font-weight: 500; }
.progress { height: 7px; background: rgba(255,255,255,.13); margin: 12px 0 9px; overflow: hidden; border-radius: 2px; }
.progress span { display: block; height: 100%; width: 0; transition: width .25s ease; }
.macro-card[data-key="carbs"] .progress span { background: var(--gold); }
.macro-card[data-key="protein"] .progress span { background: #7bbf91; }
.macro-card[data-key="fat"] .progress span { background: var(--coral); }
.macro-diff { font-size: 11px; color: #aeb6a9; }
.macro-diff.over { color: #f0a18d; }

.section-heading { margin: 38px 0 16px; display: flex; align-items: end; justify-content: space-between; }
.meal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.meal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 280px; display: flex; flex-direction: column; }
.meal-header { padding: 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.meal-header h3 { font-size: 16px; margin: 0; }
.meal-kcal { color: var(--muted); font-size: 12px; margin-top: 3px; }
.add-button { width: 34px; height: 34px; border: 0; background: var(--green-soft); color: var(--green); border-radius: 6px; font-size: 23px; line-height: 1; }
.meal-list { padding: 7px 18px; flex: 1; }
.meal-empty { color: var(--muted); font-size: 13px; padding: 32px 0; text-align: center; }
.meal-item { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; padding: 12px 0; border-bottom: 1px solid #edf0ea; }
.meal-item:last-child { border-bottom: 0; }
.meal-item strong { font-size: 13px; overflow-wrap: anywhere; }
.meal-item small { color: var(--muted); font-size: 11px; }
.remove-entry { border: 0; background: transparent; color: #9b655b; padding: 2px 4px; font-size: 16px; grid-row: span 2; }
.meal-footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 13px; color: var(--muted); font-size: 10px; }

dialog { width: min(480px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 8px; background: transparent; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(24, 27, 23, .55); backdrop-filter: blur(3px); }
.wide-dialog { width: min(720px, calc(100% - 28px)); }
.dialog-card { padding: 26px; background: var(--surface); overflow-y: auto; max-height: calc(100vh - 28px); }
.dialog-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 24px; }
.dialog-header .icon-button { border: 0; background: var(--surface-soft); }
.field { border: 0; padding: 0; margin: 0 0 17px; display: grid; gap: 8px; min-width: 0; }
.field > span, .field legend { font-size: 12px; font-weight: 700; color: #4f554d; padding: 0; }
input, select { width: 100%; height: 44px; padding: 0 12px; border: 1px solid #ccd2c8; border-radius: 5px; background: white; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(39,103,73,.1); }
.input-with-unit { position: relative; }
.input-with-unit input { padding-right: 48px; }
.input-with-unit span { position: absolute; right: 13px; top: 13px; color: var(--muted); font-size: 12px; }
.intensity-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.intensity-option { position: relative; }
.intensity-option input { position: absolute; opacity: 0; }
.intensity-option label { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.intensity-option strong { display: block; font-size: 13px; }
.intensity-option small { color: var(--muted); font-size: 10px; }
.intensity-option input:checked + label { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.form-note { color: var(--muted); font-size: 11px; line-height: 1.6; margin: -3px 0 18px; }
.app-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.backup-panel { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.backup-panel > div:first-child { display: grid; gap: 4px; }
.backup-panel strong { font-size: 13px; }
.backup-panel small { color: var(--muted); font-size: 10px; }
.backup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.nutrition-preview { background: var(--surface-soft); border-radius: 6px; padding: 14px; margin-bottom: 18px; display: flex; justify-content: space-around; gap: 8px; font-size: 11px; color: var(--muted); }
.nutrition-preview strong { color: var(--ink); display: block; margin-top: 3px; font-size: 14px; }

.library-toolbar { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.segmented { display: flex; padding: 3px; background: var(--surface-soft); border-radius: 6px; }
.segmented button { border: 0; background: transparent; color: var(--muted); border-radius: 4px; padding: 0 12px; font-size: 12px; }
.segmented button.active { background: white; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.food-list { border-top: 1px solid var(--line); }
.food-row { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.food-row strong { display: block; font-size: 13px; }
.food-row small { color: var(--muted); font-size: 10px; }
.food-macros { color: var(--muted); font-size: 11px; white-space: nowrap; }
.delete-food { border: 0; background: transparent; color: var(--danger); font-size: 12px; }
.built-in { font-size: 10px; color: #8b9189; }
.macro-form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.recipe-row { display: grid; grid-template-columns: 1fr 120px 34px; gap: 8px; margin-bottom: 9px; }
.recipe-row button { border: 1px solid var(--line); background: white; border-radius: 5px; color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 18px); background: var(--ink); color: white; padding: 10px 16px; border-radius: 5px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .topbar { padding: env(safe-area-inset-top) 14px 0; height: calc(62px + env(safe-area-inset-top)); }
  .app-shell { padding: 16px 12px calc(38px + env(safe-area-inset-bottom)); }
  .brand-mark { width: 34px; height: 34px; }
  .summary-band { padding: 22px 18px; }
  .summary-heading { align-items: start; gap: 18px; }
  .profile-summary { text-align: right; max-width: 130px; }
  h1 { font-size: 37px; }
  .macro-grid { grid-template-columns: 1fr; gap: 20px; }
  .meal-grid { grid-template-columns: 1fr; }
  .quiet-button { position: static; padding: 0 6px; min-width: 44px; }
  .date-button { min-width: 118px; padding-inline: 4px; }
  .date-row { gap: 5px; margin-bottom: 16px; }
  .date-row .icon-button { width: 44px; height: 44px; }
  .section-heading { margin-top: 30px; }
  .macro-form-grid { grid-template-columns: 1fr; gap: 0; }
  .library-toolbar { align-items: stretch; flex-direction: column; }
  .segmented button { min-height: 36px; flex: 1; padding: 0 5px; }
  .food-row { grid-template-columns: 1fr auto; }
  .food-macros { grid-column: 1; }
  .recipe-row { grid-template-columns: 1fr 90px 34px; }
  input, select { font-size: 16px; }
  dialog, .wide-dialog { width: 100%; max-width: none; max-height: calc(100dvh - env(safe-area-inset-top)); margin: auto 0 0; border-radius: 8px 8px 0 0; }
  .dialog-card { max-height: calc(100dvh - env(safe-area-inset-top)); padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); }
  .dialog-header { position: sticky; top: -22px; z-index: 2; margin: -22px -18px 20px; padding: 20px 18px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .nutrition-preview { overflow-x: auto; justify-content: flex-start; }
  .nutrition-preview span { min-width: 66px; }
}

@media (display-mode: standalone) {
  .topbar { background: var(--bg); }
}
