:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2421;
  --muted: #6b716d;
  --line: #e3dfd6;
  --accent: #2f6d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe8;
  --warn: #b3261e;
  --chip: #efece5;
  --weekday: #2f6d4f;
  --weekend: #9a5b13;
  --radius: 12px;
  --tabs-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816; --card: #1f2321; --ink: #ecefed; --muted: #9aa39e; --line: #323835;
    --accent: #5fb38a; --accent-ink: #0d1a13; --accent-soft: #23362c; --chip: #2a2f2c;
    --weekday: #5fb38a; --weekend: #e0a25a; --warn: #ff8a80;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); }
.top {
  position: sticky; top: 0; z-index: 5; background: var(--accent); color: var(--accent-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
main { max-width: 760px; margin: 0 auto; padding: 12px; }
.pad { padding: 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
h1 { font-size: 22px; margin: 8px 4px 12px; }
h2 { font-size: 17px; margin: 20px 4px 8px; }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); font-size: 12px; gap: 2px;
}
.tabs a .ico { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.on .ico { filter: none; opacity: 1; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; min-height: 42px; white-space: nowrap;
}
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 8px; min-height: 36px; }
button.danger { color: var(--warn); }
button.small, .btn.small { padding: 5px 10px; min-height: 34px; font-size: 14px; }
button:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; width: 100%; min-height: 42px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.chip.weekday { background: var(--accent-soft); color: var(--weekday); }
.chip.weekend { background: color-mix(in srgb, var(--weekend) 15%, transparent); color: var(--weekend); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { min-height: 34px; padding: 5px 12px; font-size: 14px; border-radius: 99px; }
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* This week / fridge list */
.meal { display: flex; gap: 12px; align-items: center; }
.meal .tick {
  width: 34px; height: 34px; min-height: 34px; border-radius: 50%; padding: 0; justify-content: center;
  border: 2px solid var(--line); flex: none; font-size: 18px; color: transparent;
}
.meal.cooked .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.meal.cooked .name { text-decoration: line-through; color: var(--muted); }
.meal .name { font-weight: 650; font-size: 18px; line-height: 1.25; }
.meal .where { font-size: 15px; margin-top: 2px; }
.meal .where b { font-weight: 600; }
.meal .btns { display: flex; flex-direction: column; gap: 2px; }
.counts { display: flex; gap: 8px; margin: 0 4px 12px; flex-wrap: wrap; }

/* Recipe list */
.list .item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list .item .title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; }
.list .item .meta { font-size: 13px; color: var(--muted); }
.addbtn { min-width: 76px; justify-content: center; }
.addbtn.added { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }

/* Shopping */
.shop-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.shop-item:last-child { border-bottom: 0; }
.shop-item input[type=checkbox] { width: 22px; height: 22px; min-height: 22px; margin-top: 1px; flex: none; accent-color: var(--accent); }
.shop-item.have .txt { text-decoration: line-through; color: var(--muted); }
.shop-item .for { display: block; font-size: 12px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; margin: 0; color: var(--ink); font-size: 15px; }
.check input { width: 20px; height: 20px; min-height: 20px; flex: none; accent-color: var(--accent); }

/* Edit form ingredient rows */
.ing-row { display: grid; grid-template-columns: 1fr 56px 88px 30px; gap: 6px; margin-bottom: 6px; align-items: center; }
.ing-row .extra { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.ing-row input, .ing-row select { padding: 7px 8px; font-size: 15px; }
.ing-row .rm { padding: 0; min-height: 34px; justify-content: center; }
.new-tag { font-size: 11px; color: var(--weekend); }

table.ings { width: 100%; border-collapse: collapse; }
table.ings td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ings td.q { white-space: nowrap; color: var(--muted); width: 1%; padding-right: 12px; }

.login { max-width: 360px; margin: 12vh auto 0; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.warnbox { border-color: var(--weekend); }
.err { color: var(--warn); }
pre.code { background: var(--chip); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: .2s; max-width: 90vw; z-index: 10; font-size: 15px;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media print {
  .top, .tabs, .actions, .meal .btns, .noprint { display: none !important; }
  body { padding: 0; background: #fff; }
  .card { border: 0; border-bottom: 1px solid #ccc; border-radius: 0; }
}
