:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --line: #e6e2d9;
  --ink: #1d211a;
  --muted: #6b7167;
  --accent: #3f7d3a;
  --accent-ink: #2c5c28;
  --warn-bg: #fdf6e6;
  --warn-line: #e8d8a8;
  --warn-ink: #7a5c12;
  --prot: #3f7d3a;
  --carb: #c8963e;
  --fat: #a4574a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 26, 18, .05), 0 4px 16px rgba(20, 26, 18, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11150f;
    --surface: #191e16;
    --line: #2c3328;
    --ink: #e8ece4;
    --muted: #99a293;
    --accent: #7cc073;
    --accent-ink: #a8d9a0;
    --warn-bg: #241f10;
    --warn-line: #4a3f1c;
    --warn-ink: #dcc47e;
    --prot: #7cc073;
    --carb: #dcae5e;
    --fat: #d08376;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(720px, 100% - 2rem); margin-inline: auto; }

.top { padding: 2.6rem 0 1.4rem; }
h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 2.6rem);
  letter-spacing: -.03em;
  font-weight: 640;
}
.tag { margin: .4rem 0 0; color: var(--muted); font-size: 1.02rem; max-width: 34rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.lbl { display: block; font-weight: 600; font-size: .84rem; letter-spacing: .04em;
       text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }

textarea {
  width: 100%;
  padding: .8rem .9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: .55rem; flex-wrap: wrap; margin-top: .75rem; }

button {
  font: inherit; font-weight: 560; cursor: pointer;
  border-radius: 9px; padding: .6rem 1.05rem;
  border: 1px solid transparent; transition: filter .12s, background .12s;
}
button:active { transform: translateY(1px); }
.primary { background: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.07); }
.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.ghost:hover { color: var(--ink); border-color: var(--muted); }
.small { padding: .38rem .7rem; font-size: .86rem; }

.err { color: var(--fat); margin: .7rem 0 0; font-size: .92rem; }

/* ── total */
.total-card { padding: 1.25rem 1.15rem 1.05rem; }
.total-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.total-kcal { font-size: clamp(2.4rem, 10vw, 3.4rem); font-weight: 660;
              letter-spacing: -.035em; line-height: 1; }
.total-kcal .unit { font-size: .3em; font-weight: 500; color: var(--muted);
                    margin-left: .45em; letter-spacing: 0; }
.total-range { color: var(--muted); font-size: .95rem; margin-top: .35rem; }
.total-range span { font-variant-numeric: tabular-nums; }

.macros { display: flex; gap: 1.6rem; margin-top: 1rem; }
.macro span { font-size: 1.15rem; font-weight: 620; font-variant-numeric: tabular-nums; }
.macro small { display: block; color: var(--muted); font-size: .78rem; }

.macro-bar { display: flex; height: 7px; border-radius: 99px; overflow: hidden;
             margin-top: .85rem; background: var(--line); }
.macro-bar i { display: block; height: 100%; }
.macro-bar .p { background: var(--prot); }
.macro-bar .c { background: var(--carb); }
.macro-bar .f { background: var(--fat); }

/* ── items */
.sec { font-size: .84rem; letter-spacing: .05em; text-transform: uppercase;
       color: var(--muted); margin: 1.6rem 0 .7rem; }
.sec.flush { margin: 0; }

details.item { background: var(--surface); border: 1px solid var(--line);
               border-radius: var(--radius); margin-bottom: .55rem; box-shadow: var(--shadow); }
details.item > summary {
  list-style: none; cursor: pointer; padding: .85rem 1rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
details.item > summary::-webkit-details-marker { display: none; }
.item-name { font-weight: 570; }
.item-sub { color: var(--muted); font-size: .84rem; margin-top: .15rem; }
.item-kcal { font-variant-numeric: tabular-nums; font-weight: 620; white-space: nowrap; }
.item-kcal small { display: block; font-weight: 440; color: var(--muted);
                   font-size: .74rem; text-align: right; }

.chip { display: inline-block; font-size: .7rem; font-weight: 600; letter-spacing: .03em;
        text-transform: uppercase; padding: .1rem .42rem; border-radius: 5px;
        border: 1px solid var(--line); color: var(--muted); margin-left: .4rem; }
.chip.high { color: var(--accent-ink); border-color: var(--accent); }
.chip.low  { color: var(--warn-ink); border-color: var(--warn-line); background: var(--warn-bg); }

.detail { padding: 0 1rem 1rem; border-top: 1px solid var(--line); margin-top: .2rem; }
.portion { display: flex; align-items: center; gap: .5rem; margin: .8rem 0 .2rem;
           font-size: .87rem; color: var(--muted); flex-wrap: wrap; }
.portion button { padding: .25rem .6rem; font-size: .82rem; border: 1px solid var(--line);
                  background: transparent; color: var(--muted); border-radius: 7px; }
.portion button[aria-pressed="true"] { background: var(--accent); color: #fff;
                                       border-color: var(--accent); }

table.parts { width: 100%; border-collapse: collapse; margin-top: .8rem; font-size: .88rem; }
table.parts th { text-align: left; font-weight: 600; color: var(--muted);
                 font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
                 padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
table.parts td { padding: .34rem .4rem; border-bottom: 1px solid var(--line); }
table.parts td:nth-child(2), table.parts td:nth-child(3),
table.parts th:nth-child(2), table.parts th:nth-child(3) {
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.parts tr:last-child td { border-bottom: none; }
.proxy-note { color: var(--warn-ink); font-size: .78rem; }
.note { color: var(--muted); font-size: .84rem; margin: .7rem 0 0; font-style: italic; }

/* ── warn + history + footer */
.warn-card { background: var(--warn-bg); border-color: var(--warn-line); }
.warn-card h3 { margin: 0 0 .3rem; font-size: 1rem; }
.warn-card p { margin: 0 0 .5rem; font-size: .92rem; }
.warn-card ul { margin: 0 0 .7rem; padding-left: 1.15rem; }
.warn-card li { font-size: .92rem; }

.hist-head { display: flex; justify-content: space-between; align-items: center;
             margin-bottom: .6rem; }
.hist-row { display: flex; justify-content: space-between; gap: 1rem;
            padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.hist-row:last-child { border-bottom: none; }
.hist-row .when { color: var(--muted); }
.hist-row .kc { font-variant-numeric: tabular-nums; font-weight: 600; }

.disclaimer { color: var(--muted); font-size: .87rem; margin: 1.2rem 0 0;
              padding: .85rem 1rem; border-left: 3px solid var(--line); }

.foot { margin-block: 3rem 2.5rem; color: var(--muted); font-size: .84rem; }
.foot p { margin: .5rem 0; }
.foot a { color: var(--accent-ink); }

@media (max-width: 430px) {
  .macros { gap: 1.1rem; }
  .total-head { flex-direction: column-reverse; align-items: flex-start; gap: .6rem; }
  /* keep the three portion buttons on one row under their label */
  .portion > span { flex: 1 0 100%; }
  .portion button { flex: 1; }
}
