:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --surface-2: #f1ebe4;
  --text: #2a2220;
  --muted: #6f625c;
  --line: #e4dbd2;
  --accent: #8f1d22;
  --accent-ink: #ffffff;
  --accent-soft: #f7e3e0;
  --steaks: #b3322f;
  --roasts: #b8741a;
  --stew: #5f7a3a;
  --other: #5b6b8c;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --shadow: 0 1px 2px rgba(60, 30, 20, 0.06), 0 4px 14px rgba(60, 30, 20, 0.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171312;
    --surface: #221c1a;
    --surface-2: #2c2422;
    --text: #f2ebe7;
    --muted: #b3a59e;
    --line: #3a302d;
    --accent: #e0645c;
    --accent-ink: #1b0f0e;
    --accent-soft: #3b2220;
    --steaks: #e0645c;
    --roasts: #e0a447;
    --stew: #9dbb6f;
    --other: #93a6cc;
    --warn: #f0b860;
    --warn-soft: #3a2c16;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171312; --surface: #221c1a; --surface-2: #2c2422; --text: #f2ebe7; --muted: #b3a59e;
  --line: #3a302d; --accent: #e0645c; --accent-ink: #1b0f0e; --accent-soft: #3b2220;
  --steaks: #e0645c; --roasts: #e0a447; --stew: #9dbb6f; --other: #93a6cc;
  --warn: #f0b860; --warn-soft: #3a2c16; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.3rem; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); margin: 0; }
