/* Цвета берутся из темы Telegram; запасные значения — для обычного браузера */
:root {
  --fb-bg: #ffffff; --fb-bg2: #f2f2f7; --fb-text: #111111; --fb-hint: #8e8e93; --fb-accent: #2481cc;
  --bg: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-bg)));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --line: rgba(127, 127, 127, .18);
  --ok: #22c55e; --bad: #ef4444; --warn: #f59e0b;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --fb-bg: #1c1c1e; --fb-bg2: #000000; --fb-text: #f2f2f7; --fb-hint: #8e8e93; --fb-accent: #3e9bea; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
h3 { margin: 0 32px 12px 0; font-size: 18px; }
small, .small { font-size: 13px; }
.muted { color: var(--hint); }
.center { text-align: center; justify-content: center; }
.hidden { display: none !important; }
.loader { text-align: center; color: var(--hint); padding: 40px 0; }

.card { background: var(--bg); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card > b:first-child { display: block; margin-bottom: 8px; }
.card.error { color: var(--bad); }
.row { display: flex; align-items: center; gap: 0; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; margin-bottom: 8px;
}
.row input, .row select { margin-bottom: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
/* iOS рисует поля даты и времени системным элементом с минимальной шириной — вылезают за край */
input[type="date"], input[type="time"] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%;
  min-height: 42px; line-height: 1.3; text-align: left;
}
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
.row input[type="date"], .row input[type="time"] { display: inline-block; }
.time-in { text-align: center; }
.time-in::-webkit-date-and-time-value { text-align: center; }
textarea { min-height: 60px; resize: vertical; }
.field { display: block; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 4px 2px; }

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
.btn { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 10px 14px; font-weight: 600; white-space: nowrap; }
.btn:active { opacity: .8; }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.ghost { background: var(--bg2); color: var(--accent); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.full { width: 100%; display: block; text-align: center; margin-top: 4px; }
.btn.huge { font-size: 26px; padding: 16px 28px; border-radius: 18px; }
label.btn { cursor: pointer; }
.icon { padding: 6px 10px; font-size: 18px; border-radius: 8px; }
.icon.muted { color: var(--hint); font-size: 14px; }

.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 9px; font-size: 14px; }
.seg button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: default; }
.item[data-act] { cursor: pointer; }
.card > .item:first-of-type { border-top: 0; }
.list .item:first-child { border-top: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot.big { width: 14px; height: 14px; margin-right: 8px; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex: none; background: var(--bg2);
  display: flex; align-items: center; justify-content: center; font-size: 20px; }
.photo { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: var(--bg2); margin-bottom: 8px; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 20px; background: var(--bg2); color: var(--hint); white-space: nowrap; }
.badge.done { background: rgba(34, 197, 94, .15); color: var(--ok); }
.time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.scroll-x::-webkit-scrollbar { display: none; }
.chip.sel { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip { white-space: nowrap; border: 1.5px solid var(--line); border-radius: 20px; padding: 6px 12px; font-size: 14px; background: var(--bg); }

/* Календарь */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.wd { text-align: center; font-size: 12px; color: var(--hint); padding-bottom: 4px; }
.day { aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; font-variant-numeric: tabular-nums; }
.day.today span { color: var(--accent); font-weight: 700; }
.day.sel { background: var(--accent); }
.day.sel span { color: var(--accent-text); }
.dots { display: flex; gap: 2px; height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }

/* Тренировка */
.title-input { font-size: 18px; font-weight: 700; background: transparent; border-color: transparent; padding: 4px; margin: 0; }
.set { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.set .n { width: 22px; height: 22px; border-radius: 50%; background: var(--bg2); font-size: 12px;
  display: flex; align-items: center; justify-content: center; color: var(--hint); }
.sets { margin: 8px 0; }
.set-form input { text-align: center; }

/* Плитки и полоски */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tiles.two { grid-template-columns: 1fr 1fr; }
.tile { background: var(--bg2); border-radius: 12px; padding: 10px; }
.tile .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .l { font-size: 12px; color: var(--hint); }
.tile .d { font-size: 12px; }
.up { color: var(--ok); } .down { color: var(--bad); }
.macro { margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 4px; transition: width .3s; }
.calc { background: var(--bg2); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 14px; }
.big { font-size: 56px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big small { font-size: 22px; color: var(--hint); font-weight: 600; }
.big.bad { color: var(--bad); }
.grams { width: 72px; text-align: center; margin: 0; padding: 6px; }
.meal-head { display: flex; justify-content: space-between; align-items: center; }
.colors { display: flex; gap: 8px; margin-bottom: 10px; }
.color { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.color.sel { border-color: var(--text); }
.checklist { max-height: 40vh; overflow-y: auto; margin-bottom: 10px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.check input { width: 20px; height: 20px; margin: 0; flex: none; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 12px 0 2px; }
.reader { width: 100%; min-height: 200px; border-radius: 12px; overflow: hidden; background: #000; margin-bottom: 8px; }
.reader p { color: #ccc; padding: 16px; margin: 0; }

/* Главная и подсказки */
.hint { border: 1.5px solid var(--accent); }
.hint ol { margin: 6px 0 10px; padding-left: 20px; }
.hint li { margin-bottom: 4px; }
.home-head { padding: 4px 4px 12px; }
.home-head h2 { margin: 0; font-size: 22px; }
.step { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.step .mark { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 13px; }
.step.done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done .t { color: var(--hint); text-decoration: line-through; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-grid .card { margin: 0; cursor: pointer; }
.home-card { cursor: pointer; }
.home-card .label { font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.home-card .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result { background: var(--bg2); border-radius: 12px; padding: 12px; margin: 4px 0 10px; }
.result .big-num { font-size: 28px; font-weight: 800; }
details summary { cursor: pointer; color: var(--accent); margin: 6px 0 10px; }

/* Маскот */
.mascot-card { display: flex; gap: 14px; align-items: center; cursor: pointer; }
.mascot { position: relative; width: 112px; height: 112px; flex: none; display: flex; align-items: center; justify-content: center; }
.mascot .body { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  transform: scale(var(--s, 1)); transition: transform .4s, filter .4s; }
.mascot img { width: 100%; height: 100%; object-fit: contain; }
.m-emoji { font-size: 76px; line-height: 1; }
.mascot .acc { position: absolute; font-size: 26px; z-index: 1; }
.mascot .acc.top { top: -8px; left: 50%; transform: translateX(-50%); }
.mascot .acc.side { right: -4px; bottom: 4px; }
.mascot .acc.mood { left: -2px; top: 10px; font-size: 22px; }
.mascot.sad .body { filter: grayscale(.65) brightness(.85); transform: scale(var(--s, 1)) rotate(-8deg); }
.mascot.happy .body { animation: m-bounce 1.6s ease-in-out infinite; }
.mascot.legend::before { content: ''; position: absolute; inset: -8px; border-radius: 50%;
  background: radial-gradient(circle, rgba(250, 204, 21, .45), transparent 70%); animation: m-glow 2.4s ease-in-out infinite; }
@keyframes m-bounce { 0%, 100% { transform: scale(var(--s, 1)) translateY(0); } 50% { transform: scale(var(--s, 1)) translateY(-7px); } }
@keyframes m-glow { 50% { opacity: .35; } }
.mascot canvas { width: 100%; height: 100%; display: block; }
.mascot.big { width: 230px; height: 230px; }
.mascot.is3d .body { transform: none; animation: none; filter: none; }
.mascot.is3d .acc, .mascot.is3d::before { display: none; }
.streak { font-size: 22px; font-weight: 800; }
.mascot-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.mascot-pick button { background: var(--bg2); border: 2px solid transparent; border-radius: 14px; padding: 10px 4px; }
.mascot-pick button.sel { border-color: var(--accent); }
.mascot-pick .mascot { width: 80px; height: 80px; margin: 0 auto; }
.mascot-pick .m-emoji { font-size: 54px; }
.stage-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.stage-row.cur { font-weight: 700; color: var(--accent); }

/* Уведомления и расписание */
.bell { font-size: 22px; width: 44px; height: 44px; border-radius: 50%; background: var(--bg); flex: none; }
.notif-row { padding: 8px 0; border-top: 1px solid var(--line); gap: 8px; }
.notif-row label { cursor: pointer; }
.time-in { width: 110px; margin: 0; padding: 6px 8px; flex: none; }
.chk { width: 20px; height: 20px; margin: 0; flex: none; }
.off { opacity: .45; pointer-events: none; }
.card .btn.ghost.small { margin-top: 10px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 15px; background: var(--line); transition: background .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 12px; }
.wdbtn { padding: 10px 0; border-radius: 10px; background: var(--bg2); font-weight: 600; }
.wdbtn.sel { background: var(--accent); color: var(--accent-text); }

/* Админ-панель */
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th { font-size: 12px; color: var(--hint); font-weight: 500; text-align: right; padding: 4px 6px; }
.tbl td { padding: 7px 6px; border-top: 1px solid var(--line); text-align: right; }
.tbl th:first-child, .tbl td:first-child { text-align: left; padding-left: 0; }
.link { color: var(--accent); font-size: 14px; padding: 0 0 0 4px; }

/* Нижняя навигация */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--hint); padding: 2px 0; }
#tabs button span { font-size: 21px; filter: grayscale(1); opacity: .7; }
#tabs button.active { color: var(--accent); font-weight: 600; }
#tabs button.active span { filter: none; opacity: 1; }

/* Модальное окно-шторка */
#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { position: relative; background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.close { position: absolute; top: 10px; right: 8px; color: var(--hint); }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(0, 0, 0, .8); color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; }
