/* Obiady — prywatna książka kucharska. Mobile first. */

:root {
  --bg: #fbf8f3;
  --surface: #fff;
  --surface-2: #f4efe6;
  --ink: #1a1713;
  --muted: #6d6459;
  --line: #e5dfd4;
  --accent: #bf4429;
  --accent-soft: #fbe9e3;
  --olive: #4e6a3e;
  --olive-soft: #eaf0e3;
  --amber: #9a6b12;
  --amber-soft: #f8eed6;

  --r: 14px;
  --pad: 16px;
  --tap: 46px;
  --shadow: 0 1px 2px rgba(26, 23, 19, .06), 0 8px 24px -16px rgba(26, 23, 19, .3);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1e1b17;
    --surface-2: #262218;
    --ink: #f3ede3;
    --muted: #9c9385;
    --line: #2f2a23;
    --accent: #e2694b;
    --accent-soft: #35211b;
    --olive: #9dbb84;
    --olive-soft: #1f2719;
    --amber: #d9a94a;
    --amber-soft: #2b2313;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -18px #000;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.02em; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- logowanie ---------- */

body.gate { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }

.login { width: 100%; max-width: 320px; text-align: center; }
.login-mark { font-size: 34px; font-weight: 800; letter-spacing: -.04em; color: var(--accent); }
.login-sub { margin: 4px 0 28px; color: var(--muted); font-size: 14px; }
.login form { display: grid; gap: 10px; }
.login input {
  height: var(--tap); padding: 0 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); text-align: center;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login button {
  height: var(--tap); border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 650; cursor: pointer;
}
.login-err { color: var(--accent); font-size: 14px; }

/* ---------- szkielet ---------- */

#top {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.bar {
  display: flex; align-items: center; gap: 8px;
  min-height: 54px; padding: 0 var(--pad);
}
.bar h1 { font-size: 21px; flex: 1; }
.bar-actions { display: flex; gap: 6px; }

#view { padding: 12px var(--pad) calc(96px + env(safe-area-inset-bottom)); }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  position: relative; display: grid; justify-items: center; gap: 3px;
  padding: 9px 0 7px; color: var(--muted); font-size: 11px; font-weight: 600;
}
#tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--accent); }
#tabs b {
  position: absolute; top: 4px; right: calc(50% - 22px);
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}

/* ---------- elementy wspolne ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); font-size: 14px;
  font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.icon { min-width: 38px; padding: 0 9px; }
.btn.wide { width: 100%; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border: 0; border-radius: 999px; background: var(--surface-2);
  font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.chip.meat { background: var(--accent-soft); color: var(--accent); }
.chip.veg { background: var(--olive-soft); color: var(--olive); }
.chip.keep { background: var(--amber-soft); color: var(--amber); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding: 0 var(--pad) 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; height: 32px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface); font-size: 13px;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.filters button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
/* oddziela filtry zawężające od tagów kategorii (te działają na LUB) */
.filters .fdiv { flex: none; width: 1px; align-self: stretch; margin: 4px 4px; background: var(--line); }

.search { padding: 0 var(--pad) 10px; }
.search input {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface);
}

.empty { padding: 48px 16px; text-align: center; color: var(--muted); font-size: 15px; }
.section-title {
  margin: 22px 0 8px; font-size: 12px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}

