:root {
  color-scheme: light dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #111);
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}
/* Вкладка "Профиль" — полноэкранная "комната", без обычной прокрутки/отступа под неё */
body.room-active { padding-bottom: 0; overflow: hidden; }

#app { max-width: 480px; margin: 0 auto; padding: 12px; }

.screen { padding: 16px; }
.hidden { display: none !important; }

.tab-panel { padding: 0; }

/* --- Нижняя навигация: плавающий "пульт" поверх любой вкладки, включая комнату.
   Порт шаблона пользователя: CSS-grid на 4 равные колонки, активная кнопка целиком
   подсвечивается радиальным оранжевым свечением (без отдельного "приподнятого кружка"). --- */
#bottom-nav {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  width: calc(100% - 28px); max-width: calc(480px - 28px);
  height: 76px;
  background: rgba(16, 16, 16, .94);
  backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px);
  border-radius: 32px;
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  padding: 6px;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 1px solid transparent; border-radius: 24px; cursor: pointer; padding: 4px 2px;
  color: rgba(255,255,255,.5); transition: color .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.nav-btn .icon { font-size: 19px; line-height: 1; }
.nav-btn .nav-text { font-size: 9px; line-height: 1.1; text-align: center; }
.nav-btn.active {
  color: #ff6a34;
  background: radial-gradient(circle, rgba(255,96,40,.22), rgba(255,96,40,.04) 65%);
  border: 1px solid rgba(255,101,50,.3);
  box-shadow: inset 0 0 24px rgba(255,96,40,.08), 0 0 22px rgba(255,96,40,.12);
}
.nav-btn.active .nav-text { color: #ff6a34; font-weight: 700; }

/* Иконка меню (крайняя правая кнопка панели) — три полоски рисуются в CSS, а не эмодзи/шрифтом,
   чтобы вид не зависел от системного шрифта и совпадал по цвету с остальными иконками
   (currentColor подхватывает обычный/активный цвет .nav-btn автоматически). */
.nav-icon.hamburger-icon {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 3px; width: 19px; height: 15px;
}
.nav-icon.hamburger-icon span { display: block; width: 17px; height: 2px; border-radius: 1px; background: currentColor; }

/* Меню (список разделов + настройка нижней панели) — открывается крайней правой кнопкой */
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: rgba(127,127,127,.08); border: none; border-radius: 10px; padding: 10px 12px;
  font-size: 14px; color: var(--tg-theme-text-color, #111); cursor: pointer;
}
.menu-item .nav-icon { font-size: 18px; line-height: 1; }
.menu-item.current { background: rgba(127,127,127,.18); font-weight: 600; }

.card {
  background: var(--tg-theme-secondary-bg-color, #fff);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.muted { color: var(--tg-theme-hint-color, #888); }
.small { font-size: 13px; }

/* --- "Комната": фоновое фото зала, кот в полный рост стоит в нём --- */
.room-screen {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  max-width: 480px; margin: 0 auto;
  overflow: hidden; cursor: pointer;
  z-index: 1;
  background: #1a1b1e; /* подложка на случай, пока SVG-сцена не отрисовалась */
}
.room-scene {
  position: absolute; inset: 0; z-index: 0;
  width: 100%; height: 100%; display: block;
  background:
    linear-gradient(to bottom, rgba(0,0,0,.12), rgba(0,0,0,.02) 40%, rgba(0,0,0,.75) 100%),
    url('assets/gym_bg.jpg?v=20260901f') center top / cover no-repeat;
  background-color: #1a1b1e;
}
.room-shadow {
  position: absolute; left: 50%; z-index: 1; transform: translateX(-50%);
  bottom: calc(98px + env(safe-area-inset-bottom, 0px));
  width: min(46vw, 200px); height: 20px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0,0,0,.55), transparent 75%);
}
.room-cat {
  position: absolute; left: 50%; z-index: 2; transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  width: min(64vw, 300px); height: auto; max-height: 58vh;
  object-fit: contain; object-position: bottom center;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.5));
  transition: transform .15s ease;
}
.room-screen:active .room-cat { transform: translateX(-50%) scale(1.03); }
.room-fallback {
  position: absolute; left: 50%; z-index: 2; transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  font-size: 108px; line-height: 1;
}
/* Колокольчик уведомлений — пока чисто декоративный элемент (нет backend для уведомлений/
   напоминаний внутри мини-аппа, они и так приходят от бота в чат) — визуально на своём месте,
   чтобы при появлении реальных уведомлений не нужно было менять вёрстку, только навесить логику. */
