/* ===========================================================================
   Интерфейс Mini App. Токены — в tokens.css.
   =========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* Видимый фокус — обязателен для доступности */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) {
  outline: none;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: var(--tracking-display);
  line-height: var(--leading-tight);
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------------------------------------------------------------- Заставка */
.boot,
.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-4);
  padding: var(--space-6);
  text-align: center;
  background: var(--surface);
  z-index: 50;
}

.boot__mark {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  background: linear-gradient(160deg, var(--sprout), var(--leaf));
  animation: breathe 1.6s var(--ease-out) infinite;
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.82);
    opacity: 0.65;
  }
}

.boot__text,
.fatal__text {
  color: var(--text-muted);
  margin: 0;
  max-width: 30ch;
}

.fatal__emoji {
  font-size: 3rem;
}
.fatal__title {
  font-size: var(--text-xl);
}

/* ------------------------------------------------------------- Каркас окна */
.app {
  padding: var(--space-4) var(--space-4) calc(84px + var(--safe-bottom));
  max-width: 620px;
  margin: 0 auto;
}

.app[hidden],
.tabbar[hidden] {
  display: none;
}

.screen {
  display: grid;
  gap: var(--space-4);
  animation: rise var(--dur-med) var(--ease-out);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.screen__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.screen__title {
  font-size: var(--text-2xl);
}

.screen__sub {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: var(--space-1) 0 0;
}

/* ---------------------------------------------------------------- Карточки */
.card {
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  border: 1px solid var(--border);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card__title {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 500;
  letter-spacing: var(--tracking-display);
  margin: 0 0 var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.card__hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: var(--space-2) 0 0;
}

/* ------------------------------------------- ФИРМЕННЫЙ ЭЛЕМЕНТ: наполнение */
.fill {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
}

.fill__wave {
  animation: wave-drift var(--wave-dur) linear infinite;
}

@keyframes wave-drift {
  to {
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fill__wave {
    animation: none;
  }
  .screen {
    animation: none;
  }
  .boot__mark {
    animation: none;
  }
}

/* Крупный показатель в центре «тарелки» */
.plate {
  position: relative;
  display: grid;
  place-items: center;
  padding: var(--space-2) 0;
}

.plate__readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
}

.plate__value {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: var(--tracking-display);
  line-height: 1;
}

.plate__unit {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.plate__caption {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-2);
}

/* --------------------------------------------------------------- Макросы */
.macros {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.macro {
  text-align: center;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}

.macro__label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.macro__value {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 500;
}

.macro__bar {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border);
  margin-top: var(--space-2);
  overflow: hidden;
}

.macro__bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease-out);
}

/* --------------------------------------------------------------- Кнопки */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: var(--space-3) var(--space-5);
  font-weight: 600;
  font-size: var(--text-md);
  transition: transform var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
  min-height: 44px; /* комфортная зона нажатия */
}

.btn:active {
  transform: scale(0.97);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn--soft {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.btn--block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ------------------------------------------------------- Быстрые действия */
.quick {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--space-2);
}

.quick__btn {
  display: grid;
  gap: var(--space-1);
  justify-items: center;
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  transition: transform var(--dur-fast) var(--ease-out);
}

.quick__btn:active {
  transform: scale(0.96);
}

.quick__icon {
  font-size: 1.35rem;
  line-height: 1;
}

.quick__label {
  font-size: var(--text-sm);
  font-weight: 500;
}

.quick__meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ------------------------------------------------------------ Список еды */
.meals {
  display: grid;
  gap: var(--space-3);
}

.meal-group__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.entry {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
}

.entry + .entry {
  margin-top: var(--space-2);
}

.entry__body {
  flex: 1;
  min-width: 0;
}

.entry__name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry__meta {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.entry__kcal {
  font-family: var(--font-display);
  font-weight: 500;
  white-space: nowrap;
}

.entry__del {
  background: none;
  border: none;
  padding: var(--space-2);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 0;
}

/* ------------------------------------------------------------ Пустые состояния */
.empty {
  display: grid;
  gap: var(--space-3);
  justify-items: center;
  text-align: center;
  padding: var(--space-6) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-strong);
  background: var(--surface-raised);
}

.empty__art {
  width: 84px;
  height: 84px;
}

.empty__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 500;
}

.empty__text {
  color: var(--text-muted);
  font-size: var(--text-sm);
  max-width: 34ch;
  margin: 0;
}

/* ------------------------------------------------------------------ Стрик */
.streak {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.streak__count {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--honey);
  line-height: 1;
}

.streak__label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.streak__week {
  display: flex;
  gap: 5px;
  margin-left: auto;
}

.streak__day {
  width: 12px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: var(--border);
  position: relative;
  overflow: hidden;
}

