:root {
  --bg: #111110;
  --surface: #1a1a18;
  --raised: #222220;
  --line: #2b2b29;
  --text: #ecebe7;
  --muted: #8e8d87;
  --faint: #5c5b56;
  --over: #e0705f;
  --radius: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --display: "Cormorant Garamond", "Times New Roman", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); }
body {
  color: var(--text);
  font: 400 15px/1.4 "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: normal;
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

#app { padding: 8px 20px calc(var(--tabs-h) + var(--safe-b) + 28px); max-width: 560px; margin: 0 auto; }

/* ---------- день ---------- */
.daybar { display: flex; align-items: center; justify-content: space-between; height: 48px; margin-bottom: 18px; }
.daylabel { font-weight: 500; font-size: 15px; padding: 8px 12px; border-radius: 10px; }
.icon {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px; line-height: 1; color: var(--muted);
}
.icon:active { background: var(--surface); }
.icon:disabled { opacity: .25; }

/* ---------- остаток ---------- */
.left-label { color: var(--muted); font-size: 14px; }
.left-num { display: flex; align-items: baseline; gap: 8px; margin: 2px 0 14px; }
.left-num b { font-weight: 300; font-size: 64px; line-height: 1; letter-spacing: -0.02em; }
.left-num span { color: var(--muted); font-size: 17px; }
.left-num.over b { color: var(--over); }

.bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--text); border-radius: 2px; transition: width .35s ease; }
.bar.over i { background: var(--over); }
.left-sub { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 8px; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 30px 0 8px; }
.macro .name { color: var(--muted); font-size: 13px; }
.macro .val { font-size: 22px; font-weight: 400; margin: 2px 0 8px; white-space: nowrap; }
.macro .val small { font-size: 13px; color: var(--muted); margin-left: 2px; }
.macro.over .val { color: var(--over); }
.macro .of { color: var(--faint); font-size: 12px; margin-top: 6px; }

