:root {
  --bg: #f7f1e8;
  --card: #fffdf9;
  --ink: #2b2118;
  --muted: #7a6a5a;
  --faint: #a8998a;
  --line: #e8dccb;
  --accent: #c4622d;
  --accent-ink: #fff;
  --accent-soft: #f6e3d6;
  --good: #4f7a3a;
  --good-soft: #e3eddb;
  --try: #2f6690;
  --try-soft: #dde9f3;
  --some: #8a6d3b;
  --some-soft: #f1e8d6;
  --no: #8d4b4b;
  --no-soft: #f3dede;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 14px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130f; --card: #231d18; --ink: #f1e7da; --muted: #b3a291; --faint: #85766a; --line: #3a3029;
    --accent: #e3804b; --accent-ink: #1b120c; --accent-soft: #3d281b;
    --good: #9cc77f; --good-soft: #263321; --try: #8dbde3; --try-soft: #1f2d3a;
    --some: #d8b77a; --some-soft: #342b1d; --no: #e09a9a; --no-soft: #3a2323;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17130f; --card: #231d18; --ink: #f1e7da; --muted: #b3a291; --faint: #85766a; --line: #3a3029;
  --accent: #e3804b; --accent-ink: #1b120c; --accent-soft: #3d281b;
  --good: #9cc77f; --good-soft: #263321; --try: #8dbde3; --try-soft: #1f2d3a;
  --some: #d8b77a; --some-soft: #342b1d; --no: #e09a9a; --no-soft: #3a2323;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
main svg, .sheet svg, .toast svg, .cart-bar svg { width: 18px; height: 18px; flex: none; }

/* ---------- shell ---------- */
#app { max-width: 680px; margin: 0 auto; padding: 0 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px); }
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 0 10px; display: flex; align-items: center; gap: 8px;
}
.top h1 { font-size: 26px; font-weight: 750; letter-spacing: -.01em; flex: 1; min-width: 0; }
.top .sub { display: block; font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.icon-btn {
  border: 0; background: var(--card); box-shadow: var(--shadow); width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; flex: none; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:disabled { opacity: .35; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 680px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tabbar); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); text-decoration: none; font-size: 11px; font-weight: 600; position: relative;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent); }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px); background: var(--accent); color: var(--accent-ink);
  font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin: 10px 0; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 2px 6px; display: flex; align-items: baseline; gap: 8px; }
.section-title .count { font-weight: 500; letter-spacing: 0; text-transform: none; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; text-decoration: none; color: inherit;
}
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .meta { font-size: 13px; color: var(--muted); margin-top: 1px; }
.row .chev { color: var(--faint); flex: none; }
button.row:active, a.row:active { background: var(--accent-soft); }

/* ---------- week ---------- */
.day { padding: 0; overflow: hidden; }
.day-head { display: flex; align-items: baseline; gap: 10px; padding: 12px 14px 8px; }
.day-head h2 { font-size: 18px; font-weight: 700; }
.day-head .date { color: var(--muted); font-size: 13px; }
.day-head .theme { margin-left: auto; font-size: 12px; color: var(--muted); text-align: right; max-width: 55%; }
.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.day.today .day-head h2::after { content: "Today"; font-size: 11px; font-weight: 700; color: var(--accent-ink); background: var(--accent); border-radius: 6px; padding: 2px 6px; margin-left: 8px; vertical-align: 2px; }
.entry { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--line); }
.entry .name { flex: 1; min-width: 0; font-weight: 550; text-decoration: none; color: inherit; }
.entry.done .name { color: var(--muted); }
.entry.text .name { font-style: italic; font-weight: 450; }
.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); background: none; flex: none;
  display: grid; place-items: center; padding: 0; color: transparent;
}
.check svg { width: 16px; height: 16px; }
.check.on { background: var(--good); border-color: var(--good); color: var(--card); }
.x { border: 0; background: none; color: var(--faint); width: 28px; height: 28px; padding: 0; flex: none; display: grid; place-items: center; }
.x svg { width: 16px; height: 16px; }
.add-line { display: flex; gap: 8px; padding: 8px 14px 12px; border-top: 1px solid var(--line); }
.add-btn { border: 1px dashed var(--line); background: none; color: var(--accent); font-weight: 600; border-radius: 10px; padding: 8px 12px; flex: 1; text-align: left; }

