:root {
  --bg: #f5f6f3; --card: #ffffff; --text: #1d2330; --muted: #5f6672; --line: #e4e6e1; --track: #e7e9e4;
  --accent: #1f8a4c; --accent-ink: #17703d; --soft: #e6f3eb; --shadow: rgba(0,0,0,.06);
  --carb: #2a78d6; --protein: #eb6834; --fat: #1baf7a; --fiber: #8a6bd1;
  --t0: #0f7f0f; --t1: #2e9e2e; --t2: #fab219; --t3: #ec835a; --t4: #d03b3b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --card: #1c1c1f; --text: #f0efec; --muted: #a8a8b0; --line: #2e2e33; --track: #2e2e33;
    --accent: #2f9e5c; --accent-ink: #7fd6a3; --soft: #1f3327; --shadow: rgba(0,0,0,.4);
    --carb: #3987e5; --protein: #d95926; --fat: #199e70; --fiber: #9a7fe0;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
main { max-width: 760px; margin: 0 auto; padding: 14px 16px 24px; }
h1, h2, h3 { margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; margin: 22px 0 10px; }
a { color: var(--accent-ink); }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.back { text-decoration: none; font-weight: 600; display: inline-block; margin-bottom: 8px; }
input[type=search], select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
select { width: auto; padding: 8px 10px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.cat {
  position: relative; display: flex; align-items: flex-end; min-height: 96px; border-radius: 14px; overflow: hidden;
  text-decoration: none; color: #fff; background: var(--accent) center/cover; box-shadow: 0 1px 3px var(--shadow);
}
.cat::before { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, rgba(0,0,0,.65)); }
.cat span { position: relative; padding: 10px 12px; font-weight: 650; line-height: 1.2; }
.cat small { display: block; font-weight: 400; opacity: .85; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line);
  text-decoration: none; color: var(--text); font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.row-scroll { display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.card {
  display: flex; flex-direction: column; background: var(--card); border-radius: 14px; overflow: hidden;
  text-decoration: none; color: var(--text); box-shadow: 0 1px 3px var(--shadow);
}
.ph { aspect-ratio: 4/3; background: var(--soft); display: grid; place-items: center; font-size: 2.4rem; overflow: hidden; }
.ph img { width: 100%; height: 100%; object-fit: cover; }
.card .cn { padding: 8px 10px 2px; font-weight: 600; font-size: .92rem; line-height: 1.25; }
.card .cm { padding: 2px 10px 10px; font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; align-items: center; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 650; color: #fff; }
.t0 { background: var(--t0); } .t1 { background: var(--t1); } .t2 { background: var(--t2); color: #1d2330; }
.t3 { background: var(--t3); color: #1d2330; } .t4 { background: var(--t4); } .tn { background: var(--track); color: var(--muted); }

.hero { margin: 0 -16px; aspect-ratio: 16/9; max-height: 360px; background: var(--soft); display: grid; place-items: center; font-size: 5rem; overflow: hidden; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
@media (min-width: 760px) { .hero { margin: 0; border-radius: 16px; } }
.credit { font-size: .72rem; color: var(--muted); margin: 4px 0 12px; }
.crumb { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.crumb a { color: var(--muted); }

.panel { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: 0 1px 3px var(--shadow); margin-top: 12px; }
.kcal { font-size: 2rem; font-weight: 750; }
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.macro { text-align: center; }
.macro b { display: block; font-size: 1.05rem; }
.macro i { display: block; width: 10px; height: 10px; border-radius: 3px; margin: 0 auto 4px; }
.stack { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--track); margin-top: 12px; }

.score { display: flex; align-items: center; gap: 14px; }
.score .big { font-size: 2rem; font-weight: 750; min-width: 72px; text-align: center; padding: 6px 10px; border-radius: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { padding: 4px 10px; border-radius: 999px; background: var(--soft); color: var(--accent-ink); font-size: .85rem; text-decoration: none; }
.tag.src { background: var(--track); color: var(--text); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 14px 0 4px; }
td { padding: 7px 0; border-top: 1px solid var(--line); vertical-align: middle; }
td.v { text-align: right; white-space: nowrap; padding-left: 8px; }
td.p { width: 34%; padding-left: 12px; }
tr.link { cursor: pointer; }
.bar { position: relative; height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 4px; }
.pct { font-size: .75rem; color: var(--muted); }
td.sub { padding-left: 14px; color: var(--muted); }

.rank { list-style: none; padding: 0; margin: 0; }
.rank li a { display: grid; grid-template-columns: 30px 48px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--text); }
.rank .n { color: var(--muted); font-size: .85rem; text-align: right; }
.rank .th { width: 48px; height: 48px; border-radius: 10px; background: var(--soft); overflow: hidden; display: grid; place-items: center; font-size: 1.4rem; }
.rank .th img { width: 100%; height: 100%; object-fit: cover; }
.rank .val { text-align: right; font-weight: 650; white-space: nowrap; }
.rank .nm small { display: block; color: var(--muted); font-size: .78rem; }
.rank .bar { margin-top: 4px; height: 5px; }

.prose p, .prose li { line-height: 1.55; }
.tabs {
  position: fixed; inset: auto 0 0 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs a { flex: 1; text-align: center; padding: 14px 0; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.on { color: var(--accent-ink); }
