:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #0f172a;
  --text-dim: #64748b;
  --primary: #4f7cff;
  --primary-soft: #e3ecff;
  --accent: #bb9af7;
  --danger: #ef4444;
  --success: #10b981;
  --border: #e2e8f0;
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --radius: 14px;
  --radius-lg: 22px;
  --nav-h: 64px;
  --input-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tap: 44px;
  --ease: cubic-bezier(.22,.61,.36,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2e;
    --surface-2: #1b2440;
    --text: #e8ecf5;
    --text-dim: #8b94ad;
    --primary: #7aa2f7;
    --primary-soft: #1e2a4d;
    --accent: #bb9af7;
    --border: #1f2a47;
    --shadow: 0 6px 20px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(15px, 4.1vw, 17px);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  line-height: 1.4;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  width: 100%;
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- Layout shell ---------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-t);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; }
.topbar .icon-btn { font-size: 1.4rem; min-width: var(--tap); min-height: var(--tap); display: grid; place-items: center; border-radius: 12px; }
.topbar .icon-btn:active { background: var(--surface-2); }

.view {
  flex: 1;
  padding: 16px 14px calc(var(--nav-h) + var(--input-h) + var(--safe-b) + 24px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.bottom-nav button {
  min-height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .02em;
  transition: color .15s var(--ease), transform .15s var(--ease);
}
.bottom-nav button .ico { font-size: 1.4rem; line-height: 1; }
.bottom-nav button.active { color: var(--primary); }
.bottom-nav button:active { transform: scale(.94); }

/* ---------- Cards / List rows ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
}
.card.tap { transition: transform .12s var(--ease); }
.card.tap:active { transform: scale(.985); }

.row { display: flex; align-items: center; gap: 12px; }
.row.spread { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.color-dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 14px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.2); }
.muted { color: var(--text-dim); }
.small { font-size: .85rem; }
.right { margin-left: auto; }
.grow { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  min-height: var(--tap);
  transition: transform .12s var(--ease), background .15s var(--ease);
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--primary); color: white; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: white; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: .85rem; min-height: 36px; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 18px);
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 1.8rem;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px rgba(79, 124, 255, .45);
  z-index: 25;
  transition: transform .15s var(--ease);
}
.fab:active { transform: scale(.92); }

/* ---------- List items ---------- */
.items { display: flex; flex-direction: column; gap: 0; }
.cat-heading {
  display: flex; align-items: center; gap: 8px;
  font-size: .78rem; font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 14px 6px 6px;
}
.cat-heading .ico { font-size: 1rem; }

.item {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(15,23,42,.04);
  transition: opacity .2s var(--ease), background .15s var(--ease);
}
.item.dragging { opacity: .5; }
.item.drop-target { background: var(--primary-soft); }
.item .check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: all .15s var(--ease);
}
.item.done .check { background: var(--primary); border-color: var(--primary); color: white; }
.item.done .name { text-decoration: line-through; color: var(--text-dim); }
.item .name { font-weight: 500; line-height: 1.25; }
.item .meta { font-size: .8rem; color: var(--text-dim); }
.item .qty-pill {
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface-2);
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.item .handle {
  color: var(--text-dim);
  font-size: 1.1rem;
  padding: 0 4px;
  cursor: grab;
  touch-action: none;
}

.divider {
  text-align: center;
  color: var(--text-dim);
  font-size: .78rem;
  margin: 18px 0 8px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ---------- Swipe ---------- */
.swipe { position: relative; overflow: hidden; border-radius: var(--radius); margin-bottom: 8px; }
.swipe-bg {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  font-size: 1.1rem;
  color: white;
  border-radius: var(--radius);
}
.swipe-bg.left { background: linear-gradient(90deg, var(--success), color-mix(in srgb, var(--success) 70%, white)); }
.swipe-bg.right { background: linear-gradient(90deg, color-mix(in srgb, var(--danger) 70%, white), var(--danger)); }
.swipe-fg { position: relative; z-index: 1; transition: transform .25s var(--ease); }
.swipe.dragging .swipe-fg { transition: none; }

/* ---------- Input bar (sticky bottom) ---------- */
.input-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  z-index: 28;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.input-bar .field {
  display: flex; gap: 8px; align-items: center;
}
.input-bar input {
  border-radius: 999px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-color: transparent;
}
.input-bar .add {
  background: var(--primary);
  color: white;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.input-bar .add:active { transform: scale(.94); }
.input-bar .add[disabled] { opacity: .4; }

/* ---------- Suggest ---------- */
.suggest {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(100% + 6px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  max-height: 50dvh;
  overflow-y: auto;
}
.suggest .s-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.suggest .s-item:last-child { border-bottom: 0; }
.suggest .s-item.active { background: var(--primary-soft); }
.suggest .s-item .ico { font-size: 1.2rem; }
.suggest .s-item .name { flex: 1; font-weight: 500; }
.suggest .s-item .hint { font-size: .8rem; color: var(--text-dim); }

/* ---------- Modal / Bottom Sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  animation: fade .2s var(--ease);
}
.sheet {
  background: var(--surface);
  width: 100%;
  border-radius: 24px 24px 0 0;
  padding: 14px 18px calc(18px + var(--safe-b));
  max-height: 90dvh;
  overflow-y: auto;
  animation: slide-up .25s var(--ease);
}
.sheet h2 { margin: 6px 0 14px; font-size: 1.1rem; }
.sheet .grabber {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 12px;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--input-h) + var(--safe-b) + 14px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  z-index: 60;
  animation: toast-in .25s var(--ease);
  max-width: 90vw;
}
.toast .undo {
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: .78rem;
  letter-spacing: .05em;
}
@keyframes toast-in { from { transform: translate(-50%, 40px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Color swatches ---------- */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 16px; }
.swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: transform .15s var(--ease);
}
.swatch.active { border-color: var(--text); transform: scale(1.1); }

/* ---------- Recipes ---------- */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.recipe-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.recipe-card .img {
  aspect-ratio: 4/3;
  background: var(--surface-2);
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
}
.recipe-card .info {
  padding: 10px 12px 12px;
}
.recipe-card .info h3 { margin: 0 0 4px; font-size: .98rem; }
.recipe-card .info p { margin: 0; font-size: .78rem; color: var(--text-dim); }

.servings {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px;
}
.servings button {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface);
  font-weight: 700;
  font-size: 1.1rem;
}
.servings .v { font-weight: 700; min-width: 30px; text-align: center; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty .ico { font-size: 3rem; }
.empty h2 { margin: 12px 0 6px; color: var(--text); font-size: 1.1rem; }

/* ---------- Misc ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 600;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .85rem;
  margin: 4px 4px 0 0;
}
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }

label.field-label {
  font-size: .8rem; color: var(--text-dim); font-weight: 600;
  display: block; margin: 12px 0 6px;
}

.ing-row {
  display: grid;
  grid-template-columns: 1fr 60px 56px 36px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.ing-row input { padding: 10px; border-radius: 10px; font-size: .9rem; }
.ing-row button.x { color: var(--danger); font-size: 1.2rem; min-height: var(--tap); min-width: var(--tap); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
