/* ОБЛАСТЬ УЧЕНИКОВ */
/*
  Внешний вид Mini App «Zehn» в стиле Grok: чёрный фон, один акцентный цвет, мало рамок.
  Кто редактирует: ученики.
  Палитра — в :root; меняйте цвета, скругления и тени здесь; классы и переменные темы
  не переименовывайте (их ищет app.js). Смешивание цветов функцией не используем: старые WebView его
  не знают, прозрачность пишем через rgba().
*/

/* ========== 1. Переменные: тёмная тема (по умолчанию) ========== */
:root {
  --bg: #000000;          /* фон, как у Grok */
  --surface: #111214;     /* карточки, пузырь ученика */
  --surface-2: #1a1b1e;   /* поле ввода, чипы при наведении */
  --border: #27272a;      /* тонкие рамки */
  --text: #fafafa;
  --muted: #a1a1aa;       /* подписи, «1/2-qadam» */
  --accent: #22d3ee;      /* ОДИН акцент: свечение Zehn, активный чип, кнопка отправки */
  --accent-ink: #06202a;  /* текст на акцентной кнопке */
  --ok: #4ade80;          /* «Barakalla» */
  --glow: rgba(34, 211, 238, 0.45); /* свечение вокруг Zehn */
  --radius: 18px;
  --radius-pill: 999px;
  --side: 16px;           /* боковые отступы */
}

/* Светлая тема: браузер просит светлую, а Telegram не сказал «тёмная» */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --surface: #f4f4f5;
    --surface-2: #e4e4e7;
    --border: #e4e4e7;
    --text: #09090b;
    --muted: #6b6b74;
    --ok: #15803d;         /* светло-зелёный на белом не читается — берём темнее */
    --glow: rgba(14, 116, 144, 0.35);
  }
}

/* Светлая тема из Telegram (app.js ставит data-theme="light") */
html[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f4f4f5;
  --surface-2: #e4e4e7;
  --border: #e4e4e7;
  --text: #09090b;
  --muted: #6b6b74;
  --ok: #15803d;
  --glow: rgba(14, 116, 144, 0.35);
}

/* ========== 2. Базовые стили ========== */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", Inter, Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: default;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  height: var(--tg-viewport-stable-height, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.muted-text {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

/* Кнопки внизу экранов */
.btn {
  min-height: 48px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.4;
}

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

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

/* ========== 3. Шапка ========== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px var(--side);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Знак Zehn: картинка служит маской, цвет — цвет текста */
.logo {
  width: 24px;
  height: 24px;
  background: currentColor;
  -webkit-mask: url("/static/img/zehn-logo.svg") center / contain no-repeat;
  mask: url("/static/img/zehn-logo.svg") center / contain no-repeat;
}

.app-title {
  font-size: 18px;
  font-weight: 600;
}

/* Переключатель режимов — пилюля из двух сегментов */
.mode-switch {
  display: flex;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  min-width: 0;
}

