:root {
  --bg: #f6efe4;
  --card: #fffaf2;
  --card-2: #f1e8d9;
  --ink: #3a2e28;
  --muted: #8b7b6e;
  --line: #e7dbc8;
  --accent: #bf6a4b;
  --accent-ink: #fff8f1;
  --sage: #7a9a76;
  --honey: #d6a043;
  --clay: #bf6a4b;
  --danger: #b4473c;
  --shadow: 0 1px 2px rgba(80, 55, 35, .06), 0 6px 18px rgba(80, 55, 35, .06);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1815;
    --card: #28211d;
    --card-2: #322a25;
    --ink: #f1e6d8;
    --muted: #a39384;
    --line: #3b3029;
    --accent: #d27b5a;
    --accent-ink: #20150f;
    --sage: #94b490;
    --honey: #e2b058;
    --clay: #d27b5a;
    --danger: #e06a5d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
button, .btn, .chip, label, [data-act] { touch-action: manipulation; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 520px; margin: 0 auto; min-height: 100%; padding: env(safe-area-inset-top) 14px calc(86px + env(safe-area-inset-bottom)); }
.screen { padding-top: 14px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .1px; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.gap { margin-top: 12px; }
.gap-s { margin-top: 8px; }
.gap-l { margin-top: 20px; }

/* карточки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.cards { display: grid; gap: 10px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.cols-5 { grid-template-columns: 1.1fr 1fr 1fr 1fr 1fr; }
.mini { padding: 10px 12px; }

/* кнопки: компактные, по размеру текста */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { padding: 11px 20px; font-size: 15px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.linkbtn { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 4px 2px; }

/* поля */
label.f { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
label.f > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 16px; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink);
  appearance: none; -webkit-appearance: none; min-height: 42px;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 54%, calc(100% - 13px) 54%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { resize: none; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); border-color: transparent; }
.num-sm { padding: 8px 6px; text-align: center; min-height: 38px; font-size: 16px; }

/* чипы */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.optcard { text-align: left; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px; width: 100%; }
.optcard.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.optcard b { display: block; font-family: var(--serif); font-size: 16px; }
.optcard span { color: var(--muted); font-size: 13px; }

/* навигация */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
}
.tabbar-in { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 64px 1fr 1fr 1fr; align-items: center; }
.tab { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--accent); }
.fab { width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin: -22px auto 0; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.fab svg { width: 26px; height: 26px; }

/* шапка дня */
.daynav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daynav .title { text-align: center; }
.daynav .title h1 { font-size: 22px; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; color: var(--ink); }
.iconbtn svg { width: 18px; height: 18px; }

/* кольцо */
.ringwrap { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .bg { stroke: var(--card-2); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring .fg.over { stroke: var(--honey); }
.ring .mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .mid b { font-family: var(--serif); font-size: 28px; line-height: 1; }
.ring .mid span { font-size: 12px; color: var(--muted); }
.stat b { font-family: var(--serif); font-size: 20px; }
.stat span { display: block; font-size: 12px; color: var(--muted); }

.macro { padding: 10px 12px; }
.macro .top { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.macro b { font-family: var(--serif); font-size: 18px; color: var(--ink); text-transform: none; letter-spacing: 0; }
.bar { height: 6px; border-radius: 6px; background: var(--card-2); overflow: hidden; margin-top: 7px; }
.bar i { display: block; height: 100%; border-radius: 6px; transition: width .5s ease; }
.macro small { color: var(--muted); font-size: 12px; }

/* список еды */
.meal-h { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 2px 6px; }
.meal-h h3 { font-size: 15px; }
.entry { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); width: 100%; text-align: left; margin-bottom: 6px; }
.thumb { width: 46px; height: 46px; border-radius: 10px; background: var(--card-2); flex: none; object-fit: cover; display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 22px; height: 22px; }
.entry .t { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .s { font-size: 12px; color: var(--muted); }
.entry .k { font-family: var(--serif); font-weight: 600; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 14px; }

/* совет */
.advice h3 { margin-bottom: 4px; }
.advice ul { margin: 8px 0 0; padding-left: 18px; }
.advice li { margin: 4px 0; font-size: 14px; }
.advice .next { margin-top: 10px; padding: 10px 12px; background: var(--card-2); border-radius: 12px; font-size: 14px; }

/* модалка */
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: rgba(30, 20, 14, .45); display: flex; align-items: flex-end; justify-content: center; animation: fadebg .15s ease; }
@keyframes fadebg { from { opacity: 0; } to { opacity: 1; } }
.sheet { width: 100%; max-width: 520px; max-height: 94vh; max-height: 94dvh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 14px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: -6px auto 10px; }

.photo-box { border: 1.5px dashed var(--line); border-radius: 16px; min-height: 150px; display: grid; place-items: center; text-align: center; color: var(--muted); overflow: hidden; background: var(--card); }
.photo-box img { width: 100%; max-height: 300px; object-fit: cover; display: block; }

.itemrow { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.itemrow .nm { font-weight: 600; }
.itemrow label.f { font-size: 10px; text-align: center; }
.itemrow label.f > span { margin-bottom: 2px; }

.total { display: flex; justify-content: space-between; gap: 6px; text-align: center; }
.total div { flex: 1; }
.total b { font-family: var(--serif); font-size: 20px; display: block; }
.total span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.notice { padding: 10px 12px; border-radius: 12px; font-size: 13px; background: var(--card-2); }
.notice.warn { background: color-mix(in srgb, var(--honey) 22%, var(--card)); }
.notice.err { background: color-mix(in srgb, var(--danger) 16%, var(--card)); }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* онбординг */
.dots { display: flex; gap: 6px; justify-content: center; margin: 4px 0 18px; }
.dots i { width: 22px; height: 4px; border-radius: 4px; background: var(--line); }
.dots i.on { background: var(--accent); }
.hero { font-family: var(--serif); font-size: 30px; line-height: 1.15; }

/* тост */
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; max-width: 90%; text-align: center; box-shadow: var(--shadow); animation: fade .2s ease; }

/* графики */
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--sans); }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td { padding: 6px 0; border-bottom: 1px solid var(--line); }
table.simple tr:last-child td { border-bottom: 0; }
table.simple td:last-child { text-align: right; font-weight: 600; }

/* история */
.hrow { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.hrow .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hrow .d { font-weight: 600; }
.hrow .k { font-family: var(--serif); font-weight: 600; }
.hrow .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.tag.ok { background: color-mix(in srgb, var(--sage) 25%, var(--card)); color: var(--ink); }
.tag.hi { background: color-mix(in srgb, var(--honey) 28%, var(--card)); color: var(--ink); }
.ideas { margin-top: 10px; display: grid; gap: 6px; }
.idea { background: var(--card-2); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.idea b { font-family: var(--serif); }

/* быстрая запись, вода, вдвоём */
.btn.sm { padding: 6px 10px; font-size: 13px; }
.dots { display: flex; align-items: center; gap: 6px; }
.dots .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--card-2); border: 1px solid var(--line, rgba(0,0,0,.12)); display: inline-block; }
.dots .dot.on { background: var(--sage); border-color: transparent; }

/* iPhone приближает экран, если шрифт поля меньше 16px */
input, select, textarea { font-size: max(16px, 1em); }

/* несколько фото одного блюда */
.shots { display: flex; flex-wrap: wrap; gap: 8px; }
.shot { position: relative; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; background: var(--card-2); }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 15px; line-height: 22px; text-align: center; }

.warn-line { color: #b4561f; margin-top: 4px; }
.itemrow .linkbtn { margin-top: 4px; }

.shoprow { padding: 4px 0; border-bottom: 1px solid var(--line, rgba(0,0,0,.08)); }
.shopchk { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 6px 0; text-align: left; color: inherit; font: inherit; flex: 1; }
.shopchk .box { width: 22px; height: 22px; border: 2px solid var(--sage, #8aa58a); border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; flex: none; }
.shoprow.done .shopchk span:last-child { text-decoration: line-through; opacity: .55; }

button.photo-box { width: 100%; font: inherit; cursor: pointer; color: var(--muted); }
.shopres { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; background: var(--card); }
.gsug { width: 100%; height: 56px; border: 0; margin-top: 8px; }
a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
.tab span { white-space: nowrap; }
@media (max-width: 400px) { .tab { font-size: 10px; letter-spacing: -.1px; } .tab svg { width: 22px; height: 22px; } }

.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* режим «Без цифр»: скрываем всё, что помечено cx */
html.calm .cx { display: none !important; }

/* свёрнутые карточки (профиль) */
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '▾'; float: right; color: var(--muted); }
details.card[open] > summary::after { content: '▴'; }
