:root {
  --bg: #f6f4ef; --card: #ffffff; --ink: #1d2420; --muted: #5d6a63; --line: #e2ded4; --soft: #f0ede5;
  --brand: #2f7d5b; --brand-ink: #ffffff; --brand-soft: #e3f1e9; --accent: #e9962f;
  --protein: #3d7fc4; --carbs: #e0a72e; --fat: #c95b4a; --fiber: #5d9c4c;
  --warn: #9a5a00; --warn-bg: #fff4e0; --err: #b3261e; --ok: #1f7a4a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121614; --card: #1b201d; --ink: #e8ece9; --muted: #9aa7a0; --line: #2d3430; --soft: #232926;
  --brand: #4fb184; --brand-ink: #0d1a13; --brand-soft: #1f3329; --accent: #f0a648;
  --protein: #6aa6e6; --carbs: #f0c254; --fat: #e57f6e; --fiber: #86c272;
  --warn: #f2b45a; --warn-bg: #2e2617; --err: #ff8a80; --ok: #6fd3a0;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }
a { color: var(--brand); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--card); padding: 6px 10px; z-index: 50; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.warn { color: var(--warn); }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }

.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1160px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.lnk { color: var(--muted); text-decoration: none; font-size: 14px; }
.pill { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 14px; min-height: 32px; }
.btn-lg { padding: 12px 22px; font-size: 17px; }
.icon-btn { font: inherit; background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 10px; width: 38px; height: 38px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.icon-sm { width: 30px; height: 30px; font-size: 16px; }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: var(--brand); text-decoration: underline; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .drop:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(26px, 4.4vw, 40px); line-height: 1.15; margin: 0 0 10px; letter-spacing: -.01em; }
.lede { margin: 0; max-width: 760px; color: var(--muted); font-size: 17px; }
.lede strong { color: var(--ink); }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; padding: 18px 0 40px; align-items: start; }
.col-main, .col-side { display: grid; gap: 20px; min-width: 0; }
.col-side { position: sticky; top: 72px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 20px; margin: 0 0 14px; }
.card h3 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }

.drop { border: 2px dashed var(--line); border-radius: 12px; background: var(--soft); cursor: pointer; min-height: 180px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; transition: border-color .15s; }
.drop:hover, .drop.dragging { border-color: var(--brand); }
.drop-empty { display: grid; gap: 4px; justify-items: center; }
.drop-icon { font-size: 34px; }
.drop-full { width: 100%; display: grid; gap: 8px; }
.drop-full img { max-height: 340px; width: 100%; object-fit: contain; border-radius: 8px; }
.drop-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }

.lbl { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.lbl-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
textarea, input[type="text"], input[type="search"], input[type="number"], input[type="date"], select {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
input[type="date"], select, input[type="number"] { width: auto; }
textarea { resize: vertical; }

.run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.meter { margin: 0; font-size: 14px; color: var(--muted); }
.gate { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--ink); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }

.progress { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--soft); }
.progress-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.psteps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.pstep { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.step-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); }
.pstep-on { color: var(--ink); font-weight: 600; }
.pstep-on .step-dot { border-color: var(--brand); animation: pulse 1s infinite alternate; }
.pstep-done .step-dot { background: var(--brand); border-color: var(--brand); }
.pstep-failed .step-dot { background: var(--err); border-color: var(--err); }
.step-note { font-size: 12px; }
@keyframes pulse { to { background: var(--brand); } }
@media (prefers-reduced-motion: reduce) { .pstep-on .step-dot { animation: none; background: var(--brand); } }

