:root {
  --bg: #f5f7f6;
  --card: #ffffff;
  --text: #17201d;
  --muted: #64716c;
  --line: #e1e7e4;
  --accent: #0f766e;
  --accent-soft: #d5f0ec;
  --protein: #2563eb;
  --carbs: #d97706;
  --fat: #c026d3;
  --danger: #dc2626;
  --ok: #16a34a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --card: #17201d;
    --text: #e8efec;
    --muted: #93a39d;
    --line: #26332e;
    --accent: #2dd4bf;
    --accent-soft: #123a35;
    --protein: #60a5fa;
    --carbs: #fbbf24;
    --fat: #e879f9;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; margin: 0; }
.who { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; color: var(--muted); font-size: 14px; }
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar button { background: none; border: 0; padding: 8px 0 10px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabbar button span { font-size: 20px; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; padding: 12px 16px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; width: 100%; }
@media (prefers-color-scheme: dark) { .btn { color: #04201c; } }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: none; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: none; color: var(--danger); border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; width: auto; font-size: 14px; }
.btn:disabled { opacity: .5; }
.datenav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.datenav strong { font-size: 17px; }
.datenav button { background: var(--card); border: 1px solid var(--line); border-radius: 10px; width: 44px; height: 40px; font-size: 18px; }
.summary { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; }
.ring { position: relative; width: 120px; height: 120px; }
.ring svg { transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring .center b { font-size: 22px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 4px 0 8px; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.macro { font-size: 13px; display: flex; justify-content: space-between; }
.list-item { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; cursor: pointer; }
.list-item:first-of-type { border-top: 0; }
.list-item img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; flex: none; }
.list-item .ph { width: 52px; height: 52px; border-radius: 10px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 22px; flex: none; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .kcal { font-weight: 700; white-space: nowrap; }
.photo-drop { border: 2px dashed var(--line); border-radius: 14px; padding: 24px 12px; text-align: center; cursor: pointer; }
.photo-drop img { max-width: 100%; max-height: 300px; border-radius: 10px; }
.item-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.item-row .grid4 input { padding: 8px 6px; text-align: center; }
.item-row .mini { font-size: 11px; color: var(--muted); text-align: center; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; padding: 10px 0; }
.totals b { display: block; font-size: 18px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.set-row { display: grid; grid-template-columns: 28px 1fr 1fr 32px; gap: 6px; align-items: center; margin-bottom: 6px; }
.set-row input { padding: 8px; text-align: center; }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.ex-block { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 70px; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 14px; }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chart { width: 100%; height: 160px; }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
.spinner { width: 18px; height: 18px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.login { max-width: 380px; margin: 40px auto; }
.stack > * + * { margin-top: 8px; }
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 130px; }
.msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; white-space: normal; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
@media (prefers-color-scheme: dark) { .msg.user { color: #04201c; } }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0 6px; padding-left: 20px; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); padding: 8px 16px; z-index: 9; }
.composer .inner { max-width: 640px; margin: 0 auto; }
.composer .row textarea { min-height: 44px; max-height: 140px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 10px; font-size: 13px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chips .chip { display: inline-flex; align-items: center; }
.chips .chip .x { border: 0; padding: 0 4px; font-size: 14px; }
.chips a.btn { width: auto; flex: none; text-decoration: none; }
label.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-weight: normal; }
label.check input { width: auto; }
.plan-ex { padding: 8px 0; border-top: 1px solid var(--line); }
.plan-ex:first-of-type { border-top: 0; }
.plan ul { margin: 0; padding-left: 20px; } .plan li { margin-bottom: 6px; }
.alert { margin-top: 8px; padding: 8px 10px; border-radius: 10px; font-size: 14px; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.alert.warn { border-left-color: var(--carbs); background: color-mix(in srgb, var(--carbs) 14%, var(--card)); }
.alert.danger { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, var(--card)); }
.alert .btn { margin-top: 6px; }
#menuDays button { min-width: 40px; padding: 6px 4px; }
