:root {
  --bg: #f2f2f7;
  --paper: #ffffff;
  --ink: #1c1c1e;
  --muted: #8e8e93;
  --line: rgba(60, 60, 67, 0.12);
  --fill: #e5e5ea;
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --tomato: #ff3b30;
  --tomato-dim: rgba(255, 59, 48, 0.14);
  --sage: #34c759;
  --sage-dim: rgba(52, 199, 89, 0.16);
  --gold: #ff9f0a;
  --gold-dim: rgba(255, 159, 10, 0.16);
  --blue-dim: rgba(0, 122, 255, 0.14);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --paper: #1c1c1e;
    --ink: #f5f5f7;
    --muted: #8e8e93;
    --line: rgba(84, 84, 88, 0.65);
    --fill: #2c2c2e;
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.22);
    --tomato: #ff453a;
    --tomato-dim: rgba(255, 69, 58, 0.22);
    --sage: #30d158;
    --sage-dim: rgba(48, 209, 88, 0.22);
    --gold: #ffd60a;
    --gold-dim: rgba(255, 214, 10, 0.2);
    --blue-dim: rgba(10, 132, 255, 0.22);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  max-width: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(118px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.sync {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.eyebrow {
  margin: 0;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
h1 {
  font-size: 34px;
  margin: 2px 0 0;
  letter-spacing: -0.04em;
  font-weight: 700;
}
h2 {
  font-size: 28px;
  margin: 0 0 10px;
  letter-spacing: -0.03em;
  font-weight: 700;
}
h3 { font-weight: 700; font-size: 20px; }
p { color: var(--muted); line-height: 1.45; margin: 0 0 8px; }

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.spread {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.card {
  background: var(--paper);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.stack { display: grid; gap: 10px; }

button, select, input, textarea {
  font: inherit;
  color: var(--ink);
}

button {
  border: 0;
  cursor: pointer;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.secondary { background: var(--fill); color: var(--ink); }
button.ghost {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 8px 10px;
}
button.danger { background: var(--tomato); }
button.sage { background: var(--sage); }
button.small { padding: 6px 10px; font-size: 13px; font-weight: 600; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  border: 0;
  background: var(--fill);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }

label.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}
label.field span { color: var(--muted); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--fill);
  font-size: 13px;
}
.chip button {
  padding: 0;
  width: 18px;
  height: 18px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tomato-dim);
  color: var(--tomato);
}
.pill.full { background: var(--tomato-dim); color: var(--tomato); }
.pill.main { background: var(--blue-dim); color: var(--accent); }
.pill.side { background: var(--sage-dim); color: var(--sage); }
.pill.snack { background: var(--gold-dim); color: var(--gold); }

.seg, .slot-toggles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.chip-toggle {
  background: var(--fill);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 16px;
  font-weight: 600;
}
.chip-toggle.on {
  background: var(--accent-soft);
  color: var(--accent);
}

.toggles { display: flex; flex-wrap: wrap; gap: 12px; }
.toggles label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-weight: 600;
  font-size: 15px;
}
.toggles input { width: 18px; height: 18px; accent-color: var(--accent); }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  display: flex;
  justify-content: space-around;
  gap: 0;
  padding: 10px 6px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  border: 0;
  border-top: 0.5px solid var(--line);
  border-radius: 0;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: none;
  z-index: 20;
}
.tabs button {
  background: transparent;
  color: var(--muted);
  min-width: 0;
  flex: 1;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 700;
  padding: 14px 4px;
  min-height: 48px;
}
.tabs button.on {
  background: transparent;
  color: var(--accent);
}

.meal-list, .shop-list { display: grid; gap: 8px; }
.meal { display: grid; gap: 8px; }
.meal header, .shop-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.meal h3, .shop-item h3 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.ing { color: var(--muted); font-size: 15px; }

.meal-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: transparent;
  padding: 4px 0;
  border-radius: 0;
  width: auto;
  flex: 1;
  min-width: 0;
}
.meal-notes {
  background: transparent;
  padding: 6px 0 0;
  font-size: 15px;
  color: var(--muted);
  border-radius: 0;
}
.pick-list {
  display: grid;
  gap: 2px;
  max-height: 46vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.pick-row {
  text-align: left;
  background: transparent;
  color: var(--ink);
  padding: 12px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.pick-row:hover, .pick-row.new { background: var(--fill); }
.pick-row.new { color: var(--accent); font-weight: 700; }

.plan-grid { display: grid; gap: 10px; }
.day { display: grid; gap: 8px; }
.day .slots {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 720px) {
  .day .slots { grid-template-columns: 1fr 1fr; }
}
.day .slots.one { grid-template-columns: 1fr; }
.slot {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 10px;
  background: var(--fill);
  border-radius: 12px;
}
.slot b {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.slot .hint { font-size: 12px; color: var(--muted); }
.sides { display: grid; gap: 6px; margin-top: 6px; }
.sides.hidden { display: none; }
.plate-name { font-size: 13px; color: var(--ink); font-weight: 650; }

.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.check input {
  width: 22px;
  height: 22px;
  margin-top: 1px;
  accent-color: var(--accent);
}
.check.got h3, .check.got .ing { text-decoration: line-through; opacity: 0.45; }

.stat { display: flex; gap: 8px; flex-wrap: wrap; }
.stat b {
  background: var(--fill);
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  display: grid;
  place-items: end center;
  z-index: 40;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
}
.modal.hidden { display: none; }
.sheet {
  width: min(560px, 100%);
  background: var(--paper);
  border-radius: 18px 18px 14px 14px;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: min(90vh, 760px);
  overflow: auto;
}
@media (min-width: 700px) {
  .modal { place-items: center; }
  .sheet { border-radius: 18px; padding-bottom: 18px; }
}

.empty {
  padding: 28px 10px;
  text-align: center;
  color: var(--muted);
}

.file-btn { position: relative; overflow: hidden; }
.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.need { color: var(--tomato); font-weight: 700; font-size: 12px; }
.have { color: var(--sage); font-weight: 700; font-size: 12px; }

.suggest-wrap { position: relative; }
.suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--paper);
  border: 0.5px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  max-height: 220px;
  overflow: auto;
  z-index: 5;
}
.suggest button {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 11px 14px;
  font-weight: 500;
}
.suggest button:hover,
.suggest button.active { background: var(--fill); }
.suggest .new { color: var(--accent); font-weight: 700; }
.pantry-actions { display: flex; gap: 4px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; align-items: flex-start; }
.more { position: relative; }
.more summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 8px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.more summary.export-btn {
  background: var(--fill);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  letter-spacing: 0;
  font-weight: 600;
}
.more summary::-webkit-details-marker { display: none; }
.more-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  padding: 6px;
  display: grid;
  min-width: 120px;
  z-index: 6;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-content: start;
  padding: calc(28px + env(safe-area-inset-top)) 16px 20px;
  background: var(--bg);
  overflow: auto;
}
.gate.hidden { display: none; }
.gate-card {
  width: min(400px, 100%);
  margin: 0 auto;
  background: var(--paper);
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 16px;
  display: grid;
  gap: 10px;
}
.gate-card h1 { margin: 0; font-size: 28px; }
.gate-card p { font-size: 15px; }
.hidden { display: none !important; }
.gate-err { color: var(--tomato); font-weight: 700; margin: 0; }
.app.locked { display: none; }

@media (max-width: 480px) {
  h1 { font-size: 28px; }
  .top { align-items: flex-start; }
  .gate { padding: calc(16px + env(safe-area-inset-top)) 12px 16px; align-content: start; }
  .gate-card { padding: 16px 14px; }
  .gate-card h1 { font-size: 26px; }
}

.meals-wrap { display: flex; gap: 6px; align-items: flex-start; }
.meals-wrap .meal-list { flex: 1; min-width: 0; }
.letter-rail {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 18px;
}
.letter-rail button {
  background: transparent;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 0;
  min-height: 0;
  line-height: 1.15;
}
button:disabled { opacity: 0.4; }
