:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: #191714;
  background: #ececec;
  font-synthesis: none;
  --accent: #a85e0a;
  --accent-strong: #884900;
  --surface: #ffffff;
  --grouped: #f3f3f5;
  --ink: #191714;
  --muted: #625f5a;
  --separator: #dedddd;
  --protein: #5551c8;
  --carbs: #087b76;
  --fat: #c85d13;
  --danger: #b42318;
  --tab-height: 70px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: #ececec; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell {
  width: min(430px, 100vw);
  height: min(900px, 100dvh);
  min-height: 620px;
  margin: max(0px, calc((100dvh - 900px) / 2)) auto 0;
  background: var(--surface);
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.14);
}

.app-header {
  height: 91px;
  padding: max(18px, env(safe-area-inset-top)) 18px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid transparent;
  position: relative;
  z-index: 3;
}
.date-label { margin: 0 0 3px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.app-header h1 { margin: 0; font-size: 2rem; line-height: 1; letter-spacing: -.03em; }
.profile-picker { display: flex; min-height: 44px; align-items: center; gap: 7px; border: 0; border-radius: 999px; background: var(--grouped); padding: 4px 7px 4px 4px; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: white; font-weight: 750; }
.profile-picker select { max-width: 102px; border: 0; background: transparent; color: var(--ink); font-size: .84rem; font-weight: 650; outline: 0; }

main { position: absolute; inset: 91px 0 var(--tab-height); }
.view { display: none; height: 100%; position: relative; }
.view.active { display: block; }
.today-scroll, .content-scroll { height: 100%; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-width: none; padding: 10px 16px 105px; }
.content-scroll { padding-top: 18px; }
.today-scroll::-webkit-scrollbar, .content-scroll::-webkit-scrollbar { display: none; }

.calorie-summary { display: flex; align-items: center; gap: 19px; padding: 17px; background: var(--grouped); border-radius: 14px; }
.calorie-ring { width: 116px; height: 116px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--accent) var(--progress, 0%), #dddddf 0); position: relative; }
.calorie-ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--grouped); }
.calorie-ring > div { position: relative; display: grid; text-align: center; }
.calorie-ring strong { font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.calorie-ring span { color: var(--muted); font-size: .72rem; }
.calorie-detail { min-width: 0; flex: 1; }
.calorie-detail h2 { margin: 0 0 14px; font-size: 1rem; font-variant-numeric: tabular-nums; }
.calorie-detail dl { display: grid; gap: 7px; margin: 0; }
.calorie-detail dl div { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .78rem; }
.calorie-detail dd { margin: 0; font-variant-numeric: tabular-nums; }

.activity-row { margin: 13px 0 0; padding: 12px 3px 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--separator); }
.activity-row h2 { margin: 0 0 3px; font-size: .92rem; }
.activity-row p { margin: 0; max-width: 225px; color: var(--muted); font-size: .72rem; line-height: 1.35; }
.activity-row label { display: flex; align-items: center; background: var(--grouped); border-radius: 9px; padding: 0 8px; color: var(--muted); font-size: .72rem; }
.activity-row input { width: 58px; min-height: 42px; padding: 0 4px; border: 0; outline: 0; background: transparent; text-align: right; font-weight: 700; color: var(--ink); }

