:root {
  --bg: #f4f6f4; --card: #fff; --text: #1b2a22; --muted: #6b7c72;
  --accent: #2f8f5b; --accent-ink: #fff; --over: #d6453d; --border: #dde5df;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111613; --card: #1a221d; --text: #e7efe9; --muted: #8fa397;
          --accent: #3fb878; --accent-ink: #0b130e; --over: #ff6b62; --border: #2a362e; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
main { max-width: 520px; margin: 0 auto; padding: 12px 16px 48px; }
header { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; }
.brand { font-weight: 700; font-size: 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px;
        padding: 16px; margin-bottom: 14px; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 12px; }
button { font: inherit; border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
         background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); font-weight: 500; }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; font-weight: 500; }
input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
        background: var(--bg); color: var(--text); min-width: 0; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { display: grid; gap: 10px; width: 100%; max-width: 340px; }
.error { color: var(--over); margin: 0; font-size: 14px; }

.daynav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.daynav button { font-size: 24px; padding: 4px 14px; }
.daybtn { background: none; color: var(--text); font-weight: 600; }

.remaining-card { text-align: center; }
.label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.remaining { font-size: 64px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.remaining.over { color: var(--over); }
.bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin: 12px 0 8px; }
#bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s; }
#bar-fill.over { background: var(--over); }
.sub { color: var(--muted); font-size: 14px; }

.foods { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.food { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
        background: var(--bg); color: var(--text); border: 1px solid var(--border); text-align: left;
        padding: 12px; min-height: 64px; }
.food:active { transform: scale(.97); }
.food .kcal { color: var(--muted); font-weight: 500; font-size: 14px; }
.food .del { position: absolute; top: 2px; right: 6px; color: var(--muted); font-size: 16px; padding: 2px 4px;
             background: none; }
.food-form { display: grid; grid-template-columns: 1fr 80px auto; gap: 8px; margin-top: 14px; }

.entries { list-style: none; margin: 0; padding: 0; }
.entries li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.entries li:last-child { border-bottom: 0; }
.entries .name { flex: 1; }
.entries .cal { font-variant-numeric: tabular-nums; color: var(--muted); }
.entries .undo { background: none; color: var(--muted); padding: 2px 8px; font-size: 18px; }
.empty { color: var(--muted); padding: 6px 0; }

/* calendar */
:root { --c-over: #d6453d; --c-ok: #2f8f5b; --c-under: #8a948e; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
.cal-head button { font-size: 22px; padding: 2px 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { color: var(--muted); font-size: 12px; text-align: center; margin-bottom: 4px; }
.cal-day { aspect-ratio: 1; padding: 0; border-radius: 10px; background: var(--bg); color: var(--text);
           font-weight: 500; border: 2px solid transparent; }
.cal-day.over { background: var(--c-over); color: #fff; }
.cal-day.ontarget { background: var(--c-ok); color: #fff; }
.cal-day.under { background: var(--c-under); color: #fff; }
.cal-day.today { border-color: var(--text); }
.cal-day.selected { outline: 3px solid var(--accent); outline-offset: 1px; }
.cal-pad { visibility: hidden; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dot.over { background: var(--c-over); } .dot.ontarget { background: var(--c-ok); } .dot.under { background: var(--c-under); }

.weight-form { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; }
.unit { color: var(--muted); }

/* foods page + protein */
.h2row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.h2row h2 { margin: 0; }
a.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.stack { display: grid; gap: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
select { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); min-width: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 10px; border: 1px solid var(--border);
            background: var(--bg); color: var(--text); font-weight: 500; cursor: pointer; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg input:disabled + span { opacity: .6; cursor: default; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.total { font-weight: 600; margin: 4px 0 0; }
.comp-row { display: grid; grid-template-columns: 1fr 90px auto auto; gap: 8px; align-items: center; }
.row-btns { display: flex; gap: 8px; }
.entries small { display: block; color: var(--muted); font-size: 13px; }
.food .kcal + .kcal { margin-top: -2px; }
.entries .undo[data-edit], .entries .undo[data-copy] { font-size: 14px; font-weight: 500; }
.comp-row .undo { background: none; color: var(--muted); padding: 2px 8px; font-size: 18px; }