/* ---------- lista przepisow ---------- */

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 359px) { .grid { grid-template-columns: 1fr; } }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden;
}
.card:active { transform: scale(.985); }
.card .ph { position: relative; aspect-ratio: 4/3; background: var(--surface-2); }
.card .ph img { width: 100%; height: 100%; object-fit: cover; }
.card .fav {
  position: absolute; top: 2px; right: 2px; width: 36px; height: 36px;
  border: 0; background: none; cursor: pointer; font-size: 17px; color: #fff;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .6));
}
.card .fav.on { color: #ffd45e; }
.card .fav:active { transform: scale(.85); }
.card .keepbadge {
  position: absolute; left: 7px; bottom: 7px; padding: 2px 7px; border-radius: 999px;
  background: rgba(20, 18, 16, .78); color: #fff; font-size: 10.5px; font-weight: 700;
  border: 1px solid transparent;
}
/* wyblakłe = moja podpowiedź, pełny kolor = decyzja użytkownika */
.card .keepbadge.guess { background: rgba(20, 18, 16, .45); font-weight: 500; }
.chip.keep.guess { background: transparent; color: var(--muted); }

/* ---------- moje oznaczenia ---------- */

ul.marks { list-style: none; margin: 0; padding: 0; }
ul.marks li {
  display: flex; align-items: center; gap: 10px; padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}
ul.marks img { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; flex: none; }
ul.marks .m-name { flex: 1; min-width: 0; }
ul.marks .m-name b { display: block; font-size: 14.5px; line-height: 1.25; }
ul.marks .m-name span { font-size: 12px; color: var(--muted); }
ul.marks .fav { border: 0; background: none; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px; }
ul.marks .fav.on { color: #d9a12c; }
ul.marks .keeptoggle {
  flex: none; min-width: 84px; height: 32px; border: 1px solid var(--line);
  border-radius: 999px; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 700; cursor: pointer; opacity: .5;
}
ul.marks li.keep .keeptoggle { color: var(--amber); border-color: var(--amber); }
ul.marks li.mine .keeptoggle { opacity: 1; background: var(--surface-2); }
ul.marks li.keep.mine .keeptoggle { background: var(--amber-soft); }
.card .txt { padding: 9px 10px 11px; }
.card h3 { font-size: 14.5px; line-height: 1.25; }
.card .meta { margin-top: 5px; display: flex; gap: 8px; font-size: 12px; color: var(--muted); }

/* ---------- przepis ---------- */

.hero { margin: -12px calc(var(--pad) * -1) 0; position: relative; }
.hero img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.hero .play {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: linear-gradient(transparent 45%, rgba(15,13,11,.55));
  cursor: pointer; border: 0; width: 100%;
}
.hero .play span {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px;
  border-radius: 999px; background: rgba(255,255,255,.94); color: #17140f;
  font-weight: 700; font-size: 14px;
}
.hero iframe { width: 100%; aspect-ratio: 16/9; border: 0; display: block; }
.hero iframe.vertical { aspect-ratio: 9/16; max-height: 78vh; }
.hero .yt-out {
  display: block; padding: 8px var(--pad); font-size: 13px;
  color: var(--muted); text-decoration: underline; text-align: center;
}

.r-head { padding: 16px 0 4px; }
.r-head h2 { font-size: 25px; line-height: 1.15; }
.r-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.r-actions { display: flex; gap: 8px; margin: 14px 0 4px; }
.r-actions .btn { flex: 1; }

.scaler { display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; }
.scaler .lbl { font-size: 13px; color: var(--muted); flex: 1; }
.scaler button {
  width: 44px; height: 32px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--muted);
}
.scaler button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

ul.ings { list-style: none; margin: 0; padding: 0; }
ul.ings li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 9px 2px; border-bottom: 1px solid var(--line); cursor: pointer;
}
ul.ings li .q { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
ul.ings li .n { flex: 1; }
ul.ings li .n em { display: block; font-style: normal; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
ul.ings li.off { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
ul.ings li.off .n em { text-decoration: none; }
ul.ings li.swapped .n { color: var(--olive); font-weight: 600; }
ul.ings .swap {
  flex: none; width: 32px; height: 28px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--muted); font-size: 13px; cursor: pointer;
  align-self: center;
}
ul.ings .swap:active { transform: scale(.9); }

.swapnote {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--olive-soft); color: var(--olive); font-size: 13px; line-height: 1.4;
}
.swapnote b { font-weight: 700; }
.linkbtn { border: 0; background: none; padding: 0; color: inherit; font: inherit;
  text-decoration: underline; cursor: pointer; }

.rnote { margin: 0 0 8px; font-size: 14.5px; }
.source { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.hero .noimg {
  aspect-ratio: 16/7; display: grid; place-items: center; background: var(--surface-2);
  color: var(--muted); font-size: 13px; letter-spacing: .05em;
}

/* ---------- formularz własnego przepisu ---------- */

.form { display: grid; gap: 14px; padding-bottom: 12px; }
.fld { display: grid; gap: 5px; }
.fld > span { font-size: 12.5px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.fld input[type=text], .fld input:not([type]), .fld input[type=number], .fld select, .fld textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); font-size: 16px;
}
.fld textarea { resize: vertical; line-height: 1.5; font-family: inherit; }
.fld small { font-size: 12px; color: var(--muted); }
.fld.check { grid-auto-flow: column; justify-content: start; align-items: center; gap: 10px; }
.fld.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.fld.check span { font-size: 15px; font-weight: 500; color: var(--ink); }
.fld-row { display: flex; gap: 10px; }
.fld-row .fld { flex: 1; min-width: 0; }
.fld .thumb { margin-top: 8px; width: 120px; height: 90px; object-fit: cover; border-radius: 10px; }
.form-actions { display: grid; gap: 8px; margin-top: 6px; }
ul.ings .grp {
  border: 0; padding: 16px 0 4px; font-size: 12px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; color: var(--accent); cursor: default;
}

ol.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
ol.steps li {
  counter-increment: s; display: grid; grid-template-columns: 26px 1fr; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
ol.steps li::before {
  content: counter(s); font-size: 13px; font-weight: 800; color: var(--accent);
  padding-top: 2px; font-variant-numeric: tabular-nums;
}
ol.steps li.off { color: var(--muted); }
ol.steps li.off::before { color: var(--muted); }

/* ---------- tydzien ---------- */

.day {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); margin-bottom: 10px; overflow: hidden;
}
.day.today { border-color: var(--accent); }
.day-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.day-head .dw { font-weight: 700; font-size: 14px; text-transform: capitalize; }
.day-head .dd { font-size: 12px; color: var(--muted); flex: 1; }
.day-head .warn { font-size: 11px; font-weight: 700; color: var(--amber); }
.dish { display: flex; gap: 10px; padding: 10px 12px; align-items: center; }
.dish + .dish { border-top: 1px solid var(--line); }
.dish img { width: 54px; height: 54px; border-radius: 9px; object-fit: cover; flex: none; }
.dish .d-txt { flex: 1; min-width: 0; }
.dish .d-txt b { display: block; font-size: 14.5px; line-height: 1.25; }
.dish .d-sub { margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; }
.dish.leftover { background: var(--amber-soft); }
.dish.done b { text-decoration: line-through; color: var(--muted); }
.day-add {
  display: block; width: 100%; padding: 12px; border: 0; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; text-align: left;
}

/* ---------- zakupy ---------- */

.shop-add { display: flex; gap: 8px; margin-bottom: 12px; }
.shop-add input {
  flex: 1; height: 42px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface);
}
ul.shop { list-style: none; margin: 0 0 4px; padding: 0; }
ul.shop li {
  display: flex; align-items: center; gap: 11px; padding: 11px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
ul.shop .box {
  width: 21px; height: 21px; border: 1.8px solid var(--line); border-radius: 6px;
  flex: none; display: grid; place-items: center; font-size: 13px; color: transparent;
}
ul.shop li.on .box { background: var(--olive); border-color: var(--olive); color: #fff; }
ul.shop li.on .nm { text-decoration: line-through; color: var(--muted); }
ul.shop .nm { flex: 1; font-size: 15px; }
ul.shop .qty { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
ul.shop li.have .nm::after {
  content: 'masz'; margin-left: 7px; padding: 1px 6px; border-radius: 999px;
  background: var(--olive-soft); color: var(--olive); font-size: 10.5px; font-weight: 700;
  text-decoration: none; display: inline-block; vertical-align: middle;
}
ul.shop .del { color: var(--muted); padding: 0 4px; font-size: 17px; }

/* ---------- lodowka ---------- */

.pantry-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px; margin-bottom: 14px;
}
.pantry-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.pantry-tags .chip { background: var(--olive-soft); color: var(--olive); padding: 5px 10px; font-size: 13px; }
.pantry-tags .chip b { cursor: pointer; opacity: .6; font-weight: 700; }
.pantry-in { position: relative; }
.pantry-in input {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--bg);
}
.sugg {
  position: absolute; left: 0; right: 0; top: 46px; z-index: 5;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 240px; overflow: auto;
}
.sugg button {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  border: 0; background: none; font-size: 15px; cursor: pointer;
}
.sugg button + button { border-top: 1px solid var(--line); }

.match { display: flex; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); align-items: center; }
.match img { width: 58px; height: 58px; border-radius: 9px; object-fit: cover; flex: none; }
.match .m-txt { flex: 1; min-width: 0; }
.match .m-txt b { font-size: 14.5px; line-height: 1.25; display: block; }
.match .miss { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.match .miss em { font-style: normal; color: var(--accent); font-weight: 600; }
.match .pct { font-size: 13px; font-weight: 800; color: var(--olive); font-variant-numeric: tabular-nums; }

/* ---------- sheet ---------- */

#sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-bg { position: absolute; inset: 0; background: rgba(16, 13, 10, .5); }
.sheet-box {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 8px var(--pad) calc(18px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(14px); opacity: .4; } }
/* uchwyt i ✕ — na telefonie tło bywa zasłonięte, musi być co dotknąć */
.sheet-grab {
  flex: none; width: 100%; height: 22px; border: 0; background: none;
  cursor: pointer; display: grid; place-items: center; padding: 0; margin-bottom: 6px;
}
.sheet-grab::before { content: ''; width: 40px; height: 4px; border-radius: 2px; background: var(--muted); opacity: .45; }
.sheet-grab:active::before { opacity: .8; }
.sheet-x {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface);
  color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer; z-index: 2;
}
.sheet-x:active { transform: scale(.9); }
.sheet-body { overflow: auto; -webkit-overflow-scrolling: touch; }
.sheet-body h3 { font-size: 18px; margin-bottom: 12px; padding-right: 40px; }
.sheet-list { list-style: none; margin: 0; padding: 0; }
.sheet-list li { border-bottom: 1px solid var(--line); }
.sheet-list button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 2px;
  border: 0; background: none; text-align: left; font-size: 15px; cursor: pointer;
}
.sheet-list img { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; flex: none; }
.sheet-list .s-sub { font-size: 12px; color: var(--muted); }
.sheet-body a { color: var(--accent); text-decoration: underline; }

.form-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.form-row > label { flex: 1; font-size: 15px; }
.form-row input[type=date], .form-row input[type=number], .form-row select, .form-row input[type=password] {
  height: 38px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--surface);
}
.form-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.seg { display: flex; gap: 4px; }
.seg button {
  height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

#toast {
  position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 70;
  background: var(--ink); color: var(--bg); padding: 10px 16px;
  border-radius: 999px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