.eyebrow {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 6px;
}
[hidden] { display: none !important; }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; }
.top-link { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem; }
.top-link:hover { color: var(--text); }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 10px 18px; font-weight: 700; cursor: pointer;
  min-height: 44px; transition: transform 0.08s, background 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.icon-btn {
  appearance: none; border: 0; background: var(--surface-2); border-radius: 999px;
  width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Executive summary */
.summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin: 20px 0 28px;
}
.total { display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; }
.total-num { font-size: 3.2rem; font-weight: 900; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.total-label { font-size: 1.05rem; color: var(--muted); font-weight: 600; }
.categories { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.cat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.cat-top { display: flex; flex-direction: column-reverse; gap: 2px; }
.cat-name { font-weight: 700; font-size: 0.9rem; line-height: 1.25; }
.cat-num { font-weight: 900; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.cat-bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.cat-bar span { display: block; height: 100%; border-radius: 3px; }
.cat-sub { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.notes { display: grid; gap: 8px; margin-top: 14px; }
.note {
  display: flex; gap: 10px; align-items: flex-start; font-size: 0.95rem;
  padding: 10px 12px; border-radius: 10px; background: var(--surface-2);
}
.note.warn { background: var(--warn-soft); }
.note b { white-space: nowrap; }
.note .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-top: 8px; flex: none; }
.note.warn .dot { background: var(--warn); }

/* Inventory */
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }
.group { margin-bottom: 22px; }
.group-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  margin: 0 0 8px;
}
.group-title i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.cuts { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .cuts { grid-template-columns: 1fr 1fr; } }
.cut {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: grid; gap: 12px;
  grid-template-columns: 1fr auto; align-items: center;
}
.cut.empty { opacity: 0.6; }
.cut-open {
  appearance: none; background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  display: grid; gap: 2px; min-width: 0;
}
.cut-name { font-weight: 800; font-size: 1.05rem; }
.cut-note { color: var(--muted); font-size: 0.85rem; }
.cut-ideas { color: var(--accent); font-size: 0.85rem; font-weight: 700; }
.cut-open:hover .cut-name { text-decoration: underline; text-underline-offset: 3px; }
.cut-count { text-align: right; }
.cut-count b { font-size: 2rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; display: block; }
.cut-count span { font-size: 0.75rem; color: var(--muted); }
.pkgs { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 5px; }
.pkg { width: 18px; height: 18px; border-radius: 5px; }
.pkg.gone { background: transparent !important; border: 2px dashed var(--line); }
.cut-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.cut-actions .use { flex: 1; }
.cut-actions .add { width: 48px; padding: 0; font-size: 1.3rem; }

/* Add form */
.add-cut {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 16px; margin: 8px 0 28px;
}
.add-cut summary { cursor: pointer; font-weight: 700; padding: 12px 0; }
.add-form { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; padding-bottom: 16px; }
.add-form label { display: grid; gap: 4px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.add-form label:first-child { grid-column: 1 / -1; }
.add-form input, .add-form select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.add-form .btn { grid-column: 1 / -1; }

/* History */
#history { padding-bottom: 60px; scroll-margin-top: 70px; }
#history h2 { margin-bottom: 10px; }
.log { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.log li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log .what { flex: 1; min-width: 0; }
.log .when { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.log .undone .what { text-decoration: line-through; color: var(--muted); }
.log .tag { font-size: 0.75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.log .tag.plus { background: var(--surface-2); color: var(--stew); }
.log .link-btn { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 4px; }
.log .empty-row { color: var(--muted); }

/* Dinner ideas dialog */
.ideas {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(640px, 100vw); max-height: min(88vh, 900px);
  border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.ideas[open] { display: flex; flex-direction: column; }
.ideas::backdrop { background: rgba(20, 10, 8, 0.55); }
@media (max-width: 640px) {
  .ideas { margin: auto 0 0; max-width: 100vw; width: 100vw; max-height: 92vh; border-radius: 18px 18px 0 0; }
}
.ideas-head { display: flex; justify-content: space-between; gap: 12px; padding: 18px 18px 10px; border-bottom: 1px solid var(--line); }
.ideas-head h2 { font-size: 1.35rem; }
.ideas-list { overflow-y: auto; padding: 12px 18px; display: grid; gap: 12px; }
.ideas-foot { display: flex; gap: 10px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.ideas-foot .btn { flex: 1; }
.recipe { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.recipe summary { list-style: none; cursor: pointer; padding: 14px; display: grid; gap: 4px; }
.recipe summary::-webkit-details-marker { display: none; }
.recipe-title { font-weight: 800; font-size: 1.05rem; display: flex; justify-content: space-between; gap: 10px; }
.recipe-title::after { content: "+"; color: var(--accent); font-weight: 900; }
.recipe[open] .recipe-title::after { content: "–"; }
.recipe-meta { font-size: 0.85rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.recipe-meta .ai { color: var(--other); font-weight: 700; }
.recipe-body { padding: 0 14px 14px; }
.recipe-body h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 12px 0 6px; }
.recipe-body ul, .recipe-body ol { margin: 0; padding-left: 1.2em; }
.recipe-body li { margin-bottom: 4px; }
.recipe-sides { margin: 12px 0 0; font-size: 0.95rem; }
.loading { color: var(--muted); padding: 14px; text-align: center; }

/* Lock screen */
.lock { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.lock-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 24px; text-align: center; box-shadow: var(--shadow); display: grid; gap: 10px;
}
.lock-icon { width: 36px; height: 36px; fill: var(--accent); margin: 0 auto; }
.lock-card p { margin: 0; color: var(--muted); }
.lock-card input {
  text-align: center; font-size: 1.6rem; letter-spacing: 0.3em; padding: 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); width: 100%;
}
.error { color: var(--accent) !important; font-weight: 600; min-height: 1.5em; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); border-radius: 999px;
  padding: 10px 10px 10px 20px; display: flex; align-items: center; gap: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3); max-width: calc(100vw - 32px);
}
.toast-undo { background: none; border: 0; color: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; padding: 6px 10px; }

/* Login and account */
.top-nav { display: flex; align-items: center; gap: 14px; }
.me { color: var(--muted); font-size: 0.9rem; }
.link-btn { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: var(--accent); font-weight: 700; }
.top-link.link-btn { color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.top-link.link-btn:hover { color: var(--text); }
.lock-logo { margin: 0 auto; }
.lock-card input[type="email"] { font-size: 1.05rem; letter-spacing: 0; text-align: left; padding: 12px 14px; }
.lock-card .small { font-size: 0.9rem; }
.log .who { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
@media (max-width: 420px) { .me { display: none; } }
