:root {
  --bg: #fbf6ec;
  --card: #fffdf8;
  --ink: #2b1d12;
  --ink-2: #4a3626;        /* secondary text: still dark, never faint gray */
  --line: #e4d6bd;
  --accent: #a8461f;       /* terracotta */
  --accent-ink: #ffffff;
  --accent-soft: #f6e3d6;
  --good: #2f6b2f; --good-soft: #e1f0dc;
  --okay: #7a5a00; --okay-soft: #f8edc8;
  --bad: #9b2c2c; --bad-soft: #f8dede;
  --changed: #1f5a8a; --changed-soft: #e0ecf7;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 14px;
  --head: 'Fraunces', Georgia, serif;
  --body: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1712; --card: #26201a; --ink: #f6eee2; --ink-2: #dccdb8; --line: #43372b;
    --accent: #e0814f; --accent-ink: #1c1712; --accent-soft: #3e2a1e;
    --good: #9fd69a; --good-soft: #233a22; --okay: #f0d27a; --okay-soft: #3b3219;
    --bad: #f3a3a3; --bad-soft: #432323; --changed: #9cc8f0; --changed-soft: #1d3247;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1712; --card: #26201a; --ink: #f6eee2; --ink-2: #dccdb8; --line: #43372b;
  --accent: #e0814f; --accent-ink: #1c1712; --accent-soft: #3e2a1e;
  --good: #9fd69a; --good-soft: #233a22; --okay: #f0d27a; --okay-soft: #3b3219;
  --bad: #f3a3a3; --bad-soft: #432323; --changed: #9cc8f0; --changed-soft: #1d3247;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 18px/1.5 var(--body); }
h1, h2, h3 { font-family: var(--head); font-weight: 700; line-height: 1.15; margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { min-height: 80vh; display: grid; place-items: center; text-align: center; font-family: var(--head); font-size: 22px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px 80px; }
.top { display: flex; align-items: center; gap: 12px; padding: 18px 0 8px; }
.top .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.top .brand img { width: 40px; height: 40px; }
.top h1 { font-size: 28px; }
.top .spacer { flex: 1; }
.menu { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 16px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; }

/* search */
.searchbox { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 12px; }
.search { position: relative; }
.search input { width: 100%; min-height: 58px; padding: 12px 52px 12px 52px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--card); font-size: 20px; box-shadow: var(--shadow); }
.search input:focus { outline: none; border-color: var(--accent); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.search .icon { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; color: var(--ink-2); }
.search .clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 16px; margin: 8px 4px 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card);
  font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { font-weight: 400; margin-left: 4px; }

.section-title { font-size: 24px; margin: 26px 0 12px; display: flex; align-items: baseline; gap: 10px; }
.section-title .count { font: 600 16px var(--body); color: var(--ink-2); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.card:hover { border-color: var(--accent); }
.card h3 { font-size: 20px; }
.card .meta { color: var(--ink-2); font-size: 15px; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.card .why { margin-top: 8px; font-size: 16px; color: var(--ink); }
.card .why b { background: var(--accent-soft); border-radius: 4px; padding: 0 2px; font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 14px; font-weight: 700; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.okay { background: var(--okay-soft); color: var(--okay); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.changed { background: var(--changed-soft); color: var(--changed); }
.empty { text-align: center; padding: 40px 10px; color: var(--ink-2); }

/* recipe */
.back { display: inline-flex; margin: 6px 0 10px; }
.recipe-head h1 { font-size: 36px; margin-top: 4px; }
.recipe-head .intro { font-family: var(--head); font-style: italic; font-size: 20px; color: var(--ink-2); margin-top: 6px; }
.recipe-head .facts { display: flex; gap: 8px 16px; flex-wrap: wrap; margin-top: 10px; color: var(--ink-2); font-size: 16px; }
.recipe-head .facts b { color: var(--ink); }
.tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 6px; }
.cols { display: grid; grid-template-columns: minmax(280px, 2fr) 3fr; gap: 20px; margin-top: 16px; align-items: start; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.panel h2 { font-size: 24px; margin-bottom: 8px; }
.panel h3.grp { font: 700 16px var(--body); text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin: 14px 0 4px; }
.ings { list-style: none; padding: 0; margin: 0; }
.ings li { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.ings li:last-child { border-bottom: 0; }
.ings input[type=checkbox] { width: 24px; height: 24px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.ings li.done .txt { text-decoration: line-through; opacity: .6; }
.steps { padding-left: 0; margin: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 8px 0 12px 44px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 6px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; }
.tips { margin: 0; padding-left: 22px; }
.tips li { margin: 6px 0; }
.chg { display: inline-flex; margin-left: 6px; vertical-align: 2px; border: 0; cursor: pointer; }
.was { margin: 6px 0 0; padding: 8px 12px; background: var(--changed-soft); border-radius: 10px; font-size: 16px; }
.was .old { text-decoration: line-through; }
.photo { width: 100%; max-height: 420px; object-fit: cover; border-radius: var(--radius); margin-top: 14px; border: 1px solid var(--line); }

/* notes */
.notes { margin-top: 26px; }
.note-form, .note { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 12px; }
.note-form { border: 2px solid var(--accent); }
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg); min-height: 46px; }
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); }
.rate { display: flex; gap: 8px; flex-wrap: wrap; }
.rate button { min-height: 46px; padding: 6px 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--bg); font-weight: 700; cursor: pointer; }
.rate button[aria-pressed="true"][data-r="good"] { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.rate button[aria-pressed="true"][data-r="okay"] { background: var(--okay-soft); border-color: var(--okay); color: var(--okay); }
.rate button[aria-pressed="true"][data-r="bad"] { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.note .when { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-weight: 700; }
.note .body { white-space: pre-wrap; margin-top: 6px; }
.note .next { margin-top: 8px; padding: 8px 12px; background: var(--okay-soft); border-radius: 10px; white-space: pre-wrap; }
.note .locked { margin-top: 10px; padding: 8px 12px; background: var(--changed-soft); border-radius: 10px; font-size: 16px; }
.note .locked ul { margin: 4px 0 0; padding-left: 20px; }
.note .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.history li { margin: 8px 0; }
.history .undone { opacity: .6; text-decoration: line-through; }

/* dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(30, 20, 10, .45); }
.dlg { padding: 18px 20px; }
.dlg h2 { font-size: 24px; margin-bottom: 6px; }
.change { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.change .row select { flex: 1 1 180px; min-height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); padding: 6px 8px; }
.change textarea { width: 100%; margin-top: 8px; min-height: 60px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); padding: 8px 10px; }
.change .from { font-size: 16px; color: var(--ink-2); margin-top: 6px; }
.dlg .foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; position: sticky; bottom: 0; background: var(--card); padding-top: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px;
  border-radius: 999px; font-weight: 600; z-index: 50; max-width: calc(100vw - 32px); }
.err { color: var(--bad); font-weight: 600; margin-top: 8px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }

.signin { max-width: 440px; margin: 10vh auto 0; text-align: center; }
.signin img { width: 84px; height: 84px; }
.signin h1 { font-size: 36px; margin: 10px 0 4px; }
.signin p { color: var(--ink-2); }
.signin .field { text-align: left; }
.signin input { font-size: 22px; text-align: center; }
.foot-stamp { text-align: center; color: var(--ink-2); font-size: 14px; margin-top: 40px; }

@media (max-width: 760px) {
  body { font-size: 17px; }
  .top h1 { font-size: 22px; }
  .top .brand img { width: 34px; height: 34px; }
  .cols { grid-template-columns: 1fr; }
  .recipe-head h1 { font-size: 30px; }
  .menu .btn .lbl { display: none; }
}
@media print {
  .top, .searchbox, .tools, .notes, .back, .foot-stamp, .chg, .history-panel { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .cols { grid-template-columns: 1fr 1.6fr; }
}
