@font-face { font-family: "Work Sans"; font-weight: 400; font-display: swap; src: url("fonts/work-sans-400.woff2") format("woff2"); }
@font-face { font-family: "Work Sans"; font-weight: 500; font-display: swap; src: url("fonts/work-sans-500.woff2") format("woff2"); }
@font-face { font-family: "Work Sans"; font-weight: 600; font-display: swap; src: url("fonts/work-sans-600.woff2") format("woff2"); }
@font-face { font-family: "Work Sans"; font-weight: 700; font-display: swap; src: url("fonts/work-sans-700.woff2") format("woff2"); }

:root {
  --bg: #f3f4f1; --card: #ffffff; --raised: #f0f2ee; --line: #e2e5df;
  --text: #121512; --soft: #2b302b;
  --accent: #1f7a4d; --accent-press: #186640; --on-accent: #ffffff;
  --protein: #127e95; --carbs: #b7780e; --fat: #7b4bc4;
  --track: #e6e9e3; --tag-bg: #e3f1e8; --tag: #1b5e3c;
  --warn-bg: #fdf1e0; --warn: #7a4a06;
  --field: #b9c1b9; --shade: rgba(18, 21, 18, .45); --ink: #17241d;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: "Work Sans", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
body { font-size: 16px; line-height: 1.4; overscroll-behavior-y: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(104px + env(safe-area-inset-bottom)); min-height: 100vh; }
#app.no-tabs { padding-bottom: 32px; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 10px; padding: calc(14px + env(safe-area-inset-top)) 0 14px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.top h1 { font-size: 22px; margin: 0; line-height: 1.2; }
.top .grow { flex: 1; min-width: 0; }
.top .sub { font-size: 15px; font-weight: 500; color: var(--soft); margin-top: 2px; }
.iconbtn { width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; flex: none; padding: 0; }
.iconbtn svg { width: 20px; height: 20px; }
.backbtn { height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); padding: 0 14px 0 10px; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; flex: none; }
.backbtn svg { width: 18px; height: 18px; }
.who { width: 44px; height: 44px; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 18px; display: grid; place-items: center; flex: none; border: 0; }
.date { flex: 1; text-align: center; min-width: 0; }
.date .d1 { font-size: 19px; font-weight: 700; }
.date .d2 { font-size: 15px; font-weight: 500; color: var(--soft); margin-top: 2px; }
.title { font-size: 24px; margin: 4px 2px 4px; line-height: 1.25; }
.subtitle { font-size: 15px; margin: 0 2px 16px; color: var(--soft); }

