:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #fbf9f4;
  --line: #e8e1d4;
  --text: #1d2a36;
  --muted: #6b7480;
  --accent: #128a68;
  --accent-soft: #e3f3ec;
  --accent-ink: #0b5e47;
  --lightbox: #071a3d;
  --glass: #7fc4ff;
  --good: #1a9a64;
  --warn: #c27712;
  --bad: #d43f4a;
  --protein: #e0573f;
  --carbs: #1f9fd0;
  --sugar: #d63a8a;
  --fat: #e0a62c;
  --fiber: #3aa65c;
  --sodium: #8a97a6;
  --micro: #8e6bd6;
  --display: "Fraunces", Georgia, serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(29, 42, 54, .04), 0 8px 28px rgba(29, 42, 54, .07);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(255, 196, 140, .35), transparent 62%),
    radial-gradient(760px 480px at -6% 18%, rgba(140, 214, 178, .32), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 17px/1.55 var(--body);
  min-height: 100vh;
}
main { max-width: 1200px; margin: 0 auto; padding: 0 16px 40px; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); line-height: 1.04; font-weight: 800; }
h1 em { font-style: italic; font-weight: 400; color: var(--accent); }
h3 { font-size: 1.3rem; }
b { color: var(--text); }
b.good, .good b { color: var(--good); }
b.bad, .bad { color: var(--bad); }
[hidden] { display: none !important; }