.section-block { margin-top: 26px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 15px; }
.section-heading h2, .content-scroll > section > h2, .settings-screen section > h2 { margin: 0 0 13px; font-size: 1.22rem; letter-spacing: -.015em; }
.section-heading > span { color: var(--muted); font-size: .75rem; text-align: right; }
.macro-row { margin-bottom: 16px; }
.macro-row > div { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; font-size: .88rem; }
.macro-row strong { font-weight: 650; }
.macro-row span, .macro-row small { color: var(--muted); font-variant-numeric: tabular-nums; }
.macro-row small { display: block; margin-top: 5px; text-align: right; font-size: .69rem; }
progress { display: block; width: 100%; height: 7px; border: 0; appearance: none; }
progress::-webkit-progress-bar { background: #e5e5e5; border-radius: 9px; }
progress::-webkit-progress-value { border-radius: 9px; background: var(--bar, var(--protein)); }
progress::-moz-progress-bar { border-radius: 9px; background: var(--bar, var(--protein)); }
.macro-row.carbs { --bar: var(--carbs); }
.macro-row.fat { --bar: var(--fat); }

.meal-list { border-top: 1px solid var(--separator); }
.empty-state { padding: 30px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--ink); font-size: .95rem; }
.empty-state p { margin: 0 0 16px; font-size: .8rem; line-height: 1.4; }
.inline-add { min-height: 44px; padding: 0 15px; border: 0; border-radius: 10px; background: var(--grouped); color: var(--accent-strong); font-weight: 700; }
.meal-group h3 { display: flex; justify-content: space-between; margin: 18px 0 4px; font-size: .92rem; }
.meal-group h3 span { color: var(--muted); font-size: .75rem; font-weight: 500; }
.food-row { width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 2px; border: 0; border-bottom: 1px solid var(--separator); background: transparent; text-align: left; }
.food-row > span:first-child { display: grid; gap: 3px; }
.food-row strong { font-size: .86rem; }
.food-row small { color: var(--muted); font-size: .72rem; }
.food-row .row-calories { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.floating-action { position: absolute; right: 18px; bottom: 17px; min-height: 48px; padding: 0 18px; border: 0; border-radius: 999px; background: var(--accent); color: white; box-shadow: 0 4px 8px rgba(74,40,0,.25); font-weight: 750; }
.floating-action span { font-size: 1.25rem; vertical-align: -1px; }

.log-options section + section, .settings-screen section + section { margin-top: 28px; }
.feature-action, .action-list button, .recent-list button { width: 100%; min-height: 60px; border: 0; background: var(--surface); display: flex; align-items: center; gap: 12px; padding: 10px 3px; text-align: left; }
.feature-action { min-height: 76px; padding: 12px; border-radius: 12px; background: var(--grouped); }
.action-icon { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; background: #f4e7d6; color: var(--accent-strong); font-size: 1.3rem; font-weight: 500; }
.feature-action > span:nth-child(2), .action-list button > span:nth-child(2), .recent-list button > span:first-child { min-width: 0; flex: 1; display: grid; gap: 3px; }
.feature-action strong, .action-list strong, .recent-list strong { font-size: .9rem; }
.feature-action small, .action-list small, .recent-list small { color: var(--muted); font-size: .72rem; line-height: 1.3; }
.privacy-note, .supporting-copy { color: var(--muted); font-size: .75rem; line-height: 1.45; }
.privacy-note { margin: 8px 12px 0; }
.action-list, .settings-group { border-top: 1px solid var(--separator); border-bottom: 1px solid var(--separator); }
.action-list button + button, .settings-group > * + * { border-top: 1px solid var(--separator); }
.recent-list .empty-state { padding-top: 18px; }
.recent-list button { border-bottom: 1px solid var(--separator); }

.period-control { display: grid; grid-template-columns: repeat(3,1fr); padding: 2px; border-radius: 9px; background: #e9e9eb; }
.period-control button { min-height: 34px; border: 0; border-radius: 7px; background: transparent; font-size: .78rem; font-weight: 650; }
.period-control button.selected { background: white; box-shadow: 0 1px 3px rgba(0,0,0,.16); }
.trend-overview { display: grid; grid-template-columns: repeat(3,1fr); margin-top: 19px; padding: 15px 2px; border-radius: 12px; background: var(--grouped); }
.trend-overview > div { display: grid; text-align: center; padding: 0 4px; border-right: 1px solid var(--separator); }
.trend-overview > div:last-child { border: 0; }
.trend-overview strong { font-size: 1.12rem; font-variant-numeric: tabular-nums; }
.trend-overview span { margin-top: 3px; color: var(--muted); font-size: .66rem; line-height: 1.25; }
.chart { height: 210px; display: flex; align-items: flex-end; gap: 4px; padding-top: 14px; border-bottom: 1px solid #a9a9a9; position: relative; }
.chart::before { content: "Goal"; position: absolute; left: 0; right: 0; bottom: 60%; border-top: 1px dashed #777; color: var(--muted); font-size: .62rem; }
.chart-bar { flex: 1 1 0; min-width: 3px; max-width: 18px; height: var(--height); background: var(--accent); border-radius: 3px 3px 0 0; opacity: .88; position: relative; }
.chart.empty { display: grid; place-items: center; border: 0; color: var(--muted); font-size: .8rem; text-align: center; }
.chart.empty::before { display: none; }

.text-button { min-height: 44px; border: 0; background: transparent; color: var(--accent-strong); font-weight: 700; font-size: .82rem; }
.settings-group > button, .settings-group > label { width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 8px 2px; border: 0; background: transparent; text-align: left; font-size: .86rem; }
.profile-setting { gap: 10px; }
.profile-setting .avatar { width: 32px; height: 32px; font-size: .78rem; }
.profile-setting strong { flex: 1; }
.profile-setting small { color: var(--muted); }
.goal-grid { display: grid; gap: 10px; }
.goal-grid label, .sheet-body > label, .advanced-settings label { min-height: 52px; display: grid; grid-template-columns: 1fr minmax(90px, 120px) auto; align-items: center; gap: 6px; padding: 0 10px; background: var(--grouped); border-radius: 9px; font-size: .82rem; font-weight: 600; }
.goal-grid input, .sheet-body input, .sheet-body select, .advanced-settings input { width: 100%; min-height: 42px; border: 0; outline: 0; background: transparent; text-align: right; color: var(--ink); }
.goal-grid label > span { color: var(--muted); font-size: .72rem; }
.goal-grid.two-column { grid-template-columns: 1fr 1fr; }
.goal-grid.two-column label { grid-template-columns: 1fr; padding: 8px 10px; }
.goal-grid.two-column input { text-align: left; min-height: 32px; }
.goal-grid.two-column .primary-button { grid-column: 1/-1; }
.primary-button, .secondary-button { width: 100%; min-height: 48px; border-radius: 10px; font-weight: 750; }
.primary-button { border: 0; background: var(--accent); color: white; }
.primary-button:disabled { opacity: .55; cursor: wait; }
.secondary-button { border: 1px solid #aaa; background: var(--surface); color: var(--ink); }
.watch-note { margin-top: 14px; padding: 13px; border-radius: 10px; background: #edf4fb; color: #263a4c; }
.watch-note strong { font-size: .82rem; }
.watch-note p { margin: 4px 0 0; font-size: .74rem; line-height: 1.4; }
.file-button { cursor: pointer; }
.advanced-settings { margin-top: 28px; padding: 12px 0; border-top: 1px solid var(--separator); border-bottom: 1px solid var(--separator); }
.advanced-settings summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; font-size: .9rem; cursor: pointer; }
.advanced-settings form { display: grid; gap: 10px; padding-top: 8px; }
.advanced-settings label { grid-template-columns: 1fr; padding: 8px 10px; }
.advanced-settings input { text-align: left; }
.danger-button { width: 100%; min-height: 46px; margin-top: 24px; border: 0; background: transparent; color: var(--danger); font-weight: 700; }

.tabbar { position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; height: calc(var(--tab-height) + env(safe-area-inset-bottom)); padding: 5px 8px max(8px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4,1fr); background: rgba(249,249,249,.97); border-top: 1px solid var(--separator); }
.tabbar button { min-height: 48px; border: 0; background: transparent; color: #696663; display: grid; place-items: center; align-content: center; gap: 2px; font-size: .64rem; }
.tabbar button span { font-size: 1.25rem; line-height: 1; }
.tabbar button.active { color: var(--accent-strong); font-weight: 750; }

dialog { width: min(430px, 100vw); max-height: min(840px, 94dvh); margin: auto auto 0; padding: 0; border: 0; border-radius: 16px 16px 0 0; background: var(--surface); color: var(--ink); box-shadow: 0 -4px 12px rgba(0,0,0,.16); }
dialog::backdrop { background: rgba(0,0,0,.38); }
.compact-dialog { margin: auto; border-radius: 14px; width: min(390px, calc(100vw - 28px)); }
.sheet-header { min-height: 55px; display: grid; grid-template-columns: 70px 1fr 70px; align-items: center; border-bottom: 1px solid var(--separator); padding: 0 9px; }
.sheet-header h2 { margin: 0; text-align: center; font-size: 1rem; }
.sheet-header button { min-height: 44px; border: 0; background: transparent; color: var(--accent-strong); text-align: left; }
.sheet-body { display: grid; gap: 12px; overflow-y: auto; max-height: calc(92dvh - 55px); padding: 17px 16px max(22px, env(safe-area-inset-bottom)); }
.sheet-body > label { grid-template-columns: 1fr; padding: 7px 11px; }
.sheet-body > label input, .sheet-body > label select { min-height: 32px; text-align: left; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row label, .macro-inputs label { display: grid; gap: 5px; padding: 8px 10px; border-radius: 9px; background: var(--grouped); font-size: .75rem; font-weight: 650; }
.form-row input, .form-row select, .macro-inputs input { min-width: 0; width: 100%; min-height: 33px; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }
.macro-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.macro-inputs label { position: relative; }
.macro-inputs input { font-size: 1.05rem; font-weight: 700; }
.macro-inputs label span { position: absolute; right: 10px; bottom: 16px; color: var(--muted); font-size: .7rem; }
.form-help { margin: -2px 3px 2px; color: var(--muted); font-size: .72rem; line-height: 1.4; }
.photo-preview-wrap { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 12px; padding-bottom: 5px; }
.photo-preview-wrap img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; }
.photo-preview-wrap p { margin: 0; color: var(--muted); font-size: .76rem; line-height: 1.4; }
.lookup-form { display: flex; gap: 8px; padding: 14px 14px 10px; }
.lookup-form input { min-width: 0; flex: 1; min-height: 46px; padding: 0 12px; border: 0; border-radius: 9px; background: var(--grouped); outline: 0; }
.lookup-form .primary-button { width: auto; padding: 0 16px; }
.lookup-results { max-height: 55dvh; overflow-y: auto; padding: 0 14px 18px; }
.lookup-results button { width: 100%; min-height: 58px; display: grid; gap: 3px; padding: 8px 2px; border: 0; border-bottom: 1px solid var(--separator); background: transparent; text-align: left; }
.lookup-results small { color: var(--muted); }
.message-dialog { width: min(350px, calc(100vw - 36px)); margin: auto; border-radius: 14px; text-align: center; }
.message-dialog > div { padding: 22px; }
.message-dialog h2 { margin: 0 0 8px; font-size: 1.15rem; }
.message-dialog p { margin: 0 0 18px; color: var(--muted); line-height: 1.45; font-size: .84rem; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: calc(100vw - 32px); padding: 11px 15px; border-radius: 9px; background: #242321; color: white; font-size: .8rem; opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 430px) {
  html { background: white; }
  .app-shell { width: 100vw; height: 100dvh; min-height: 0; margin: 0; box-shadow: none; }
}
@media (max-width: 360px) {
  .calorie-summary { gap: 12px; padding: 14px; }
  .calorie-ring { width: 100px; height: 100px; }
  .goal-grid.two-column, .macro-inputs { grid-template-columns: 1fr; }
}
@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --surface:#111112; --grouped:#202022; --ink:#f4f2ef; --muted:#b2aea8; --separator:#363638; --accent:#d68a33; --accent-strong:#eda34d; --protein:#8581ef; --carbs:#32aaa4; --fat:#f28a43; background:#000; }
  html { background:#000; }
  .app-header, .tabbar { background:rgba(17,17,18,.97); }
  .calorie-ring { background:conic-gradient(var(--accent) var(--progress,0%),#3b3b3d 0); }
  .period-control { background:#29292b; }
  .period-control button.selected { background:#48484b; box-shadow:none; }
  .action-icon { background:#3a2a17; }
  .watch-note { background:#172b3a; color:#d9e8f3; }
  .chart::before { border-color:#aaa; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
