/* ============================================================
   БАЗОВОЕ
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: var(--tg-theme-bg-color, #0f0f1a);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8b8b9e);
  --button: var(--tg-theme-button-color, #8b5cf6);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1a1a2e);
  --accent: #8b5cf6;
  --accent-light: #a78bfa;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* ============================================================
   ЭКРАНЫ
   ============================================================ */

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 20px;
  padding-top: 80px;
  animation: fadeIn 0.3s ease;
}

.screen-center {
  justify-content: center;
  align-items: center;
  text-align: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-8px); }
}

/* ============================================================
   ТИПОГРАФИКА
   ============================================================ */

h1 { font-size: 28px; font-weight: 700; margin-bottom: 12px; line-height: 1.3; }
h2 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }

.subtitle {
  color: var(--hint);
  font-size: 15px;
  margin-bottom: 24px;
  line-height: 1.5;
}

.logo {
  font-size: 80px;
  margin-bottom: 20px;
  animation: bounce 1s ease infinite alternate;
}

/* ============================================================
   КНОПКИ
   ============================================================ */

.btn {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
}

.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
}

/* ============================================================
   ONBOARDING
   ============================================================ */

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--secondary-bg);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}

.option:active { opacity: 0.8; }

.option.selected {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.12);
}

.option-flag { font-size: 28px; flex-shrink: 0; }
.option-text { display: flex; flex-direction: column; text-align: left; }
.option-title { font-size: 16px; font-weight: 600; }
.option-desc { font-size: 13px; color: var(--hint); margin-top: 2px; }

.footer {
  margin-top: auto;
  padding-top: 20px;
  position: sticky;
  bottom: 20px;
}

.steps {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  justify-content: center;
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--secondary-bg);
  transition: background 0.2s, width 0.2s;
}

.step-dot.active { background: var(--accent); width: 24px; border-radius: 4px; }
.step-dot.done { background: var(--accent); }

/* ============================================================
   HOME
   ============================================================ */

.home-screen {
  padding: 0;
  max-width: 100%;
}

.home-header {
  padding: 70px 20px 8px;
  text-align: center;
}

.home-header h2 { font-size: 18px; font-weight: 600; margin: 0; }
.home-header .sub { font-size: 13px; color: var(--hint); margin-top: 2px; }

.home-title-block {
  text-align: center;
  padding: 20px 0 24px;
}

.home-title {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
  line-height: 1.1;
}

.home-subtitle {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--hint);
  text-transform: uppercase;
}

.card {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 0 20px 12px;
  border: 1px solid rgba(139, 92, 246, 0.08);
}

.streak-card { display: flex; flex-direction: column; gap: 10px; }

.streak-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--hint);
  text-transform: uppercase;
}

.streak-row { display: flex; align-items: center; gap: 16px; }

.streak-number {
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent-light);
  min-width: 50px;
}

.streak-days {
  font-size: 12px;
  color: var(--hint);
  align-self: flex-end;
  margin-bottom: 6px;
}

.streak-bubbles { display: flex; gap: 8px; margin-left: auto; }

.streak-bubble {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.1);
  border: 1.5px solid rgba(139, 92, 246, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--hint);
  gap: 1px;
}

.streak-bubble.active {
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.5);
}

.streak-bubble .num { font-size: 14px; font-weight: 700; color: var(--text); }
.streak-bubble.active .num { color: #fff; }
.streak-bubble .d { font-size: 9px; opacity: 0.7; }

.progress-card { display: flex; flex-direction: column; gap: 10px; }

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--hint);
  text-transform: uppercase;
}

.progress-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-light);
}

.progress-bar {
  height: 6px;
  background: rgba(139, 92, 246, 0.15);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #a78bfa 0%, #8b5cf6 100%);
  border-radius: 3px;
  transition: width 0.6s ease;
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.6);
}

.exam-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px 20px;
  flex: 1;
}

.exam-btn {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, #8b5cf6 0%, #6d28d9 70%);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  box-shadow:
    0 0 60px rgba(139, 92, 246, 0.6),
    0 0 100px rgba(139, 92, 246, 0.3),
    inset 0 0 40px rgba(255, 255, 255, 0.1);
  transition: transform 0.15s;
}

.exam-btn::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(139, 92, 246, 0.3);
  animation: pulseRing 2s ease-in-out infinite;
}

@keyframes pulseRing {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50%      { transform: scale(1.06); opacity: 0.2; }
}