button { font: inherit; cursor: pointer; color: inherit; }
:root { --btn-radius: 12px; --line-strong: #d8cfbe; }
/* Main action: one solid green button per screen */
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 24px; border: 0; border-radius: var(--btn-radius);
  background: var(--accent); color: #fff; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 1px 2px rgba(11, 94, 71, .35), 0 8px 18px -8px rgba(18, 138, 104, .7);
  transition: background .15s, box-shadow .15s, transform .08s;
}
.primary:hover { background: #0f7a5c; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 1px 2px rgba(11, 94, 71, .35), 0 12px 22px -8px rgba(18, 138, 104, .75); }
.primary:active { transform: translateY(1px); background: #0c6a50; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .18); }
.primary:disabled { background: #9fbfb3; box-shadow: none; cursor: not-allowed; }
/* Secondary actions: white, outlined, quieter */
.ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); color: var(--text); font-weight: 600; font-size: .92rem;
  box-shadow: 0 1px 1px rgba(29, 42, 54, .05);
  transition: border-color .15s, background .15s, color .15s;
}
.ghost:hover { border-color: var(--accent); color: var(--accent-ink); background: #f8fcfa; }
.ghost:active { background: var(--accent-soft); }
.round { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: var(--btn-radius); font-size: 1.4rem; line-height: 1; }
:focus-visible { outline: 3px solid rgba(18, 138, 104, .45); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .primary, .ghost { transition: none; } .primary:active { transform: none; } }

.masthead {
  display: flex; align-items: center; justify-content: space-between; max-width: 1200px; margin: 0 auto; padding: 20px 16px;
}
.brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; border-radius: 14px; }
.brand:hover .brand-name { color: var(--accent-ink); }
.brand-mark { display: block; width: 52px; height: 52px; flex: none; filter: drop-shadow(0 3px 6px rgba(11, 110, 82, .28)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--display); font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; }
.brand-tagline { font-size: .86rem; color: var(--muted); letter-spacing: .01em; margin-top: 2px; }

.view { animation: rise .45s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.intro { margin: 28px 0 26px; max-width: 760px; }
.eyebrow { font-family: var(--mono); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin: 0 0 10px; }
.lede { color: var(--muted); font-size: 1.12rem; max-width: 620px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.sub { color: var(--muted); font-size: .9rem; margin: 4px 0 16px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; max-width: 860px; }
.span2 { grid-column: span 2; }
label, legend { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
.unit, .opt { font-size: .78rem; opacity: .8; }
input[type=text], input[type=number], select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(18, 138, 104, .15); background: #fff; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.seg { display: flex; flex-wrap: nowrap; gap: 0; }
.seg legend { width: 100%; margin-bottom: 6px; }
.seg label { flex: 1 1 0; flex-direction: row; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 45px; padding: 0 12px; text-align: center;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: .92rem; line-height: 1.2;
  transition: background .15s, color .15s;
}
.seg label + label span { margin-left: -1px; }
.seg label:first-of-type span { border-radius: var(--btn-radius) 0 0 var(--btn-radius); }
.seg label:last-of-type span { border-radius: 0 var(--btn-radius) var(--btn-radius) 0; }
.seg span:hover { color: var(--text); background: #fff; }
.seg input:checked + span { position: relative; z-index: 1; background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg input:focus-visible + span { outline: 3px solid rgba(18, 138, 104, .45); outline-offset: 1px; z-index: 2; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.checks legend { grid-column: 1 / -1; margin-bottom: 4px; }
.checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.checks input { accent-color: var(--accent); width: 18px; height: 18px; }
.form-grid .primary { justify-self: start; align-self: end; min-width: 180px; }

.profile-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.profile-strip > div, .facts > div {
  display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px;
}
.profile-strip > div { box-shadow: var(--shadow); }
.facts > div { background: var(--surface-2); }
.profile-strip .k, .facts .k { grid-column: 1 / -1; font-family: var(--mono); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.profile-strip .v, .facts .v { font-family: var(--display); font-size: 1.45rem; font-weight: 600; }
.profile-strip .n, .facts .n { font-size: .82rem; color: var(--muted); }
.n.good { color: var(--good); } .n.warn { color: var(--warn); }

.food-form { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: end; max-width: 980px; }
.food-input input { font-size: 1.25rem; padding: 14px 16px; }
.amount { display: flex; gap: 8px; align-items: end; }
.amount input { width: 90px; }
.amount select { width: auto; }
.hint { grid-column: 1 / -1; color: var(--muted); font-size: .88rem; margin: 0; }
.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
.chips-label { grid-column: 1 / -1; margin: 6px 0 -4px; font-size: .82rem; color: var(--muted); }
.chip { min-height: 34px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); font-size: .9rem; color: var(--text); transition: border-color .15s, background .15s; }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

/* Result header */
.result-head { display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; margin: 12px 0 22px; }
.food-title h1 { font-size: clamp(2rem, 4.5vw, 3.2rem); }
.food-title .eyebrow { margin-bottom: 4px; }
.source { margin: 4px 0 0; color: var(--muted); font-size: .8rem; font-family: var(--mono); }
.grade { display: flex; align-items: center; gap: 12px; border-radius: 16px; padding: 10px 18px 10px 10px; border: 1px solid currentColor; background: var(--surface); box-shadow: var(--shadow); }
.grade .letter { font-family: var(--display); font-weight: 800; font-size: 2.4rem; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 12px; color: #fff; }
.grade .word { display: flex; flex-direction: column; font-weight: 700; color: var(--text); }
.grade small { font-weight: 400; color: var(--muted); font-size: .8rem; }
.gA { color: #1a9a64; } .gB { color: #6aa832; } .gC { color: #d29a12; } .gD { color: #e0712c; } .gE { color: #d43f4a; }
.grade.gA .letter, .grade-mini.gA { background: #1a9a64; } .grade.gB .letter, .grade-mini.gB { background: #6aa832; }
.grade.gC .letter, .grade-mini.gC { background: #d29a12; } .grade.gD .letter { background: #e0712c; } .grade.gE .letter { background: #d43f4a; }

/* Journey: a deep-blue lightbox holds the 3D body inside a light card */
.journey { display: grid; grid-template-columns: minmax(320px, 1.1fr) minmax(0, 1fr); gap: 28px; padding: 16px; position: relative; overflow: hidden; }
.body-stage { position: relative; border-radius: 16px; background: var(--lightbox); overflow: hidden; }
#body3d, #health3d { position: relative; height: min(78vh, 760px); min-height: 460px; overflow: hidden; cursor: grab; touch-action: none; }
#body3d:active, #health3d:active { cursor: grabbing; }
/* The canvas is sized by JS; keep it out of layout so the panel can shrink when the window does */
#body3d canvas, #health3d canvas { display: block; position: absolute; top: 0; left: 0; }
.body-stage, .health-right, .health-left, .story { min-width: 0; }
.organ-labels { position: absolute; inset: 0; pointer-events: none; z-index: 1; } /* one layer, so the controls and Body panel stay on top */
.organ-tag {
  font: 600 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: #fff;
  padding: 3px 8px; border-radius: 99px; background: rgba(5, 12, 23, .7); border: 1px solid rgba(127, 196, 255, .5);
  opacity: 0; transform: translateY(4px); transition: opacity .5s, transform .5s; white-space: nowrap;
}
.organ-tag.on { opacity: 1; transform: none; }
.body-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #a9bdd8; font-family: var(--mono); font-size: .85rem; }
.view-tools { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 6px; z-index: 2; }
.tool {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  border: 1px solid rgba(160, 205, 255, .22); border-radius: 10px; background: rgba(8, 20, 40, .62);
  color: #d6e3f3; font-size: .78rem; font-weight: 600; backdrop-filter: blur(8px);
  transition: background .15s, border-color .15s, color .15s;
}
.tool:hover { color: #fff; background: rgba(22, 44, 78, .78); border-color: rgba(160, 205, 255, .45); }
.tool.on { color: #062a20; background: #8fe3c2; border-color: #8fe3c2; }
/* Layer switches: one grouped panel instead of separate pills */
.layer-tools {
  position: absolute; top: 50px; left: 10px; z-index: 2; display: flex; flex-direction: column;
  border: 1px solid rgba(160, 205, 255, .22); border-radius: 12px; overflow: hidden; background: rgba(8, 20, 40, .62); backdrop-filter: blur(8px);
}
.layer-tools .tool { justify-content: flex-start; min-width: 92px; border: 0; border-radius: 0; background: transparent; backdrop-filter: none; }
.layer-tools .tool + .tool { border-top: 1px solid rgba(160, 205, 255, .14); }
.layer-tools .tool.on { background: rgba(143, 227, 194, .18); color: #8fe3c2; }
.layer-tools .tool::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid currentColor; flex: none; }
.layer-tools .tool.on::before { background: currentColor; }
.view-hint { position: absolute; bottom: 8px; left: 0; right: 0; margin: 0; text-align: center; font-size: .72rem; color: #a9bdd8; pointer-events: none; opacity: .85; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 10px 12px 14px; font-size: .8rem; color: #c3d3e8; border-top: 1px solid rgba(127, 196, 255, .15); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }

/* Story */
.story { display: flex; flex-direction: column; gap: 18px; min-width: 0; padding: 6px 4px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.steps button {
  width: 100%; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; font-size: .8rem; color: var(--muted); line-height: 1.25; min-height: 54px; transition: border-color .2s, background .2s;
}
.steps button span { display: block; font-family: var(--mono); font-size: .7rem; color: var(--accent); opacity: .6; }
.steps button:hover { border-color: var(--accent); }
.steps button.done { color: var(--text); background: #fff; }
.steps button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.steps button.on span { opacity: 1; }
.stage-card { flex: 1; animation: rise .4s ease both; }
.stage-meta { display: flex; justify-content: space-between; font-family: var(--mono); font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin: 0 0 6px; }
.clock { color: var(--accent); }
.stage-card h2 { font-size: clamp(1.7rem, 3vw, 2.4rem); margin-bottom: 12px; }
#s-lines { padding: 0; margin: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
#s-lines li { padding-left: 20px; position: relative; color: #34414e; }
#s-lines li::before { content: ""; position: absolute; left: 0; top: .55em; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.controls { display: flex; gap: 10px; align-items: center; }
.controls .primary { min-width: 120px; }

/* Panels */
.grid3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 18px; margin-top: 18px; }
.kcal-line { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; color: var(--muted); font-size: .85rem; }
.big { font-family: var(--display); font-size: 2rem; font-weight: 800; color: var(--text); }
.nrow { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "l a" "b b" "p p"; gap: 2px 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.nlabel { grid-area: l; } .namt { grid-area: a; font-family: var(--mono); }
.bar { grid-area: b; height: 7px; background: #efe9de; border-radius: 99px; position: relative; overflow: visible; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 99px; transition: width 1s cubic-bezier(.2, .8, .2, 1); }
.bar .over { position: absolute; right: -4px; top: -7px; color: var(--bad); font-size: .8rem; }
.npct { grid-area: p; font-family: var(--mono); font-size: .75rem; color: var(--muted); }
.nrow.bad .npct { color: var(--bad); } .nrow.warn .npct { color: var(--warn); } .nrow.good .npct { color: var(--good); }
.facts { display: flex; flex-direction: column; gap: 10px; }
.facts > div.bad .v { color: var(--bad); } .facts > div.good .v { color: var(--good); }
.facts .n { grid-column: 1 / -1; }
#glucose { width: 100%; height: auto; margin-bottom: 12px; }
#glucose .zone { fill: rgba(26, 154, 100, .08); }
#glucose .zlabel { fill: var(--good); font: 10px var(--mono); opacity: .8; }
#glucose .grid { stroke: var(--line); }
#glucose .tick { fill: var(--muted); font: 10px var(--mono); }
#glucose .garea { fill: rgba(31, 159, 208, .08); }
#glucose .gline { fill: none; stroke-width: 2.5; stroke: var(--good); stroke-linejoin: round; }
#glucose .gline.warn, #glucose .gpeak.warn { stroke: var(--warn); fill: var(--warn); }
#glucose .gline.bad, #glucose .gpeak.bad { stroke: var(--bad); fill: var(--bad); }
#glucose .gline.warn, #glucose .gline.bad { fill: none; }
#glucose .gpeak { fill: var(--good); }
#glucose .glabel { fill: var(--text); font: 600 11px var(--mono); }

.swaps { margin-top: 18px; }
.swap-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 14px; }
.swap { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; transition: border-color .2s, transform .2s; }
.swap:hover { border-color: var(--good); transform: translateY(-1px); }
.swap small { display: block; color: var(--muted); font-size: .8rem; }
.grade-mini { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; font: 800 1.2rem var(--display); color: #fff; }

.years-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-left: 0 !important; margin-top: 4px; }
.years-pick::before { display: none; }
.years-pick span { color: var(--muted); font-size: .88rem; margin-right: 4px; }
.chip.on { background: var(--bad); border-color: var(--bad); color: #fff; }

/* Landing page */
/* Headline across the top; the form and the 3D body side by side below it, same top and bottom */
.welcome { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); column-gap: 28px; align-items: start; }
.welcome-main { display: contents; }
.welcome-main .intro { grid-column: 1; grid-row: 1; }
.welcome-main .form-grid { grid-column: 1; grid-row: 2; max-width: none; min-width: 0; }
.welcome-body { grid-column: 2; grid-row: 2; align-self: stretch; display: flex; }
.hero-stage { flex: 1; display: flex; flex-direction: column; box-shadow: var(--shadow); }
#hero3d { position: relative; flex: 1; min-height: 420px; overflow: hidden; cursor: grab; touch-action: pan-y; }
#hero3d canvas { display: block; position: absolute; top: 0; left: 0; }
#hero3d .organ-tag { display: none; }
@media (max-width: 1180px) {
  .welcome-main .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.hero-caption { margin: 0; padding: 12px 16px 14px; color: #c3d3e8; font-size: .86rem; border-top: 1px solid rgba(127, 196, 255, .15); }

/* My body check */
.nav { display: flex; gap: 8px; }
.back { margin-top: 8px; }
.health-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 1fr); gap: 18px; align-items: start; }
.health-left { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.health-right { position: sticky; top: 12px; }
#health3d { height: min(80vh, 720px); }
.drop {
  margin-top: 14px; border: 2px dashed var(--line); border-radius: 16px; padding: 26px 16px; text-align: center;
  align-items: center; background: var(--surface-2); cursor: pointer; transition: border-color .2s, background .2s; position: relative;
}
.drop b { color: var(--text); font-size: 1.05rem; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input, .file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.privacy { font-size: .8rem; color: var(--muted); margin: 10px 0 0; }
.file-status { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; font-size: .85rem; }
.file-status li { padding: 8px 12px; border-radius: 10px; background: var(--surface-2); border-left: 3px solid var(--line); }
.file-status li span { color: var(--muted); }
.file-status li.good { border-color: var(--good); } .file-status li.warn { border-color: var(--warn); } .file-status li.bad { border-color: var(--bad); }
.mf-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.mf-head .date { flex-direction: row; align-items: center; gap: 8px; }
input[type=date] { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.mgroup { margin-top: 16px; }
.mgroup legend { font-family: var(--mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mfield { gap: 4px; }
.mname { color: var(--text); font-size: .84rem; }
.mfield input { padding: 8px 10px; }
.mstate { font-size: .72rem; min-height: 1.1em; line-height: 1.3; }
.mfield.good .mstate { color: var(--good); } .mfield.warn .mstate { color: var(--warn); } .mfield.bad .mstate { color: var(--bad); }
.mfield.good input { border-color: rgba(26, 154, 100, .45); }
.mfield.warn input { border-color: var(--warn); background: #fff8ec; }
.mfield.bad input { border-color: var(--bad); background: #fff1f1; }
.mfield.auto input { box-shadow: inset 3px 0 0 var(--micro); }
.mf-actions, .apply, .backup { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.note { font-size: .85rem; color: var(--accent-ink); }
.cmp-tools { position: absolute; bottom: 34px; left: 10px; right: 10px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; z-index: 2; }
.health-caption { position: absolute; bottom: 8px; left: 0; right: 0; margin: 0; text-align: center; font: 600 .74rem var(--mono); color: #c3d3e8; pointer-events: none; }
.findings-card, .history-card { margin-top: 18px; }
.finding-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 14px; }
.finding { border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 14px; padding: 12px 14px; background: var(--surface-2); font-size: .9rem; }
.finding.bad { border-left-color: var(--bad); }
.finding p { margin: 0 0 6px; }
.fhead { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; align-items: center; }
.fix { color: #34414e; } .fix b { color: var(--good); }
.range { font-size: .76rem; color: var(--muted); font-family: var(--mono); }
.pill { display: inline-block; font-style: normal; font-size: .76rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: #eef0f2; color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--accent-soft); color: var(--good); }
.pill.warn { background: #fdf1dc; color: var(--warn); }
.pill.bad { background: #fde6e7; color: var(--bad); }
.ok-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 14px 0 0; font-size: .85rem; color: var(--muted); }
.all-good { color: var(--good); font-weight: 700; }
.checkup { display: grid; grid-template-columns: 150px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.cdate { display: flex; flex-direction: column; }
.cdate small, .cbody small { color: var(--muted); font-size: .8rem; }
.cbody { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.cact { display: flex; gap: 6px; }
.cact .ghost { padding: 6px 12px; font-size: .85rem; }
.compare { margin-top: 18px; padding-top: 18px; border-top: 2px solid var(--line); }
.cmp-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.cmp-head select { width: auto; }
.table-wrap { overflow-x: auto; }
#cmp-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
#cmp-table th { text-align: left; font: 600 .7rem var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
#cmp-table td { padding: 8px; border-bottom: 1px solid var(--line); }
#cmp-table .num { font-family: var(--mono); white-space: nowrap; }
#cmp-table td.good { color: var(--good); } #cmp-table td.bad { color: var(--bad); }
.file-btn { flex-direction: row; cursor: pointer; position: relative; }
.tabs { display: flex; gap: 4px; margin-top: 14px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--btn-radius); }
.tab { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 9px; padding: 0 12px; color: var(--muted); font-size: .9rem; font-weight: 600; }
.tab:hover { color: var(--text); }
.tab.on { background: var(--surface); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(29, 42, 54, .12), 0 0 0 1px var(--line-strong); }
.tape-intro { margin: 14px 0 0; color: #34414e; font-size: .95rem; }
.tape-guide { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: start; margin: 12px 0 16px; }
.tape-fig { width: 100%; height: auto; }
.tape-fig .torso { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.2; }
.tape-fig .tape { fill: none; stroke: var(--fat); stroke-width: 2.4; stroke-dasharray: 4 3; }
.tape-fig .navel { fill: var(--accent-ink); }
.tape-fig text { font: 600 10px var(--mono); fill: var(--warn); }
.tape-steps { margin: 0; padding-left: 18px; font-size: .88rem; color: #34414e; display: flex; flex-direction: column; gap: 6px; }
.tape-hint { margin: 0 0 8px; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }
.tape-out { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: #fdf6e8; border: 1px solid #f1dfb8; font-size: .86rem; color: #5a4a26; }
.tape-out b { color: var(--text); }
.body-key .basis { flex-basis: 100%; margin: 4px 0 0; font-size: .8rem; color: #e8eef7; line-height: 1.45; }
.body-key .basis b { color: #ffd88a; } .body-key .basis em { color: #ffd88a; font-style: normal; text-decoration: underline dotted; }

/* Sources: small chips next to numbers, coloured by kind */
.cites { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.cite {
  display: inline-flex; align-items: center; gap: 4px; font: 600 .66rem/1.2 var(--mono); letter-spacing: .02em;
  padding: 2px 7px; border-radius: 99px; text-decoration: none; white-space: nowrap;
  background: #f1efe9; color: #4f5965; border: 1px solid var(--line);
}
.cite::before, .dot { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; display: inline-block; }
.cite:hover { border-color: var(--accent); color: var(--accent-ink); }
.k-data { --k: #1f7fb8; } .k-guide { --k: #128a68; } .k-study { --k: #7c4dbe; } .k-model { --k: #c27712; }
.cite::before, .dot { background: var(--k); }
.cite.k-model { background: #fdf3e2; border-color: #f0dcb4; }
.srcline { margin: 12px 0 0; font-size: .76rem; color: var(--muted); line-height: 1.5; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.srcline .how::before { content: "How: "; font-weight: 700; color: #4f5965; }
.profile-strip .cites { grid-column: 1 / -1; margin-top: 4px; }
.grade .cites { margin-top: 4px; }
.source .cites { margin-left: 4px; }
.range .cites { margin-left: 4px; }
.tape-out .cites { margin-left: 6px; }
#s-lines li.stage-src { padding-left: 0; }
#s-lines li.stage-src::before { display: none; }
#s-lines li.stage-src .srcline { margin-top: 2px; }
/* On the dark 3D panels */
.body-note { padding: 0 12px 12px; }
.body-note .srcline, .basis { color: #a9bdd8; }
.body-note .srcline .how::before { color: #c3d3e8; }
.body-note .cite, .basis .cite { background: rgba(255, 255, 255, .08); border-color: rgba(127, 196, 255, .25); color: #d7e3f2; }
.body-note .cite.k-model, .basis .cite.k-model { background: rgba(255, 196, 120, .12); }
/* Sources & methods page */
.kind-key { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 16px; font-size: .88rem; color: var(--muted); }
.kind-key span { display: inline-flex; align-items: center; gap: 7px; }
.src-group + .src-group { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.src-group h3 { display: flex; align-items: center; gap: 10px; }
.src-group h3 .dot { width: 10px; height: 10px; }
.src-entry { padding: 12px 14px; margin-top: 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); transition: background .4s, border-color .4s; scroll-margin: 80px; }
.src-entry.hl { background: var(--accent-soft); border-color: var(--accent); }
.src-entry h4 { margin: 0 0 4px; font-size: 1rem; }
.src-full { margin: 0 0 6px; font-size: .86rem; color: #34414e; overflow-wrap: anywhere; }
.src-full a { color: var(--accent); }
.src-used { margin: 0; font-size: .86rem; color: var(--muted); }
footer a { color: var(--accent); font-weight: 700; }
/* Body shape picker and height ruler on the 3D views */
.body-btn { margin-left: auto; }
.body-pick {
  position: absolute; top: 48px; right: 10px; z-index: 3; width: min(330px, calc(100% - 20px));
  background: rgba(5, 12, 23, .88); border: 1px solid rgba(127, 196, 255, .3); border-radius: 14px; padding: 12px;
  color: #c3d3e8; font-size: .82rem; backdrop-filter: blur(8px); display: flex; flex-direction: column; gap: 8px;
}
.bp-title { margin: 0; font: 600 .72rem var(--mono); letter-spacing: .1em; text-transform: uppercase; color: #8fe3c2; }
.bp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.bp-row span { width: 48px; color: #a9bdd8; }
.body-pick button:not(.cite) { min-height: 30px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(127, 196, 255, .25); color: #d7e3f2; border-radius: 8px; padding: 0 10px; font-size: .78rem; font-weight: 600; }
.body-pick button.on { background: #8fe3c2; border-color: #8fe3c2; color: #062a20; font-weight: 700; }
.bp-auto { align-self: flex-start; }
.bp-basis { margin: 0; color: #a9bdd8; line-height: 1.45; }
.bp-basis .cite { background: rgba(255, 255, 255, .08); border-color: rgba(127, 196, 255, .25); color: #d7e3f2; }
.ruler-tag { font: 600 10px var(--mono); color: #7fd6ff; opacity: .7; }
.ruler-tag.head { color: #ffd88a; opacity: 1; background: rgba(5, 12, 23, .7); padding: 1px 6px; border-radius: 99px; white-space: nowrap; }

.source .unmeasured { display: block; margin-top: 4px; color: var(--warn); font-family: var(--body); font-size: .8rem; }

/* Choosing a packaged product when a food isn't in the list */
.food-picks { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 14px; }
.picks-head, .picks-tip { margin: 0 0 10px; font-size: .9rem; color: #34414e; }
.picks-tip { margin: 10px 0 0; color: var(--muted); font-size: .84rem; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.pick { display: flex; flex-direction: column; gap: 2px; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.pick:hover { border-color: var(--accent); background: var(--accent-soft); }
.pick small { color: var(--muted); font-size: .78rem; }
.pick.ingredient { opacity: .8; }
.warn-tag { color: var(--warn); font-weight: 700; }

/* "Was this useful?" after the last step */
.rate { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); }
.rate-q { font-weight: 700; color: var(--accent-ink); margin-right: 4px; }
.rate .ghost { padding: 7px 14px; }
.rate-thanks { display: none; color: var(--accent-ink); font-weight: 700; }
.rate.done .ghost, .rate.done .rate-q { display: none; }
.rate.done .rate-thanks { display: inline; }

/* Privacy */
.privacy-pledge { margin: 0; font-size: .85rem; color: var(--muted); }
.privacy-pledge a, .privacy a, .privacy-text a { color: var(--accent); }
.privacy-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 18px; align-items: start; }
.privacy-controls { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 12px; }
.privacy-controls .sub { margin: 0; color: var(--text); }
.switch { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: .95rem; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.hint-sm { margin: 0; font-size: .8rem; color: var(--muted); }
.ghost.danger { color: var(--bad); border-color: #f1c4c7; }
.ghost.danger:hover { border-color: var(--bad); background: #fff1f1; }
.privacy-text h3 { margin-top: 4px; }
.privacy-text h3 + * { margin-top: 10px; }
.privacy-text h4 { margin: 18px 0 4px; font-size: 1rem; }
.privacy-text p, .privacy-text li { font-size: .92rem; color: #34414e; }
.privacy-text p { margin: 0 0 6px; }
.privacy-text ul { padding-left: 20px; margin: 0 0 6px; display: flex; flex-direction: column; gap: 6px; }
.privacy-short { list-style: none; padding: 0 !important; margin-bottom: 22px !important; }
.privacy-short li { padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); }
.privacy-short b { color: var(--accent-ink); }

footer { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); }
footer p { margin: 4px 0; }

@media (max-width: 960px) {
  .food-form { grid-template-columns: 1fr auto; }
  .food-input { grid-column: 1 / -1; }
  .journey { grid-template-columns: minmax(0, 1fr); }
  #body3d { height: 68vh; }
  .grid3 { grid-template-columns: 1fr; }
  .result-head { grid-template-columns: 1fr; }
  .health-grid { grid-template-columns: minmax(0, 1fr); }
  .welcome { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
  .welcome-main { display: contents; }          /* headline, then the body, then the form */
  .welcome-main .intro { order: 0; }
  .welcome-body { order: 1; position: static; margin: 0 0 18px; }
  .welcome-main .form-grid { order: 2; }
  #hero3d { height: 44vh; min-height: 300px; }
  .privacy-grid { grid-template-columns: minmax(0, 1fr); }
  .privacy-controls { position: static; }
  .health-right { position: static; order: -1; }
  #health3d { height: 62vh; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span2, .checks { grid-column: 1 / -1; }
  .checks { grid-template-columns: 1fr; }
  .food-form { grid-template-columns: 1fr; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 18px; }
  .journey { padding: 10px; }
  .checkup { grid-template-columns: 1fr auto; }
  .cbody { grid-column: 1 / -1; grid-row: 2; }
  .nav .ghost { padding: 7px 11px; font-size: .8rem; white-space: nowrap; }
  .masthead { flex-wrap: wrap; gap: 12px 8px; }   /* logo on its own row, buttons below */
  .nav { display: flex; gap: 8px; width: 100%; }
  .nav .ghost { flex: 1; }
  .brand-mark { width: 44px; height: 44px; }
  .brand-name { font-size: 1.6rem; }
  .brand-tagline { font-size: .74rem; }
  .tape-guide { grid-template-columns: 90px 1fr; gap: 12px; }
  .seg span { font-size: .84rem; padding: 0 6px; }
  .form-grid .primary { justify-self: stretch; width: 100%; }
}
