/* LowFOD · mobile-first stylesheet. No build step. */

:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #1d231f;
  --muted: #5d665f;
  --line: #d9ded8;
  --brand: #1f7a5c;
  --brand-ink: #ffffff;
  --like: #1f7a5c;
  --like-bg: #dff3ea;
  --dislike: #b3362f;
  --dislike-bg: #fbe3e0;
  --ok: #2e9e6b;
  --warn: #d59a1c;
  --danger: #c93b32;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 20px rgba(0, 0, 0, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --surface: #1b201d;
    --surface-2: #242a26;
    --text: #e8ece8;
    --muted: #a3aba5;
    --line: #333a35;
    --brand: #43b58c;
    --brand-ink: #0d1410;
    --like: #43b58c;
    --like-bg: #1c3b30;
    --dislike: #f07a70;
    --dislike-bg: #46221f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.25; }
p { margin: 0 0 0.75rem; }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 1rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.tabs { display: flex; gap: 0.25rem; background: var(--surface-2); padding: 0.2rem; border-radius: 999px; }
.tab { border: 0; background: transparent; padding: 0.4rem 0.9rem; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.view { display: grid; gap: 1rem; }
@media (min-width: 900px) {
  #view-generate { grid-template-columns: minmax(320px, 420px) 1fr; align-items: start; }
  .controls { position: sticky; top: 4.2rem; }
}
.controls { display: grid; gap: 1rem; }
.footer { max-width: 1100px; margin: 2rem auto; padding: 0 1rem; color: var(--muted); font-size: 0.85rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card-title { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.hint { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-weight: 600; }

/* ------------------------------------------------------------ controls */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { width: 44px; height: 44px; border: 0; background: var(--surface-2); font-size: 1.4rem; cursor: pointer; }
.stepper button:active { background: var(--line); }
.stepper output { min-width: 3.5rem; text-align: center; font-weight: 700; font-size: 1.25rem; }

.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.template-card {
  border: 2px solid var(--line); border-radius: 12px; background: var(--surface-2);
  padding: 0.75rem 0.5rem; text-align: center; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
}
.template-card:active { transform: scale(0.98); }
.template-card .icon { font-size: 1.6rem; display: block; }
.template-card .label { font-weight: 700; display: block; }
.template-card .tagline { font-size: 0.75rem; color: var(--muted); display: block; }
.template-card[aria-checked="true"] { border-color: var(--brand); background: var(--like-bg); }

.role-group { margin-top: 0.75rem; }
.role-group h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.35rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip, .chip-demo {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  padding: 0.35rem 0.7rem; font-size: 0.9rem; cursor: pointer; line-height: 1.2;
  display: inline-flex; align-items: center; gap: 0.3rem; user-select: none;
}
.chip[data-state="like"], .chip-demo.like { background: var(--like-bg); border-color: var(--like); color: var(--like); font-weight: 600; }
.chip[data-state="dislike"], .chip-demo.dislike { background: var(--dislike-bg); border-color: var(--dislike); color: var(--dislike); text-decoration: line-through; }
.chip .cls { font-size: 0.7rem; opacity: 0.7; }
.matrix-actions { margin-top: 0.75rem; }
.btn-link { border: 0; background: none; color: var(--brand); text-decoration: underline; cursor: pointer; padding: 0; }

.generate-bar { display: flex; gap: 0.5rem; position: sticky; bottom: 0.75rem; z-index: 5; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 0.8rem 1.1rem;
  font-weight: 700; cursor: pointer; box-shadow: var(--shadow); min-height: 48px;
}
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); flex: 1; }
.btn-sm { padding: 0.45rem 0.8rem; min-height: 38px; font-size: 0.9rem; box-shadow: none; }
.select-wrap select { font: inherit; padding: 0.45rem 0.6rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); }

