/* ==========================================================================
   КАРМАННЫЙ ПОМОЩНИК — СОВРЕМЕННЫЙ ДИЗАЙН В СТИЛЕ EDTECH (6 КЛАСС)
   ========================================================================== */

:root {
  /* Базовая палитра (Slate / Neutral) */
  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card-muted: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-light: rgba(15, 23, 42, 0.07);
  --border-hover: rgba(15, 23, 42, 0.15);

  /* Предметные акценты */
  --math-accent: #2563eb;
  --math-soft: #eff6ff;
  --math-dark: #1d4ed8;

  --rus-accent: #7c3aed;
  --rus-soft: #f5f3ff;
  --rus-dark: #6d28d9;

  --bio-accent: #059669;
  --bio-soft: #ecfdf5;
  --bio-dark: #047857;

  --geo-accent: #ea580c;
  --geo-soft: #fff7ed;
  --geo-dark: #c2410c;

  /* Динамическая тема (по умолчанию Математика) */
  --theme-accent: #2563eb;
  --theme-soft: #eff6ff;
  --theme-dark: #1d4ed8;

  /* Статусные цвета теста */
  --success-bg: #dcfce7;
  --success-border: #86efac;
  --success-text: #15803d;

  --error-bg: #fee2e2;
  --error-border: #fca5a5;
  --error-text: #b91c1c;

  /* Типографика */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  
  /* Тени */
  --shadow-card: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.02);
  --shadow-hover: 0 18px 30px -8px rgba(15, 23, 42, 0.1), 0 10px 12px -6px rgba(15, 23, 42, 0.03);
  --shadow-btn: 0 6px 16px -2px rgba(15, 23, 42, 0.12);
}

/* Применение динамической темы к карточке предмета */
body[data-subject="math"] {
  --theme-accent: var(--math-accent);
  --theme-soft: var(--math-soft);
  --theme-dark: var(--math-dark);
}
body[data-subject="rus"] {
  --theme-accent: var(--rus-accent);
  --theme-soft: var(--rus-soft);
  --theme-dark: var(--rus-dark);
}
body[data-subject="bio"] {
  --theme-accent: var(--bio-accent);
  --theme-soft: var(--bio-soft);
  --theme-dark: var(--bio-dark);
}
body[data-subject="geo"] {
  --theme-accent: var(--geo-accent);
  --theme-soft: var(--geo-soft);
  --theme-dark: var(--geo-dark);
}

/* ==========================================================================
   СБРОС И БАЗОВЫЕ СТИЛИ
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: var(--bg-page);
  background-image: 
    radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.04) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(124, 58, 237, 0.04) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(234, 88, 12, 0.04) 0px, transparent 50%),
    radial-gradient(at 0% 100%, rgba(5, 150, 105, 0.04) 0px, transparent 50%);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

img {
  display: block;
  max-width: 100%;
}

/* ==========================================================================
   ОБОЛОЧКА ПРИЛОЖЕНИЯ (APP SHELL)
   ========================================================================== */

.app-shell {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

@media (min-width: 768px) {
  .app-shell {
    max-width: 820px;
    padding: 2rem 1.5rem 3.5rem;
  }
}

/* Анимация плавного переключения экранов */
.screen {
  opacity: 1;
}

.screen.is-active {
  animation: screenFadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes screenFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   1. ГЛАВНЫЙ ЭКРАН (ШАПКА И МЕНЮ ПРЕДМЕТОВ)
   ========================================================================== */

.app-header {
  text-align: center;
  margin-bottom: 1.75rem;
  padding: 0.5rem 0.5rem 0;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  font-size: 0.825rem;
  font-weight: 700;
  color: var(--text-muted);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  margin-bottom: 0.85rem;
  letter-spacing: 0.02em;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.header-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-main);
  line-height: 1.2;
  margin-bottom: 0.45rem;
}

.header-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.4;
  max-width: 380px;
  margin: 0 auto;
}

@media (min-width: 768px) {
  .header-title {
    font-size: 2.25rem;
  }
  .header-subtitle {
    font-size: 1.05rem;
    max-width: 520px;
  }
}

/* ==========================================================================
   ПЛИТКИ ПРЕДМЕТОВ (СЕТКА 2x2 НА МОБИЛЬНОМ)
   ========================================================================== */

.subject-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.75rem;
}

@media (min-width: 768px) {
  .subject-grid {
    gap: 1.25rem;
  }
}

.subject-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  text-align: left;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 1.1rem 1rem 1rem;
  min-height: 168px;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), 
              box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.subject-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--border-hover);
}

.subject-card:active {
  transform: scale(0.97);
}

/* Контейнер иконки карточки */
.subject-card__icon-wrap {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.85rem;
  transition: transform 0.2s ease;
}

.subject-card:hover .subject-card__icon-wrap {
  transform: scale(1.08);
}

