:root {
  --bg: #f4f6f7; --card: #ffffff; --text: #17202a; --muted: #66727f; --border: #dde3e8;
  --accent: #0f766e; --accent-ink: #ffffff; --water: #2563eb; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1215; --card: #182026; --text: #e6edf2; --muted: #93a1ad; --border: #2a353e;
    --accent: #2dd4bf; --accent-ink: #062320; --water: #60a5fa; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
  }
}
* { 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; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.2em; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px; background: var(--bg); }
.toast { font-size: .85rem; background: var(--accent); color: var(--accent-ink); padding: 4px 10px;
  border-radius: 999px; opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }

.view { padding: 0 12px calc(84px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

button, .button, .photo-btn { font: inherit; border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; }
button:active, .button:active { transform: scale(.98); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.danger { color: var(--bad); }
.link { background: none; border: none; color: var(--accent); padding: 8px 0; }
.wide { width: 100%; margin-top: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row > * { flex: 1 1 auto; }

input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px; width: 100%; }
label { display: block; color: var(--muted); font-size: .9rem; }
label input { margin-top: 4px; }
.stack { display: grid; gap: 10px; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.inline-form input[type="datetime-local"] { grid-column: 1 / -1; grid-row: 2; }
input, select { min-width: 0; }

.bar { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; width: 0; background: var(--ok); transition: width .4s; }
.bar-fill.water { background: var(--water); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--bad); }

.big-value { font-size: 2.2rem; font-weight: 700; }
.big-value small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: var(--bg); border-radius: 10px; padding: 10px; }
.tile .label { font-size: .8rem; color: var(--muted); }
.tile .val { font-size: 1.3rem; font-weight: 650; }
.tile .when { font-size: .75rem; color: var(--muted); }

.meal-list, .history { list-style: none; padding: 0; margin: 8px 0 0; }
.meal-list li, .history li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.meal-list img, .history img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }
.history .grow, .meal-list .grow { flex: 1; min-width: 0; }
.history .sub, .meal-list .sub { font-size: .8rem; color: var(--muted); }
.history .x { border: none; background: none; color: var(--muted); padding: 6px; }

.photo-btn { width: 100%; margin: 6px 0; }
#meal-note { margin-top: 6px; }
.meal-preview { width: 100%; max-height: 280px; object-fit: cover; border-radius: 10px; margin-bottom: 8px; }
table.items { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .95rem; }
table.items th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 500; }
table.items td { padding: 6px 4px; border-top: 1px solid var(--border); vertical-align: middle; }
table.items input { padding: 6px; width: 72px; }
table.items .name input { width: 100%; }
table.items .src { font-size: .72rem; color: var(--muted); }
.add-item { display: grid; grid-template-columns: 1fr 70px auto; gap: 6px; }
.total-row { display: flex; justify-content: space-between; font-size: 1.1rem; margin: 12px 0; }

.seg { display: flex; gap: 6px; margin-bottom: 12px; }
.seg button { flex: 1; }
.seg .on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar button { flex: 1; border: none; border-radius: 0; background: none; padding: 8px 0 10px;
  font-size: .72rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabbar button span { font-size: 1.3rem; }
.tabbar button.on { color: var(--accent); font-weight: 600; }

.screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; }
.login-box form { display: grid; gap: 12px; margin-top: 12px; }

.spinner { width: 36px; height: 36px; margin: 16px auto 8px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
canvas { max-height: 260px; }
