/* Цвета берём из темы Telegram — приложение само подстраивается под светлую
   и тёмную схему пользователя. Значения после запятой — запасные, на случай
   открытия страницы вне Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f4f7);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8b95a1);
  --link: var(--tg-theme-link-color, #2f80ed);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --radius: 18px;
  --ok: #2eb872;
  --err: #e5484d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.screen { padding: 16px 16px 0; flex: 1; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.subtitle { margin: 4px 0 0; font-size: 14px; color: var(--hint); }

.counter {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  background: var(--secondary-bg);
  padding: 6px 12px;
  border-radius: 100px;
}

/* ------------------------------------------------------------------ карточки */

.deck { position: relative; touch-action: pan-y; }

.card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  overflow: hidden;
  animation: fade 0.22s ease;
}

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

.card-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
  background: linear-gradient(135deg, rgba(127,127,127,.12), rgba(127,127,127,.04));
}

.card-body { padding: 16px 18px 20px; }

.word-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.article {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 3px 9px;
  border-radius: 8px;
}

.lemma { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }

.speak {
  margin-left: auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 19px;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.speak:active { transform: scale(0.92); }
.speak.playing { opacity: 0.55; }

.translation { font-size: 19px; margin: 10px 0 0; }
.plural { font-size: 13px; color: var(--hint); margin: 6px 0 0; }

.example {
  margin: 16px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.45;
}
.example .de { font-style: italic; }
.example .ru { color: var(--hint); margin-top: 5px; font-size: 14px; }

.hint {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--hint);
}

/* ----------------------------------------------------------------- навигация */

.deck-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 0 8px;
}

.nav-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.nav-btn:disabled { opacity: 0.32; }

.dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hint);
  opacity: 0.32;
  transition: opacity 0.15s, transform 0.15s;
}
.dot.active { opacity: 1; transform: scale(1.35); background: var(--accent); }

/* --------------------------------------------------------------------- тест */

.quiz-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 20px 18px;
}

.question { font-size: 19px; line-height: 1.4; margin: 0 0 18px; }
.question code {
  font-family: inherit;
  font-style: italic;
  color: var(--hint);
}

.options { display: flex; flex-direction: column; gap: 9px; }

.option {
  width: 100%;
  text-align: left;
  padding: 15px 16px;
  font-size: 16px;
  border: 2px solid transparent;
  border-radius: 13px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.option:active { transform: scale(0.99); }
.option.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, var(--bg)); }
.option.wrong { border-color: var(--err); background: color-mix(in srgb, var(--err) 13%, var(--bg)); }
.option:disabled { cursor: default; }

.feedback { margin-top: 16px; font-size: 15px; line-height: 1.5; }
.feedback .verdict { font-weight: 700; font-size: 17px; }
.feedback .verdict.ok { color: var(--ok); }
.feedback .verdict.no { color: var(--err); }
.feedback .explain {
  margin-top: 9px;
  padding: 11px 13px;
  background: var(--bg);
  border-radius: 11px;
  color: var(--hint);
}

.primary {
  width: 100%;
  margin: 16px 0 8px;
  padding: 15px;
  border: none;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* ----------------------------------------------------------------- прогресс */

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.stat {
  background: var(--secondary-bg);
  border-radius: 15px;
  padding: 16px;
}
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.stat .label { font-size: 13px; color: var(--hint); margin-top: 3px; }
.stat.wide { grid-column: 1 / -1; }

.bar {
  height: 7px;
  border-radius: 4px;
  background: var(--bg);
  margin-top: 11px;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* -------------------------------------------------------------- служебное */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid color-mix(in srgb, var(--hint) 22%, transparent);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 11px;
  padding: 9px 0 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.tab span { font-size: 21px; line-height: 1; }
.tab.active { color: var(--accent); }

.loader { display: grid; place-items: center; min-height: 65vh; }
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid color-mix(in srgb, var(--hint) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice {
  margin: 28px 18px;
  padding: 20px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
  text-align: center;
  font-size: 15px;
  line-height: 1.5;
  color: var(--hint);
}
.notice p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
