:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-2: #f4eee6;
  --ink: #352f2a;
  --ink-soft: #5c544c;
  --muted: #9a8f84;
  --line: #ebe3d8;
  --line-strong: #ddd1c2;
  --accent: #e07a5f;
  --accent-press: #c9624a;
  --accent-soft: #fbeee9;
  --ok: #3f9a78;
  --ok-soft: #e7f4ee;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(53, 47, 42, 0.04), 0 8px 28px rgba(53, 47, 42, 0.07);
  --shadow-sm: 0 1px 2px rgba(53, 47, 42, 0.05);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap {
  width: 100%;
  max-width: 940px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 246, 240, 0.85);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-mark {
  font-size: 22px;
}
.brand-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 999px;
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  color: var(--ink-soft);
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover {
  color: var(--ink);
}
.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ---------------- views ---------------- */
main {
  padding-top: 28px;
  padding-bottom: 80px;
}
.view {
  display: none;
  animation: fade 0.2s ease;
}
.view.is-active {
  display: block;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0;
}
.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  max-width: 52ch;
}

/* ---------------- inputs / buttons ---------------- */
.input {
  appearance: none;
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder {
  color: var(--muted);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn {
  appearance: none;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, opacity 0.15s;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-press);
}
.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent-press);
}
.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}
.btn[disabled] {
  opacity: 0.55;
  cursor: default;
}
.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

/* ---------------- dishes ---------------- */
.newdish {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}
.newdish .input {
  flex: 1;
}
.dishes {
  display: grid;
  gap: 16px;
}
.dish {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dish-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
}
.dish-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 2px 4px;
  border-radius: 6px;
}
.dish-title:focus {
  outline: none;
  background: var(--surface-2);
}
.dish-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.dish-body {
  padding: 0 18px 16px;
}
.ings {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 2px;
}
.ing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
}
.ing:hover {
  background: var(--surface-2);
}
.ing-name {
  font-size: 14.5px;
  font-weight: 500;
}
.ing-qty {
  font-size: 13px;
  color: var(--muted);
}
.ing-spacer {
  flex: 1;
}
.ing .icon-btn {
  opacity: 0;
}
.ing:hover .icon-btn {
  opacity: 1;
}
.badge-dup {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-press);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  cursor: help;
}
.add-ing {
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-ing .input {
  padding: 8px 11px;
  font-size: 14px;
}
.add-ing .ing-name-in {
  flex: 2;
}
.add-ing .ing-qty-in {
  flex: 1;
  min-width: 80px;
}
.dish-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.recipe-steps {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.recipe-steps h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.recipe-steps ol {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

/* ---------------- empty ---------------- */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty .big {
  font-size: 30px;
  margin-bottom: 8px;
}

/* ---------------- week ---------------- */
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.palette-label {
  font-size: 12px;
  color: var(--muted);
  align-self: center;
  margin-right: 4px;
}
.chip {
  font-size: 13.5px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 7px 13px;
  border-radius: 999px;
  cursor: grab;
  user-select: none;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.chip:hover {
  border-color: var(--accent);
}
.chip.is-selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip.dragging {
  opacity: 0.5;
}
.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}
.day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 130px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.12s, border-color 0.12s;
}
.day.drop-hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.day.can-place {
  border-style: dashed;
  border-color: var(--accent);
}
.day-name {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.day-dishes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.plan-chip {
  font-size: 13px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: grab;
}
.plan-chip .nm {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.plan-chip .x {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}
.plan-chip .x:hover {
  color: var(--accent-press);
}

/* ---------------- grocery ---------------- */
.grocery-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
}
.seg-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.grocery {
  display: grid;
  gap: 10px;
}
.gcat {
  margin-bottom: 6px;
}
.gcat h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 16px 0 8px;
}
.gitem {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.gitem.checked .g-name {
  text-decoration: line-through;
  color: var(--muted);
}
.check {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background 0.12s, border-color 0.12s;
}
.check:checked {
  background: var(--ok);
  border-color: var(--ok);
}
.check:checked::after {
  content: "✓";
  color: #fff;
  font-size: 13px;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.g-name {
  font-weight: 500;
  font-size: 15px;
}
.g-meta {
  font-size: 13px;
  color: var(--muted);
}
.g-spacer {
  flex: 1;
}

/* ---------------- modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(53, 47, 42, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade 0.15s ease;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(53, 47, 42, 0.25);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 600;
}
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}
.sugg {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: grid;
  gap: 4px;
}
.sugg li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
}
.sugg li:hover {
  background: var(--surface-2);
}
.sugg .s-name {
  flex: 1;
  font-size: 14.5px;
  font-weight: 500;
}
.sugg .s-qty {
  font-size: 13px;
  color: var(--muted);
}
.modal-note {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 14px;
}
.modal-steps {
  margin-top: 8px;
}
.modal-steps summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-press);
}
.modal-steps ol {
  margin: 10px 0 0;
  padding-left: 20px;
  font-size: 14px;
  display: grid;
  gap: 6px;
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(53, 47, 42, 0.3);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------- spinner ---------------- */
.spin {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------- responsive ---------------- */
@media (max-width: 760px) {
  .week {
    grid-template-columns: repeat(2, 1fr);
  }
  .topbar-inner {
    height: 58px;
  }
  h1 {
    font-size: 24px;
  }
}
@media (max-width: 460px) {
  .week {
    grid-template-columns: 1fr;
  }
  .tab {
    padding: 7px 12px;
  }
  .newdish {
    flex-direction: column;
  }
}
