:root {
  --bg: #EBEBEF;
  --card: #FFFFFF;
  --ink: #333C4D;
  --text: #272D24;
  --muted: #737467;
  --primary: #526A97;
  --primary-soft: #C9D2E3;
  --primary-light: #A9BFE7;
  --ingredients: #DDE6F7;
  --ingredient-divider: #D3DCED;
  --divider: #E4E4E4;
  --backing: #D9D9D9;
  --danger: #B3261E;
  --easy: #00861F;
  --medium: #D75A00;
  --hard: #D70000;
  --shadow: 0 6px 18px rgba(51, 60, 77, .10);
  --radius: 16px;
  --head: "Unbounded", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171C; --card: #22252D; --ink: #E4E8F1; --text: #E2E5DE; --muted: #9C9E93;
    --primary: #6F8BC2; --primary-soft: #2E3A52; --primary-light: #3A4766; --ingredients: #1B2232;
    --ingredient-divider: #2C3550; --divider: #2C2F36; --backing: #2C2F36;
    --shadow: 0 6px 18px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--body);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--head); color: var(--ink); margin: 0; letter-spacing: -.01em; }
h1 { font-size: clamp(26px, 4vw, 36px); font-weight: 700; line-height: 1.15; }
h2 { font-size: 20px; font-weight: 500; }
.muted { color: var(--muted); }

