:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2b2622;
  --muted: #7a6f66;
  --line: #e7e0d6;
  --accent: #c2572b;
  --accent-soft: #f6e4da;
  --fav: #e0a100;
  --danger: #b3261e;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--accent); }
nav { display: flex; gap: 4px; }
nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge:not(:empty) {
  display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 2px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: .75rem; text-align: center;
}
main { max-width: 900px; margin: 0 auto; padding: 20px 16px 80px; }
h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card);
  padding: 7px 14px; border-radius: 8px; color: var(--text); text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.icon { border: none; background: none; padding: 4px 6px; font-size: 1.15rem; line-height: 1; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
textarea { resize: vertical; }
label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 4px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 200px; width: auto; }
.import { display: flex; gap: 8px; margin-bottom: 20px; }
.import input { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.card .thumb { aspect-ratio: 16/10; background: var(--accent-soft) center/cover no-repeat; display: block; }
.card .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-weight: 600; text-decoration: none; }
.card .actions { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.fav { color: var(--line); }
.fav.on { color: var(--fav); }
.in-plan { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.hero { width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--radius); margin-bottom: 16px; }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.ingredients .qty { font-weight: 600; }
.steps li { margin-bottom: 8px; }
.servings input { width: 70px; }

.ing-table { width: 100%; border-collapse: collapse; }
.ing-table td { padding: 3px 4px 3px 0; }
.ing-table td:nth-child(1) { width: 90px; }
.ing-table td:nth-child(2) { width: 110px; }
.ing-table td:last-child { width: 36px; }

.plan-item, .shop-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px;
}
.plan-item .title { flex: 1; font-weight: 600; }
.plan-item input { width: 70px; }
.shop-item input[type=checkbox] { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.shop-item .name { flex: 1; min-width: 0; }
.shop-item .name small { display: block; color: var(--muted); font-size: .8rem; }
.shop-item .qty { width: 80px; }
.shop-item .unit { width: 90px; }
.shop-item.checked .name { text-decoration: line-through; color: var(--muted); }
.add-item { display: grid; grid-template-columns: 1fr 80px 90px auto; gap: 8px; margin-top: 16px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

.user { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.user button { padding: 4px 10px; font-size: .85rem; }

.login { max-width: 360px; padding-top: 12vh; }
.login h1 { text-align: center; color: var(--accent); }
.login button { width: 100%; margin-top: 18px; }
.login-error { color: var(--danger); margin: 12px 0 0; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; max-width: 90vw;
}
#toast.error { background: var(--danger); }

@media (max-width: 600px) {
  header { padding: 8px 12px; row-gap: 6px; }
  header nav { order: 3; width: 100%; }
  #username { display: none; }
  .add-item { grid-template-columns: 1fr 70px 80px; }
  .add-item button { grid-column: 1 / -1; }
  .shop-item .unit { width: 70px; }
  .shop-item .qty { width: 64px; }
}