.subject-card__icon-wrap img {
  width: 40px;
  height: 40px;
}

.subject-card__text {
  display: flex;
  flex-direction: column;
  width: 100%;
  flex: 1;
}

.subject-card__name {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.subject-card__topic {
  font-size: 0.975rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-main);
  letter-spacing: -0.01em;
  margin-bottom: 0.65rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.subject-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: auto;
  padding-top: 0.35rem;
}

.subject-card__cta {
  font-size: 0.785rem;
  font-weight: 700;
}

.subject-card__arrow {
  font-size: 0.85rem;
  font-weight: 800;
  transition: transform 0.2s ease;
}

.subject-card:hover .subject-card__arrow {
  transform: translateX(3px);
}

/* Темы для каждой карточки */
.subject-card--math .subject-card__icon-wrap { background: var(--math-soft); }
.subject-card--math .subject-card__name { color: var(--math-accent); }
.subject-card--math .subject-card__cta { color: var(--math-accent); }
.subject-card--math .subject-card__arrow { color: var(--math-accent); }

.subject-card--rus .subject-card__icon-wrap { background: var(--rus-soft); }
.subject-card--rus .subject-card__name { color: var(--rus-accent); }
.subject-card--rus .subject-card__cta { color: var(--rus-accent); }
.subject-card--rus .subject-card__arrow { color: var(--rus-accent); }

.subject-card--bio .subject-card__icon-wrap { background: var(--bio-soft); }
.subject-card--bio .subject-card__name { color: var(--bio-accent); }
.subject-card--bio .subject-card__cta { color: var(--bio-accent); }
.subject-card--bio .subject-card__arrow { color: var(--bio-accent); }

.subject-card--geo .subject-card__icon-wrap { background: var(--geo-soft); }
.subject-card--geo .subject-card__name { color: var(--geo-accent); }
.subject-card--geo .subject-card__cta { color: var(--geo-accent); }
.subject-card--geo .subject-card__arrow { color: var(--geo-accent); }

/* Подвал главного экрана */
.home-footer {
  margin-top: 1.5rem;
}

.footer-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg-surface);
  border: 1px dashed var(--border-light);
  border-radius: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-icon {
  font-size: 1.35rem;
  flex-shrink: 0;
}

.footer-card strong {
  display: block;
  color: var(--text-main);
  margin-bottom: 0.1rem;
  font-size: 0.875rem;
}

/* ==========================================================================
   КНОПКИ НАВИГАЦИИ (ВЕРХНИЕ ПАНЕЛИ)
   ========================================================================== */

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
  transition: all 0.15s ease;
}

.btn-back:hover {
  background: var(--bg-card-muted);
  border-color: var(--border-hover);
  transform: translateX(-2px);
}

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

.btn-back--subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  box-shadow: none;
}

.btn-back--subtle:hover {
  background: var(--bg-surface);
  border-color: var(--border-light);
}

.icon-arrow {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   2. ЭКРАН ТЕМЫ (КАРТОЧКА-ШПАРГАЛКА)
   ========================================================================== */

.topic-sheet,
.test-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 24px;
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}

@media (min-width: 768px) {
  .topic-sheet,
  .test-sheet {
    padding: 1.75rem 2rem;
    border-radius: 28px;
  }
}

/* Верхний баннер темы */
.topic-hero {
  margin-bottom: 1.25rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border-light);
}

.topic-hero__badge-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.pill-badge {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--theme-soft);
  color: var(--theme-accent);
}

.pill-meta {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.topic-hero__main {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.topic-hero__icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--theme-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topic-hero__icon-wrap img {
  width: 44px;
  height: 44px;
}

.topic-hero__title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
  color: var(--text-main);
}

@media (min-width: 768px) {
  .topic-hero__title {
    font-size: 1.65rem;
  }
}

/* ==========================================================================
   ИНФОРМАЦИОННЫЕ КАРТОЧКИ ШПАРГАЛКИ
   ========================================================================== */

.info-card {
  border-radius: 18px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.9rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
}

.info-card__header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}

.info-card__icon {
  font-size: 1.15rem;
}

.info-card__header h3 {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.info-card__text {
  font-size: 0.975rem;
  line-height: 1.55;
  color: var(--text-main);
  overflow-wrap: break-word;
}

/* 1. Блок «Главное правило» */
.info-card--rule {
  background: #fdfefe;
  border-left: 4px solid var(--theme-accent);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.02);
}

.info-card--rule .info-card__header h3 {
  color: var(--theme-accent);
}

/* 2. Блок «Пошаговый алгоритм» со стильными кружками (1, 2, 3) */
.info-card--steps {
  background: var(--bg-card-muted);
  border-color: rgba(15, 23, 42, 0.06);
}

