:root {
  --accent: #c44818;
  --accent-strong: #9d3410;
  --accent-soft: #fff0e9;
  --accent-ink: #ffffff;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --grouped: #f1f3f5;
  --page-bg: #e7eaee;
  --header-bg: #f8f9fa;
  --tab-bg: rgba(250, 250, 251, .96);
  --ink: #17191c;
  --muted: #626971;
  --separator: #e2e5e8;
  --control-border: #b8bec5;
  --placeholder: #686f77;
  --progress-track: #dfe3e6;
  --selected-surface: #ffffff;
  --icon-surface: #fff0e9;
  --protein: #4657c8;
  --carbs: #087f73;
  --fat: #c44818;
  --danger: #b42318;
  --info-surface: #edf4fa;
  --info-ink: #213e54;
  --tab-inactive: #777e86;
  --header-height: calc(82px + env(safe-area-inset-top));
  --tab-height: 72px;
  --radius-control: 12px;
  --radius-panel: 16px;
}

html { background: var(--page-bg); }
body { background: var(--page-bg); color: var(--ink); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { letter-spacing: -.01em; }
button { transition: transform .16s cubic-bezier(.16,1,.3,1), filter .16s ease, background-color .16s ease; }
button:active { transform: scale(.98); filter: none; }

.app-shell {
  width: min(430px, 100vw);
  height: min(926px, 100dvh);
  margin: max(0px, calc((100dvh - 926px) / 2)) auto 0;
  background: #f8f9fa;
  box-shadow: 0 8px 24px rgba(33, 37, 41, .14);
}

.app-header {
  height: var(--header-height);
  padding: env(safe-area-inset-top) 18px 12px;
  background: var(--header-bg);
}
.date-label { margin-bottom: 5px; color: var(--muted); font-size: .74rem; font-weight: 650; }
.app-header h1 { font-size: 1.88rem; font-weight: 780; letter-spacing: -.035em; }
.profile-picker {
  min-height: 44px;
  padding: 4px 9px 4px 4px;
  border: 1px solid var(--separator);
  background: var(--surface);
}
.avatar { width: 34px; height: 34px; font-size: .86rem; box-shadow: inset 0 0 0 1px rgba(255,255,255,.24); }
.profile-picker select { max-width: 92px; font-size: .9rem; }

main { inset: var(--header-height) 0 calc(var(--tab-height) + env(safe-area-inset-bottom)); }
.today-scroll, .content-scroll { padding: 8px 16px 104px; }
.content-scroll { padding-top: 16px; }

.calorie-summary {
  min-height: 166px;
  gap: 18px;
  padding: 18px;
  overflow: hidden;
  border-radius: var(--radius-panel);
  background: #1e2429;
  color: #f9fafb;
  position: relative;
}
.calorie-summary::after {
  content: "";
  width: 116px;
  height: 116px;
  border-radius: 50%;
  position: absolute;
  right: -44px;
  top: -52px;
  background: rgba(196, 72, 24, .34);
  pointer-events: none;
}
.calorie-ring {
  width: 124px;
  height: 124px;
  background: conic-gradient(#f37742 var(--progress, 0%), rgba(255,255,255,.14) 0);
}
.calorie-ring::before { inset: 11px; background: #1e2429; }
.calorie-ring strong { color: #ffffff; font-size: 1.8rem; font-weight: 800; letter-spacing: -.035em; }
.calorie-ring span { margin-top: 2px; color: #c9d0d5; font-size: .7rem; }
.calorie-detail { position: relative; z-index: 1; }
.calorie-detail > p { margin: 0 0 5px; color: #d1d6da; font-size: .74rem; font-weight: 650; }
.calorie-detail h2 { margin: 0 0 20px; color: #ffffff; font-size: 1.08rem; }
.calorie-detail dl { gap: 9px; }
.calorie-detail dl div { color: #c5ccd1; font-size: .78rem; }
.calorie-detail dd { color: #ffffff; font-weight: 700; }

.activity-row {
  margin-top: 10px;
  padding: 12px 4px 13px;
  justify-content: flex-start;
  border-bottom-color: var(--separator);
}
.activity-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 1.1rem;
}
.activity-row > div { min-width: 0; flex: 1; }
.activity-row h2 { margin: 0 0 2px; font-size: .92rem; }
.activity-row p { overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.activity-row label { min-width: 86px; justify-content: flex-end; border-radius: var(--radius-control); background: var(--surface); box-shadow: inset 0 0 0 1px var(--separator); }
.activity-row input { width: 54px; }

.section-block { margin-top: 26px; }
.section-heading { align-items: center; }
.section-heading h2, .content-scroll > section > h2, .settings-screen section > h2 {
  margin-bottom: 12px;
  font-size: 1.16rem;
  font-weight: 760;
  letter-spacing: -.025em;
}
.section-heading > span { max-width: 17ch; color: var(--muted); font-size: .7rem; line-height: 1.25; }

#macroRows { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.macro-row {
  min-width: 0;
  margin: 0;
  padding: 12px 10px 11px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--separator);
}
.macro-row > div { display: grid; gap: 6px; margin-bottom: 10px; }
.macro-row strong { overflow: hidden; font-size: .76rem; text-overflow: ellipsis; }
.macro-row span { font-size: .71rem; white-space: nowrap; }
.macro-row progress { height: 6px; }
.macro-row small { min-height: 28px; margin-top: 7px; text-align: left; font-size: .66rem; line-height: 1.2; }

.meal-list { border-top: 0; }
.meal-section { padding-bottom: 24px; }
.empty-state {
  padding: 28px 18px;
  border-radius: var(--radius-panel);
  background: var(--surface);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--separator);
}
.empty-state strong { font-size: .96rem; }
.empty-state p { max-width: 30ch; margin: 5px auto 16px; font-size: .8rem; }
.inline-add { background: var(--accent-soft); color: var(--accent-strong); }
.meal-group { padding: 4px 12px 0; border-radius: var(--radius-panel); background: var(--surface); box-shadow: inset 0 0 0 1px var(--separator); }
.meal-group + .meal-group { margin-top: 10px; }
.meal-group h3 { margin: 10px 0 2px; }
.food-row { padding-inline: 0; }
.food-row:last-child { border-bottom: 0; }
.food-row strong { font-size: .91rem; }
.food-row small { font-size: .68rem; }

.floating-action {
  right: 16px;
  bottom: 16px;
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 18px;
  background: var(--accent);
  box-shadow: 0 5px 8px rgba(116, 43, 14, .24);
  font-size: .9rem;
}
.floating-action i { font-size: 1.05rem; }

.log-options section + section, .settings-screen section + section { margin-top: 28px; }
.chat-log-section {
  padding: 17px;
  border-radius: var(--radius-panel);
  background: #1e2429;
  color: #ffffff;
}
.chat-log-section h2 { color: #ffffff; font-size: 1.18rem; }
.chat-composer { border: 0; border-radius: 14px; background: #ffffff; }
.chat-composer textarea { color: #17191c; }
.chat-composer textarea::placeholder { color: #60676e; }
.chat-composer button { background: var(--accent); color: #ffffff; }
.chat-log-status { color: #cbd1d5; font-size: .77rem; }
.chat-manual-fallback { color: #ffb18e; }

.feature-action {
  padding: 13px;
  border-radius: var(--radius-panel);
  background: var(--accent-soft);
  color: var(--ink);
}
.action-icon { border-radius: var(--radius-control); background: rgba(196,72,24,.12); color: var(--accent-strong); }
.action-icon i { font-size: 1.22rem; }
.feature-action > i, .action-list button > i { color: var(--muted); }
.feature-action strong, .action-list strong, .recent-list strong { font-size: .92rem; }
.feature-action small, .action-list small, .recent-list small { font-size: .77rem; }
.action-list { overflow: hidden; border: 0; border-radius: var(--radius-panel); background: var(--surface); box-shadow: inset 0 0 0 1px var(--separator); }
.action-list button { padding: 10px 13px; background: transparent; }
.action-list button + button { border-top-color: var(--separator); }
.privacy-note, .supporting-copy { font-size: .79rem; }

.period-control, .library-control { border-radius: var(--radius-control); background: #e6e9ec; }
.period-control button, .library-control button { border-radius: 10px; }
.period-control button.selected, .library-control button.selected { box-shadow: 0 1px 3px rgba(38,42,46,.13); }
.trend-overview { border-radius: var(--radius-panel); background: #1e2429; color: #ffffff; }
.trend-overview > div { border-right-color: rgba(255,255,255,.14); }
.trend-overview span { color: #c8cfd4; }
.chart-bar { background: var(--accent); }

.settings-group, .saved-meal-list, .recent-list {
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--separator);
}
.settings-group > button, .settings-group > label, .settings-group > a { padding-inline: 13px; }
.goal-summary, .meal-total { border-radius: var(--radius-panel); background: var(--accent-soft); }
.primary-button { background: var(--accent); color: #ffffff; }
.secondary-button { border-color: var(--control-border); background: var(--surface); }
.goal-grid label, .sheet-body > label, .advanced-settings label, .form-row label, .macro-inputs label, .wizard-step > label {
  border-radius: var(--radius-control);
  background: var(--grouped);
}

.tabbar {
  height: calc(var(--tab-height) + env(safe-area-inset-bottom));
  padding: 5px 10px max(7px, env(safe-area-inset-bottom));
  background: var(--tab-bg);
  border-top-color: var(--separator);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.tabbar button { display: flex; flex-direction: column; gap: 3px; color: var(--tab-inactive); font-size: .67rem; }
.tabbar button i { font-size: 1.32rem; }
.tabbar button span { font-size: .67rem; }
.tabbar button.active { color: var(--accent-strong); }

dialog { border-radius: var(--radius-panel) var(--radius-panel) 0 0; box-shadow: 0 -5px 12px rgba(20,24,28,.16); }
.compact-dialog, .message-dialog { border-radius: var(--radius-panel); }
.sheet-header { min-height: 58px; }
.sheet-header h2 { font-size: 1.05rem; }
.sheet-body { gap: 12px; }
.scanner-guide { border-radius: var(--radius-control); }

.onboarding-dialog {
  width: min(430px, 100vw);
  height: min(926px, 100dvh);
  max-height: 100dvh;
  margin: auto;
  overflow: hidden;
  border-radius: 0;
  background: #f8f9fa;
  color: #17191c;
  box-shadow: none;
}
.onboarding-dialog::backdrop { background: rgba(12,14,16,.68); }
.onboarding-form { min-height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.onboarding-topbar {
  min-height: calc(66px + env(safe-area-inset-top));
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: end;
  gap: 10px;
  padding: env(safe-area-inset-top) 16px 10px;
}
.onboarding-back, .onboarding-skip { min-height: 44px; border: 0; background: transparent; }
.onboarding-back[hidden] { display: block !important; visibility: hidden; pointer-events: none; }
.onboarding-back { text-align: left; font-size: 1.18rem; }
.onboarding-skip { color: #565d64; text-align: right; font-size: .82rem; font-weight: 650; }
.onboarding-progress { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; padding-bottom: 18px; }
.onboarding-progress i { height: 4px; border-radius: 4px; background: #d9dde1; transition: background-color .2s ease; }
.onboarding-progress i.active { background: var(--accent); }
.onboarding-step {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 22px;
  overflow-y: auto;
  padding: 32px 22px 24px;
}
.onboarding-step > div:first-child h2 { max-width: 12ch; margin: 6px 0 10px; font-size: 2rem; line-height: 1.04; letter-spacing: -.04em; text-wrap: balance; }
.onboarding-step > div:first-child > p:last-child { max-width: 34ch; margin: 0; color: #5c636a; font-size: .94rem; line-height: 1.5; }
.onboarding-kicker { margin: 0; color: var(--accent-strong); font-size: .78rem; font-weight: 750; }
.onboarding-welcome { align-content: space-between; padding-top: 44px; padding-bottom: 34px; background: #1e2429; color: #ffffff; }
.onboarding-welcome > div:first-child h2 { max-width: 13ch; }
.onboarding-welcome > div:first-child > p:last-child { color: #cbd1d5; }
.onboarding-welcome .onboarding-kicker { color: #ffad88; }
.welcome-mark {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 2rem;
}
.welcome-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.welcome-methods span { min-height: 66px; display: grid; place-items: center; gap: 4px; border-radius: 14px; background: rgba(255,255,255,.08); color: #e7ebee; font-size: .72rem; }
.welcome-methods i { font-size: 1.3rem; }

.onboarding-field { display: grid; gap: 7px; color: #3f454b; font-size: .77rem; font-weight: 700; }
.onboarding-field input, .onboarding-field select {
  width: 100%;
  min-height: 52px;
  padding: 0 13px;
  border: 1px solid #c8cdd2;
  border-radius: var(--radius-control);
  background: #ffffff;
  color: #17191c;
  outline: 0;
}
.onboarding-field input:focus, .onboarding-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(196,72,24,.15); }
.choice-stack { display: grid; gap: 9px; padding: 0; border: 0; }
.choice-stack label { cursor: pointer; }
.choice-stack input { position: absolute; opacity: 0; pointer-events: none; }
.choice-stack span {
  min-height: 72px;
  display: grid;
  grid-template-columns: 42px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  padding: 12px;
  border: 1px solid #d9dde1;
  border-radius: 14px;
  background: #ffffff;
}
.choice-stack i { grid-row: 1 / 3; color: var(--accent-strong); font-size: 1.25rem; }
.choice-stack b { font-size: .92rem; }
.choice-stack small { color: #656c73; font-size: .75rem; }
.choice-stack input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice-stack input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.onboarding-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.onboarding-grid-wide { grid-column: 1 / -1; }
.onboarding-result { gap: 17px; }
.result-calories { display: flex; align-items: center; justify-content: space-between; padding: 18px; border-radius: var(--radius-panel); background: #1e2429; color: #ffffff; }
.result-calories > span { color: #d4d9dd; font-size: .82rem; }
.result-calories label { display: flex; align-items: baseline; }
.result-calories input { width: 104px; padding: 0; border: 0; background: transparent; color: #ffffff; font-size: 1.8rem; font-weight: 800; text-align: right; outline: 0; }
.result-calories small { margin-left: 5px; color: #c6cdd2; }
.result-macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.result-macros label { min-width: 0; display: grid; gap: 7px; padding: 13px 10px; border-radius: 14px; background: #ffffff; box-shadow: inset 0 0 0 1px #dfe3e6; }
.result-macros span { color: #5c636a; font-size: .72rem; font-weight: 700; }
.result-macros input { min-width: 0; width: 100%; border: 0; background: transparent; color: #17191c; font-size: 1.22rem; font-weight: 800; outline: 0; }
.result-macros small { color: #71777e; font-size: .7rem; }
.result-note { display: flex; gap: 8px; margin: 0; color: #626970; font-size: .76rem; line-height: 1.4; }
.result-note i { color: var(--accent-strong); font-size: 1rem; }
.onboarding-footer { padding: 12px 22px max(20px, env(safe-area-inset-bottom)); background: inherit; }
.onboarding-footer .primary-button { min-height: 54px; border-radius: var(--radius-control); }
.onboarding-dialog.welcome-active .onboarding-topbar,
.onboarding-dialog.welcome-active .onboarding-footer { background: #1e2429; }
.onboarding-dialog.welcome-active .onboarding-skip { color: #d8dde1; }
.onboarding-dialog.welcome-active .onboarding-progress i { background: rgba(255,255,255,.18); }
.onboarding-dialog.welcome-active .onboarding-progress i.active { background: #f17c48; }

@media (max-width: 430px) {
  html, body { background: #f8f9fa; }
  .app-shell { height: 100dvh; margin: 0; box-shadow: none; }
  .today-scroll, .content-scroll { padding-inline: 14px; }
  .onboarding-dialog { width: 100vw; height: 100dvh; }
}

@media (max-width: 360px) {
  .calorie-summary { gap: 12px; padding: 14px; }
  .calorie-ring { width: 108px; height: 108px; }
  .macro-row { padding-inline: 8px; }
  .onboarding-step { padding-inline: 18px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #f17c48;
    --accent-strong: #ffad88;
    --accent-soft: #3a241c;
    --accent-ink: #17100c;
    --surface: #1b1f22;
    --surface-raised: #23282c;
    --grouped: #252a2f;
    --page-bg: #0b0d0f;
    --header-bg: #111416;
    --tab-bg: rgba(17,20,22,.96);
    --ink: #f4f6f7;
    --muted: #b7bec4;
    --separator: #3d444a;
    --control-border: #747d85;
    --placeholder: #a8b0b7;
    --progress-track: #454c52;
    --selected-surface: #363c42;
    --icon-surface: #3a241c;
    --protein: #9ca8ff;
    --carbs: #66d8ca;
    --fat: #ff9e73;
    --info-surface: #19303e;
    --info-ink: #dceffa;
    --tab-inactive: #aab2b9;
  }
  .app-shell, .onboarding-dialog { background: #111416; }
  .calorie-summary, .chat-log-section, .trend-overview, .result-calories { background: #242a2f; }
  .calorie-ring::before { background: #242a2f; }
  .period-control, .library-control { background: #252a2f; }
  .onboarding-dialog { color: #f4f6f7; }
  .onboarding-step > div:first-child > p:last-child, .choice-stack small, .result-note { color: #b7bec4; }
  .onboarding-field { color: #d4d9dd; }
  .onboarding-field input, .onboarding-field select, .choice-stack span, .result-macros label { border-color: #464d53; background: #1b1f22; color: #f4f6f7; }
  .choice-stack input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
  .result-macros input { color: #f4f6f7; }
  .result-macros span, .result-macros small { color: #b7bec4; }
  .onboarding-progress i { background: #3d444a; }
  .onboarding-skip { color: #c2c8cd; }
  .onboarding-welcome { background: #111416; }
  .primary-button { color: #24130c; }
}

@media (prefers-reduced-motion: reduce) {
  button, .onboarding-progress i { transition: none; }
}