.free { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.examples { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.ex { font: inherit; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 6px; cursor: pointer; color: var(--ink); display: grid; gap: 4px; text-align: left; }
.ex:hover { border-color: var(--brand); }
.ex img { width: 100%; height: auto; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; display: block; }
.ex-title { font-size: 13px; font-weight: 600; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag-free { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.tag-hidden { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag-conf-low { color: var(--warn); }

.result-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.result-head h2 { margin: 0; }
.result-top { display: flex; gap: 14px; align-items: flex-start; margin: 12px 0 6px; }
.result-img { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.result-top-text { flex: 1; min-width: 0; }
.title-input { font-size: 20px !important; font-weight: 700; border-color: transparent !important; padding: 4px 6px !important; background: transparent !important; }
.title-input:hover, .title-input:focus { border-color: var(--line) !important; }
.result-top-text p { margin: 4px 6px 0; }
.notice { margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); font-size: 14px; }

.totals { margin: 14px 0; padding: 16px; border-radius: 12px; background: var(--brand-soft); }
.kcal-big, .day-kcal { display: grid; gap: 2px; }
.kcal-num { font-size: clamp(26px, 5vw, 36px); font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kcal-sub { color: var(--muted); font-size: 14px; }
.macro-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.macro { background: var(--card); border-radius: 10px; padding: 8px 10px; border-left: 4px solid var(--line); min-width: 0; }
.macro-protein { border-left-color: var(--protein); } .macro-carbs { border-left-color: var(--carbs); }
.macro-fat { border-left-color: var(--fat); } .macro-fiber { border-left-color: var(--fiber); }
.macro-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.macro-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.split { display: flex; height: 10px; border-radius: 99px; overflow: hidden; margin-top: 12px; background: var(--card); }
.split-protein { background: var(--protein); } .split-carbs { background: var(--carbs); } .split-fat { background: var(--fat); }
.split-legend { margin: 6px 0 0; }

.items { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.item-hidden { border-style: dashed; }
.item-off { opacity: .55; }
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-head input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.item-name { font-weight: 700; flex: 1 1 auto; min-width: 120px; }
.item-kcal { font-weight: 700; margin-left: auto; }
.item-seen { margin: 2px 0 0 26px; }
.item-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0 0 26px; }
.item-range { font-size: 14px; font-weight: 600; }
.grams { width: 90px !important; padding: 5px 8px !important; }
.item-src { margin-left: auto; text-align: right; }
.item-macros { margin: 6px 0 0 26px; color: var(--muted); }
.item .warn { margin: 6px 0 0 26px; }
.empty { margin: 4px 0; }

.add-row { margin-top: 14px; position: relative; }
.hits { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 4px; }
.hit { font: inherit; width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; color: var(--ink); cursor: pointer; text-align: left; }
.hit:hover { border-color: var(--brand); }
.questions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.questions .lbl { width: 100%; margin: 0; }
.chip { font: inherit; font-size: 14px; background: var(--soft); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; cursor: pointer; color: var(--ink); text-align: left; }
.chip:hover { border-color: var(--brand); }
.recheck { margin-top: 10px; }
.recheck .gate { margin-top: 8px; }
.save-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.export-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.disclaimer { font-size: 13px; color: var(--muted); margin: 14px 0 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--soft); border-radius: 0 8px 8px 0; }

.day-nav { display: flex; gap: 8px; align-items: center; }
.day-nav input { flex: 1; }
.day-totals { margin: 14px 0 10px; padding: 14px; border-radius: 12px; background: var(--brand-soft); }
.day-totals p { margin: 6px 0 0; }
.tmeter { display: flex; height: 8px; border-radius: 99px; background: var(--card); overflow: hidden; margin-top: 8px; }
.tmeter-lo { background: var(--brand); } .tmeter-hi { background: color-mix(in srgb, var(--brand) 40%, transparent); }
.target input { width: 90px; }
.log-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.log-item { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.log-open { font: inherit; flex: 1; min-width: 0; display: grid; grid-template-columns: 74px 1fr auto; gap: 8px; align-items: center; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; color: var(--ink); text-align: left; }
.log-open:hover { border-color: var(--brand); }
.log-slot { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.log-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-kcal { font-size: 13px; }
.how ol { padding-left: 18px; margin: 0 0 8px; }
.how li { margin-bottom: 6px; }

.foot { border-top: 1px solid var(--line); padding: 18px 0 28px; font-size: 14px; color: var(--muted); }
.foot-in { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 14px; z-index: 60; box-shadow: var(--shadow); }
.toast-err { background: var(--err); color: #fff; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .col-side { position: static; }
}
@media (max-width: 560px) {
  .hide-sm { display: none; }
  .card { padding: 16px; }
  .examples { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .macro-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item-ctl, .item-seen, .item-macros, .item .warn { margin-left: 0; }
  .item-src { margin-left: 0; text-align: left; flex-basis: 100%; }
  .result-img { width: 84px; height: 64px; }
  .brand span { font-size: 14px; line-height: 1.15; max-width: 92px; }
  .top-in { gap: 8px; padding: 8px 12px; }
  .top-actions { flex-wrap: nowrap; gap: 6px; }
  .pill { padding: 3px 8px; font-size: 12px; }
}
