:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #14181f; --muted: #5b6472; --line: #e2e6ec;
  --accent: #2f7d32; --accent-ink: #ffffff; --accent-soft: #e8f3e8;
  --ok: #157f3b; --ok-soft: #e7f6ec; --warn: #a15c00; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea;
  --c1: #2563eb; --c2: #0f766e; --c3: #d97706; --c4: #9333ea; --c5: #db2777; --c6: #64748b; --c7: #0891b2; --c8: #65a30d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161b22; --ink: #e6edf3; --muted: #9aa5b1; --line: #2a313c;
  --accent: #7bd88f; --accent-ink: #0b2611; --accent-soft: #15301b;
  --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #33270b; --bad: #f87171; --bad-soft: #3a1414;
  --c1: #60a5fa; --c2: #2dd4bf; --c3: #fbbf24; --c4: #c084fc; --c5: #f472b6; --c6: #94a3b8; --c7: #22d3ee; --c8: #a3e635;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.backlink { text-decoration: none; color: var(--muted); white-space: nowrap; }
.backlink:hover { color: var(--ink); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.freebadge { font-size: 12px; color: var(--ok); background: var(--ok-soft); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 5px 10px; cursor: pointer; font: inherit; }
.ghost:hover { border-color: var(--muted); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 40px; }
.hero h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.15; margin: 0 0 6px; letter-spacing: -.01em; }
.lede { color: var(--muted); margin: 0 0 14px; max-width: 680px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.exlabel { font-size: 13px; color: var(--muted); margin-right: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.mini { padding: 3px 10px; font-size: 12px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.grid { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.results { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.controls { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
legend { font-weight: 650; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; padding: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); min-width: 0; }
.field small { font-weight: 400; }
input[type="number"], select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); margin: 4px 0 10px; cursor: pointer; }
.check.small { margin: 0; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.shape { font-size: 12px; color: var(--muted); margin: -2px 0 8px; }
.custom { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 4px; }
.custom.drag { border-color: var(--accent); background: var(--accent-soft); }
.msg { font-size: 12px; color: var(--muted); margin: 4px 0 8px; min-height: 1em; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }
.seg { display: flex; flex-wrap: wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg label { flex: 1 1 auto; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px 8px; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg input:checked + span { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small { margin: 0; }
.seg.small span { padding: 3px 8px; font-size: 12px; }

.btn {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.filebtn { position: relative; overflow: hidden; display: inline-block; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.phead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.phead h2 { margin: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
tfoot th { border-bottom: 0; font-size: 15px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tablewrap { overflow-x: auto; }
.exports { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.foot { max-width: 1240px; margin: 0 auto; padding: 0 20px 30px; font-size: 13px; color: var(--muted); }

/* --- carbon footprint --- */
.grid { grid-template-columns: minmax(320px, 430px) minmax(0, 1fr); }
.basics { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.tabs { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; border-bottom: 1px solid var(--line); margin: 4px 0 14px; padding-bottom: 8px; }
.tab { background: none; border: 1px solid transparent; border-radius: 8px; padding: 5px 2px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; display: inline-flex; min-width: 0; flex-direction: column; align-items: center; line-height: 1.2; }
.tab:hover { color: var(--ink); }
.tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.tabkg { font-size: 10px; font-weight: 500; color: var(--muted); min-height: 12px; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.qty { display: flex; gap: 8px; align-items: flex-end; }
.qty .field { flex: 0 0 auto; width: 96px; }
.qty .field.grow { flex: 1 1 auto; width: auto; }
.gridnote { font-size: 12px; color: var(--muted); margin: -4px 0 8px; }
.sub { font-size: 13px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.rowcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); position: relative; }
.rowcard .field { margin-bottom: 6px; }
.rowcard input, .rowcard select { background: var(--panel); }
.rowhead { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 6px; gap: 8px; }
.rowhead b { color: var(--ink); font-size: 13px; }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.x:hover { color: var(--bad); background: var(--bad-soft); }
.r2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.r3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.ap { position: relative; }
.ap input[type="text"] { font: inherit; font-size: 14px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; text-transform: none; }
.ap input.bad { border-color: var(--bad); }
.sugg { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15); margin: 2px 0 0; padding: 4px; list-style: none; max-height: 260px; overflow: auto; }
.sugg li { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--ink); }
.sugg li b { font-family: ui-monospace, Menlo, Consolas, monospace; margin-right: 6px; }
.sugg li small { color: var(--muted); }
.sugg li.act, .sugg li:hover { background: var(--accent-soft); }
.fdist { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.dietrows { display: flex; flex-direction: column; gap: 6px; }
.dietrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.dietrow span { font-size: 13px; }
.dietrow small { display: block; color: var(--muted); font-size: 11px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; cursor: pointer; }
.stepper output { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.spendgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.formfoot { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); margin: 8px 0; cursor: pointer; }
.check.small { margin: 0; color: var(--muted); }

.headline { border-left: 5px solid var(--accent); }
.bignums { display: flex; flex-wrap: wrap; gap: 12px 36px; align-items: baseline; }
.big { display: flex; flex-direction: column; }
.bigval { font-size: clamp(36px, 6vw, 52px); font-weight: 750; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.big.alt .bigval { font-size: clamp(24px, 4vw, 32px); color: var(--muted); }
.bigunit { font-size: 13px; color: var(--muted); margin-top: 4px; }
.trees { font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.empty { font-size: 13px; color: var(--muted); margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.brow { display: grid; grid-template-columns: 190px 1fr 84px; gap: 10px; align-items: center; font-size: 13px; }
.brow .bl { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .bt { height: 16px; background: var(--bg); border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.brow .bf { height: 100%; border-radius: 4px 0 0 4px; min-width: 0; }
.brow .bv { text-align: right; font-variant-numeric: tabular-nums; }
.brow .bv small { display: block; font-size: 11px; color: var(--muted); }
.brow.you .bl { font-weight: 700; }
.brow.zero { opacity: .5; }
.levers { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.lever { display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-size: 13px; }
.lever.na { opacity: .5; }
.lever.na .sv { color: var(--muted); font-weight: 400; }
.lever small { color: var(--muted); display: block; font-size: 11px; }
.lever .ctl { display: flex; align-items: center; gap: 6px; }
.lever input[type="range"] { width: 110px; accent-color: var(--accent); }
.lever select { width: auto; padding: 4px 6px; font-size: 13px; }
.lever .sv { font-variant-numeric: tabular-nums; color: var(--ok); font-weight: 600; min-width: 64px; text-align: right; }
.lever .sv.worse { color: var(--bad); }
.hint.warn { color: var(--warn); }
.planout { border-top: 1px solid var(--line); padding-top: 12px; font-size: 14px; }
.planout .pbig { font-size: 22px; font-weight: 700; }
.lines td { font-size: 13px; }
.lines td small { display: block; color: var(--muted); font-size: 11px; }
.lines.nonotes td small { display: none; }
.lines .catrow td { background: var(--bg); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.srclist { margin: 0; padding-left: 18px; font-size: 13px; }
.srclist li { margin-bottom: 4px; }
.srclist small { color: var(--muted); }
.method { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.method li { margin-bottom: 4px; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; }
}
@media (max-width: 520px) {
  .wrap { padding: 16px 16px 32px; }
  .topbar { padding: 10px 16px; }
  .freebadge { display: none; }
  .panel { padding: 14px; }
  .brow { grid-template-columns: 112px 1fr 70px; gap: 6px; }
  .tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .qty .field { width: 84px; }
  .spendgrid { grid-template-columns: 1fr; }
  .lever { grid-template-columns: auto 1fr auto; }
  .lever .sv { grid-column: 3; grid-row: 1; }
  .lever .ctl { grid-column: 2 / 4; grid-row: 2; }
  .lines thead { display: none; }
  .lines tbody tr, .lines tfoot tr { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .lines td, .lines tfoot th { border-bottom: 0; padding: 2px 4px; }
  .lines td:nth-child(1), .lines td:nth-child(5), .lines .catrow td { grid-column: 1 / -1; }
  .lines td:nth-child(2) { grid-column: 1; grid-row: 2; text-align: left; color: var(--muted); }
  .lines td:nth-child(3) { display: none; }
  .lines td:nth-child(4) { grid-column: 2; grid-row: 2; font-weight: 600; }
  .lines td:nth-child(4)::after { content: " kg"; font-weight: 400; color: var(--muted); }
  .lines td:nth-child(5) small { display: inline; margin-left: 4px; }
  .lines .catrow { padding: 0; }
}
@media print {
  .topbar, .controls, .examples, .exports, .levers, #theme { display: none !important; }
  .grid { grid-template-columns: 1fr; }
  body { background: #fff; }
}
