:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --text: #121a16;
  --muted: #6b7a72;
  --line: #e3e8e4;
  --accent: #0f9d6b;
  --accent-2: #3fcf92;
  --accent-soft: #e0f4ea;
  --warn: #f08c2b;
  --warn-soft: #fdeedd;
  --over: #e5484d;
  --over-soft: #fde4e4;
  --protein: #3b82f6;
  --fat: #f5a524;
  --carbs: #8b5cf6;
  --shadow: 0 1px 2px rgba(16, 40, 30, .05), 0 8px 28px rgba(16, 40, 30, .07);
  --r: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1210; --card: #151d1a; --text: #ecf2ee; --muted: #8e9d95; --line: #25302b;
    --accent: #2fbf86; --accent-2: #5ad6a4; --accent-soft: #143024; --warn-soft: #3a2712; --over-soft: #3b1818;
    --shadow: 0 1px 2px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: var(--text); }
body { font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 30px; line-height: 1.12; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 24px; margin: 0 0 6px; letter-spacing: -.02em; }
h3 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.pad { padding: 8px 16px 24px; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Камера ===== */
.cam { position: fixed; inset: 0; background: #000; color: #fff; overflow: hidden; }
.cam video, .cam #shot { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-top { position: absolute; top: calc(var(--safe-t) + 12px); left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: center; z-index: 3; }
.pill {
  display: flex; align-items: center; gap: 10px; border: 0; color: #fff; padding: 6px 16px 6px 6px; border-radius: 40px;
  background: rgba(0,0,0,.42); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
}
.pill span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; }
.pill b { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.pill small { font-size: 12px; opacity: .8; }
.mini-ring { width: 44px; height: 44px; transform: rotate(-90deg); }
.mini-ring circle { stroke-width: 5; }
.mr-bg { stroke: rgba(255,255,255,.22); }
.mr-fg { stroke: #5ee0a6; transition: stroke-dashoffset .8s cubic-bezier(.2,.8,.2,1); }
.round {
  width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff;
  background: rgba(0,0,0,.42); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.round svg { width: 24px; height: 24px; }
.big-round { width: 58px; height: 58px; }
.big-round svg { width: 27px; height: 27px; }

.frame { position: absolute; left: 10%; right: 10%; top: 22%; bottom: 33%; pointer-events: none; transition: all .35s cubic-bezier(.2,.8,.2,1); }
.frame i { position: absolute; width: 38px; height: 38px; border: 4px solid rgba(255,255,255,.9); }
.frame i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 22px; }
.frame i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 22px; }
.frame i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 22px; }
.frame i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 22px; }
.frame.label { left: 16%; right: 16%; top: 20%; bottom: 31%; }
.cam-hint { position: absolute; left: 0; right: 0; top: calc(67% + 6px); text-align: center; font-size: 17px; font-weight: 600; text-shadow: 0 1px 8px rgba(0,0,0,.7); pointer-events: none; }

.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 0 calc(var(--safe-b) + 22px); z-index: 3;
  background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.modes { display: flex; justify-content: center; gap: 8px; margin-bottom: 18px; }
