  :root {
    --bg: #f5f3ee; --card: #ffffff; --ink: #1c2621; --muted: #6a756e; --line: #e4e0d6;
    --chip: #eeebe3; --accent: #2e7a53; --accent-soft: #e3f1e8; --accent-ink: #ffffff;
    --s-low: #3a7bd5; --s-ok: #2f9a5c; --s-high: #d39b12; --s-over: #d4472f;
    --shadow: 0 1px 2px rgba(20,30,25,.06), 0 4px 16px rgba(20,30,25,.05);
    --radius: 14px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
            "Hiragino Sans", "Apple SD Gothic Neo", "Noto Sans KR", Roboto, sans-serif;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #111513; --card: #1a201d; --ink: #e8ede9; --muted: #98a39c; --line: #2a322e;
      --chip: #232b27; --accent: #55b585; --accent-soft: #1f3529; --accent-ink: #0d1a13;
      --s-low: #6aa6f6; --s-ok: #5cc08a; --s-high: #f0c24b; --s-over: #f27b63;
      --shadow: 0 1px 2px rgba(0,0,0,.3);
    }
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px;
    -webkit-text-size-adjust: 100%; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  button, input, select, textarea { font: inherit; color: inherit; }
  input, select, textarea { font-size: 16px; }
  [hidden] { display: none !important; }
  .muted { color: var(--muted); }
  .num { font-variant-numeric: tabular-nums; }
  small { font-size: 12px; }

  /* Header */
  .top { position: sticky; top: 0; z-index: 20; background: var(--bg); background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
  .top-inner { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
  .brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
  .tabs { margin-left: auto; display: flex; background: var(--chip); border-radius: 10px; padding: 3px; }
  .tab { border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
  .tab.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
  .sync { flex: none; height: 34px; min-width: 34px; padding: 0 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
    font-weight: 700; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
  .sync.pending { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .sync.error { background: var(--s-over); color: #fff; border-color: var(--s-over); }

  main { max-width: 1080px; margin: 0 auto; padding: 12px 16px 48px; }
  .card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
  .card + .card { margin-top: 12px; }

  .datebar { display: flex; align-items: center; gap: 6px; margin: 4px 0 12px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
    font-size: 20px; line-height: 1; display: inline-grid; place-items: center; flex: none; }
  .date-pick { position: relative; flex: 1; min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
    display: flex; align-items: center; justify-content: center; font-weight: 650; cursor: pointer; padding: 0; }
  .date-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; }
  .ghost { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 0 12px; height: 40px; cursor: pointer; font-weight: 600; }
  .ghost.small { font-size: 14px; }
  .primary { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 12px; height: 48px; padding: 0 18px; font-weight: 700; cursor: pointer; }
  .primary:disabled, .ghost:disabled { opacity: .55; cursor: default; }
  .block { width: 100%; }
  .danger { color: var(--s-over); }
  .link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 650; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

  /* Day */
  .day-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
  @media (min-width: 880px) { .day-grid { grid-template-columns: 370px minmax(0, 1fr); align-items: start; } #totalsCard { position: sticky; top: 72px; } }
  .day-count { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin: -6px -4px 4px 0; font-size: 12.5px; color: var(--muted); }
  .day-count .swc { height: 30px; width: 44px; }
  #totalsCard.skipped .kc-row, #totalsCard.skipped .rbar.lg, #totalsCard.skipped .nut-grid { opacity: .5; }
  .kc-row { display: flex; align-items: stretch; justify-content: space-between; gap: 8px; }
  .kc-right { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 8px; flex: none; }
  .big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
  .kc-left { font-weight: 700; }
  .day-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 2px 0 14px; }
  .meta-chip { border: 1px solid var(--line); background: var(--chip); border-radius: 99px; padding: 5px 11px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
  .meta-chip small { color: var(--muted); font-weight: 500; }
  .meta-chip.static { cursor: default; }
  .tap { cursor: pointer; }
  .nut.tap { border-radius: 8px; margin: -4px; padding: 4px; }
  @media (hover: hover) { .nut.tap:hover { background: var(--chip); } }
  /* breakdown popup */
  .brk-sum { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
  .brk-sum .v { font-size: 26px; font-weight: 750; }
  .brk-list { list-style: none; margin: 10px 0 0; padding: 0; }
  .brk { display: grid; grid-template-columns: minmax(0, 1fr) auto 52px; column-gap: 10px; row-gap: 5px; align-items: center; width: 100%;
    text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 2px; cursor: pointer; color: inherit; font: inherit; }
  .brk .nm { font-weight: 600; overflow-wrap: anywhere; }
  .brk .nm small { color: var(--muted); font-weight: 500; }
  .brk .vv { font-weight: 650; white-space: nowrap; text-align: right; }
  .brk .pp { font-weight: 750; text-align: right; white-space: nowrap; }
  .brk .sb { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--chip); overflow: hidden; }
  .brk .sb i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
  .brk.none { cursor: pointer; color: var(--muted); }
  .rbar { position: relative; height: 7px; background: var(--chip); border-radius: 99px; overflow: hidden; }
  .rbar.lg { height: 11px; margin: 10px 0 12px; }
  .rbar .zone { position: absolute; top: 0; bottom: 0; background: rgba(47,154,92,.18); background: color-mix(in srgb, var(--s-ok) 20%, transparent); }
  .rbar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--muted); transition: width .25s; }
  .s-low { --sc: var(--s-low); } .s-ok { --sc: var(--s-ok); } .s-high { --sc: var(--s-high); } .s-over { --sc: var(--s-over); }
  .fill.s-low, .fill.s-ok, .fill.s-high, .fill.s-over { background: var(--sc); }
  .txt.s-low, .txt.s-ok, .txt.s-high, .txt.s-over, td.s-low, td.s-ok, td.s-high, td.s-over { color: var(--sc); }
  .nut-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; } /* equal columns whatever the numbers */
  .nut-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 13px; margin-bottom: 5px; }
  .nut-top .lbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nut-top .val { font-weight: 700; white-space: nowrap; }
  .nut-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: flex; justify-content: space-between; gap: 6px; white-space: nowrap; }
  .nut-sub > span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .nut-sub .pct, .kc-pct { font-weight: 700; color: var(--ink); }
  .footnote { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
  details.micro { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
  details.micro summary { cursor: pointer; font-weight: 650; font-size: 14px; color: var(--muted); list-style: none; display: flex; justify-content: space-between; }
  details.micro summary::-webkit-details-marker { display: none; }
  details.micro summary::after { content: '▾'; }
  details.micro[open] summary::after { content: '▴'; }
  details.micro .nut-grid { margin-top: 12px; }

  .meal { padding: 0; overflow: hidden; }
  .meal + .meal { margin-top: 12px; }
  .meal-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; }
  .meal-head h3 { margin: 0; font-size: 16px; }
  .meal-head .add-mini { margin-left: auto; }
  .add-mini { width: 32px; height: 32px; border-radius: 9px; border: 0; background: var(--accent-soft); color: var(--accent); font-size: 20px; cursor: pointer; display: inline-grid; place-items: center; }
  .items { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
  /* item rows: [switch] [name, quantity below] [P] [F] [C] [$] [E] [x]; everything lines up with the name's first line */
  .item { display: grid; grid-template-columns: 40px minmax(0, 1fr) repeat(4, 30px) 38px 22px; column-gap: 3px; align-items: start;
    padding: 8px 2px 8px 2px; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 19px; }
  .item:last-child { border-bottom: 0; }
  .item-main { min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; color: inherit; font: inherit; }
  .item-name { display: block; font-weight: 600; font-size: 13.5px; overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; }
  .item-name .qty { display: block; color: var(--accent); font-weight: 600; font-size: 12.5px; line-height: 17px; }
  .item .c { text-align: right; white-space: nowrap; cursor: pointer; }
  .item .c.k { font-weight: 700; }
  .item .c .d1 { display: none; }
  .item.off .item-main, .item.off .c { opacity: .4; }
  .item.off .item-name { text-decoration: line-through; text-decoration-thickness: 1px; }
  @media (min-width: 641px) {
    .item { grid-template-columns: 46px minmax(0, 1fr) repeat(5, 64px) 34px; column-gap: 6px; font-size: 15px; line-height: 22px; padding: 10px 4px 10px 0; }
    .item-name { font-size: 15px; }
    .item-name .qty { font-size: 13.5px; line-height: 19px; }
    .item .c .d1 { display: inline; }
    .item .c .d0 { display: none; }
  }
  /* column titles: short on phones, full words on wider screens */
  .meal-th { border-top: 1px solid var(--line); border-bottom: 0; font-size: 11.5px; line-height: 15px; color: var(--muted); padding-top: 5px; padding-bottom: 3px; }
  /* each title is centered over its numbers: a box as wide as the widest number, at the right edge of the column */
  .meal-th .c { cursor: default; display: flex; justify-content: flex-end; }
  .meal-th .c .tt { display: flex; justify-content: center; white-space: nowrap; }
  .meal-th b { font-weight: 600; }
  .meal-th .fl { display: none; }
  @media (min-width: 641px) { .meal-th { font-size: 12.5px; line-height: 16px; } .meal-th .ab { display: none; } .meal-th .fl { display: inline; } }
  .meal-sum { background: color-mix(in srgb, var(--chip) 55%, var(--card)); font-weight: 700; }
  .meal-sum .lbl { justify-self: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
  .meal-sum .c { cursor: default; }
  /* switch cell = the name line + the quantity line, so the switch sits in their middle and stays there when a long name wraps */
  .swc { height: 36px; display: flex; align-items: center; justify-content: center; }
  @media (min-width: 641px) { .swc { height: 41px; } }
  .sw { margin: 0; width: 32px; height: 18px; padding: 0; border: 0; border-radius: 99px; background: color-mix(in srgb, var(--muted) 45%, transparent); position: relative; cursor: pointer; flex: none; }
  .sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
  .sw.on { background: var(--accent); }
  .sw.on::after { transform: translateX(14px); }
  /* iPhone's own switch draws at about 68x30; shrink it to ~34 px around its centre */
  .nsw { flex: none; margin: 0; accent-color: var(--accent); transform: scale(.48); }
  .del { justify-self: end; border: 0; background: none; color: var(--muted); width: 22px; height: 20px; padding: 0; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1; }
  @media (min-width: 641px) { .del { width: 32px; font-size: 17px; } }
  .del.confirm { width: auto; padding: 0 10px; background: var(--s-over); color: #fff; font-size: 13px; font-weight: 700; position: relative; z-index: 1; white-space: nowrap; }
  .empty { padding: 0 14px 14px; color: var(--muted); font-size: 14px; }
  .unsynced { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: 2px; }

  .badge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; padding: 2px 6px; border-radius: 6px; background: var(--chip); color: var(--muted); flex: none; }
  .b-TFDA { background: #e2f1e7; color: #23704a; } .b-JP { background: #fbe7e3; color: #a7372a; }
  .b-KR { background: #e4ecfa; color: #2b57ad; } .b-USDA { background: #eee8fa; color: #6542b1; }
  @media (prefers-color-scheme: dark) {
    .b-TFDA { background: #1f3a2b; color: #8fd6ae; } .b-JP { background: #3d2320; color: #f0a497; }
    .b-KR { background: #1f2b44; color: #9dbcf5; } .b-USDA { background: #2d2442; color: #c2abf5; }
  }

  /* Calendar */
  .cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
  .cal-head .m { flex: 1; text-align: center; font-weight: 750; font-size: 16px; }
  .cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
  .cal .wd { text-align: center; font-size: 11.5px; color: var(--muted); font-weight: 650; padding-bottom: 2px; }
  .cd { border: 0; border-radius: 10px; min-height: 50px; padding: 5px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
    background: var(--chip); color: var(--muted); }
  .cd span { font-weight: 700; font-size: 14px; }
  .cd small { font-size: 10px; font-weight: 600; }
  .cd.s-low, .cd.s-ok, .cd.s-high, .cd.s-over { background: color-mix(in srgb, var(--sc) 24%, var(--card)); color: var(--ink); }
  .cd.s-low small, .cd.s-ok small, .cd.s-high small, .cd.s-over small { color: var(--sc); filter: brightness(.85); }
  .cd.skip small { text-decoration: line-through; color: var(--muted); }
  .cd.today span { text-decoration: underline; text-underline-offset: 3px; }
  .cd.sel { outline: 2px solid var(--ink); outline-offset: 1px; }

  /* Week */
  .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px; }
  .stats .card + .card { margin-top: 0; }
  .stat { padding: 12px; }
  .stat .k { font-size: 12.5px; color: var(--muted); }
  .stat .v { font-size: 21px; font-weight: 750; margin-top: 4px; }
  @media (max-width: 560px) { .stats { grid-template-columns: 1fr 1fr; } }
  .chart-wrap { position: relative; padding-top: 20px; margin-bottom: 8px; }
  .chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
  .col { display: flex; flex-direction: column; align-items: center; cursor: pointer; border: 0; background: none; padding: 0; min-width: 0; }
  .track { position: relative; width: 100%; height: 160px; display: flex; align-items: flex-end; justify-content: center; }
  .col.skip .barv { background: var(--chip); }
  .col.skip .cap { text-decoration: line-through; color: var(--muted); }
  tr.skip td { color: var(--muted); }
  tr.skip td small { font-size: 11px; }
  .barv { width: 100%; max-width: 46px; background: var(--sc, var(--chip)); border-radius: 8px 8px 3px 3px; min-height: 3px; }
  .goal-tick { position: absolute; left: 8%; right: 8%; border-top: 2px dashed var(--ink); opacity: .45; }
  .cap { position: absolute; left: 0; right: 0; text-align: center; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
  .col .day { font-size: 12px; margin-top: 6px; color: var(--muted); white-space: nowrap; }
  .col.today .day { color: var(--ink); font-weight: 700; }
  .table-wrap { overflow-x: auto; padding: 0; }
  table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
  th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
  th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; }
  thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
  tbody tr { cursor: pointer; }
  tfoot td { font-weight: 700; }
  td.dim { color: var(--muted); }
  /* week table: nutrients down the side, days across */
  table.wk tbody tr { cursor: default; }
  table.wk td[data-goto], table.wk th.dh { cursor: pointer; }
  table.wk td:first-child small { color: var(--muted); font-size: 11.5px; }
  table.wk th.dh small { font-weight: 500; }
  table.wk th.dh { width: 10%; } /* the seven day columns share the width evenly */
  table.wk th.today { color: var(--accent); }
  table.wk .skip { color: var(--muted); }
  table.wk td.skip { text-decoration: line-through; }
  table.wk .sep { border-left: 1px solid var(--line); }
  table.wk td.b { font-weight: 700; }

  /* Foods tab & forms */
  .row { display: flex; gap: 8px; align-items: center; }
  .only-narrow { display: none; }
  @media (max-width: 640px) { .only-wide { display: none; } .only-narrow { display: inline; } }
  .item.soff .item-main, .item.soff .c { opacity: .45; }
  /* supplement nutrients: label + box pairs (one pair per row on phones, two on wider screens) */
  .nf-grid.sp-grid { grid-template-columns: minmax(0, 1fr) 120px; column-gap: 10px; }
  @media (min-width: 641px) { .nf-grid.sp-grid { grid-template-columns: minmax(0, 1fr) 110px minmax(0, 1fr) 110px; column-gap: 14px; } }
  .supp-card .meal-head .ghost { margin-left: auto; }
  .grow { flex: 1; min-width: 0; }
  .inp { height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--card); color: var(--ink); width: 100%; }
  textarea.inp { height: 70px; padding: 10px 12px; resize: vertical; }
  .inp:focus { outline: 2px solid rgba(46,122,83,.4); border-color: var(--accent); }
  .inp.from-ref { background: var(--accent-soft); }
  .form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .form-grid.one { grid-template-columns: 1fr; }
  .form-grid.two { grid-template-columns: 1fr 1fr; }
  label.fld { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
  .form-grid .span2 { grid-column: 1 / -1; }
  .fhint { font-size: 12px; color: var(--muted); }
  label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
  label.check input { width: 20px; height: 20px; }
  h2 { font-size: 17px; margin: 0 0 4px; }
  .help { font-size: 13px; color: var(--muted); margin: 4px 0 12px; line-height: 1.45; }
  .steps { margin: 0 0 12px; padding-left: 22px; font-size: 14px; line-height: 1.55; }
  .steps li { margin: 6px 0; }
  /* sizes and add-ons */
  .opt-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 8px; }
  #optPick:not(:empty) { margin: -4px 0 14px; }
  .opt-line .pill { line-height: 1.25; }
  .opt-k { font-size: 13px; color: var(--muted); min-width: 62px; }
  .pill.addon:not(.on) { border-style: dashed; }
  .opt-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 8px; }
  .opt-list:empty { display: none; }
  .opt-row { display: flex; align-items: center; gap: 6px; }
  .opt-main { flex: 1; min-width: 0; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; font: inherit; color: var(--ink); cursor: pointer; }
  .opt-main .muted { font-size: 13px; }
  .opt-row.open .opt-main { border-color: var(--accent); }
  .opt-edit { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0 0 8px; background: var(--bg); }
  .bm-btn { display: inline-block; padding: 3px 10px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 650; text-decoration: none; cursor: grab; white-space: nowrap; }
  .help a { color: var(--accent); }
  .list { padding: 0; overflow: hidden; }
  .list-row { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 11px 14px; cursor: pointer; }
  .list-row:last-child { border-bottom: 0; }
  .lr-main { flex: 1; min-width: 0; }
  .lr-name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lr-sub { font-size: 12.5px; color: var(--muted); display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lr-right { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
  .lr-right b { color: var(--ink); }

  .nf-grid { display: grid; grid-template-columns: minmax(0, 1fr) 110px minmax(70px, auto); gap: 6px 8px; align-items: center; }
  .nf-l { font-size: 14px; }
  .nf-l small { color: var(--muted); }
  .nf-grid .inp { height: 40px; }
  .hint { border: 1px dashed var(--accent); background: none; color: var(--accent); border-radius: 8px; height: 34px; padding: 0 8px; font-size: 13px; font-weight: 650; cursor: pointer; white-space: nowrap; }
  .hint.none { border-color: var(--line); color: var(--muted); cursor: default; }
  .refbox { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px 10px; margin: 14px 0 6px; background: color-mix(in srgb, var(--chip) 45%, var(--card)); }
  .picked { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0 0; }
  .picked .nm { flex: 1; min-width: 160px; font-size: 14px; font-weight: 600; }
  /* reference matches: a scrolling list five rows tall */
  .res.ref-list { overflow-y: auto; overscroll-behavior: contain; border-bottom: 1px solid var(--line); }
  .res.ref-list li:last-child > button { border-bottom: 0; }
  /* "Nutrition per …" with the fill button beside it */
  /* reference values (per 100 g) scaled to a weight of your choice */
  .ref-w-row { display: flex; align-items: center; gap: 8px; margin: -2px 0 10px; font-size: 13px; color: var(--muted); }
  .ref-w-row .inp { width: 96px; height: 36px; }
  .nut-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0 6px; }
  .nut-head .sec-title { margin: 0; }
  .nut-head .ghost.small { padding: 6px 12px; flex: none; }
  .nut-btns { display: flex; gap: 6px; flex: none; }
  .nut-head .sec-title { flex: 1 1 auto; min-width: 0; }

  .rg-head, .rg-row { display: grid; grid-template-columns: 1.9fr 1fr 1fr 1fr 1fr; gap: 6px; align-items: center; }
  .rg-head { font-size: 11.5px; color: var(--muted); font-weight: 600; margin: 8px 0 4px; }
  .rg-head span:nth-child(2) { color: var(--s-low); } .rg-head span:nth-child(3) { color: var(--s-ok); } .rg-head span:nth-child(4) { color: var(--s-high); }
  .rg-item { padding: 10px 0; border-top: 1px solid var(--line); }
  .rg-name { font-weight: 650; font-size: 14px; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
  .rg-name small { color: var(--muted); font-weight: 500; }
  .rg-row .inp { height: 40px; padding: 0 8px; }
  .rg-row select.inp { padding: 0 4px; font-size: 14px; }
  @media (max-width: 560px) {
    .rg-head, .rg-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .rg-head span:first-child { display: none; }
    .rg-row select.inp { grid-column: 1 / -1; font-size: 16px; }
  }

  /* Sheet (modal) */
  .overlay { position: fixed; inset: 0; z-index: 50; background: rgba(10,15,12,.42); display: flex; align-items: flex-end; justify-content: center; }
  .sheet { width: 100%; max-width: 580px; max-height: 92vh; max-height: 92dvh; background: var(--card); border-radius: 18px 18px 0 0;
    display: flex; flex-direction: column; overflow: hidden; padding-bottom: env(safe-area-inset-bottom); animation: up .18s ease-out; }
  @media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; max-height: 88vh; } }
  .sheet.tall { height: 92vh; height: 92dvh; }
  @media (min-width: 700px) { .sheet.tall { height: 88vh; } }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
  .sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; }
  .sheet-title { flex: 1; min-width: 0; font-weight: 750; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sheet-body { padding: 4px 14px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .search { position: relative; padding: 0 14px 8px; }
  .search.flush { padding: 0; }
  .search .inp { padding-left: 38px; height: 46px; }
  .search .ico { position: absolute; left: 27px; top: 13px; color: var(--muted); pointer-events: none; }
  .search.flush .ico { left: 13px; }
  .meal-pick { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 8px; scrollbar-width: none; }
  .pill { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 13.5px; cursor: pointer; white-space: nowrap; font-weight: 600; }
  .pill.on { background: var(--ink); color: var(--card); border-color: var(--ink); }
  /* tags: Add food shows one tag at a time ("Whole food" = foods without a tag) */
  .tag-pick { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 8px; scrollbar-width: none; }
  .tag-pick:empty { display: none; }
  .tag-pick.flush { padding: 0 0 10px; }
  /* the sheet is a flex column: keep the pickers and search at full height, only the list below shrinks and scrolls */
  .sheet > .meal-pick, .sheet > .tag-pick, .sheet > .search, .sheet > .sheet-head { flex: none; }
  .sheet > .sheet-body { flex: 1 1 auto; min-height: 0; }
  .tpill { border: 0; background: var(--chip); color: var(--muted); border-radius: 8px; padding: 5px 10px; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; flex: none; }
  .tpill.on { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
  .tag-sugg { display: flex; flex-wrap: wrap; gap: 6px; }
  small.ftag { color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; margin-left: 6px; font-size: 11.5px; font-weight: 600; vertical-align: 1px; }
  .other-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .sec-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 6px; }
  /* food editor: headings in the same sentence case as its field labels */
  .ffe .sec-title { font-size: 13px; font-weight: 400; text-transform: none; letter-spacing: 0; }
  .res { list-style: none; margin: 0; padding: 0; }
  .res li > button { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: none; padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
  .res .r-main { flex: 1; min-width: 0; }
  .res .r-name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  small.fbrand { color: var(--muted); font-weight: 500; margin-left: 4px; font-size: 12.5px; }
  .res .r-sub { display: flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 2px; min-width: 0; }
  .res .r-sub .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .res .r-kcal { font-size: 13px; color: var(--muted); white-space: nowrap; text-align: right; }
  .res .r-kcal b { color: var(--ink); font-size: 14px; }
  .res li.on > button { background: var(--accent-soft); }
  .variants { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
  .more { display: grid; gap: 8px; margin-top: 12px; }
  .note { font-size: 13px; color: var(--muted); padding: 10px 0; line-height: 1.45; }
  .warnbox { font-size: 13px; color: var(--s-high); margin: 8px 0; }
  .per100 { font-size: 13px; color: var(--muted); background: var(--chip); border-radius: 10px; padding: 8px 10px; margin-bottom: 14px; line-height: 1.55; }
  .amount-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
  .unit-g { color: var(--muted); font-weight: 600; padding-right: 4px; }
  .chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
  .preview { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 10px; }
  .alln { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; margin-bottom: 14px; font-size: 13.5px; }
  .alln > div { display: flex; justify-content: space-between; gap: 8px; padding: 5px 2px; border-bottom: 1px dashed var(--line); }
  .alln > div span { color: var(--muted); }
  .alln small { color: var(--muted); font-weight: 500; }
  @media (max-width: 380px) { .alln { grid-template-columns: 1fr; } }
  .pv { background: var(--chip); border-radius: 10px; padding: 8px 4px; text-align: center; }
  .pv .k { font-size: 11.5px; color: var(--muted); }
  /* units sit in their own column so the numbers line up (g, mg, µg) */
  /* item panel: units flush right, numbers end in one place. Day summary: the unit simply follows its number */
  .alln .u { display: inline-block; width: 1.75em; margin-left: 4px; text-align: right; }
  .nut-top .val { position: relative; }
  .nut-top .val .u { margin-left: 3px; }
  .nut-top .val .miss { position: absolute; left: 100%; top: -4px; font-size: .85em; }
  .nut-top .val .miss:empty { display: none; }
  .pv .v { font-weight: 700; margin-top: 2px; }
  .pv.main { background: var(--accent-soft); }
  .pv.main .v { color: var(--accent); }
  .actions { display: grid; gap: 10px; margin-top: 12px; }
  .seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 3px; }
  .seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
  .seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

  .toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80;
    background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(92vw, 520px);
    box-shadow: 0 6px 24px rgba(0,0,0,.25); white-space: pre-line; }
  .toast.err { background: var(--s-over); color: #fff; }
  .spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -2px; }
  @keyframes sp { to { transform: rotate(360deg); } }
  .loading { padding: 30px; text-align: center; color: var(--muted); }
  @media (max-width: 440px) {
    .tab { padding: 6px 8px; font-size: 13.5px; }
    .brand .word { display: none; }
    .big { font-size: 30px; }
    .preview { grid-template-columns: repeat(3, 1fr); }
    .nf-grid { grid-template-columns: minmax(0, 1fr) 96px minmax(64px, auto); }
  }