.step-list {
  list-style: none;
  counter-reset: step-counter;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.step-item {
  counter-increment: step-counter;
  position: relative;
  padding-left: 2.35rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-main);
}

.step-item::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 0.05rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--theme-soft);
  color: var(--theme-accent);
  border: 1.5px solid var(--theme-accent);
  font-size: 0.775rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 3. Блок «Пример с разбором» */
.info-card--example {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.info-card--example .info-card__header h3 {
  color: #15803d;
}

.info-card--example .info-card__text {
  color: #14532d;
}

/* 4. Блок «Ловушка (частая ошибка)» */
.info-card--mistake {
  background: #fff1f2;
  border: 1px solid #fecdd3;
}

.info-card--mistake .info-card__header h3 {
  color: #be123c;
}

.info-card--mistake .info-card__text {
  color: #881337;
}

/* ==========================================================================
   ГЛАВНАЯ КНОПКА ДЕЙСТВИЯ (CTA)
   ========================================================================== */

.action-footer {
  margin-top: 1.25rem;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 3.4rem;
  padding: 0.85rem 1.25rem;
  background: var(--theme-accent);
  color: #ffffff;
  border-radius: 16px;
  font-size: 1.025rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.35);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-action:hover {
  background: var(--theme-dark);
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -4px rgba(37, 99, 235, 0.45);
}

.btn-action:active {
  transform: scale(0.98);
}

.btn-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.icon-arrow-next {
  width: 18px;
  height: 18px;
  transition: transform 0.2s ease;
}

.btn-action:hover .icon-arrow-next {
  transform: translateX(4px);
}

/* ==========================================================================
   3. ЭКРАН МИНИ-ТЕСТА
   ========================================================================== */

.test-header {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-light);
}

.test-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.test-step-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.test-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.test-question {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text-main);
}

/* Варианты ответов */
.options-group {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  min-height: 3.5rem;
  padding: 0.85rem 1rem;
  background: var(--bg-surface);
  border: 2px solid var(--border-light);
  border-radius: 16px;
  text-align: left;
  color: var(--text-main);
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.option:hover:not(:disabled) {
  border-color: var(--theme-accent);
  background: var(--theme-soft);
  transform: translateY(-1px);
}

.option:active:not(:disabled) {
  transform: scale(0.99);
}

.option__marker {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--bg-card-muted);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.18s ease;
}

.option__label {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-main);
}

/* Выбранный вариант */
.option.is-chosen {
  border-color: var(--theme-accent);
  background: var(--theme-soft);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.option.is-chosen .option__marker {
  background: var(--theme-accent);
  color: #ffffff;
}

/* Правильный ответ */
.option--right {
  border-color: var(--success-border) !important;
  background: var(--success-bg) !important;
  color: var(--success-text) !important;
}

.option--right .option__marker {
  background: var(--success-text) !important;
  color: #ffffff !important;
}

.option--right .option__label {
  color: var(--success-text) !important;
  font-weight: 700;
}

/* Неправильный ответ */
.option--wrong {
  border-color: var(--error-border) !important;
  background: var(--error-bg) !important;
  color: var(--error-text) !important;
}

.option--wrong .option__marker {
  background: var(--error-text) !important;
  color: #ffffff !important;
}

.option--wrong .option__label {
  color: var(--error-text) !important;
}

.option:disabled {
  cursor: default;
}

.test-hint {
  min-height: 1.4rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--error-text);
  margin-bottom: 0.65rem;
  text-align: center;
}

/* ==========================================================================
   РЕЗУЛЬТАТ И ОБЪЯСНЕНИЕ (С АНИМАЦИЕЙ ПОЯВЛЕНИЯ)
   ========================================================================== */

.result-banner {
  margin-top: 1.25rem;
  padding: 1.15rem;
  border-radius: 20px;
  border: 1.5px solid transparent;
}

.animate-slide-up {
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-banner--ok {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.result-banner--bad {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.result-badge-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.result-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.result-text {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.7);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  margin-bottom: 0.9rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn-secondary {
  flex: 1 1 140px;
  min-height: 2.85rem;
  padding: 0.65rem 1rem;
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-radius: 14px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
  transition: all 0.15s ease;
  text-align: center;
}

.btn-secondary:hover {
  background: var(--bg-card-muted);
  border-color: var(--border-hover);
}

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

/* ==========================================================================
   АДАПТИВНОСТЬ
   ========================================================================== */

@media (max-width: 360px) {
  .app-shell {
    padding: 0.85rem 0.65rem 2rem;
  }
  .subject-grid {
    gap: 0.65rem;
  }
  .subject-card {
    padding: 0.85rem 0.75rem;
    min-height: 156px;
  }
  .subject-card__topic {
    font-size: 0.875rem;
  }
  .topic-hero__title {
    font-size: 1.2rem;
  }
}