.streak__day--on {
  background: linear-gradient(180deg, var(--honey), #ff8f3c);
}

.streak__day--today {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- Прогресс веса */
.weight-track {
  position: relative;
  height: 44px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.weight-track__fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, var(--water), var(--sprout));
  transition: width var(--dur-slow) var(--ease-out);
}

.weight-track__labels {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  mix-blend-mode: normal;
}

.weight-chart {
  width: 100%;
  height: 120px;
  overflow: visible;
}

/* --------------------------------------------------------------- Достижения */
.badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: var(--space-3);
}

.badge {
  display: grid;
  gap: var(--space-1);
  justify-items: center;
  text-align: center;
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}

.badge--locked {
  opacity: 0.45;
  filter: grayscale(1);
}

.badge__emoji {
  font-size: 1.6rem;
  line-height: 1;
}

.badge__title {
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.25;
}

.badge__progress {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ Табы */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.tab {
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: var(--space-2) var(--space-1);
  background: none;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease-out);
}

.tab[aria-current="page"] {
  color: var(--accent);
}

.tab__icon svg {
  width: 24px;
  height: 24px;
  display: block;
}

.tab__label {
  font-size: var(--text-xs);
  font-weight: 500;
}

/* ----------------------------------------------------------------- Тосты */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lift);
  z-index: 40;
  max-width: min(90vw, 420px);
  text-align: center;
  animation: toast-in var(--dur-med) var(--ease-out);
}

.toast[hidden] {
  display: none;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
}

/* ------------------------------------------------------------ Модальный лист */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  align-items: end;
}

.sheet[hidden] {
  display: none;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 31, 24, 0.5);
  animation: fade-in var(--dur-fast) var(--ease-out);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.sheet__panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-5) var(--space-4) calc(var(--space-5) + var(--safe-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: sheet-up var(--dur-med) var(--ease-out);
  display: grid;
  gap: var(--space-4);
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  margin: 0 auto;
}

.sheet__title {
  font-size: var(--text-xl);
  text-align: center;
}

/* ------------------------------------------------------------------ Формы */
.field {
  display: grid;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
}

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
  min-height: 48px;
}

.input:focus-visible {
  border-color: var(--accent);
}

textarea.input {
  resize: vertical;
  min-height: 92px;
}

/* Плитки выбора (онбординг, настройки) */
.choices {
  display: grid;
  gap: var(--space-2);
}

.choices--2 {
  grid-template-columns: 1fr 1fr;
}

.choice {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface-raised);
  text-align: left;
  transition: border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}

.choice[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice__title {
  font-weight: 600;
}

.choice__hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* Числовой степпер */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.stepper__btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  font-size: var(--text-xl);
  line-height: 1;
  display: grid;
  place-items: center;
}

.stepper__value {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
}

.stepper__unit {
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 400;
  color: var(--text-muted);
  margin-left: var(--space-1);
}

/* --------------------------------------------------------------- Онбординг */
.onb {
  display: grid;
  gap: var(--space-5);
  min-height: 78vh;
  align-content: start;
  padding-top: var(--space-5);
}

.onb__progress {
  display: flex;
  gap: 6px;
}

.onb__dot {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border);
  overflow: hidden;
}

.onb__dot span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width var(--dur-med) var(--ease-out);
}

.onb__dot--done span {
  width: 100%;
}

.onb__step {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.onb__question {
  font-size: var(--text-2xl);
}

.onb__hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0;
}

/* --------------------------------------------------------------- Подписка */
.plan {
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  background: var(--surface-raised);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
}

.plan--active {
  border-color: var(--accent);
}

.plan__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.plan__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

.plan__badge {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
}

.plan__features {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.plan__features li {
  display: flex;
  gap: var(--space-2);
  align-items: start;
}

.plan__features li::before {
  content: "";
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 3px;
  border-radius: var(--radius-pill);
  background: var(--sprout-soft);
  box-shadow: inset 0 0 0 2px var(--sprout);
}

.periods {
  display: grid;
  gap: var(--space-2);
}

.period {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
}

.period__months {
  font-weight: 600;
}

.period__price {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 500;
}

.period__save {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--leaf);
  background: var(--sprout-soft);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

:root[data-theme="dark"] .period__save {
  color: var(--sprout);
}

/* ----------------------------------------------------------- Мелочи */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.row + .row {
  border-top: 1px solid var(--border);
}

.row__label {
  font-weight: 500;
}

.row__hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.row__value {
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: right;
}

/* Переключатель */
.switch {
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  border: none;
  flex: none;
  transition: background-color var(--dur-fast) var(--ease-out);
}

.switch[aria-checked="true"] {
  background: var(--accent);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--dur-fast) var(--ease-out);
}

.switch[aria-checked="true"]::after {
  transform: translateX(20px);
}

.chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.chip {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  font-size: var(--text-sm);
  font-weight: 500;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.stat {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
}

.stat__value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
}

.stat__label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.note {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
