/* ── Tokens ───────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #efebe3;
  --text: #1c2420;
  --muted: #6a736d;
  --line: #e5e0d6;
  --primary: #2d6b4c;
  --primary-hover: #245a3f;
  --primary-ink: #ffffff;
  --primary-soft: #e2eee6;
  --primary-soft-ink: #234f39;
  --danger: #b93f2a;
  --danger-soft: #fbe9e5;
  --shadow: 0 1px 2px rgb(30 35 30 / 6%), 0 6px 24px -8px rgb(30 35 30 / 12%);
  --ring: 0 0 0 3px rgb(45 107 76 / 30%);

  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 64px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101412;
    --surface: #181d1a;
    --surface-2: #212823;
    --text: #edf1ee;
    --muted: #97a29b;
    --line: #29312c;
    --primary: #5dbb8a;
    --primary-hover: #74c99c;
    --primary-ink: #0b1a12;
    --primary-soft: #1d3628;
    --primary-soft-ink: #a6dcbe;
    --danger: #f0806b;
    --danger-soft: #3a1f1a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 28px -10px rgb(0 0 0 / 50%);
    --ring: 0 0 0 3px rgb(93 187 138 / 35%);
  }
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

h1, h2 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.6rem, 4vw, 2rem); font-weight: 750; }
h2 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
small { color: var(--muted); font-size: 0.82rem; font-weight: 400; }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.icon { flex: none; }

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

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 10px; }

/* ── Layout ───────────────────────────────────────────────── */
.page {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.page-wide { max-width: 1080px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 0;
}
.page-head p { margin-top: 4px; }
.head-row { display: flex; align-items: center; gap: 8px; }

.stack { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card > h2 { margin-bottom: 12px; }
section.card.stack > h2 { margin-bottom: 0; }

/* ── Navigation ───────────────────────────────────────────── */
.topbar { display: none; }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--primary); }

@media (min-width: 768px) {
  body { padding-bottom: 32px; }
  .tabbar { display: none; }

  .topbar {
    display: block;
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: saturate(1.4) blur(16px);
    -webkit-backdrop-filter: saturate(1.4) blur(16px);
    border-bottom: 1px solid var(--line);
  }
  .topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 750; font-size: 1.1rem; }
  .brand .icon { color: var(--primary); }
  .topnav { display: flex; gap: 4px; }
  .topnav a {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
  }
  .topnav a:hover { color: var(--text); background: var(--surface-2); }
  .topnav a[aria-current="page"] { color: var(--primary-soft-ink); background: var(--primary-soft); }
  .page { padding-top: 32px; }
}

/* ── Buttons & fields ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-soft { background: var(--primary-soft); border-color: transparent; color: var(--primary-soft-ink); }
.btn-soft:hover { background: color-mix(in srgb, var(--primary-soft) 80%, var(--primary)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn-icon { width: 48px; min-height: 48px; padding: 0; flex: none; }

.icon-link {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 999px;
  color: var(--muted);
}
.icon-link:hover { background: var(--surface-2); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 650; font-size: 0.92rem; }

input, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* ≥16px stops iOS zooming on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
textarea { resize: vertical; line-height: 1.7; }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 550;
}
.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-soft-ink);
  font-weight: 550;
}

/* ── Auth ─────────────────────────────────────────────────── */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(60rem 30rem at 10% -10%, var(--primary-soft), transparent 60%),
    radial-gradient(40rem 30rem at 110% 110%, color-mix(in srgb, var(--primary-soft) 60%, transparent), transparent 60%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.auth-card form { margin-top: 16px; }
.auth-logo {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
}

/* ── Shopping list ────────────────────────────────────────── */
.progress {
  appearance: none;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}
.progress::-webkit-progress-bar { background: var(--surface-2); }
.progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; transition: width 0.3s ease; }
.progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }

.add-bar {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.add-bar input { border: 0; background: transparent; padding-left: 14px; box-shadow: none; min-height: 48px; }
.add-bar:focus-within { box-shadow: var(--shadow), var(--ring); }

.entries { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 4px 14px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-soft-ink);
  font-size: 0.9rem;
  font-weight: 600;
}
.chip button {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border: 0; border-radius: 999px;
  background: transparent; color: inherit;
  cursor: pointer;
}
.chip button:hover { background: color-mix(in srgb, var(--primary) 18%, transparent); }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.items li + li { border-top: 1px solid var(--line); }

.item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 58px;
  padding: 12px 18px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.item:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.item:focus-visible { border-radius: 0; box-shadow: inset var(--ring); }

.box {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent);
  border-radius: 9px;
  color: transparent;
  transition: background 0.18s, border-color 0.18s, transform 0.18s cubic-bezier(.3, 1.6, .5, 1);
}
.item-text { transition: color 0.18s; }

.item.is-checked .box {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  transform: scale(1.06);
}
.item.is-checked .item-text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.list-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }

/* ── Empty states ─────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 16px;
  text-align: center;
}
.empty p { max-width: 34ch; }
.empty .btn { margin-top: 8px; }
.empty-art {
  display: grid; place-items: center;
  width: 88px; height: 88px;
  margin-bottom: 6px;
  border-radius: 28px;
  background: var(--primary-soft);
  color: var(--primary);
}
.empty-code { font-size: 3rem; font-weight: 800; color: var(--primary); }

/* ── Recipes ──────────────────────────────────────────────── */
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}
.search input { border: 0; background: transparent; padding-left: 0; box-shadow: none; }
.search:focus-within { box-shadow: var(--ring); border-color: var(--primary); }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 14px;
}

.recipe { display: flex; flex-direction: column; gap: 12px; padding: 16px 16px 14px; }
.recipe-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.recipe-head h2 { padding-top: 8px; overflow-wrap: anywhere; }
.recipe-head .icon-link { margin: -2px -6px 0 0; }

.ingredients {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  align-content: flex-start;
}
.ingredients li {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.86rem;
}
.ingredients li.muted { background: transparent; }

.recipe-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-size: 0.86rem;
  font-weight: 650;
}

/* ── Recipe editor ────────────────────────────────────────── */
.recipe-editor { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .recipe-editor { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  .preview-card { position: sticky; top: 88px; }
}

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

.eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Grid so every amount pill shares the widest pill's width. */
.preview { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; }
.preview li { display: contents; }
.amount {
  padding: 2px 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-soft-ink);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.amount-none { background: var(--surface-2); color: var(--muted); font-weight: 500; }

.danger-zone { display: flex; justify-content: flex-start; }

/* ── Account ──────────────────────────────────────────────── */
.profile { display: flex; align-items: center; gap: 14px; }
.avatar {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 750;
  font-size: 1.2rem;
}
.avatar-sm { width: 30px; height: 30px; font-size: 0.85rem; background: var(--primary-soft); color: var(--primary-soft-ink); }

.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.members li { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: 14px; color: var(--muted); }
.copy-row .btn.is-copied { background: var(--primary); color: var(--primary-ink); }

/* ── Motion ───────────────────────────────────────────────── */
.htmx-request .item, .htmx-request.item-form .item { opacity: 0.85; }

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