.notif-btn {
  position: absolute; z-index: 4;
  top: calc(6px + env(safe-area-inset-top, 0px)); right: 16px;
  width: 34px; height: 34px; border-radius: 50%; padding: 0;
  background: rgba(15, 16, 20, .55);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: none; display: flex; align-items: center; justify-content: center;
  color: #fff; cursor: pointer;
}
.notif-btn .bell-icon { width: 17px; height: 17px; }
.notif-btn .notif-dot {
  position: absolute; top: 6px; right: 7px;
  width: 7px; height: 7px; border-radius: 50%;
  background: #ff3b30; border: 1.5px solid rgba(15,16,20,.9);
}

/* --- Карточка КБЖУ: 4 кольца-индикатора на conic-gradient (без SVG) — порт шаблона
   пользователя. Прогресс/цвет каждого кольца заданы инлайн через CSS-переменные
   --value (0..100) и --color, см. targetItem() в app.js. --- */
.macros {
  position: absolute; left: 12px; right: 12px;
  top: calc(48px + env(safe-area-inset-top, 0px));
  z-index: 3; background: rgba(15, 16, 20, .55);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: 16px; padding: 12px 8px;
}
.targets-row { display: flex; justify-content: space-around; gap: 4px; }
.macro { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.ring {
  position: relative; width: 68px; height: 68px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--color, #fff) calc(var(--value, 0) * 1%), rgba(255,255,255,.16) 0);
  transition: background .35s ease;
}
.ring::after {
  content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #141414;
}
.ring-content {
  position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; text-align: center; padding: 0 4px;
}
.macro-icon { font-size: 14px; line-height: 1; }
.macro-value { font-size: 9px; font-weight: 700; color: #fff; line-height: 1.15; white-space: nowrap; }
.macro-label { font-size: 10.5px; color: rgba(255,255,255,.68); }

/* --- Карточка профиля: заголовок стадии + уровень одной объединённой карточкой —
   порт шаблона пользователя (раньше было две отдельных карточки). --- */
.profile-card {
  position: absolute; left: 12px; right: 12px; z-index: 3;
  bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px;
  background: rgba(15, 16, 20, .6);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: 20px; color: #fff; padding: 14px;
}
.profile-card > div:first-child { flex: 1; min-width: 0; }
.profile-title { font-size: 15px; font-weight: 700; margin: 0 0 2px; }
.profile-title .score { color: #ff6a34; }
.profile-text { font-size: 12.5px; color: rgba(255,255,255,.78); }
.edit-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; margin-top: 10px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px; padding: 9px 10px;
  color: #fff; font-size: 12.5px; font-weight: 600; cursor: pointer;
}

.level { flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.level-ring {
  position: relative; width: 56px; height: 56px; border-radius: 50%;
  background: conic-gradient(#ff6a34 calc(var(--progress, 0) * 1%), rgba(255,255,255,.16) 0);
}
.level-ring::after {
  content: ""; position: absolute; inset: 5px; border-radius: 50%; background: #141414;
}
.level-inner {
  position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.paw { font-size: 13px; line-height: 1; }
.level-number { font-size: 15px; font-weight: 800; color: #ff6a34; line-height: 1; }
.level-label { font-size: 9px; color: rgba(255,255,255,.6); }
.xp { font-size: 10.5px; color: #aaa; font-weight: 600; }
.xp strong { color: #ff6a34; }

/* --- Экран "профиль ещё не заполнен": кнопка на всю ширину --- */
#onboarding-needed .btn { width: 100%; margin-top: 14px; }

/* --- Календарь --- */
.calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.calendar-header #cal-title { font-weight: 600; }
.icon-btn {
  background: none; border: none; font-size: 20px; padding: 4px 10px; cursor: pointer;
  color: var(--tg-theme-link-color, #007aff);
}
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center;
}
.cal-weekday { font-size: 11px; color: var(--tg-theme-hint-color, #888); padding-bottom: 4px; }
.cal-day {
  position: relative; padding: 8px 0; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.cal-day.empty { visibility: hidden; }
.cal-day.selected { background: var(--tg-theme-button-color, #007aff); color: var(--tg-theme-button-text-color, #fff); }
.cal-day.today:not(.selected) { font-weight: 700; }
.cal-day .dots { position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%); display: flex; gap: 2px; }
.cal-day .dot { width: 4px; height: 4px; border-radius: 50%; }
.cal-day .dot.food { background: #34c759; }
.cal-day .dot.workout { background: #ff9500; }

/* --- День --- */
.day-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#day-title { font-weight: 600; }
.day-totals { display: flex; gap: 10px; font-size: 13px; color: var(--tg-theme-hint-color, #888); margin-bottom: 8px; }

/* Закреплённые дата + КБЖУ во вкладке "Дневник питания" — остаются на месте, пока список
   продуктов под ними прокручивается. Отрицательный margin компенсирует паддинг #app, чтобы
   фон "прилипшего" блока доходил до самых краёв экрана (иначе по бокам просвечивал бы список,
   проезжающий под ним). */
.day-sticky-head {
  position: sticky; top: 0; z-index: 5;
  background: var(--tg-theme-bg-color, #f2f2f7);
  margin: -12px -12px 10px; padding: 12px 12px 6px;
}
.day-sticky-head .day-header,
.day-sticky-head .day-totals { margin-bottom: 6px; }
.section-title {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
  margin: 14px 0 6px; display: flex; justify-content: space-between; align-items: center;
  color: var(--tg-theme-hint-color, #888);
}
.link-btn {
  background: none; border: none; color: var(--tg-theme-link-color, #007aff); font-size: 13px; cursor: pointer;
  text-transform: none; letter-spacing: 0; font-weight: 500;
}
.entry-list { display: flex; flex-direction: column; gap: 6px; }
.entry-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: rgba(127,127,127,.08); border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.entry-row .main { flex: 1; min-width: 0; }
.entry-row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-row .meta { font-size: 12px; color: var(--tg-theme-hint-color, #888); }
.entry-row .del-btn {
  background: none; border: none; color: #ff3b30; font-size: 18px; cursor: pointer; padding: 2px 6px;
}
.empty-hint { color: var(--tg-theme-hint-color, #888); font-size: 13px; padding: 6px 0; }

/* --- Модалки (тренировка / продукт / поп-ап дня) --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; z-index: 50; /* выше #bottom-nav (40) — иначе плавающая
  панель перекрывает нижнюю часть модалки и перехватывает клики по кнопкам в ней */
}
.modal-content {
  background: var(--tg-theme-bg-color, #fff); width: 100%; border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 10px;
}
.modal-content h3 { margin: 0 0 4px; }
.modal-content label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; color: var(--tg-theme-hint-color, #888); }
.modal-content input, .modal-content select {
  font-size: 15px; padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(127,127,127,.3);
  background: var(--tg-theme-secondary-bg-color, #f2f2f7); color: var(--tg-theme-text-color, #111);
}
.fields-row { display: flex; gap: 8px; }
.fields-row label { flex: 1; min-width: 0; }
/* Видимый текст ошибки сохранения в модалках (например анкеты профиля) — раньше неудачный
   запрос падал молча, и пользователь видел просто "ничего не произошло". */
.form-error { color: #ff3b30; font-size: 13px; margin-top: -2px; }
.fields-row input { width: 100%; min-width: 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.btn { flex: 1; padding: 10px; border-radius: 10px; border: none; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--tg-theme-button-color, #007aff); color: var(--tg-theme-button-text-color, #fff); }
.btn.secondary { background: rgba(127,127,127,.15); color: var(--tg-theme-text-color, #111); }

/* --- Поп-ап дня (из календаря) --- */
.day-modal-content { max-height: 82vh; overflow-y: auto; }
.day-modal-header { display: flex; justify-content: space-between; align-items: center; }
.day-modal-header #day-modal-title { font-weight: 600; font-size: 16px; }
.day-modal-header .icon-btn { font-size: 16px; padding: 4px 8px; color: var(--tg-theme-hint-color, #888); }