/* ---------- Верхня панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; font: 700 18px var(--head); color: var(--ink); }
.brand img { border-radius: 9px; }
.tabs { display: flex; gap: 4px; padding: 5px; background: var(--card); border-radius: 26px; box-shadow: var(--shadow); }
.tabs a { padding: 7px 16px; border-radius: 22px; color: var(--muted); font-size: 14px; }
.tabs a.active { background: var(--primary); color: #EEE; font-weight: 700; }

main { max-width: 1180px; margin: 0 auto; padding: 8px 16px 120px; }

/* ---------- Книга ---------- */
.page-head { display: flex; align-items: baseline; gap: 10px; margin: 18px 4px 16px; flex-wrap: wrap; }
.page-head .count { color: var(--muted); font-size: 16px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 14px; background: var(--card); border-radius: 12px;
}
.search input { flex: 1; border: 0; outline: 0; background: transparent; min-width: 0; }
.search svg { flex: none; color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; max-width: 100%; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 18px; border: 0;
  background: var(--card); color: var(--ink); font-size: 14px; white-space: nowrap;
}
.chip.active { background: var(--primary); color: #EEE; font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 26px 20px; }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 14px; } }

.card { position: relative; display: block; }
.card .backing {
  position: absolute; inset: 6px 4px -6px 4px; background: var(--backing);
  border-radius: var(--radius); transform: rotate(-3deg); transition: transform .2s;
}
.card:nth-child(even) .backing { transform: rotate(3deg); }
.card:hover .backing { transform: rotate(0deg) translateY(4px); }
.card .face { position: relative; background: var(--card); border-radius: var(--radius); overflow: hidden; height: 100%; }
.card .photo { aspect-ratio: 4 / 5; background: var(--primary-soft); object-fit: cover; width: 100%; }
.card .info { padding: 10px 12px 12px; display: grid; gap: 4px; }
.card .title {
  font: 500 14px/1.3 var(--head); color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.add-btn {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: color-mix(in srgb, var(--card) 92%, transparent); color: var(--ink);
  display: grid; place-items: center; box-shadow: var(--shadow); transition: transform .15s, background .15s;
}
.add-btn:hover { transform: scale(1.06); }
.add-btn.on { background: var(--primary); color: #fff; }

.badge { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--bg); }
.badge.easy { color: var(--easy); } .badge.medium { color: var(--medium); } .badge.hard { color: var(--hard); }
.placeholder { display: grid; place-items: center; color: var(--muted); }

.empty { text-align: center; padding: 60px 16px; color: var(--muted); }
.empty h2 { margin-bottom: 8px; }

/* ---------- Рецепт ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin: 14px 0 10px; font-size: 14px; }
.back:hover { color: var(--ink); }
.recipe-hero { display: grid; grid-template-columns: minmax(0, 380px) 1fr; gap: 32px; align-items: start; }
.recipe-hero .cover { border-radius: 22px; overflow: hidden; aspect-ratio: 4 / 5; background: var(--primary-soft); }
.recipe-hero .cover img { width: 100%; height: 100%; object-fit: cover; }
.hero-text { display: grid; gap: 14px; padding-top: 6px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; }
.fact { background: var(--card); border-radius: 12px; padding: 8px 12px; font-size: 14px; color: var(--ink); }
.fact b { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.summary { font-size: 16px; line-height: 1.6; margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border-radius: 24px; border: 0;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 15px;
}
.btn.ghost { background: var(--card); color: var(--ink); }
.btn:disabled { background: var(--muted); cursor: default; opacity: .7; }
.source { font-size: 13px; color: var(--muted); }
.source a { text-decoration: underline; }

.recipe-body { display: grid; grid-template-columns: minmax(0, 380px) 1fr; gap: 32px; margin-top: 32px; align-items: start; }
.ingredients { background: var(--ingredients); border-radius: 22px; padding: 18px; position: sticky; top: 76px; }
.ingredients h2 { margin-bottom: 12px; }
.portions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg); border-radius: 10px; padding: 6px 6px 6px 12px; margin-bottom: 10px;
}
.portions small { display: block; font-size: 11px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; background: var(--bg); border-radius: 20px; }
.portions .stepper { background: transparent; }
.stepper button { width: 34px; height: 34px; border: 0; background: transparent; font-size: 20px; color: var(--ink); border-radius: 50%; }
.stepper button:disabled { color: var(--muted); cursor: default; }
.stepper span { min-width: 22px; text-align: center; font-weight: 600; color: var(--primary); }
.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--ingredient-divider); }
.ing-list li:last-child { border-bottom: 0; }
.ing-list .amount { color: var(--ink); font-weight: 600; text-align: right; white-space: nowrap; }
.ing-list label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.ing-list input { accent-color: var(--primary); margin-top: 4px; }
.ing-list li.done .name { text-decoration: line-through; color: var(--muted); }

.steps { display: grid; gap: 18px; }
.steps > h2 { margin-bottom: -4px; }
.step { background: var(--card); border-radius: 22px; overflow: hidden; display: grid; grid-template-columns: 220px 1fr; }
.step.noimg { grid-template-columns: 1fr; }
.step img { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 3 / 4; background: var(--primary-soft); cursor: zoom-in; }
.step .txt { padding: 16px 18px; display: grid; gap: 6px; align-content: start; }
.step .num { font: 500 12px var(--head); color: var(--primary); }
.step h3 { font-size: 16px; font-weight: 500; }
.step p { margin: 0; font-size: 15px; line-height: 1.6; }
.step b { color: var(--ink); }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 20px; cursor: zoom-out; }
.lightbox img { max-height: 92vh; border-radius: 12px; }

@media (max-width: 820px) {
  .recipe-hero, .recipe-body { grid-template-columns: 1fr; gap: 20px; }
  .recipe-hero .cover { aspect-ratio: 4 / 3; max-height: 60vh; }
  .ingredients { position: static; }
}
@media (max-width: 520px) {
  .step { grid-template-columns: 1fr; }
  .step img { aspect-ratio: 4 / 3; }
}

/* ---------- Меню ---------- */
.menus { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.menu-card { background: var(--card); border-radius: var(--radius); padding: 16px; display: grid; gap: 8px; transition: transform .15s; }
.menu-card:hover { transform: translateY(-2px); }
.menu-card h3 { font-size: 17px; font-weight: 500; }
.menu-card .who { font-size: 13px; color: var(--muted); }
.menu-card .dishes { font-size: 14px; }
.menu-card .covers { display: flex; }
.menu-card .covers img, .menu-card .covers .ph { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid var(--card); margin-left: -12px; background: var(--primary-soft); }
.menu-card .covers > :first-child { margin-left: 0; }
.menu-card .comment { font-size: 13px; color: var(--muted); font-style: italic; }

.menu-view { max-width: 760px; }
.menu-view .comment { background: var(--primary-soft); border-radius: 14px; padding: 14px 16px; margin: 16px 0; white-space: pre-wrap; }
.dish { display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.dish img, .dish .ph { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; flex: none; background: var(--primary-soft); }
.dish .grow { flex: 1; min-width: 0; display: grid; gap: 2px; }
.dish .name { font-weight: 600; color: var(--ink); }
.dish .sub { font-size: 13px; color: var(--muted); }
.dish .gone { color: var(--danger); font-size: 13px; }
.dish .remove { border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px; border-radius: 50%; font-size: 20px; }
.dish .remove:hover { background: var(--bg); color: var(--danger); }

.form { display: grid; gap: 12px; margin-top: 18px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .form .row { grid-template-columns: 1fr; } }
.field { display: grid; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); padding-left: 4px; }
.field input, .field textarea {
  border: 1.5px solid transparent; outline: 0; background: var(--card); border-radius: 12px; padding: 12px 14px; width: 100%;
}
.field input:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { min-height: 90px; resize: vertical; }
.error { color: var(--danger); font-size: 14px; }

/* ---------- Плаваюча панель чернетки меню ---------- */
.draftbar {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-radius: 28px;
  background: var(--primary); color: #fff; font-weight: 600; box-shadow: 0 10px 28px rgba(51, 60, 77, .3);
  white-space: nowrap;
}
.draftbar .n { background: #fff; color: var(--primary); border-radius: 12px; padding: 0 8px; font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 40;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px; font-size: 14px; box-shadow: var(--shadow);
}
.skeleton { background: linear-gradient(90deg, var(--card), var(--bg), var(--card)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { to { background-position: -200% 0; } }
[hidden] { display: none !important; }

@media (max-width: 520px) {
  .brand span { display: none; }
  .tabs a { padding: 7px 12px; font-size: 13px; }
}
