:root {
  --bg: #0e1113; --card: #171b1f; --card2: #1f252a; --line: #2a3138; --text: #eceff1; --muted: #8b959e;
  --accent: #7bd88f; --accent-ink: #08130b; --danger: #ff6b6b;
  --A: #2e9e5b; --B: #86c440; --C: #e8c22e; --D: #ee8a2b; --E: #e5483f;
  --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 { height: 100%; margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior-y: contain; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
small { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); font-size: 14px; } .small { font-size: 12px; }

.screen { min-height: 100%; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.center { align-items: center; justify-content: center; text-align: center; padding: 24px; }
.center h1 { font-size: 34px; margin: 0 0 12px; } .center p { color: var(--muted); max-width: 300px; margin: 0 auto; }

.top { display: flex; align-items: center; gap: 4px; padding: 8px 8px 4px; }
.date-label { flex: 1; font-size: 18px; font-weight: 600; text-align: center; padding: 8px; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; font-size: 22px; display: grid; place-items: center; flex: none; }
.icon-btn:active { background: var(--card2); }
.icon-btn.light { background: rgba(0,0,0,.45); color: #fff; }
.icon-btn.danger, .link-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: .25; }

.totals { margin: 4px 16px 12px; padding: 14px 16px; background: var(--card); border-radius: 18px;
  display: flex; align-items: center; gap: 16px; }
.kcal { display: flex; flex-direction: column; align-items: flex-start; min-width: 92px; }
.kcal span { font-size: 38px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.macros { flex: 1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; }
.macros b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.macros small { font-size: 10.5px; }

.offline-bar { margin: 0 16px 10px; padding: 8px 12px; border-radius: 12px; background: #3a2f12; color: #f3d98b; font-size: 13px; }
.feed { flex: 1; padding: 0 16px calc(170px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.empty { position: absolute; left: 0; right: 0; top: 46%; text-align: center; color: var(--muted); padding: 0 40px; }

.tile { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 16px; padding: 10px;
  text-align: left; width: 100%; }
.tile:active { background: var(--card2); }
.thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--card2); flex: none;
  display: grid; place-items: center; font-size: 26px; color: var(--muted); }
.tile-main { flex: 1; min-width: 0; }
.tile-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 15px; }
.tile-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tile-side { text-align: right; flex: none; }
.tile-kcal { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.grade { display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 7px;
  font-size: 13px; font-weight: 700; color: #111; margin-top: 3px; }
.grade.A { background: var(--A); color: #fff; } .grade.B { background: var(--B); } .grade.C { background: var(--C); }
.grade.D { background: var(--D); } .grade.E { background: var(--E); color: #fff; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .9s linear infinite; margin-left: auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.tile.warn .tile-desc { color: var(--danger); }
.badge { font-size: 10.5px; padding: 1px 6px; border-radius: 6px; background: var(--card2); color: var(--muted); margin-left: 6px; }

.bottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(14px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 72%, transparent); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.text-row { display: flex; align-items: center; gap: 6px; width: 100%; background: var(--card); border-radius: 22px; padding: 0 4px 0 16px; }
.text-row input { flex: 1; min-width: 0; height: 44px; background: none; border: 0; outline: 0; }
.text-row input::placeholder { color: var(--muted); }
.text-row.ghost { background: rgba(0,0,0,.45); } .text-row.ghost input { color: #fff; } .text-row.ghost input::placeholder { color: #c5cbd0; }
.mic { font-size: 18px; } .mic.on { background: var(--danger); }
.send { color: var(--accent); }
.camera-btn { width: 84px; height: 84px; border-radius: 42px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 24px rgba(123,216,143,.28); }
.camera-btn:active { transform: scale(.96); }

.overlay { position: fixed; inset: 0; z-index: 10; }
.overlay.dark { background: #000; }
#video, #preview-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#preview-img { object-fit: contain; }
.cam-top { position: absolute; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; }
.cam-bottom { position: absolute; bottom: calc(26px + var(--safe-b)); left: 0; right: 0; display: flex; align-items: center; justify-content: space-around; }
.spacer { width: 44px; }
.shutter { width: 78px; height: 78px; border-radius: 50%; background: #fff; border: 5px solid rgba(255,255,255,.35); background-clip: padding-box; }
.shutter:active { transform: scale(.94); }
.pill { background: rgba(0,0,0,.5); color: #fff; padding: 6px 12px; border-radius: 16px; font-size: 13px; }
.pill.toggle { display: flex; align-items: center; gap: 6px; }
.pv-bottom { position: absolute; left: 16px; right: 16px; bottom: calc(22px + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; }
.pv-actions { display: flex; align-items: center; justify-content: space-between; }
.ok-btn { width: 92px; height: 92px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.ok-btn:active, .round-btn:active { transform: scale(.95); }
.round-btn { width: 60px; height: 60px; border-radius: 50%; background: rgba(255,255,255,.18); color: #fff; font-size: 34px; line-height: 1; }
.round-spacer { width: 60px; }

.sheet { background: var(--bg); overflow-y: auto; }
.sheet-body { max-width: 560px; margin: 0 auto; padding: calc(6px + var(--safe-t)) 16px calc(40px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.sheet-top { display: flex; align-items: center; justify-content: space-between; }
.sheet-title { font-weight: 600; }
.d-photo { width: 100%; max-height: 46vh; object-fit: cover; border-radius: 16px; }
.d-summary { display: flex; align-items: center; gap: 14px; }
.d-summary b { font-size: 30px; } .d-summary .grade { min-width: 44px; height: 40px; font-size: 22px; border-radius: 12px; margin: 0; }
.components { display: flex; flex-direction: column; background: var(--card); border-radius: 16px; overflow: hidden; }
.comp { display: flex; align-items: center; gap: 8px; padding: 10px 6px 10px 14px; border-bottom: 1px solid var(--line); }
.comp:last-child { border-bottom: 0; }
.comp-name { flex: 1; min-width: 0; font-size: 15px; }
.comp-name small { display: block; }
.comp input { width: 68px; height: 38px; text-align: right; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; }
.comp .unit { color: var(--muted); font-size: 13px; width: 12px; }
.comp .icon-btn { width: 36px; height: 36px; font-size: 16px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; color: var(--muted); background: var(--card); padding: 5px 10px; border-radius: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field.row { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--text); }
.field input[type=datetime-local], .field input[type=number] { height: 44px; background: var(--card); border: 0; border-radius: 14px; padding: 0 14px; color: var(--text); min-width: 0; flex: 1; }
.field .text-row { background: none; padding: 0; gap: 10px; }
.field > input { flex: none; width: 100%; }
.truth { background: var(--card); border-radius: 16px; padding: 12px 14px; }
.truth summary { font-weight: 600; cursor: pointer; }
.truth-row { display: flex; gap: 8px; margin: 8px 0; }
.truth-row input { height: 40px; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; min-width: 0; }
.truth-row input:first-child { flex: 1; } .truth-row input:last-child { width: 84px; text-align: right; }
.primary-btn { background: var(--accent); color: var(--accent-ink); font-weight: 650; height: 44px; border-radius: 14px; padding: 0 18px; width: 100%; margin-top: 8px; }
.primary-btn.small { width: auto; margin: 0; flex: none; }
.link-btn { color: var(--accent); padding: 8px 0; text-align: left; }
.toast { position: fixed; left: 50%; bottom: calc(190px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  background: #2b3238; color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; max-width: 86vw; text-align: center; }
.code-row { display: flex; flex-direction: column; gap: 4px; align-items: center; margin: 22px auto 14px; max-width: 240px; }
.code-row input { width: 100%; height: 56px; text-align: center; font-size: 28px; letter-spacing: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; outline: 0; }
.code-out { font-size: 34px; font-weight: 700; letter-spacing: 6px; text-align: center; margin: 0; }
.code-out small { display: block; letter-spacing: 0; font-weight: 400; }
