:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-alt: #f4ece1;
  --border: #e4d9ca;
  --text: #3b2f27;
  --muted: #7a6a5c;
  --accent: #c4633f;
  --accent-soft: #f6e5dc;
  --accent-text: #ffffff;
  --danger: #a8402b;
  --success: #4f7a4a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(59, 47, 39, .06), 0 8px 24px rgba(59, 47, 39, .06);
  --space: 1rem;
}

[data-theme="dark"] {
  --bg: #1c1815;
  --surface: #26211d;
  --surface-alt: #2f2925;
  --border: #3d352e;
  --text: #f0e8de;
  --muted: #b1a294;
  --accent: #e08a63;
  --accent-soft: #3a2b23;
  --accent-text: #1c1815;
  --danger: #e0705a;
  --success: #93c08c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #1c1815;
    --surface: #26211d;
    --surface-alt: #2f2925;
    --border: #3d352e;
    --text: #f0e8de;
    --muted: #b1a294;
    --accent: #e08a63;
    --accent-soft: #3a2b23;
    --accent-text: #1c1815;
    --danger: #e0705a;
    --success: #93c08c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
p { margin: 0; }
a { color: var(--accent); }

.container {
  width: 100%;
  max-width: 56rem;
  margin: 0 auto;
  padding: var(--space);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: var(--space); }
.stack--tight { gap: .35rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: var(--space); }
.page-head { display: flex; flex-direction: column; gap: .25rem; }
.page-head--row { flex-direction: row; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }

/* Recipes */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1; min-width: 8rem; }
.filters select { width: auto; }

.list__item--link { padding: 0; transition: background-color .12s ease, border-color .12s ease; }
.list__item--link:hover, .list__item--link:focus-within { background: var(--accent-soft); border-color: var(--accent); }

.list__cover {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: .1rem;
  padding: .75rem;
  color: inherit;
  text-decoration: none;
}

.list__cover span { font-size: .85rem; }
.list__aside { margin: .5rem .75rem .5rem 0; }

.stepper {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: .15rem .5rem .15rem .15rem;
}