/* ---------- controls ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 650; background: var(--card); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.btn.ghost { background: none; box-shadow: none; color: var(--accent); padding: 8px 10px; }
.btn.danger { color: var(--no); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; }
input[type=text], input[type=url], input[type=search], input[type=password], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; outline: none;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.search { position: relative; margin: 4px 0 8px; }
.search input { padding-left: 38px; border-radius: 12px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding-left: 0; padding-right: 0; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px;
  font-weight: 550; white-space: nowrap; flex: none; color: var(--ink);
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg { display: flex; background: var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 7px 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.tier { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 7px; white-space: nowrap; flex: none; }
.tier-staple { background: var(--good-soft); color: var(--good); }
.tier-try { background: var(--try-soft); color: var(--try); }
.tier-sometimes { background: var(--some-soft); color: var(--some); }
.tier-no { background: var(--no-soft); color: var(--no); }

/* ---------- meal page ---------- */
.meal-name { font-size: 24px; font-weight: 750; border: 0; background: none; padding: 0; width: 100%; outline: none; line-height: 1.25; resize: none; min-height: 0; overflow: hidden; }
.field-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 6px; display: flex; align-items: center; gap: 8px; }
.field-label .btn.ghost { margin-left: auto; padding: 0 4px; font-size: 13px; text-transform: none; letter-spacing: 0; }
.ing { list-style: none; padding: 0; margin: 0; }
.ing li { padding: 7px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.ing li:first-child { border-top: 0; }
.ing .amt { color: var(--muted); min-width: 70px; flex: none; font-variant-numeric: tabular-nums; }
.steps { margin: 0; padding-left: 22px; }
.steps li { padding: 5px 0; }
.links a { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); text-decoration: none; overflow-wrap: anywhere; }
.links a:first-child { border-top: 0; }
.notes { white-space: pre-wrap; }
.history-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; margin-right: 6px; }
.day-pick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-pick button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 0; font-weight: 650; font-size: 14px; }
.day-pick button.has { border-color: var(--accent); color: var(--accent); }

/* ---------- shopping ---------- */
.shop-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.shop-row:first-child { border-top: 0; }
.shop-row .grow { flex: 1; min-width: 0; }
.shop-row.off .title { text-decoration: line-through; color: var(--faint); }
.shop-row.off .meta { color: var(--faint); }
.qty { display: flex; align-items: center; gap: 2px; flex: none; }
.qty button { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: none; font-weight: 700; padding: 0; }
.qty span { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 650; }
.need-product { color: var(--accent); font-size: 13px; font-weight: 600; border: 0; background: none; padding: 2px 0 0; display: block; text-align: left; }
.shop-row .title::first-letter { text-transform: uppercase; }
.cart-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); z-index: 9;
  padding: 10px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.cart-bar .inner { max-width: 648px; margin: 0 auto; display: flex; gap: 8px; }
.cart-bar .btn.primary { flex: 1; }

/* ---------- sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20, 12, 6, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet {
  background: var(--bg); width: 100%; max-width: 680px; max-height: 88vh; border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; animation: up .2s ease-out; padding-bottom: env(safe-area-inset-bottom);
}
.sheet-head { padding: 14px 16px 8px; display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { flex: 1; font-size: 19px; }
.sheet-head .sub { display: block; font-size: 13px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.sheet-body { overflow-y: auto; padding: 0 16px 20px; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 80px);
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 12px 10px 16px; z-index: 30;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100% - 32px); animation: up .2s ease-out;
}
.toast button { border: 0; background: color-mix(in srgb, var(--bg) 18%, transparent); color: var(--bg); border-radius: 10px; padding: 6px 10px; font-size: 18px; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.pill-note { display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 650; }
.sync { font-size: 12px; color: var(--faint); text-align: center; margin: 24px 0 0; }
code.token { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 14px; overflow-wrap: anywhere; user-select: all; }
ol.howto { padding-left: 20px; margin: 8px 0; }
ol.howto li { padding: 4px 0; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 340px; text-align: center; }
.login img { border-radius: 22px; box-shadow: var(--shadow); }
.login h1 { font-size: 30px; margin-top: 14px; }
.login form { text-align: left; margin-top: 22px; display: grid; gap: 10px; }
.login label { font-weight: 650; font-size: 14px; }
.login .error { color: var(--no); margin: 0; font-size: 14px; }
