:root {
  --linen: #f3eee4;
  --paper: #fffdf8;
  --paper-2: #f7f1e7;
  --ink: #1d2a24;
  --ink-soft: #4f5f57;
  --line: #e3d8c6;
  --herb: #2f6b4f;
  --herb-deep: #24563f;
  --herb-soft: #e6f3eb;
  --herb-mid: #3d8b64;
  --clay: #c45c26;
  --clay-deep: #a44918;
  --clay-soft: #fde8dc;
  --gold: #c9a227;
  --warn: #8a4b12;
  --warn-bg: #fff3e0;
  --danger: #9b2c2c;
  --danger-bg: #fdecec;
  --shadow: 0 10px 30px rgba(40, 32, 18, 0.08);
  --shadow-sm: 0 2px 8px rgba(40, 32, 18, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Nunito Sans", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 50% -8%, #fffaf1 0%, var(--linen) 58%, #e8decd 100%);
  min-height: 100%;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: calc(18px + var(--safe-t)) 16px calc(36px + var(--safe-b));
}

.site-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 22px;
}

.logo-mark {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--herb);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.logo-mark svg { width: 30px; height: 30px; }

.brand {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
}

.tagline {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.98rem;
  max-width: 34em;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
}

.card h2 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 1.28rem;
  font-weight: 600;
}

.plan-form {
  display: grid;
  gap: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 560px) {
  .field-row { grid-template-columns: 1fr; }
}

.field label,
.field .label {
  display: block;
  font-weight: 700;
  font-size: 0.86rem;
  margin-bottom: 6px;
}

.hint {
  display: block;
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.input, .stepper input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font: 600 1.05rem/1.2 var(--font);
  color: var(--ink);
  outline: none;
}

.input:focus, .stepper input:focus, button:focus-visible {
  box-shadow: 0 0 0 3px rgba(47, 107, 79, 0.28);
  border-color: var(--herb);
}

.budget-wrap {
  position: relative;
}
.budget-wrap .dollar {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  font-weight: 700;
  pointer-events: none;
}
.budget-wrap .input { padding-left: 28px; }

.stepper {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.stepper button {
  appearance: none;
  border: 0;
  background: var(--paper-2);
  color: var(--ink);
  width: 48px;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.stepper button:hover { background: var(--herb-soft); }
.stepper input {
  border: 0;
  border-radius: 0;
  text-align: center;
  flex: 1;
  min-width: 0;
  padding: 12px 4px;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { appearance: none; }

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px 8px 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.92rem;
  user-select: none;
}
.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--herb);
  margin: 0;
}
.toggle:has(input:checked) {
  background: var(--herb-soft);
  border-color: #b7d4c3;
  color: var(--herb-deep);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font: 750 1rem/1.1 var(--font);
  cursor: pointer;
  min-height: 44px;
}
.btn-primary {
  background: var(--herb);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 6px 16px rgba(47, 107, 79, 0.22);
}
.btn-primary:hover { background: var(--herb-deep); }
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--paper-2); color: var(--ink); }
.btn-tiny {
  padding: 8px 12px;
  font-size: 0.85rem;
  min-height: 40px;
  background: var(--paper-2);
  color: var(--herb-deep);
  border: 1px solid var(--line);
}
.btn-tiny:hover { background: var(--herb-soft); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#status { margin-top: 16px; }

.banner {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid;
  font-size: 0.95rem;
}
.banner strong { font-family: var(--display); font-weight: 600; }
.banner-ok {
  background: var(--herb-soft);
  border-color: #b7d4c3;
  color: var(--herb-deep);
}
.banner-tight {
  background: var(--warn-bg);
  border-color: #f0d0a0;
  color: var(--warn);
}
.banner-err {
  background: var(--danger-bg);
  border-color: #f3c4c4;
  color: var(--danger);
}

#results { margin-top: 18px; display: grid; gap: 18px; }
#results[hidden] { display: none; }

.budget-board {
  display: grid;
  gap: 10px;
}
.budget-figures {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  align-items: baseline;
}
.budget-total {
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 600;
}
.budget-total span { color: var(--ink-soft); font-size: 0.7em; font-weight: 500; font-family: var(--font); }
.budget-meta { color: var(--ink-soft); font-size: 0.92rem; }

.bar {
  height: 12px;
  background: #efe6d6;
  border-radius: 999px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--herb-mid), var(--herb));
  border-radius: inherit;
  transition: width 0.4s ease;
}
.bar.is-over > i { background: linear-gradient(90deg, #d46a3a, var(--danger)); }

.estimate-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

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

.dinner {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 14px 12px;
  background: #fff;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: start;
}
.dinner-day {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clay);
}
.dinner-name {
  margin: 2px 0 0;
  font-family: var(--display);
  font-size: 1.16rem;
  font-weight: 600;
  line-height: 1.2;
}
.dinner-desc {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.dinner-tags {
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 750;
  background: var(--paper-2);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.pill-veg { background: var(--herb-soft); color: var(--herb-deep); border-color: #b7d4c3; }
.dinner-cost {
  text-align: right;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.12rem;
  white-space: nowrap;
}
.dinner-cost small {
  display: block;
  font-family: var(--font);
  font-weight: 650;
  font-size: 0.7rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.dinner-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.section-head h2 { margin: 0; }

.grocery-group + .grocery-group { margin-top: 16px; }
.grocery-group h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--herb-deep);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.grocery-group h3 span { color: var(--ink-soft); letter-spacing: 0; text-transform: none; font-weight: 700; }

.g-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-top: 1px solid #f0e8da;
}
.g-item:first-of-type { border-top: 0; }
.g-item label { font-weight: 700; cursor: pointer; }
.g-item .qty { color: var(--ink-soft); font-weight: 600; font-size: 0.88rem; }
.g-item .needed { display: block; font-weight: 500; font-size: 0.75rem; color: #7a8a82; }
.g-item .price { font-weight: 750; white-space: nowrap; }
.g-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--herb);
}
.g-item.is-checked label,
.g-item.is-checked .qty,
.g-item.is-checked .price { text-decoration: line-through; opacity: 0.55; }

.grocery-total {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px solid var(--line);
  display: flex;
  justify-content: space-between;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 600;
}

.site-footer {
  margin-top: 28px;
  color: var(--ink-soft);
  font-size: 0.84rem;
}
.site-footer p { margin: 0 0 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}
.toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

@media print {
  body { background: #fff; color: #000; }
  .app { max-width: none; padding: 0; }
  .site-header { margin-bottom: 12px; }
  .logo-mark { box-shadow: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  #plan-card, .dinner-actions, .actions, .btn, .toast, .toggles, .plan-form,
  .g-item input, .site-footer .no-print { display: none !important; }
  #results { display: grid !important; margin: 0; }
  #results[hidden] { display: none !important; }
  .banner { border-color: #999; }
  .dinner, .g-item { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  .print-only { display: block !important; }
}

.print-only { display: none; }
