/* Палитра берётся из темы Telegram, значения после запятой — запасные. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #101014);
  --muted: var(--tg-theme-hint-color, #7d7d85);
  --accent: var(--tg-theme-button-color, #2f8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f8cff);
  --danger: var(--tg-theme-destructive-text-color, #e0524b);
  --radius: 14px;
  --gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.screen { animation: rise .22s ease-out; }
.screen--center { text-align: center; padding-top: 12vh; }

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

@media (prefers-reduced-motion: reduce) {
  .screen, .pen, .spin { animation: none; }
}

/* --- Заголовки --- */
.title { font-size: 22px; font-weight: 700; margin: 4px 0 6px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 24px 0 10px; font-weight: 600; }

.hero { text-align: center; padding: 8px 0 4px; }
.hero__emoji { font-size: 44px; line-height: 1; }
.hero__title { font-size: 24px; font-weight: 700; margin: 10px 0 4px; }
.hero__subtitle { color: var(--muted); margin: 0; }

.steps { list-style: none; padding: 0; margin: 22px 0 0;
  display: flex; flex-direction: column; gap: 8px; }
.steps__item { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.steps__num {
  flex: 0 0 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}

/* --- Карточки выбора --- */
.cards { display: flex; flex-direction: column; gap: var(--gap); }

.card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.card:active { transform: scale(.985); opacity: .85; }
.card__icon { font-size: 24px; flex: 0 0 auto; }
.card__body { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.card__title { font-weight: 600; }
.card__hint { color: var(--muted); font-size: 14px; }
.card__chevron { color: var(--muted); font-size: 22px; line-height: 1; }
.card--selected { outline: 2px solid var(--accent); }

/* --- Поля ввода --- */
.field { margin-bottom: 16px; }
.field__label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field__optional { color: var(--muted); font-weight: 400; }
.field__counter { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }

.input {
  width: 100%; padding: 13px 14px; font: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid transparent; border-radius: var(--radius);
  outline: none; -webkit-appearance: none;
}
.input:focus { border-color: var(--accent); }
.input--area { resize: vertical; min-height: 88px; }
.input--error { border-color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border: 0; border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: 14px; cursor: pointer;
}
.chip:active { opacity: .7; }

/* --- Классы --- */
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.grade {
  aspect-ratio: 1 / 1; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 20px; font-weight: 600; cursor: pointer;
  display: grid; place-items: center;
  transition: transform .12s ease;
}
.grade:active { transform: scale(.94); }
.grade--selected { background: var(--accent); color: var(--accent-text); }

/* --- Подтверждение --- */
.summary { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
/* Ключ строкой над значением: длинная тема не сжимается в узкий столбик. */
.summary__row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  align-items: center; width: 100%;
  padding: 12px 14px; border: 0; background: none; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.summary__row + .summary__row { border-top: 1px solid var(--bg); }
.summary__key { grid-column: 1; color: var(--muted); font-size: 13px; }
.summary__value { grid-column: 1; font-weight: 600; min-width: 0; }
.summary__edit { grid-column: 2; grid-row: 1 / span 2; color: var(--link); font-size: 14px; }

/* --- Процесс --- */
.pen { font-size: 46px; animation: nod 1.6s ease-in-out infinite; }
@keyframes nod {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg) translateY(-4px); }
}

.progress { list-style: none; padding: 0; margin: 24px auto 0; max-width: 260px;
  display: flex; flex-direction: column; gap: 12px; text-align: left; }
.progress__item { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.progress__dot {
  flex: 0 0 10px; height: 10px; border-radius: 50%;
  background: var(--muted); opacity: .35;
}
.progress__item--active { color: var(--text); font-weight: 600; }
.progress__item--active .progress__dot { background: var(--accent); opacity: 1; animation: pulse 1.2s infinite; }
.progress__item--done .progress__dot { background: var(--accent); opacity: 1; }
@keyframes pulse { 50% { transform: scale(1.5); } }

.note { color: var(--muted); font-size: 14px; margin-top: 24px; }

/* --- Результат --- */
.result-head { margin-bottom: 14px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border-radius: 10px;
  padding: 8px 11px; font-size: 13px; color: var(--muted);
}
.stat b { color: var(--text); font-size: 15px; }
.stat--warn b { color: var(--danger); }

.essay {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; white-space: pre-wrap; word-wrap: break-word;
  font-size: 16px; line-height: 1.6;
}

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 16px; }

.btn {
  padding: 13px 14px; border: 0; border-radius: var(--radius);
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text);
  transition: opacity .12s ease;
}
.btn:active { opacity: .7; }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--wide { display: block; width: 100%; margin-top: 22px; padding: 15px; font-size: 17px; }

.backlink {
  border: 0; background: none; color: var(--link);
  font: inherit; font-size: 16px; padding: 4px 0 12px; cursor: pointer;
}
.btn[disabled] { opacity: .5; cursor: default; }

.disclaimer { color: var(--muted); font-size: 13px; margin-top: 16px; text-align: center; }

/* --- Правила --- */
.rules { margin-top: 26px; background: var(--surface); border-radius: var(--radius); }
.rules__summary { padding: 13px 14px; cursor: pointer; font-weight: 600; list-style: none; }
.rules__summary::-webkit-details-marker { display: none; }
.rules__summary::after { content: " ›"; color: var(--muted); }
.rules[open] .rules__summary::after { content: " ⌄"; }
.rules__body { padding: 0 14px 14px; }
.rules__label { font-weight: 600; margin: 14px 0 6px; }
.rules__list { list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px; }
.rules__list li { display: flex; gap: 8px; font-size: 14px; color: var(--muted); }
.rules__list li::before { flex: 0 0 auto; }
.rules__list--ok li::before { content: "✅"; }
.rules__list--no li::before { content: "🚫"; }

/* --- Тост --- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px;
  z-index: 10; animation: rise .2s ease-out;
}
