:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-soft: #e9efe9;
  --text: #17211d;
  --muted: #66736d;
  --line: #d9e1db;
  --brand: #173f35;
  --brand-contrast: #ffffff;
  --accent: #d9f3e4;
  --accent-text: #155b40;
  --danger: #9d342f;
  --shadow: 0 12px 35px rgba(23, 63, 53, .08);
  font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101713;
    --surface: #18211d;
    --surface-soft: #22302a;
    --text: #eff7f1;
    --muted: #a3b3aa;
    --line: #33423a;
    --brand: #87d6aa;
    --brand-contrast: #102219;
    --accent: #204b39;
    --accent-text: #c7f6d8;
    --danger: #ffaaa3;
    --shadow: 0 12px 35px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0 auto;
  min-width: 320px;
  max-width: 760px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

button { color: inherit; }

button, summary, select, input[type="checkbox"] { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent);
  outline-offset: 2px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) 20px 12px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
}

h1, h2, h3, p { overflow-wrap: anywhere; }

h1 { margin: 0; font-size: clamp(28px, 7vw, 38px); line-height: 1.05; letter-spacing: -.035em; }
h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
h3 { margin: 0; font-size: 16px; }

main { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); }

.view { animation: view-in .18s ease-out; }

@keyframes view-in {
  from { opacity: .5; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.icon-button, .small-button, .primary-button, .secondary-button, .text-button {
  border: 0;
  border-radius: 14px;
  min-height: 44px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.icon-button svg, .bottom-nav svg, .empty-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-button, .secondary-button, .text-button, .small-button {
  padding: 10px 15px;
  font-weight: 700;
}

.primary-button { background: var(--brand); color: var(--brand-contrast); }
.secondary-button { background: var(--surface-soft); color: var(--text); }
.text-button { background: transparent; color: var(--brand); padding-inline: 8px; }
.small-button { min-height: 36px; padding: 7px 11px; background: var(--surface-soft); }
.block-button { width: 100%; }
.danger-button { color: var(--danger); }

.date-switcher {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.date-copy { text-align: center; }
.date-copy strong { display: block; font-size: 17px; }
.date-copy span { color: var(--muted); font-size: 13px; }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  padding: 13px 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
}

.stat span { display: block; color: var(--muted); font-size: 11px; }
.stat strong { display: block; margin: 3px 0; font-size: clamp(18px, 5.5vw, 24px); letter-spacing: -.03em; }
.stat small { color: var(--muted); font-size: 10px; }

.meal-card, .section-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.meal-card { margin-bottom: 11px; overflow: hidden; }
.meal-card[open] { border-color: color-mix(in srgb, var(--brand) 38%, var(--line)); }
.meal-card summary { list-style: none; padding: 15px; }
.meal-card summary::-webkit-details-marker { display: none; }
.meal-summary { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 11px; align-items: center; }

.meal-check, .grocery-check {
  appearance: none;
  display: grid;
  place-content: center;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.meal-check::before, .grocery-check::before {
  width: 11px;
  height: 6px;
  border: solid var(--brand-contrast);
  border-width: 0 0 2px 2px;
  content: "";
  transform: rotate(-45deg) scale(0);
}

.meal-check:checked, .grocery-check:checked { border-color: var(--brand); background: var(--brand); }
.meal-check:checked::before, .grocery-check:checked::before { transform: rotate(-45deg) scale(1); }

.meal-title-line { min-width: 0; }
.meal-title-line span { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.meal-title-line strong { display: block; margin-top: 3px; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-title-line .done { text-decoration: line-through; color: var(--muted); }
.meal-kcal { color: var(--muted); font-size: 12px; white-space: nowrap; }

.meal-detail { padding: 0 15px 16px 50px; border-top: 1px solid var(--line); }
.meal-detail label { display: block; margin: 13px 0 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.meal-detail select, .field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 11px;
  background: var(--bg);
  color: var(--text);
}

.macro-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.pill { border-radius: 999px; padding: 6px 9px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; }
.ingredients { margin: 0 0 12px; padding-left: 19px; color: var(--text); }
.ingredients li { margin: 5px 0; }
.prep { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.cost { margin-top: 10px; color: var(--muted); font-size: 12px; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 6px 2px 12px;
}

.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.week-list, .grocery-groups, .history-list { display: grid; gap: 10px; }

.week-day {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.week-day.is-today { border-color: var(--brand); }
.day-badge { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--surface-soft); font-weight: 800; }
.week-day.is-today .day-badge { background: var(--brand); color: var(--brand-contrast); }
.week-copy strong, .week-copy span { display: block; }
.week-copy span { margin-top: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-macros { color: var(--muted); font-size: 12px; text-align: right; }
.week-macros strong { display: block; color: var(--text); font-size: 15px; }

.progress-bar { height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-soft); }
.progress-bar span { display: block; height: 100%; background: var(--brand); transition: width .2s ease; }

.shopping-controls { margin-bottom: 14px; padding: 16px; }
.shopping-controls .section-heading { margin: 0 0 13px; }
.range-selector {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-soft);
}
.range-selector button {
  min-width: 0;
  min-height: 40px;
  padding: 7px 4px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.range-selector button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: 0 3px 10px rgba(23, 63, 53, .1); }
.shopping-date-switcher {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  margin-top: 13px;
}
.shopping-date-switcher .icon-button { background: var(--surface-soft); box-shadow: none; }
.shopping-progress { margin-bottom: 14px; }
.shopping-progress p { display: flex; justify-content: space-between; margin: 0 2px 8px; color: var(--muted); font-size: 13px; }
.grocery-group { overflow: hidden; }
.grocery-group h3 { padding: 14px 15px 10px; }
.grocery-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px 15px; border-top: 1px solid var(--line); }
.grocery-row label { min-width: 0; }
.grocery-row label.checked { text-decoration: line-through; color: var(--muted); }
.grocery-row span { color: var(--muted); font-size: 13px; white-space: nowrap; }

.goal-card { padding: 17px; margin-bottom: 14px; }
.goal-line { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.goal-line strong { font-size: 25px; }
.goal-line span { color: var(--muted); font-size: 12px; }
.goal-progress { margin-top: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field label { display: block; margin: 0 0 6px 2px; color: var(--muted); font-size: 12px; font-weight: 700; }
.weight-form { padding: 16px; margin-bottom: 14px; }
.weight-form .primary-button { margin-top: 11px; }

.chart-card { padding: 16px; margin-bottom: 14px; }
.weight-chart { width: 100%; height: auto; margin-top: 10px; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--brand); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: var(--surface); stroke: var(--brand); stroke-width: 2.5; }
.chart-label { fill: var(--muted); font-size: 10px; }

.history-row { display: flex; justify-content: space-between; gap: 14px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.history-row span { color: var(--muted); }
.empty-state { padding: 30px 18px; text-align: center; color: var(--muted); }
.empty-icon { display: grid; place-items: center; margin: 0 auto 10px; }

.settings-stack { display: grid; gap: 12px; }
.settings-card { padding: 16px; }
.settings-card h2 { margin-bottom: 5px; }
.settings-card > p { margin: 0 0 14px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.settings-card .form-grid + .form-grid { margin-top: 10px; }
.install-steps { margin: 10px 0 15px; padding-left: 20px; color: var(--muted); }
.install-steps li { margin: 7px 0; }
.notice { padding-left: 12px; border-left: 3px solid var(--brand); }

.bottom-nav {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.bottom-nav button {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 52px;
  padding: 6px 2px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.bottom-nav button[aria-current="page"] { background: var(--surface-soft); color: var(--brand); }
.bottom-nav svg { width: 21px; height: 21px; }

.toast {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 18px;
  max-width: 500px;
  margin: 0 auto;
  padding: 12px 15px;
  border-radius: 14px;
  background: var(--brand);
  color: var(--brand-contrast);
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 700;
}

@media (min-width: 620px) {
  .meal-stack { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .meal-card { margin: 0; }
  .meal-detail { padding-left: 15px; }
  .grocery-groups { grid-template-columns: 1fr 1fr; align-items: start; }
  .settings-stack { grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 380px) {
  .app-header { padding-inline: 16px; }
  main { padding-inline: 12px; }
  .meal-summary { grid-template-columns: auto minmax(0, 1fr); }
  .meal-kcal { grid-column: 2; }
  .form-grid { grid-template-columns: 1fr; }
  .range-selector { grid-template-columns: 1fr 1fr; }
}