.stepper__btn {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.stepper__btn:hover { background: var(--accent); color: var(--accent-text); }
.stepper__value { min-width: 1.5rem; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }
.stepper__label { color: var(--muted); font-size: .8125rem; }

/* Shopping list */
.shop-item { padding: 0; gap: 0; }
.shop-item__form { flex: 1; min-width: 0; display: flex; }

.shop-item__toggle {
  display: flex;
  align-items: center;
  gap: .625rem;
  flex: 1;
  min-width: 0;
  padding: .625rem .75rem;
  font: inherit;
  text-align: left;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.shop-item__toggle:hover { background: var(--accent-soft); }
.shop-item.is-checked .shop-item__name,
.shop-item.is-checked .shop-item__amount { text-decoration: line-through; color: var(--muted); }

.shop-item__check {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-size: .9rem;
  font-weight: 700;
}

.shop-item.is-checked .shop-item__check { background: var(--accent-soft); border-color: var(--accent); }
.shop-item__amount { min-width: 4.5rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.shop-item__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-item__delete { flex: none; padding-right: .375rem; }

.add-item { display: flex; gap: .375rem; align-items: center; }
.add-item input[name="quantity"] { width: 3.5rem; flex: none; }
.add-item select { width: 5rem; flex: none; }
.add-item input[name="name"] { flex: 1; min-width: 0; }
.add-item input, .add-item select { padding: .45rem .5rem; }
.add-item .btn { flex: none; min-height: 2.4rem; padding: .35rem .85rem; font-size: 1.1rem; }

.export {
  margin: 0;
  padding: .75rem;
  max-height: 18rem;
  overflow: auto;
  white-space: pre-wrap;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .875rem;
}

/* Weekly plan */
.plan-day { flex-direction: column; align-items: stretch; gap: .5rem; }
.plan-day__head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.plan-day__date { display: flex; gap: .5rem; align-items: baseline; }
.plan-day__date span { font-size: .8125rem; }
.plan-day__title { font-weight: 650; color: var(--text); text-decoration: none; }
.plan-day__title:hover { color: var(--accent); }
.plan-day__actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.plan-day__swap { flex: 1; min-width: 10rem; }

@media (min-width: 768px) {
  .plan-day { flex-direction: row; align-items: center; }
  .plan-day__head { width: 14rem; flex: none; }
  .plan-day__meal { flex: 1; min-width: 0; }
  .plan-day__actions { flex: none; }
  .plan-day__swap { min-width: 14rem; }
}

.ingredient-row { display: grid; grid-template-columns: 4.5rem 6rem 1fr; gap: .35rem; }
.ingredient-row input[name="ingredient_note"] { grid-column: 1 / -1; }

.ingredients { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.ingredients li { display: flex; gap: .6rem; border-bottom: 1px solid var(--border); padding-bottom: .35rem; }
.ingredients__amount { min-width: 5.5rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.steps { margin: 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: .5rem; }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding-block: .6rem;
}

.header__brand {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.header__brand span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo { width: 1.7rem; height: 1.7rem; flex: none; }
.logo__accent { stroke: var(--accent); }

.header__actions { display: flex; align-items: center; gap: .5rem; }
.header__switch { display: flex; gap: .25rem; }
.header__switch select { max-width: 9rem; }

.chip {
  display: none;
  padding: .2rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: .8125rem;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  text-decoration: none;
  flex: none;
}

.avatar--sm { width: 1.9rem; height: 1.9rem; font-size: .8rem; }

/* Cards & lists */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space);
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.list__item {
  display: flex;
  align-items: center;
  gap: .625rem;
  flex-wrap: wrap;
  padding: .625rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
}

.list__body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.list__body span { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }
.list__actions { display: flex; gap: .375rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .75rem;
  font-weight: 600;
}

.badge--member { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  letter-spacing: .08em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .2rem .5rem;
}

.placeholder { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.placeholder ul { margin: 0; padding-left: 1.1rem; }

/* Forms */
label { font-size: .875rem; font-weight: 600; color: var(--muted); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .625rem .75rem;
  width: 100%;
  min-width: 0;
}

.row input { flex: 1; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:disabled { background: var(--surface-alt); color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font: inherit;
  font-weight: 600;
  padding: .625rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 2.75rem;
}

.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn--danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn--sm { padding: .35rem .625rem; min-height: 2.25rem; font-size: .8125rem; }
.btn--block { width: 100%; }
.btn:hover { filter: brightness(.97); }

.flash {
  padding: .75rem 1rem;
  border-radius: 10px;
  margin-bottom: var(--space);
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.flash--error { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.flash--success { border-color: color-mix(in srgb, var(--success) 40%, transparent); color: var(--success); }

/* Auth */
.auth { max-width: 26rem; margin: 3rem auto 0; text-align: center; display: flex; flex-direction: column; gap: .5rem; }
.auth__logo { display: flex; justify-content: center; color: var(--text); }
.auth__logo .logo { width: 4rem; height: 4rem; }
.auth__card { display: flex; flex-direction: column; gap: var(--space); text-align: left; }
.auth__intro { text-align: center; }
.dev-login summary { cursor: pointer; color: var(--muted); font-size: .875rem; }
.dev-login form { margin-top: .75rem; }

/* Navigation: bottom bar on mobile, inline in the header on desktop */
.nav--top { display: none; }

.nav--bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  padding: .55rem .25rem;
  font-size: .7rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}

.nav__icon { font-size: 1.15rem; line-height: 1; }
.nav__item.is-active { color: var(--accent); }

@media (min-width: 768px) {
  body { padding-bottom: var(--space); }
  h1 { font-size: 1.875rem; }
  .grid--2 { grid-template-columns: 1fr 1fr; }
  .chip { display: inline-block; }
  .nav--bottom { display: none; }
  .ingredient-row { grid-template-columns: 4.5rem 6rem 1fr 1fr; }
  .ingredient-row input[name="ingredient_note"] { grid-column: auto; }

  .nav--top {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex: 1;
    justify-content: center;
  }

  .nav--top .nav__item {
    flex-direction: row;
    gap: .4rem;
    font-size: .875rem;
    padding: .35rem .7rem;
    border-radius: 999px;
    white-space: nowrap;
  }

  .nav--top .nav__item.is-active { background: var(--accent-soft); }
  .nav--top .nav__icon { font-size: 1rem; }
}
