:root {
  --bg: #14130f;
  --card: #1f1d18;
  --card2: #2a2720;
  --line: #3a362c;
  --fg: #f3efe4;
  --muted: #a59e8c;
  --accent: #f2a93b;      /* calories */
  --p: #e8615a;           /* protein */
  --c: #5fb7d4;           /* carbs */
  --f: #b58de0;           /* fat */
  --good: #7cc36b;
  --danger: #e8615a;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.4;
  padding-bottom: calc(84px + var(--safe-b));
  min-height: 100vh;
}
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0; }
.center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: rgba(20,19,15,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.date-btn { background: none; border: 0; color: var(--fg); font-size: 1.05rem; font-weight: 600; padding: 8px 16px; border-radius: 999px; }
.date-btn:active { background: var(--card2); }
.icon-btn { background: none; border: 0; color: var(--fg); font-size: 1.6rem; width: 44px; height: 44px; border-radius: 50%; line-height: 1; }
.icon-btn:active { background: var(--card2); }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }

.summary { display: flex; gap: 16px; align-items: center; }
.ring-wrap { position: relative; width: 128px; height: 128px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--card2); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ring-fg.over { stroke: var(--danger); }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-text .big { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ring-text .sub { font-size: .75rem; color: var(--muted); }
.macros { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.macro .top { display: flex; justify-content: space-between; font-size: .85rem; }
.macro .top b { font-weight: 600; }
.macro .top span { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 99px; transition: width .4s; }

.quick { display: flex; gap: 10px; margin-bottom: 12px; }
.quick .btn { flex: 1; padding: 12px 8px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card2); color: var(--fg);
  font: inherit; font-weight: 600; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #1b1608; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.full { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.file-btn { position: relative; }

label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; color: var(--fg); }
input, select {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; color: var(--fg);
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input[type=checkbox] { width: auto; margin: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row input { margin-top: 0; }
.unit { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
.grid4 input { padding: 10px 8px; }
details.calc { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
details.calc summary { cursor: pointer; font-weight: 600; margin-bottom: 10px; }

.meal { margin-bottom: 12px; }
.meal-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; padding: 4px 4px 6px; }
.entry {
  display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 14px;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer; width: 100%; border: 0; color: inherit; font: inherit; text-align: left;
}
.entry img, .entry .ph { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: none; background: var(--card2); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.entry .info { flex: 1; min-width: 0; }
.entry .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .mac { font-size: .8rem; color: var(--muted); }
.entry .kc { font-weight: 700; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 3px; vertical-align: 1px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(31,29,24,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b));
}
.tab { background: none; border: 0; color: var(--muted); font: inherit; font-size: .72rem; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; }
.tab span { font-size: 1.3rem; }
.tab.active { color: var(--fg); }
.tab.snap span { background: var(--accent); width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; margin-top: -18px; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.tabbar { grid-template-columns: 1fr 1fr 1fr 1fr; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + var(--safe-b));
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }
.photo-area img { width: 100%; max-height: 260px; object-fit: cover; border-radius: 14px; margin-bottom: 10px; }
.photo-area { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.items { font-size: .85rem; color: var(--muted); margin: -4px 0 10px; }
.items:empty { display: none; }
.items ul { margin: 4px 0 0; padding-left: 18px; }
.items .conf { font-size: .8rem; margin-top: 6px; }
.portion { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; font-size: .8rem; color: var(--muted); }
.chip { background: var(--card2); border: 1px solid var(--line); color: var(--fg); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--card2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .72rem; color: var(--muted); }
.chart svg { width: 100%; height: 180px; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; }
.wrow { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.wrow button { background: none; border: 0; color: var(--muted); font-size: 1rem; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: .9rem; z-index: 30; max-width: 90vw; text-align: center; }