.exam-btn:active { transform: scale(0.96); }
.exam-title { font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.exam-sub { font-size: 12px; opacity: 0.8; }

.bottom-actions {
  display: flex;
  gap: 10px;
  padding: 0 20px 90px;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border-radius: 14px;
  background: var(--secondary-bg);
  border: 1px solid rgba(139, 92, 246, 0.15);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.action-btn:active { transform: scale(0.97); background: rgba(139, 92, 246, 0.15); }
.action-btn .icon { font-size: 18px; }

/* ============================================================
   TABBAR
   ============================================================ */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70px;
  background: var(--secondary-bg);
  border-top: 1px solid rgba(139, 92, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 100;
  max-width: 500px;
  margin: 0 auto;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  cursor: pointer;
  color: var(--hint);
  transition: color 0.15s;
}

.tab .tab-icon { font-size: 22px; line-height: 1; }
.tab .tab-label { font-size: 11px; font-weight: 500; }
.tab.active { color: var(--accent-light); }
.tab.active .tab-icon { filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.8)); }

/* ============================================================
   LEVELS
   ============================================================ */

.levels-screen {
  padding-top: 70px;
  padding-left: 16px;
  padding-right: 16px;
}

.levels-header { margin-bottom: 20px; }
.levels-header h1 { font-size: 24px; margin-bottom: 6px; }

.sections-list { display: flex; flex-direction: column; gap: 20px; }

.section-block {
  background: var(--secondary-bg);
  border-radius: 18px;
  padding: 16px;
  border: 1px solid rgba(139, 92, 246, 0.12);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.section-icon { font-size: 32px; line-height: 1; }
.section-info { flex: 1; min-width: 0; }
.section-title { font-size: 16px; font-weight: 700; }
.section-desc { font-size: 12px; color: var(--hint); margin-top: 2px; }
.section-count { font-size: 13px; font-weight: 600; color: var(--accent-light); white-space: nowrap; }

.section-progress {
  height: 5px;
  background: rgba(139, 92, 246, 0.15);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}

.section-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.lvl {
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.12);
  border: 1.5px solid rgba(139, 92, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
  user-select: none;
}

.lvl:active { transform: scale(0.92); }

.lvl-done {
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
}

.lvl-locked {
  background: rgba(139, 92, 246, 0.05);
  border-color: rgba(139, 92, 246, 0.12);
  color: var(--hint);
  opacity: 0.55;
}

.lvl-exam {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.5);
  color: #fbbf24;
}

.lvl-exam.lvl-done {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #1a1a2e;
  border-color: transparent;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.5);
}

/* ============================================================
   LESSON
   ============================================================ */

.lesson-wrapper {
  padding: 0 !important;
  min-height: 100vh;
}

.lesson-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 80px 20px 30px;
  animation: fadeIn 0.3s ease;
}

.lesson-top { margin-bottom: 24px; }

.lesson-progress {
  height: 8px;
  background: rgba(139, 92, 246, 0.15);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.lesson-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #a78bfa, #8b5cf6);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.lesson-counter {
  font-size: 13px;
  color: var(--hint);
  text-align: right;
}

.lesson-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--secondary-bg);
  border-radius: 24px;
  padding: 40px 20px;
  margin-bottom: 20px;
  border: 1px solid rgba(139, 92, 246, 0.15);
  text-align: center;
}

.lesson-front {
  font-size: 120px;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 24px;
}

.lesson-back {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.lesson-hint {
  font-size: 15px;
  color: var(--hint);
  padding: 8px 16px;
  background: rgba(139, 92, 246, 0.1);
  border-radius: 12px;
}

.lesson-actions { display: flex; gap: 10px; }
.lesson-actions .btn { flex: 1; }

.quiz-question {
  text-align: center;
  padding: 30px 0;
  margin-bottom: 20px;
}

.quiz-label {
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--hint);
  text-transform: uppercase;
  margin-bottom: 16px;
}

.quiz-front {
  font-size: 90px;
  font-weight: 800;
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.quiz-options { display: flex; flex-direction: column; gap: 10px; }

.quiz-option {
  padding: 18px;
  background: var(--secondary-bg);
  border: 2px solid rgba(139, 92, 246, 0.2);
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
  color: var(--text);
}

.quiz-option:active { transform: scale(0.98); }

.quiz-option.correct {
  background: rgba(52, 211, 153, 0.2);
  border-color: #34d399;
  color: #34d399;
}

.quiz-option.wrong {
  background: rgba(248, 113, 113, 0.2);
  border-color: #f87171;
  color: #f87171;
}

.lesson-done {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.done-icon {
  font-size: 100px;
  margin-bottom: 20px;
  animation: bounce 0.6s ease;
}

/* ============================================================
   УТИЛИТЫ
   ============================================================ */

.mt-auto { margin-top: auto; }