/* ---------- приёмы пищи ---------- */
#meals { margin-top: 30px; }
.meal { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.meal-head { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.meal-head h3 { font-weight: 500; font-size: 17px; }
.meal-head .sum { color: var(--muted); font-size: 14px; margin-left: auto; margin-right: 6px; }
.add {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); font-size: 20px; line-height: 1;
  display: grid; place-items: center; color: var(--text);
}
.add:active { background: var(--surface); }
.entry {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  width: 100%; text-align: left; padding: 10px 0;
}
.entry + .entry { border-top: 1px solid #1f1f1d; }
.entry .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .t em { font-style: normal; color: var(--muted); margin-left: 6px; }
.entry .k { text-align: right; }
.entry .m { grid-column: 1 / -1; color: var(--faint); font-size: 13px; }
.empty { color: var(--faint); font-size: 14px; padding: 4px 0 10px; }

/* ---------- заголовки разделов ---------- */
.viewhead { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin-bottom: 6px; }
h1 { font-weight: 500; font-size: 24px; letter-spacing: -0.01em; }
.note { color: var(--muted); font-size: 14px; margin-bottom: 18px; max-width: 42ch; }
.link { color: var(--text); font-weight: 500; padding: 8px 0 8px 12px; }

/* ---------- продукты ---------- */
.search {
  width: 100%; height: 44px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  outline: none; margin-bottom: 8px;
}
.search:focus { border-color: var(--faint); }
.food {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  width: 100%; text-align: left; padding: 13px 0; border-bottom: 1px solid var(--line);
}
.food .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food .k { text-align: right; }
.food .m { grid-column: 1 / -1; color: var(--faint); font-size: 13px; }
.food:active, .entry:active { opacity: .6; }

/* ---------- формы ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 13px; }
.field input {
  height: 48px; padding: 0 14px; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  outline: none; font-size: 17px;
}
.field input:focus { border-color: var(--faint); }
.field input::placeholder { color: var(--faint); }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid4 .field input { padding: 0 10px; text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; min-height: 18px; }
.hint button { color: var(--text); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }

.primary {
  height: 52px; border-radius: 14px; width: 100%;
  background: var(--text); color: var(--bg); font-weight: 500; font-size: 16px;
}
.primary:active { opacity: .8; }
.primary:disabled { opacity: .35; }
.danger { height: 48px; width: 100%; color: var(--over); font-size: 15px; }

.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; height: 38px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--raised); color: var(--text); }

.check { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--text); }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { text-align: center; }
.stepper button {
  flex: none; width: 48px; height: 48px; border-radius: 12px;
  border: 1px solid var(--line); font-size: 20px;
}
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button {
  height: 32px; padding: 0 12px; border-radius: 16px;
  border: 1px solid var(--line); color: var(--muted); font-size: 13px;
}

.preview {
  display: grid; grid-template-columns: repeat(4, 1fr); text-align: center;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 4px;
}
.preview b { display: block; font-weight: 400; font-size: 18px; }
.preview span { color: var(--muted); font-size: 12px; }

/* ---------- лист снизу ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  max-width: 560px; margin: 0 auto;
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 20px; }
.sheet-head h2 { font-weight: 500; font-size: 19px; }
.sheet-body { overflow-y: auto; padding: 8px 20px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.sheet-body .form { gap: 14px; }
.sheet .food:last-child { border-bottom: 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  height: calc(var(--tabs-h) + var(--safe-b)); padding: 8px 12px var(--safe-b);
  background: rgba(17,17,16,.92); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.tabs button {
  flex: 1; max-width: 160px; height: 44px; border-radius: 12px;
  color: var(--faint); font-size: 14px; font-weight: 500;
}
.tabs button.on { color: var(--text); background: var(--surface); }

.toast {
  position: fixed; left: 16px; right: 16px; z-index: 30;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 12px);
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 14px; animation: up .2s ease;
}
.toast button { font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 32px; text-align: center; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.sheet .hint:empty { display: none; }

/* крупные стрелки листания */
.icon.big { width: 52px; height: 52px; font-size: 34px; border: 1px solid var(--line); padding-bottom: 4px; }
.daybar { height: 56px; }
.daylabel { font-size: 17px; }

/* переход между вкладками свайпом */
.view.slide-next { animation: slide-next .22s ease; }
.view.slide-prev { animation: slide-prev .22s ease; }
@keyframes slide-next { from { transform: translateX(28px); opacity: 0; } }
@keyframes slide-prev { from { transform: translateX(-28px); opacity: 0; } }

/* ---------- тренировки ---------- */
.workouts { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); }
h2 { font-weight: 500; font-size: 20px; }
.monthbar { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 12px; }
.monthbar span { font-weight: 500; font-size: 16px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .wd { color: var(--faint); font-size: 12px; padding-bottom: 4px; }
.cal button {
  aspect-ratio: 1; border-radius: 12px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; font-size: 15px;
}
.cal button:active { background: var(--surface); }
.cal button.today { border: 1px solid var(--faint); }
.cal button.has { background: var(--surface); }
.cal button.future { color: var(--faint); }
.cal .dots { display: flex; gap: 3px; height: 6px; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
.dot.strength { background: var(--text); }
.dot.cardio { border: 1.5px solid var(--text); }
.legend { display: flex; gap: 18px; color: var(--muted); font-size: 13px; margin: 12px 0 18px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.workout {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  width: 100%; text-align: left; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.workout:active { opacity: .6; }
.workout .k { color: var(--muted); text-align: right; }
.workout .m { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.field textarea {
  min-height: 96px; padding: 12px 14px; width: 100%; resize: vertical;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  outline: none; font: inherit; font-size: 16px; color: var(--text);
}
.field textarea:focus { border-color: var(--faint); }
.field input[type=date] { color-scheme: dark; }

/* ---------- шрифт с характером: крупные цифры и заголовки ---------- */
h1, h2, .meal-head h3, .sheet-head h2, .monthbar span {
  font-family: var(--display); font-weight: 600; letter-spacing: 0;
}
h1 { font-size: 34px; line-height: 1.05; }
h2, .sheet-head h2 { font-size: 27px; }
.meal-head h3 { font-size: 24px; font-style: italic; font-weight: 500; }
.monthbar span { font-size: 22px; font-style: italic; font-weight: 500; }
.daylabel { font-family: var(--display); font-style: italic; font-size: 24px; font-weight: 500; }
.left-num b {
  font-family: var(--display); font-weight: 500; font-style: italic;
  font-size: 104px; line-height: .9; letter-spacing: -0.01em;
  font-variant-numeric: lining-nums proportional-nums;
}
.left-num span { font-family: var(--display); font-style: italic; font-size: 24px; }
.macro .val {
  font-family: var(--display); font-weight: 600; font-size: 34px; line-height: 1;
  font-variant-numeric: lining-nums;
}
.macro .val small { font-family: "Onest", sans-serif; font-weight: 400; }
.preview b { font-family: var(--display); font-weight: 600; font-size: 24px; font-variant-numeric: lining-nums; }
.entry .k, .food .k { font-variant-numeric: tabular-nums; }

/* день ещё грузится — показываем приглушённо, без пустого мигания */
#view-diary.loading #summary, #view-diary.loading #meals { opacity: .35; transition: opacity .2s; }

/* ---------- категории продуктов ---------- */
.chips {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 2px -20px 6px; padding: 0 20px;
}
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chips button {
  flex: none; height: 34px; padding: 0 14px; border-radius: 17px;
  border: 1px solid var(--line); color: var(--muted); font-size: 14px; white-space: nowrap;
}
.chips button.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.group {
  font-family: var(--display); font-style: italic; font-weight: 500; font-size: 22px;
  margin: 22px 0 2px;
}
.sheet .chips:not(.wrap) { margin: 0 -20px; }

#base-seg { margin-bottom: 14px; }
.food.mine .t { color: var(--muted); }
