:root {
  --green: #14532d; --green2: #166534; --accent: #b45309;
  --bg: #f7f7f4; --card: #ffffff; --line: #ddd8ce; --text: #1c1917; --muted: #78716c;
  --err: #b91c1c; --tabbar-h: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
}
h1, h2, h3, h4 { margin: 0.4em 0; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.45em 0; }
input, select, textarea {
  width: 100%; padding: 0.55em 0.6em; margin-top: 0.25em;
  border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; background: #fff; color: var(--text);
}
button {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 9px; padding: 0.55em 0.9em; font-size: 0.95rem; cursor: pointer; min-height: 40px;
}
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.small { min-height: 32px; padding: 0.3em 0.6em; font-size: 0.85rem; }
button.big { font-size: 1.05rem; padding: 0.7em 1em; }
button.full { width: 100%; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.danger { color: var(--err); border-color: var(--err); }
button.armed { background: var(--err); border-color: var(--err); color: #fff; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin: 10px 0;
}
.muted { color: var(--muted); } .small { font-size: 0.82rem; } .error { color: var(--err); min-height: 1em; }
.notice.warn { background: #fef3c7; border: 1px solid #f59e0b; border-radius: 8px; padding: 8px 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; } .row.gap { gap: 10px; margin: 10px 0; }
.grow { flex: 1; } .center { text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; }
.big-text { font-size: 1.35rem; font-weight: 700; }

/* header + tabs */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  background: var(--green); color: #fff; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar button { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tabbar button { flex: 1; border: none; border-radius: 0; background: transparent; font-size: 0.95rem; }
.tabbar button.active { color: var(--green); font-weight: 700; box-shadow: inset 0 2px 0 var(--green); }
.tabpage { padding: 10px 12px; max-width: 720px; margin: 0 auto; }

/* today */
.datenav { display: flex; gap: 8px; align-items: center; }
.datenav input { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: none; border-radius: 0; }
.seg button.active { background: var(--green); color: #fff; }
.totals .kcal { font-size: 1.5rem; font-weight: 700; }
.bar { height: 8px; background: #eee7db; border-radius: 4px; overflow: hidden; margin: 3px 0 8px; }
.bar > div { height: 100%; background: var(--green2); }
.bar.over > div { background: var(--err); }
.macro-row { display: flex; justify-content: space-between; font-size: 0.85rem; }
.meal-group h3 { display: flex; justify-content: space-between; align-items: baseline; }
.entry { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid #f0ece3; align-items: flex-start; }
.entry:last-child { border-bottom: none; }
.entry .info { flex: 1; min-width: 0; }
.entry .name { font-weight: 600; }
.entry .meta { font-size: 0.82rem; color: var(--muted); }
.entry-editor { background: #faf8f3; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin: 6px 0; }

/* sheets — baseline phone rules: background scroll locked by JS while open,
   content is a bounded contained scroller, sticky foot above safe area */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.45);
  overscroll-behavior: none;
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; top: max(4vh, env(safe-area-inset-top));
  background: var(--bg); border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto;
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 10px 14px; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  flex: 0 0 auto; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--card);
}
.result-row, .draft-row {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; margin: 8px 0;
}
.result-row .name { font-weight: 600; }
.badge { font-size: 0.7rem; border: 1px solid var(--line); border-radius: 20px; padding: 1px 7px; color: var(--muted); }
.badge.off { color: #7c2d12; border-color: #fdba74; } .badge.usda { color: #1e3a8a; border-color: #93c5fd; } .badge.saved { color: var(--green); border-color: #86efac; }
.flag { color: var(--accent); font-weight: 600; font-size: 0.82rem; }
video { width: 100%; border-radius: 10px; margin-top: 8px; }

/* fasting ring */
.ring-bg { fill: none; stroke: #eee7db; stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--green2); stroke-width: 12; stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; }
.hist-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid #f0ece3; font-size: 0.92rem; }
.hist-row:last-child { border-bottom: none; }

/* login + toast */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: #1c1917; color: #fff; padding: 10px 16px; border-radius: 24px; z-index: 40; font-size: 0.92rem;
  max-width: 92vw; text-align: center;
}
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr 1fr; } }
