:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #2b2420;
  --muted: #7d726a;
  --line: #ece4da;
  --brand: #b5432f;
  --brand-ink: #ffffff;
  --warn: #b3261e;
  --ok: #2e7d4f;
  --chip: #f2ece4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917; --card: #262220; --ink: #f1ebe4; --muted: #a89e95;
    --line: #3a3430; --brand: #d9654f; --chip: #342e2a; --ok: #5cb67f; --warn: #f07167;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.45;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); text-decoration: none; }
img { max-width: 100%; display: block; }
code { background: var(--chip); padding: 0 4px; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { font-weight: 700; font-size: 18px; color: var(--ink); }
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 15px; }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }
h1 { font-size: 24px; margin: 6px 0 12px; }
h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 24px 0 8px; }
.headrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; overflow-wrap: anywhere; }
.card.notice { border-color: var(--brand); }
.checkcard { border-color: #e9c46a; }
.checkcard p { margin: 8px 0 2px; }
.shopitem form { margin: 0; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }
.meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.note { color: var(--muted); font-size: 12px; font-style: italic; }
.chip { display: inline-block; background: var(--chip); color: var(--muted); font-size: 12px;
  padding: 1px 8px; border-radius: 999px; margin: 2px 4px 2px 0; }
.chip.carried { background: #fff1d6; color: #8a5a00; }
.chip.warnchip { background: #fde8e6; color: var(--warn); }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 600; color: var(--ink); }

/* dinner rows */
.dinner { display: flex; align-items: center; gap: 12px; }
.dinner.done { opacity: .55; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; }
.thumb.empty, .tileimg.empty { display: grid; place-items: center; background: var(--chip); font-size: 24px; }
.btncol { display: flex; gap: 6px; flex: none; }

/* recipe grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; color: var(--ink); }
.tile.inactive { opacity: .5; }
.tileimg { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.tiletext { padding: 8px 10px 10px; }

/* recipe page */
.hero { width: 100%; max-height: 340px; object-fit: cover; border-radius: 12px; margin-bottom: 10px; }
.mynotes, .directions { white-space: pre-line; }
.mynotes { border-left: 4px solid var(--brand); }
.pantry { padding-top: 8px; }
.itemsphoto { max-width: 220px; border-radius: 8px; margin: 4px 0 6px; }
.pagephoto { margin-top: 10px; border-radius: 8px; }
summary { cursor: pointer; color: var(--muted); }

/* lists */
.list { padding: 4px 14px; }
.shopitem { display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--line); color: var(--ink); }
.shopitem:last-child { border-bottom: 0; }
.shopitem.checked .name, .struck { text-decoration: line-through; color: var(--muted); }
.shopitem.checked .pthumb { opacity: .4; }
.tick { width: 30px; height: 30px; padding: 0; border-radius: 50%; flex: none;
  border: 2px solid var(--line); background: transparent; color: var(--brand-ink); font-weight: 700; }
.shopitem.checked .tick { background: var(--ok); border-color: var(--ok); }
.pthumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; flex: none; }
.pthumb.big { width: 160px; height: auto; margin-bottom: 10px; }
.more { position: relative; flex: none; }
.more summary { list-style: none; padding: 4px 8px; font-size: 18px; }
.more summary::-webkit-details-marker { display: none; }
.more .menu { position: absolute; right: 0; top: 30px; z-index: 3; display: flex; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); }

/* forms */
form.stack label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 14px; }
form.stack label.check, label.check { display: flex; align-items: center; gap: 8px;
  font-weight: 400; margin: 8px 0; }
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 16px; font-family: inherit; background: var(--card); color: var(--ink);
}
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
textarea { resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1 1 160px; }
.row > div.narrow { flex: 0 0 90px; }
.orderrow { align-items: center; margin: 4px 0; }
.addrow { margin: 6px 0 12px; flex-wrap: nowrap; }
.addrow > select, .addrow > input { flex: 1; min-width: 0; }

button, .btn {
  display: inline-block; border: 0; border-radius: 8px; padding: 9px 14px; white-space: nowrap;
  font-size: 15px; font-family: inherit; cursor: pointer; background: var(--chip); color: var(--ink);
}
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); }
button.danger { background: #fde8e6; color: var(--warn); }
button.ok { background: var(--ok); color: #fff; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.actions form { margin: 0; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom)); }

@media (max-width: 480px) {
  .dinner { gap: 10px; }
  .thumb { width: 52px; height: 52px; }
  .dinner .btncol { flex-direction: column; }
  .dinner .btncol button { padding: 7px 10px; font-size: 14px; }
}

/* home */
.countgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 8px 0 10px; }
.countgrid form { margin: 0; }
button.count { width: 100%; padding: 22px 0; font-size: 28px; font-weight: 700;
  background: var(--brand); color: var(--brand-ink); border-radius: 14px; }
a.lastlist { display: block; color: var(--ink); }
a.lastlist .small { color: var(--brand); margin-top: 6px; }

/* plan ticks */
.ticks label.check { margin: 6px 0; }
.ticks.cols { columns: 2; column-gap: 16px; }
.ticks.cols label.check { break-inside: avoid; }
a.dinnerlink { display: block; color: var(--ink); font-weight: 600; }

.deletelist { margin-top: 28px; }
.deletelist p { margin: 6px 0 0; }

/* printable list */
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.sheethead { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; font-size: 14px; }
.sheethead span { color: var(--muted); font-size: 13px; }
.sheetcols { columns: 2 220px; column-gap: 20px; }
.sec { break-inside: avoid; margin-bottom: 10px; }
.secname { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--brand); border-bottom: 1px solid var(--line); margin-bottom: 3px; }
.line { display: flex; align-items: center; gap: 8px; min-height: 26px; font-size: 15px; }
.box { width: 13px; height: 13px; border: 1.5px solid var(--muted); border-radius: 3px; flex: none; }
.lname { flex: 1; }
.lthumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }

@media print {
  @page { margin: 12mm; }
  .topbar, .noprint, .actions { display: none !important; }
  body, .sheet { background: #fff !important; color: #000 !important; }
  .wrap { max-width: none; padding: 0; }
  .sheet { border: 0; padding: 0; }
  .sheetcols { columns: 3; column-gap: 8mm; }
  .line { min-height: 0; font-size: 10.5pt; line-height: 1.5; }
  .secname { color: #000; border-color: #999; font-size: 8.5pt; }
  .sheethead span { color: #333; }
}

/* back link + photo overlay (home-screen app has no browser chrome) */
a.back { display: inline-block; margin: 0 0 10px; font-size: 16px; padding: 4px 0; }
.zoom { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center; padding: 12px; }
.zoom[hidden] { display: none; }
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.zoomclose { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 18px;
  color: #fff; font-size: 26px; line-height: 1; }