.modes button { display: flex; align-items: center; gap: 7px; border: 0; border-radius: 30px; padding: 9px 16px; font-size: 16px; font-weight: 600;
  background: rgba(0,0,0,.4); color: rgba(255,255,255,.8); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.modes button svg { width: 20px; height: 20px; }
.modes button.on { background: #fff; color: #111; }
.cam-row { display: flex; justify-content: space-evenly; align-items: center; }
.shutter { width: 88px; height: 88px; border-radius: 50%; border: 5px solid #fff; background: none; padding: 5px; transition: transform .12s; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .12s, background .2s; }
.shutter:active { transform: scale(.94); }
.shutter:active span { transform: scale(.9); }
.cam.label-mode .shutter span { background: #ffd666; }

.welcome { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px;
  padding: calc(var(--safe-t) + 40px) 28px calc(var(--safe-b) + 40px);
  background: radial-gradient(120% 80% at 50% 0%, #1b4d3a 0%, #0b1a14 60%, #060d0a 100%); }
.welcome p { margin: 0; color: rgba(255,255,255,.78); max-width: 360px; font-size: 18px; }
.welcome .small { font-size: 14px; color: rgba(255,255,255,.55); }
.welcome-icon svg { width: 112px; height: 112px; margin-bottom: 6px; }
.wi-bg { fill: rgba(94,224,166,.16); stroke: none; }
.wi-cam { stroke: #5ee0a6; stroke-width: 2.6; }
.link-light { color: rgba(255,255,255,.75); text-decoration: underline; text-underline-offset: 3px; font-size: 16px; cursor: pointer; padding: 8px; }

.busy { position: absolute; inset: 0; z-index: 5; display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(var(--safe-b) + 150px); background: rgba(0,0,0,.25); }
.busy-text { display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,.65); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); padding: 14px 22px; border-radius: 40px; font-size: 18px; font-weight: 600; }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-line { position: absolute; left: 10%; right: 10%; height: 3px; top: 22%; border-radius: 3px; background: linear-gradient(90deg, transparent, #5ee0a6, transparent); box-shadow: 0 0 20px #5ee0a6; animation: scan 1.6s ease-in-out infinite alternate; }
@keyframes scan { to { top: 66%; } }

/* ===== Страницы ===== */
.page { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--safe-b) + 28px); animation: slide .3s cubic-bezier(.2,.8,.2,1); }
.page > * { max-width: 560px; margin-left: auto; margin-right: auto; }
@keyframes slide { from { transform: translateX(30%); opacity: 0; } }
.page-top { display: flex; align-items: center; justify-content: space-between; height: 56px; margin-bottom: 6px; }
.back, .back-spacer { width: 44px; height: 44px; flex: none; }
.back { border: 0; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--accent); }
.back svg { width: 24px; height: 24px; stroke-width: 2.4; }
.page-title { font-size: 19px; }
.day-nav { display: flex; align-items: center; gap: 4px; }
.day-nav b { font-size: 19px; min-width: 150px; text-align: center; }
.day-nav button { border: 0; background: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }
.day-nav button svg { width: 22px; height: 22px; stroke-width: 2.4; }
.day-nav button:disabled { opacity: .2; }

.card { background: var(--card); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h3 { margin: 0; }

/* Кольцо */
.ring-card { background: var(--card); border-radius: 28px; padding: 22px 18px 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.ring-wrap { position: relative; width: 74%; max-width: 260px; margin: 0 auto; aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 18; stroke-linecap: round; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: url(#rg); transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1); }
.ring-fg.warn { stroke: var(--warn); }
.ring-over { stroke: var(--over); transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-num { font-size: 56px; font-weight: 750; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.ring-num.over { color: var(--over); }
.ring-label { font-size: 15px; color: var(--muted); margin-top: 4px; }
.ring-foot { display: flex; justify-content: center; gap: 22px; margin: 12px 0 16px; color: var(--muted); font-size: 15px; }
.ring-foot b { color: var(--text); font-variant-numeric: tabular-nums; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.macro { text-align: center; }
.macro .name { font-size: 13px; color: var(--muted); }
.macro .val { font-weight: 650; font-size: 16px; font-variant-numeric: tabular-nums; margin: 1px 0 6px; }
.macro .val span { color: var(--muted); font-weight: 400; font-size: 13px; }
.bar { height: 7px; border-radius: 7px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 7px; width: 0; transition: width 1s cubic-bezier(.2,.8,.2,1); }

/* Записи */
.meal { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: 20px; padding: 10px 16px 10px 10px; box-shadow: var(--shadow); margin-bottom: 10px; }
.meal .ph { width: 64px; height: 64px; border-radius: 16px; background: var(--accent-soft) center/cover; flex: none; display: grid; place-items: center; color: var(--accent); }
.meal .ph svg { width: 28px; height: 28px; }
.meal .info { flex: 1; min-width: 0; }
.meal .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal .s { font-size: 14px; color: var(--muted); }
.meal .k { text-align: right; font-weight: 750; font-size: 20px; font-variant-numeric: tabular-nums; }
.meal .k small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 20px; border-radius: var(--r); border: 2px dashed var(--line); margin-bottom: 14px; }
.empty svg { width: 40px; height: 40px; color: var(--accent); margin-bottom: 6px; }
.empty b { display: block; color: var(--text); margin-bottom: 2px; }

svg.chart { stroke: none; width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { fill: var(--muted); stroke: none; font-size: 10px; }
svg.chart rect.hit { cursor: pointer; }
.chart-note { font-size: 14px; color: var(--muted); margin-top: 10px; }

/* Кнопки и формы */
.btn { border: 0; background: var(--accent); color: #fff; font-weight: 650; border-radius: 16px; padding: 15px 20px; transition: transform .1s, opacity .2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg { width: 22px; height: 22px; stroke-width: 2.6; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.big { font-size: 19px; padding: 18px 34px; border-radius: 20px; margin-top: 10px; background: linear-gradient(145deg, #3fcf92, #0f9d6b); box-shadow: 0 10px 30px rgba(15,157,107,.45); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.gray { background: var(--line); color: var(--text); }
.btn.danger { background: none; color: var(--over); flex: 0 0 auto !important; padding-left: 8px; padding-right: 8px; }
.btn.wide { width: 100%; }
.btns { display: flex; gap: 10px; margin-top: 18px; }
.btns .btn { flex: 1; }

.seg { display: flex; background: var(--line); border-radius: 13px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 4px; border-radius: 10px; font-size: 15px; font-weight: 550; color: var(--muted); line-height: 1.15; min-width: 0; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.small-seg button { padding: 6px 12px; font-size: 14px; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.form label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.form input, .form select, .row-input input, .sheet input, .sheet textarea {
  border: 1.5px solid var(--line); background: var(--bg); border-radius: 14px; padding: 13px 14px; font-size: 17px; width: 100%; color: var(--text); outline: none;
}
.sheet textarea { resize: none; margin-top: 8px; }
.form input:focus, .row-input input:focus, .sheet input:focus, .sheet textarea:focus { border-color: var(--accent); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.row-input { display: flex; gap: 8px; margin-top: 12px; }
.code { font: 700 28px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em; text-align: center; padding: 16px; background: var(--bg); border-radius: 14px; user-select: all; margin-top: 10px; }
.norm-big { text-align: center; margin: 0 0 12px; }
.norm-big b { font-size: 46px; letter-spacing: -.03em; color: var(--accent); }
.norm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.norm-grid div { background: var(--bg); border-radius: 14px; padding: 10px 12px; }
.norm-grid b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.note { font-size: 14px; color: var(--muted); margin-top: 10px; }

/* ===== Лист ===== */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60; animation: fadein .2s; }
@keyframes fadein { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-width: 600px; margin: 0 auto; max-height: 94vh; overflow-y: auto;
  background: var(--card); color: var(--text); border-radius: 28px 28px 0 0; padding: 8px 20px calc(var(--safe-b) + 20px); animation: up .35s cubic-bezier(.2,.8,.2,1); }
@keyframes up { from { transform: translateY(100%); } }
.grip { width: 42px; height: 5px; border-radius: 5px; background: var(--line); margin: 4px auto 14px; }
.sheet-photo { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: 20px; margin-bottom: 14px; background: var(--bg); display: block; }
.res-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.res-title { font-size: 20px; font-weight: 650; line-height: 1.2; }
.res-kcal { text-align: right; flex: none; }
.res-kcal b { font-size: 44px; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.res-kcal span { display: block; font-size: 14px; color: var(--muted); }
.pfc { display: flex; gap: 16px; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; flex-wrap: wrap; margin-top: 8px; }
.pfc b { color: var(--text); }
.pfc .p::before, .pfc .f::before, .pfc .c::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.pfc .p::before { background: var(--protein); } .pfc .f::before { background: var(--fat); } .pfc .c::before { background: var(--carbs); }

.portions { display: flex; gap: 8px; margin: 16px 0 0; }
.portions button { flex: 1; border: 2px solid var(--line); background: none; border-radius: 16px; padding: 10px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.portions button svg { width: 30px; height: 30px; stroke: none; }
.portions button .pie-bg { fill: var(--line); }
.portions button .pie { fill: var(--muted); }
.portions button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.portions button.on .pie { fill: var(--accent); }

.after { margin-top: 16px; padding: 14px 16px; border-radius: 18px; background: var(--bg); }
.after .lbl { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.after .lbl b { font-size: 20px; font-variant-numeric: tabular-nums; }
.after .bar { height: 12px; margin-top: 10px; position: relative; border-radius: 12px; }
.after .bar i { position: absolute; top: 0; bottom: 0; border-radius: 0; }
.after .bar i:first-child { border-radius: 12px 0 0 12px; }

details.more { margin-top: 14px; }
details.more summary { list-style: none; color: var(--accent); font-weight: 600; font-size: 15px; padding: 6px 0; cursor: pointer; display: flex; align-items: center; gap: 6px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary svg { width: 18px; height: 18px; transition: transform .2s; }
details.more[open] summary svg { transform: rotate(180deg); }
.items { margin-top: 6px; border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item .nm { flex: 1; min-width: 0; }
.item .nm div { font-weight: 550; }
.item .nm small { color: var(--muted); font-variant-numeric: tabular-nums; }
.item input { width: 78px; text-align: right; padding: 8px 10px; font-variant-numeric: tabular-nums; }
.item .g { color: var(--muted); font-size: 14px; }
.item .x { border: 0; background: none; color: var(--muted); padding: 6px; }
.item .x svg { width: 18px; height: 18px; }

.verdict { border-radius: 22px; padding: 18px; margin: 4px 0 14px; display: flex; gap: 14px; align-items: center; }
.verdict .vi { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; }
.verdict .vi svg { width: 30px; height: 30px; stroke-width: 3; }
.verdict b { display: block; font-size: 21px; line-height: 1.15; margin-bottom: 3px; }
.verdict span { font-size: 15px; }
.verdict.ok { background: var(--accent-soft); } .verdict.ok .vi { background: var(--accent); }
.verdict.warn { background: var(--warn-soft); } .verdict.warn .vi { background: var(--warn); }
.verdict.bad { background: var(--over-soft); } .verdict.bad .vi { background: var(--over); }
.table100 { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.table100 td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.table100 td:last-child { text-align: right; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.tag { font-size: 14px; padding: 6px 12px; border-radius: 20px; background: var(--warn-soft); }
.grams { display: flex; gap: 8px; margin-top: 4px; }
.grams button { flex: 1; border: 2px solid var(--line); background: none; border-radius: 14px; padding: 10px 4px; font-weight: 650; font-size: 15px; line-height: 1.15; }
.grams button small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.grams button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.grams-custom { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.grams-custom input[type=range] { flex: 1; accent-color: var(--accent); padding: 0; border: 0; background: none; }
.grams-custom input[type=number] { width: 92px; text-align: right; }

.toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 76px); transform: translateX(-50%); z-index: 90; background: rgba(18,26,22,.92); color: #fff; padding: 13px 20px; border-radius: 30px;
  font-size: 16px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.3); width: max-content; max-width: calc(100% - 32px); text-align: center; animation: drop .35s cubic-bezier(.2,.8,.2,1); backdrop-filter: blur(10px); }
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

/* Большая кнопка «Снять ещё» внизу дневника */
.snap-space { height: 90px; }
.snap-more { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 18px); z-index: 25;
  display: flex; align-items: center; gap: 10px; border: 0; color: #fff; font-size: 19px; font-weight: 700; white-space: nowrap;
  padding: 17px 34px; border-radius: 40px; background: linear-gradient(145deg, #3fcf92, #0f9d6b); box-shadow: 0 10px 30px rgba(15,157,107,.45); }
.snap-more svg { width: 26px; height: 26px; stroke-width: 2.2; }
.snap-more:active { transform: translateX(-50%) scale(.96); }
.meal.fresh { animation: fresh 2.2s ease; }
@keyframes fresh { 0%, 40% { box-shadow: 0 0 0 3px var(--accent), var(--shadow); } 100% { box-shadow: var(--shadow); } }