/* -------------------------------------------------------------- recipe */
.recipe-card { padding: 1.25rem; }
.recipe-kicker { color: var(--muted); font-size: 0.85rem; text-transform: capitalize; margin-bottom: 0.25rem; }
.recipe-title { font-size: 1.5rem; }
.recipe-lineage { font-size: 0.85rem; color: var(--muted); }
.recipe-lineage a { color: var(--brand); }
.badge-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0 0.25rem; }
.badge { font-size: 0.75rem; font-weight: 600; padding: 0.2rem 0.55rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.badge.ok { background: var(--like-bg); color: var(--like); border-color: transparent; }
.badge.warn { background: #fff1d6; color: #7a5200; border-color: transparent; }
.badge.mine { background: var(--surface-2); }

.recipe-section { margin-top: 1.25rem; }
.recipe-section h3 { font-size: 1.05rem; }
.grocery { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.grocery th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0.25rem 0; }
.grocery td { padding: 0.45rem 0; border-top: 1px solid var(--line); vertical-align: top; }
.grocery td:nth-child(2), .grocery td:nth-child(3), .grocery th:nth-child(2), .grocery th:nth-child(3) { text-align: right; white-space: nowrap; }
.grocery .vol { display: block; color: var(--muted); font-size: 0.8rem; }
.grocery .role { display: block; color: var(--muted); font-size: 0.75rem; text-transform: capitalize; }
.steps { padding-left: 1.4rem; display: grid; gap: 0.6rem; }
.steps li::marker { color: var(--brand); font-weight: 700; }

.gauge { display: grid; gap: 0.5rem; }
.gauge-row { display: grid; grid-template-columns: 5.5rem 1fr 3.2rem; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.gauge-label { text-transform: capitalize; }
.gauge-track { position: relative; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.gauge-fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--ok); transition: width 0.3s; }
.gauge-fill.warn { background: var(--warn); }
.gauge-fill.danger { background: var(--danger); }
.gauge-mark { position: absolute; top: -2px; bottom: -2px; left: 85%; width: 2px; background: var(--text); opacity: 0.45; }
.gauge-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.gauge-value.danger { color: var(--danger); }

.action-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem; }
.action-row .btn { flex: 1 1 auto; }
.saved-link { width: 100%; display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; font-size: 0.9rem; }
.saved-link code { background: var(--surface-2); padding: 0.2rem 0.5rem; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* -------------------------------------------------------------- editor */
.editor { margin-top: 1.25rem; padding: 1rem; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--line); }
.editor h3 { font-size: 1.05rem; }
.editor-row { display: grid; grid-template-columns: 1fr 5.5rem; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.editor-row select, .editor-row input, .editor-title input {
  width: 100%; font: inherit; padding: 0.5rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.editor-row input { text-align: right; }
.editor-row .adjusted { outline: 2px solid var(--warn); }
.editor-title { margin: 0.75rem 0; }
.editor-note { font-size: 0.85rem; color: var(--muted); }
.editor-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

/* -------------------------------------------------------------- review */
.review { margin-top: 1.25rem; padding: 1rem; border-radius: 12px; border: 1px solid var(--line); }
.review h3 { font-size: 1.05rem; }
.review-aggregate { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.5rem; }
.tol-bar { display: flex; height: 8px; width: 120px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.tol-bar span { display: block; height: 100%; }
.tol-bar .g { background: #2e9e6b; } .tol-bar .y { background: #d59a1c; } .tol-bar .r { background: #c93b32; }
.stars { display: flex; gap: 0.15rem; }
.stars button { border: 0; background: none; font-size: 1.8rem; line-height: 1; cursor: pointer; color: var(--line); padding: 0.1rem; }
.stars button.on { color: #e0a80d; }
.gut-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.gut-row button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 0.45rem 0.8rem; cursor: pointer; }
.gut-row button.on { border-color: var(--brand); background: var(--like-bg); font-weight: 600; }
.review input[type="text"] { width: 100%; font: inherit; padding: 0.55rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); margin-bottom: 0.5rem; }
.review-done { color: var(--ok); font-weight: 600; }
.review-list { margin-top: 0.75rem; display: grid; gap: 0.5rem; font-size: 0.9rem; }
.review-item { padding: 0.5rem 0; border-top: 1px solid var(--line); }
.review-item .meta { color: var(--muted); font-size: 0.8rem; }

/* ---------------------------------------------------------------- feed */
.feed-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.feed-list { display: grid; gap: 0.6rem; }
@media (min-width: 700px) { .feed-list { grid-template-columns: repeat(2, 1fr); } }
.feed-card {
  text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 0.85rem; cursor: pointer;
  display: grid; gap: 0.35rem; width: 100%;
}
.feed-card:hover { border-color: var(--brand); }
.feed-card .title { font-weight: 700; font-size: 1.02rem; }
.feed-card .meta { color: var(--muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }

/* ----------------------------------------------------------- cook mode */
body.cook-mode .controls, body.cook-mode .topbar, body.cook-mode .footer,
body.cook-mode .gauge, body.cook-mode .gauge + .hint, body.cook-mode [data-field="editor"], body.cook-mode [data-field="review"] { display: none !important; }
body.cook-mode main { max-width: 760px; }
body.cook-mode #view-generate { grid-template-columns: 1fr; }
body.cook-mode .recipe-card { font-size: 1.2rem; }
body.cook-mode .steps { gap: 1rem; }
body.cook-mode .action-row .btn:not(.cook-toggle) { display: none; }

/* ------------------------------------------------------------- filters */
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 0.75rem; }
.filter-chip {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 0.4rem 0.8rem;
  font-size: 0.9rem; cursor: pointer; line-height: 1.2;
}
.filter-chip[aria-pressed="true"] { background: var(--like-bg); border-color: var(--brand); color: var(--like); font-weight: 600; }
.feed-card .badges { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.feed-card .badge { font-size: 0.72rem; }
.recipe-desc { color: var(--muted); font-size: 0.95rem; margin-top: 0.5rem; }
.recipe-source { font-size: 0.85rem; color: var(--muted); }
.recipe-source a { color: var(--brand); word-break: break-all; }
.badge.import { background: #e8f1fb; color: #1d4f8a; border-color: transparent; }
@media (prefers-color-scheme: dark) { .badge.import { background: #1c3350; color: #9cc4f5; } .badge.warn { background: #4a3a12; color: #f3cf7a; } }

/* ---------------------------------------------------------- shop & blog */
.recipe-column { display: grid; gap: 1rem; align-content: start; }
.shop .shop-group h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0.75rem 0 0.4rem; }
.shop-grid { display: grid; gap: 0.6rem; }
@media (min-width: 700px) { .shop-grid { grid-template-columns: repeat(2, 1fr); } }
.product-card { display: grid; grid-template-columns: auto 1fr; gap: 0.7rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); text-decoration: none; color: inherit; }
.product-card:hover { border-color: var(--brand); }
.product-card img { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background: #fff; }
.product-card .ph { width: 64px; height: 64px; border-radius: 8px; background: var(--like-bg); display: grid; place-items: center; font-size: 1.6rem; }
.product-card .pt { font-weight: 700; }
.product-card .pb { font-size: 0.85rem; color: var(--muted); }
.product-card .pm { font-size: 0.8rem; color: var(--brand); font-weight: 600; margin-top: 0.2rem; }
.disclosure { font-size: 0.75rem; color: var(--muted); margin-top: 0.75rem; }
.blog-list { display: grid; gap: 0.6rem; }
.blog-item { display: grid; gap: 0.2rem; padding: 0.8rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); text-decoration: none; color: inherit; }
.blog-item:hover { border-color: var(--brand); }
.blog-item .bt { font-weight: 700; font-size: 1.05rem; }
.blog-item .bd { font-size: 0.8rem; color: var(--muted); }
.post { max-width: 760px; margin: 0 auto; padding: 1.5rem; }
.post-title { font-size: 1.8rem; margin: 0.25rem 0 1rem; }
.post-body { font-size: 1.05rem; line-height: 1.65; }
.post-body h2 { font-size: 1.35rem; margin-top: 1.5rem; }
.post-body h3 { font-size: 1.1rem; margin-top: 1.25rem; }
.post-body img { border-radius: 10px; }
.post-body blockquote { border-left: 3px solid var(--brand); margin: 1rem 0; padding: 0.25rem 1rem; color: var(--muted); }
.post-body pre { background: var(--surface-2); padding: 0.75rem 1rem; border-radius: 10px; overflow-x: auto; }
.post-body code { background: var(--surface-2); padding: 0.1rem 0.35rem; border-radius: 5px; font-size: 0.9em; }
.post-body a { color: var(--brand); }
.post-body .embed-product { display: block; margin: 1rem 0; }
.post-products { margin-top: 1.5rem; }
body.cook-mode .shop { display: none !important; }