.mode-button {
  min-height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.mode-button.selected {
  background: var(--surface-2);
  color: var(--text);
}

.icon-button {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
}

/* ========== 4. Сплэш ========== */
.splash {
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 0 var(--side);
}

.splash-name {
  margin: 8px 0 0;
  font-size: 24px;
  font-weight: 600;
}

.splash .btn {
  margin-top: 16px;
}

/* ========== 5. Онбординг ========== */
.progress {
  height: 4px;
  margin: 12px var(--side) 0;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 17%;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transition: width 0.25s ease;
}

.onboarding {
  flex: 1;
  overflow-y: auto;
  padding: 24px var(--side);
}

/* Zehn слева, крестик «закрыть» справа */
.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

/* Мой прогресс (M9-5): карточка над первым вопросом профиля */
.progress-block {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.progress-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.progress-line {
  margin: 4px 0;
  line-height: 1.4;
}

.progress-note {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.step-title {
  margin: 16px 0 24px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* варианты занимают ширину по тексту и растягиваются, слова не переносятся */
.options .option {
  flex: 1 1 auto;
  white-space: nowrap;
}

/* интересы — ровно две колонки */
.options.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

/* шаг языка (он же переключатель языка в «Мой мир») — три крупные кнопки столбиком */
.options.languages {
  flex-direction: column;
}

.options.languages .option {
  padding: 14px 16px;
  font-size: 17px;
}

textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  resize: none;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.onboarding-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px var(--side) 16px;
}

.onboarding-actions .btn {
  flex: 1 1 auto;
  padding: 12px 16px;
  white-space: nowrap;
}

/* Кнопка «назад» узкая — по своему тексту */
.onboarding-actions #back {
  flex: 0 0 auto;
}

/* На последнем шаге «сохранить» — во всю ширину под «назад» и «пропустить»:
   три кнопки в одну строку на телефоне не помещаются */
.onboarding-actions #save {
  flex-basis: 100%;
}

/* ========== 6. Пустой экран и лента ========== */
.empty {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px var(--side);
  text-align: center;
}

.hello {
  margin: 16px 0 0;
  font-size: 22px;
  font-weight: 600;
}

.cards {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 128px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
}

.card:active {
  background: var(--surface-2);
}

.card-icon {
  display: flex;
  margin-bottom: 8px;
  color: var(--accent);
}

.card-title {
  font-weight: 600;
}

.card-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.topics {
  width: 100%;
  margin-top: 24px;
}

.topics .chip-row {
  justify-content: center;
  margin-top: 12px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px var(--side);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bubble {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: fade-in 0.15s ease-out;
}

/* Бот — слева: маленький Zehn и текст без пузыря */
.bubble.bot {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  align-self: stretch;
}

.bot-text {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}

/* Похвала «Barakalla» — зелёным */
.bubble.praise .bot-text {
  color: var(--ok);
  font-weight: 600;
}

/* Ученик — справа в пилюле */
.bubble.me {
  align-self: flex-end;
  max-width: 80%;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--surface);
}

/* Строка «1/2-qadam» с точками прогресса */
.step-line {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.step-line span:first-child {
  margin-right: 4px;
}

.step-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--border);
}

.step-dot.done {
  background: var(--accent);
}

.step-dot.current {
  width: 16px;
  background: var(--accent);
}

/* Индикатор «печатает»: Zehn думает (покрупнее, чтобы видно точки над головой) и три точки */
.typing .zehn-avatar {
  width: 40px;
  height: 40px;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding-top: 12px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ========== 7. Чипы ========== */
.chip {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.chip:active {
  background: var(--surface-2);
}

.chip.selected,
.chip-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.chip:disabled {
  opacity: 0.4;
}

/* кнопка «другая тема» под строкой «начнём с трудной темы» */
.other-topic {
  margin-top: 8px;
}

/* «Своя задача» рядом с «другая тема» */
.other-topic + .other-topic {
  margin-left: 8px;
}

.chip-row,
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips {
  padding: 0 var(--side) 8px;
}

.chips:empty {
  display: none;
}

/* ========== 8. Строка ввода и всплывашка ========== */
.input-row {
  padding: 4px var(--side) 12px;
}

.input-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.input-pill input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
}

/* подсказка в поле: цвет текста с прозрачностью — читается и в светлой теме */
.input-pill input::placeholder,
textarea::placeholder {
  color: var(--text);
  opacity: 0.6;
}

.send-button {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
}

.send-button:disabled {
  background: var(--muted);
  color: var(--bg);
}

.toast {
  position: fixed;
  left: var(--side);
  right: var(--side);
  bottom: 88px;
  max-width: 528px;
  margin: 0 auto;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  animation: fade-in 0.15s ease-out;
}

/* ========== 9. Персонаж Zehn ========== */
.zehn {
  display: block;
  flex-shrink: 0;
  /* мягкое плоское свечение вокруг больших Zehn */
  filter: drop-shadow(0 0 18px rgba(34, 211, 238, 0.35));
  animation: breathe 4s ease-in-out infinite;
}

.zehn-splash {
  width: 96px;
  height: 96px;
}

.zehn-hero {
  width: 112px;
  height: 112px;
}

.zehn-small {
  width: 40px;
  height: 40px;
}

/* в ленте Zehn маленький, без свечения и не «дышит», чтобы не отвлекать */
.zehn-avatar {
  width: 28px;
  height: 28px;
  filter: none;
  animation: none;
}

/* ========== 10. Анимации ========== */
@keyframes breathe {
  0%, 100% { transform: translateY(-3px); }
  50% { transform: translateY(3px); }
}

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

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

/* Ученикам, кому мешает движение, анимации выключаем */
@media (prefers-reduced-motion: reduce) {
  .zehn,
  .bubble,
  .toast,
  .typing-dots span {
    animation: none;
  }
}