/* ---------- cards and rows ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 14px; }
.card.tight { padding: 4px 18px; }
.card h2 { font-size: 19px; margin: 0 0 4px; line-height: 1.3; }
.card .lead, .lead { font-size: 15px; color: var(--soft); margin: 0 0 12px; line-height: 1.45; }
.card.planned { border-color: #b9dcc7; }
.h { font-size: 17px; font-weight: 700; margin: 22px 2px 10px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.tap { cursor: pointer; }
.row > .grow, .grow { flex: 1; min-width: 0; }
.rname { font-size: 16px; font-weight: 600; line-height: 1.3; }
.rsub { font-size: 15px; color: var(--soft); margin-top: 3px; line-height: 1.35; }
.rnum { font-size: 16px; font-weight: 700; white-space: nowrap; text-align: right; }
.slot { font-size: 14px; font-weight: 700; color: var(--soft); margin-bottom: 3px; }
.tag { display: inline-block; font-size: 13px; font-weight: 600; background: var(--tag-bg); color: var(--tag); padding: 3px 8px; border-radius: 6px; vertical-align: 1px; white-space: nowrap; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.brand { font-size: 13px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #eef0ff; color: #2c3a8c; margin-left: 6px; vertical-align: 1px; white-space: nowrap; }
.brand.lab { background: var(--raised); color: var(--soft); }
.brand.mine { background: var(--tag-bg); color: var(--tag); }
.note { font-size: 15px; line-height: 1.45; margin: 12px 2px 0; }
.empty { text-align: center; padding: 12px 4px; }
.empty .rname { margin-bottom: 6px; }

/* ---------- buttons ---------- */
.btn { height: 48px; border-radius: 8px; font-size: 16px; font-weight: 600; padding: 0 16px; border: 1px solid transparent; background: var(--raised); }
.btn.small { height: 40px; font-size: 15px; padding: 0 14px; white-space: nowrap; flex: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-press); }
.btn.secondary { background: var(--raised); border-color: var(--line); color: var(--text); }
.btn.secondary:active { background: var(--line); }
.btn.danger { background: #fbeaea; border-color: #f0cfcf; color: #8a1c1c; }
/* The one or two buttons a screen most needs found: dark, full width. */
.btn.ink { background: var(--ink); color: #ffffff; }
.btn.ink:active { background: #0b130e; }
.btn.full { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 > .wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 14px; }
.actions > .wide { grid-column: 1 / -1; }

/* ---------- segmented control, day strip, switches ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--raised); border: 1px solid var(--line); border-radius: 10px; }
.seg button { height: 40px; border-radius: 7px; border: 0; background: transparent; font-weight: 600; font-size: 15px; padding: 0 6px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
/* Which part of the day: meals on one row, drinks and extras across the next. */
.seg.pick { grid-auto-flow: row; grid-template-columns: repeat(12, 1fr); }
.seg.pick button.long { grid-column: 1 / -1; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.day { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 0; text-align: center; }
.day b { display: block; font-size: 15px; } .day span { font-size: 14px; font-weight: 500; }
.day.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.day.off { opacity: .45; }
.switch { width: 52px; height: 32px; border-radius: 16px; background: #c9cfc9; position: relative; flex: none; border: 0; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: left .15s; }
.switch.on { background: var(--accent); } .switch.on::after { left: 23px; }
.tick { width: 26px; height: 26px; border-radius: 6px; border: 2px solid #9aa39a; flex: none; display: grid; place-items: center; background: var(--card); padding: 0; }
.tick.on { background: var(--accent); border-color: var(--accent); }
.tick.on::after { content: ""; width: 7px; height: 13px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }

/* ---------- numbers ---------- */
.totals, .targets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.targets { margin-top: 0; }
.tot { background: var(--raised); border-radius: 8px; padding: 10px 6px; text-align: center; }
.tot b { display: block; font-size: 18px; } .tot span { font-size: 13px; font-weight: 600; color: var(--soft); }
.ok { font-size: 14px; font-weight: 700; color: var(--tag); background: var(--tag-bg); padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.ok.off { color: var(--warn); background: var(--warn-bg); }

/* ---------- diary ---------- */
.summary { display: grid; grid-template-columns: 128px 1fr; gap: 18px; align-items: center; }
.ringwrap { position: relative; width: 128px; height: 128px; }
.ring { width: 128px; height: 128px; }
.ring-track { fill: none; stroke: var(--track); stroke-width: 12; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; }
.ring-fill.over { stroke: #c0571f; }
.ring-mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-mid .big { font-size: 32px; font-weight: 700; line-height: 1; }
.ring-mid .lab { font-size: 14px; font-weight: 600; margin-top: 6px; color: var(--soft); }
.sum-row { display: flex; justify-content: space-between; font-size: 16px; padding: 6px 0; color: var(--soft); }
.sum-row b { color: var(--text); font-size: 17px; }
.sum-row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; color: var(--text); font-weight: 600; }
.lands { margin-top: 14px; font-size: 15px; line-height: 1.45; color: var(--soft); border-top: 1px solid var(--line); padding-top: 12px; }
.lands b { color: var(--text); }
.macros { display: grid; gap: 14px; }
.macro-head { display: flex; justify-content: space-between; align-items: baseline; }
.macro-name { font-weight: 600; font-size: 16px; }
.macro-num { font-size: 15px; color: var(--soft); }
.macro-num b { color: var(--text); font-size: 17px; }
.track { height: 10px; border-radius: 6px; background: var(--track); margin-top: 8px; overflow: hidden; }
.fill { height: 100%; border-radius: 6px; }
.fill.p { background: var(--protein); } .fill.c { background: var(--carbs); } .fill.f { background: var(--fat); }
.macro-left { font-size: 14px; color: var(--soft); margin-top: 6px; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.sec-title { font-size: 20px; font-weight: 700; }
.sec-kcal { text-align: right; white-space: nowrap; }
.sec-kcal b { font-size: 22px; font-weight: 700; display: block; line-height: 1.1; }
.sec-kcal span { font-size: 14px; color: var(--soft); }
.dishrow { padding: 12px 0 2px; }
.dish { font-size: 18px; font-weight: 600; line-height: 1.3; }
.dishmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 8px; font-size: 15px; color: var(--soft); }
.pill-status { font-size: 13px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--raised); color: var(--text); border: 1px solid var(--line); }
.pill-status.done { background: var(--tag-bg); color: var(--tag); border-color: transparent; }
.ings { margin-top: 10px; border-top: 1px solid var(--line); }
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.item:last-child { border-bottom: 0; }
.item-name { font-size: 16px; font-weight: 500; line-height: 1.3; }
.item-amt { font-size: 15px; color: var(--soft); margin-top: 3px; }
.item-kcal { font-size: 16px; font-weight: 600; white-space: nowrap; }
.snack { display: flex; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.snack-right { display: grid; justify-items: end; gap: 8px; }

/* ---------- how to make ---------- */
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 16px; line-height: 1.5; }
.steps li:last-child { border-bottom: 0; }
.steps li::before { content: counter(s); width: 30px; height: 30px; border-radius: 8px; background: var(--tag-bg); color: var(--tag); font-weight: 700; display: grid; place-items: center; }
.port-wrap { overflow-x: auto; }
table.port { width: 100%; border-collapse: collapse; font-size: 15px; }
table.port th { text-align: right; font-size: 14px; padding: 0 0 8px 6px; }
table.port th:first-child { text-align: left; padding-left: 0; }
table.port td { padding: 10px 0 10px 6px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; font-weight: 600; }
table.port td:first-child { text-align: left; padding-left: 0; white-space: normal; font-weight: 500; }
table.port tr.sum td { font-weight: 700; border-top: 2px solid var(--line); }

/* ---------- shopping ---------- */
.shoprow { display: flex; gap: 14px; align-items: flex-start; padding: 13px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.shoprow:last-child { border-bottom: 0; }
.shoprow .grow { flex: 1; }
.shoprow.done .rname { text-decoration: line-through; }

/* ---------- forms ---------- */
.ingrow { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ingrow .rname { grid-column: 1 / -1; }
.ingrow .field { height: 44px; max-width: 160px; }
.field { display: flex; align-items: center; gap: 10px; min-width: 0; height: 52px; border: 1.5px solid var(--field); border-radius: 10px; background: var(--card); padding: 0 14px; font-size: 17px; }
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 122, 77, .15); }
.field svg { width: 22px; height: 22px; flex: none; }
.field input::placeholder, textarea.area::placeholder { color: #4a514a; }
.field input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; height: 100%; font-size: 17px; padding: 0; }
.field .unit { font-weight: 600; color: var(--soft); }
.field.big input { font-size: 22px; font-weight: 700; }
textarea.area { width: 100%; min-height: 120px; border: 1.5px solid var(--field); border-radius: 10px; background: var(--card); padding: 12px 14px; font-size: 16px; line-height: 1.45; outline: 0; resize: vertical; }
textarea.area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 122, 77, .15); }
.label { display: block; font-size: 15px; font-weight: 600; margin: 14px 2px 6px; }
.label:first-child { margin-top: 0; }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form2 > *, .form4 > *, .grid2 > *, .amountbox > * { min-width: 0; }
.form4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.form4 .field { padding: 0 10px; }
.form4 .label { margin-top: 10px; font-size: 14px; }
.choice { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); margin-bottom: 8px; font-size: 16px; font-weight: 600; }
.choice.on { border-color: var(--accent); background: var(--tag-bg); color: var(--tag); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px; }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ---------- sheets and pop-ups ---------- */
.shade { position: fixed; inset: 0; background: var(--shade); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; background: var(--card); border-radius: 18px 18px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); z-index: 21; max-height: 90vh; overflow-y: auto; }
.sheet h2 { font-size: 20px; margin: 0 0 4px; line-height: 1.3; }
.sheet .lead { margin-bottom: 14px; }
.scan { position: relative; aspect-ratio: 4 / 3; margin: 0 0 14px; border-radius: 8px; overflow: hidden; background: #000; }
.scan video { display: block; width: 100%; height: 100%; object-fit: cover; }
.scan .aim { position: absolute; left: 12%; right: 12%; top: 30%; bottom: 30%; border: 2px solid #fff; border-radius: 8px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); pointer-events: none; }
.opt { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.opt .top2 { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.amountbox { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; align-items: center; }
.popup { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(400px, calc(100% - 32px)); background: var(--card); border-radius: 14px; z-index: 31; overflow: hidden; text-align: center; box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
.popup .msg { padding: 26px 22px 22px; }
.popup .msg h2 { font-size: 20px; margin: 0 0 8px; line-height: 1.3; }
.popup .msg p { font-size: 16px; margin: 0; line-height: 1.5; color: var(--soft); }
.popup .bar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; padding: 0 16px 16px; }
.popup-shade { position: fixed; inset: 0; background: var(--shade); z-index: 30; }
.busy { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(243, 244, 241, .82); }
.busy div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px 26px; font-size: 17px; font-weight: 600; text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, .12); }

/* ---------- unlock ---------- */
.unlock { min-height: 100vh; display: grid; align-content: center; padding: 24px 0; }
.logo { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 0 2px 4px; }
.pinrow { display: flex; justify-content: center; gap: 14px; margin: 20px 0 22px; }
.pindot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #9aa39a; }
.pindot.on { background: var(--accent); border-color: var(--accent); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pad button { height: 60px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 24px; font-weight: 600; }
.pad button.fn { font-size: 16px; }

/* ---------- tab bar ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-top: 1px solid var(--line); padding: 8px 8px calc(10px + env(safe-area-inset-bottom)); z-index: 10; }
.tabs-in { display: contents; }
.tab { display: grid; justify-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--soft); padding: 6px 0; border-radius: 8px; border: 0; background: none; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--text); background: var(--raised); }
/* The diary is where the app is used most: always in colour. */
.tab.hero { color: var(--on-accent); background: var(--accent); }
.tab.hero.on { background: var(--accent-press); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35); }

@media (min-width: 600px) {
  .tabs { left: 50%; transform: translateX(-50%); max-width: 560px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
