/* ==========================================================================
   «Понятно» — Современный интерфейс школьного сервиса
   Чистый дизайн без «AI slop», русская типографика, адаптивность под MAX WebApp
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-active: #1e40af;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;

  --bg-page: #f4f5f8;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;

  --text-main: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --border: #e2e8f0;
  --border-focus: #2563eb;

  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --success-text: #14532d;

  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #78350f;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 6px 18px -3px rgba(15, 23, 42, 0.04);
  --shadow-btn: 0 2px 6px rgba(37, 99, 235, 0.25);
}

/* Сброс стилей */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-page);
  color: var(--text-body);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
}

[hidden] {
  display: none !important;
}

/* Контейнер приложения */
.app {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* Верхняя панель */
.navbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  padding-top: env(safe-area-inset-top, 0px);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.brand-mascot-img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  transform: translateY(2px);
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.user-badge {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
}

/* Уведомления */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}

.alert-info {
  background: #fef9c3;
  border: 1px solid #fef08a;
  color: #854d0e;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

/* Загрузка */
.state-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.mascot-loading-wrap {
  width: 80px;
  height: 80px;
  margin-bottom: 12px;
}

.mascot-loading-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: gentlePulse 1.6s ease-in-out infinite;
}

@keyframes gentlePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.85; }
}

.loading-text {
  font-size: 14px;
}

/* Базовые карточки */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
  margin-bottom: 16px;
}

/* Кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  padding: 13px 20px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-muted);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-text {
  background: none;
  border: 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

/* ==========================================================================
   1. Экран приветствия (Welcome)
   ========================================================================== */
.welcome-screen {
  padding: 20px 0 30px;
  text-align: center;
}

.welcome-mascot-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
}

.welcome-mascot-img {
  width: 170px;
  height: 170px;
  object-fit: contain;
  margin-bottom: 12px;
}

.welcome-speech {
  background: #ffffff;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  max-width: 320px;
  line-height: 1.4;
  position: relative;
}

.welcome-speech::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 7px 7px 7px;
  border-style: solid;
  border-color: transparent transparent #ffffff transparent;
}

.welcome-actions {
  max-width: 320px;
  margin: 0 auto;
}

.welcome-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  line-height: 1.4;
}

/* ==========================================================================
   2. Главный экран (Dashboard)
   ========================================================================== */
.user-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px;
  margin-bottom: 18px;
}

.user-card-mascot {
  width: 76px;
  height: 76px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.user-mascot-img {
  width: 82px;
  height: 82px;
  object-fit: contain;
}

.user-card-content {
  flex: 1;
  min-width: 0;
}

.user-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2px;
}

.user-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.user-date {
  font-size: 11px;
  color: var(--text-muted);
}

.user-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.user-progress-wrap {
  margin-top: 4px;
}

.user-progress-track {
  height: 6px;
  background: var(--bg-muted);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.user-progress-bar {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.user-progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* Блок продолжения урока */
.resume-card {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 18px;
}

.resume-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--success-text);
  margin-bottom: 2px;
  display: block;
}

.resume-heading {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.resume-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Сетка предметов */
.catalog-section {
  margin-bottom: 20px;
}

.section-header {
  margin-bottom: 10px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.subject-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}

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

.subject-card.active {
  background: var(--primary-light);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-border);
}

.subject-card-icon {
  font-size: 22px;
  line-height: 1;
}

.subject-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

.subject-card.active .subject-card-name {
  color: var(--primary);
}

/* Форма темы */
.topic-form {
  padding: 16px;
}

.field-group {
  margin-bottom: 12px;
}

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.field-label-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.selected-subject-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.input-text {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 15px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s ease;
}

.input-text:focus {
  border-color: var(--border-focus);
}

.quick-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.quick-tags-title {
  font-size: 11px;
  color: var(--text-muted);
}

.tag-btn {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-body);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tag-btn:hover, .tag-btn:active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ==========================================================================
   3. Экран урока (Lesson View)
   ========================================================================== */
.lesson-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.lesson-subject-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.stepper-card {
  padding: 14px 16px;
  margin-bottom: 12px;
}

.step-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
}

.lesson-topic-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 1px;
}

.step-progress-track {
  height: 5px;
  background: var(--bg-muted);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: 10px 0 12px;
}

.step-progress-bar {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.step-dots {
  display: flex;
  justify-content: space-between;
  list-style: none;
}

.step-dots li {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.step-dots li span {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.step-dots li.active span {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.step-dots li.done span {
  background: var(--success);
  color: #ffffff;
  border-color: var(--success);
}

/* Карточка контента */
.lesson-content-card {
  padding: 18px;
}

.block-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 14px;
}

.lesson-section {
  margin-bottom: 16px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.theory-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
  white-space: pre-wrap;
}

.example-section {
  background: var(--bg-subtle);
  border-left: 3px solid var(--primary);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.example-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-body);
  white-space: pre-wrap;
}

.question-section {
  padding-top: 4px;
}

.question-body {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 10px;
  line-height: 1.4;
}

.textarea-input {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-main);
  resize: vertical;
  min-height: 80px;
  outline: none;
  margin-bottom: 10px;
}

.textarea-input:focus {
  border-color: var(--border-focus);
}

/* Блок проверки */
.feedback-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}

.feedback-box.needs-work {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.feedback-mascot-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.feedback-status {
  font-size: 15px;
  font-weight: 700;
  color: var(--success-text);
}

.feedback-box.needs-work .feedback-status {
  color: var(--warning-text);
}

.feedback-main-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-main);
  margin-bottom: 8px;
}

.feedback-addition-card {
  background: rgba(255, 255, 255, 0.8);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-body);
}

.feedback-buttons {
  display: flex;
  gap: 8px;
}

.feedback-buttons .btn {
  flex: 1;
}

/* ==========================================================================
   4. Экран завершения (Complete)
   ========================================================================== */
.complete-screen {
  text-align: center;
  padding: 30px 16px;
}

.complete-mascot-wrap {
  width: 140px;
  height: 140px;
  margin: 0 auto 12px;
}

.complete-mascot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.complete-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 4px;
}

.complete-topic-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}

.complete-text {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 340px;
  margin: 0 auto 20px;
  line-height: 1.4;
}

/* Подвал */
.footer {
  margin-top: auto;
  text-align: center;
  padding: 20px 0 10px;
  font-size: 11px;
  color: var(--text-light);
}
