/* =========================================
   English Quest — Modern EdTech Style 2026
   ========================================= */
:root {
  --bg-body: #F4F7FC; --bg-card: #FFFFFF;
  --primary: #3478F6; --primary-light: #E8F0FE;
  --primary-gradient: linear-gradient(135deg, #4A8BFF 0%, #3478F6 100%);
  --text-main: #1E293B; --text-muted: #64748B;
  --border-color: #E2E8F0; --border-glass: rgba(226, 232, 240, 0.6);
  --mint: #D1FAE5; --mint-text: #059669;
  --peach: #FFEDD5; --peach-text: #EA580C;
  --blue: #DBEAFE; --blue-text: #2563EB;
  --yellow: #FEF3C7; --yellow-text: #D97706;
  --radius-sm: 12px; --radius-md: 16px; --radius-lg: 24px;
  --shadow-sm: 0 2px 8px rgba(30, 41, 59, 0.04);
  --shadow-md: 0 4px 16px rgba(30, 41, 59, 0.06);
  --shadow-lg: 0 8px 24px rgba(52, 120, 246, 0.12);
  --shadow-glow: 0 4px 16px rgba(52, 120, 246, 0.35);
  --font-family: 'Nunito', -apple-system, sans-serif;
  --header-h: 68px; --nav-h: 76px;
  color-scheme: light dark;
}
[data-theme="light"] { color-scheme: light only; }
[data-theme="dark"] {
  --bg-body: #0F172A; --bg-card: #1E293B; --text-main: #F1F5F9; --text-muted: #94A3B8;
  --border-color: #334155; --border-glass: rgba(51, 65, 85, 0.6); --primary-light: #1E3A8A;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2); --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 4px 16px rgba(52, 120, 246, 0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font-family); background-color: var(--bg-body); color: var(--text-main); -webkit-font-smoothing: antialiased; overflow: hidden; cursor: pointer; transition: background-color 0.3s, color 0.3s; }
button, input { font-family: inherit; }
button { cursor: pointer; border: none; background: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }
.icon-btn svg, .icon-btn span, .nav-item svg, .nav-item span, .route-status, .theory-icon { pointer-events: none; }

.app-shell { display: flex; flex-direction: column; width: 100%; max-width: 480px; height: 100%; height: 100dvh; margin: 0 auto; background: var(--bg-body); }
.app-header { flex-shrink: 0; height: var(--header-h); display: flex; align-items: center; z-index: 100; background: rgba(244, 247, 252, 0.85); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border-glass); padding: 0 20px; }
[data-theme="dark"] .app-header { background: rgba(15, 23, 42, 0.85); }
.header-top { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 16px; }
.brand-flag { font-size: 22px; }
.header-actions { display: flex; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--text-main); background: var(--bg-card); box-shadow: var(--shadow-sm); transition: background 0.1s, transform 0.1s; }
.icon-btn:active { background: var(--primary-light); color: var(--primary); transform: scale(0.92); }

main { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; -webkit-overflow-scrolling: touch; }
.screen { animation: slideUp 0.3s ease; flex: 1; display: flex; flex-direction: column; }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.greeting { margin: 10px 0 24px; }
.greeting h1 { font-size: 32px; font-weight: 900; margin-bottom: 4px; }
.greeting p { color: var(--text-muted); font-size: 15px; font-weight: 600; }
.wave { display: inline-block; animation: wave 2.5s infinite; transform-origin: 70% 70%; }
@keyframes wave { 0%, 100% { transform: rotate(0deg); } 10% { transform: rotate(14deg); } 20% { transform: rotate(-8deg); } 30% { transform: rotate(14deg); } 40% { transform: rotate(-4deg); } 50% { transform: rotate(10deg); } 60% { transform: rotate(0deg); } }
.class-tabs { display: flex; gap: 8px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 4px; }
.class-tab { padding: 8px 16px; border-radius: 20px; font-weight: 700; font-size: 14px; color: var(--text-muted); background: var(--bg-card); border: 1px solid var(--border-color); }
.class-tab.active { background: var(--primary-gradient); color: white; border-color: transparent; }
.lesson-list { display: flex; flex-direction: column; gap: 12px; }
.lesson-item { display: flex; align-items: center; padding: 16px; background: var(--bg-card); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); text-align: left; border: 2px solid transparent; }
.lesson-item.active { background: var(--primary-light); border-color: rgba(52, 120, 246, 0.15); }
.lesson-item.locked { opacity: 0.6; filter: grayscale(0.4); }
.lesson-icon { width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; font-size: 28px; margin-right: 16px; }
.lesson-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.lesson-info strong { font-size: 16px; font-weight: 800; color: var(--text-main); }
.lesson-info small { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.bg-mint { background: var(--mint); color: var(--mint-text); }
.bg-peach { background: var(--peach); color: var(--peach-text); }
.bg-blue { background: var(--blue); color: var(--blue-text); }
.bg-yellow { background: var(--yellow); color: var(--yellow-text); }
.mascot-bubble { display: flex; align-items: center; gap: 12px; margin-top: 30px; background: var(--bg-card); padding: 16px; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.mascot-avatar { font-size: 40px; }
.mascot-text { font-weight: 800; color: var(--primary); font-size: 15px; }

.lesson-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 20px; gap: 8px; }
.lesson-header-title { text-align: center; display: flex; flex-direction: column; flex: 1; }
.lesson-header-title strong { font-size: 16px; font-weight: 800; color: var(--text-main); }
.lesson-header-title small { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.progress-container { margin-bottom: 24px; }
.progress-track { height: 8px; background: var(--border-color); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #4A8BFF, #22C55E); width: 0; transition: width 0.5s; }

/* Sticky кнопки теории */
.theory-tabs { display: flex; gap: 10px; margin-bottom: 16px; flex-shrink: 0; position: sticky; top: 0; background: var(--bg-body); z-index: 50; padding: 10px 0; margin-top: -10px; }
.theory-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-weight: 800; font-size: 14px; color: var(--primary); box-shadow: var(--shadow-sm); transition: transform 0.1s; }
.theory-btn:active { transform: scale(0.96); background: var(--primary-light); }
.theory-icon { font-size: 18px; }

.route-grid { display: grid; gap: 16px; margin-top: 8px; }
.route-card { display: flex; align-items: center; gap: 16px; padding: 20px; border: 2px solid var(--border-color); border-radius: var(--radius-lg); background: var(--bg-card); box-shadow: var(--shadow-md); text-align: left; transition: 0.15s; }
.route-card:active { transform: scale(0.97); }
.route-card.locked { opacity: 0.6; border-style: dashed; background: var(--bg-body); box-shadow: none; cursor: not-allowed; }
.route-card.locked .route-icon { filter: grayscale(1); background: transparent !important; }
.route-card.done { border-color: #22C55E; background: #F0FDF4; }
[data-theme="dark"] .route-card.done { background: #064e3b; border-color: #059669; }
.route-icon { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; font-size: 32px; flex-shrink: 0; }
.route-info { flex: 1; }
.route-info strong { display: block; font-size: 17px; font-weight: 800; margin-bottom: 4px; color: var(--text-main); }
.route-info small { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.route-status { font-size: 20px; font-weight: 800; color: var(--text-muted); margin-left: 10px; }
.route-card.done .route-status { color: #22C55E; }

.task-container { background: var(--bg-card); padding: 24px; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); margin-bottom: 20px; }
.task-badge { display: inline-block; background: var(--blue); color: var(--blue-text); padding: 4px 10px; border-radius: 8px; font-size: 11px; font-weight: 800; text-transform: uppercase; margin-bottom: 12px; }
.task-container h2 { font-size: 20px; font-weight: 800; margin-bottom: 8px; color: var(--text-main); }
.task-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }
.word-display { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.word-option { padding: 16px; border: 2px solid var(--border-color); border-radius: 12px; background: var(--bg-body); font-weight: 700; font-size: 15px; color: var(--text-main); }
.word-option.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.word-option.correct { border-color: #22C55E; background: #DCFCE7; color: #15803D; }
[data-theme="dark"] .word-option.correct { background: #064e3b; color: #6ee7b7; border-color: #059669; }
.word-option.wrong { border-color: #EF4444; background: #FEE2E2; color: #B91C1C; }
[data-theme="dark"] .word-option.wrong { background: #7f1d1d; color: #fca5a5; border-color: #ef4444; }
.word-card { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border-color); border-radius: 12px; margin-bottom: 10px; background: var(--bg-card); }
.word-picture { width: 48px; height: 48px; background: var(--primary-light); border-radius: 12px; display: grid; place-items: center; font-size: 24px; }
.word-details { flex: 1; }
.word-english { font-size: 18px; font-weight: 800; color: var(--text-main); }
.word-pronunciation { font-size: 12px; color: var(--primary); font-weight: 600; }
.word-translation { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.sound-button { width: 40px; height: 40px; border-radius: 12px; background: var(--primary-light); color: var(--primary); display: grid; place-items: center; font-size: 18px; }
.answer-input { width: 100%; padding: 16px; border: 2px solid var(--border-color); border-radius: 12px; font-size: 16px; font-weight: 700; margin-bottom: 20px; background: var(--bg-body); color: var(--text-main); outline: none; }
.answer-input:focus { border-color: var(--primary); }
.task-controls { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.secondary-controls { display: flex; gap: 10px; }
.btn { padding: 14px 20px; border-radius: 12px; font-weight: 800; font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { background: var(--primary-gradient); color: white; box-shadow: var(--shadow-glow); }
.btn-secondary { background: var(--bg-body); color: var(--text-main); flex: 1; border: 1px solid var(--border-color); }
.btn-full { width: 100%; }
.hint-box { display: none; background: var(--yellow); color: var(--yellow-text); padding: 16px; border-radius: 12px; font-size: 14px; margin-bottom: 16px; }
[data-theme="dark"] .hint-box { background: #78350f; color: #fcd34d; }
.hint-box.visible { display: block; }
.feedback-card { display: none; padding: 16px; border-radius: 12px; margin-bottom: 16px; }
.feedback-card.visible { display: block; }
.feedback-card.correct { background: #DCFCE7; color: #15803D; }
[data-theme="dark"] .feedback-card.correct { background: #064e3b; color: #6ee7b7; }
.feedback-card.wrong { background: #FEE2E2; color: #B91C1C; }
[data-theme="dark"] .feedback-card.wrong { background: #7f1d1d; color: #fca5a5; }
.feedback-title { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.feedback-card p { font-size: 14px; }

.chat-screen { display: flex; flex-direction: column; height: 100%; margin: -20px; padding: 20px; background: var(--bg-body); }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 16px; border-bottom: 1px solid var(--border-color); }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 16px 0; }
.chat-msg { display: flex; }
.chat-msg.ai { justify-content: flex-start; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble { max-width: 85%; padding: 12px 16px; border-radius: 16px; font-size: 14px; font-weight: 600; line-height: 1.55; }
.chat-msg.ai .chat-bubble { background: var(--bg-card); color: var(--text-main); border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); }
.chat-msg.user .chat-bubble { background: var(--primary); color: white; border-bottom-right-radius: 4px; }
.chat-input-area { display: flex; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border-color); }
.chat-input-area input { flex: 1; padding: 14px 20px; border: 1px solid var(--border-color); border-radius: 24px; font-size: 15px; background: var(--bg-card); color: var(--text-main); }
.chat-send-btn { width: 48px; height: 48px; border-radius: 50%; background: var(--primary); color: white; display: grid; place-items: center; }

.bottom-nav { flex-shrink: 0; height: var(--nav-h); display: flex; justify-content: space-around; padding: 10px; background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(20px); border-top: 1px solid var(--border-glass); z-index: 30; }
[data-theme="dark"] .bottom-nav { background: rgba(30, 41, 59, 0.88); }
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-muted); font-size: 11px; font-weight: 700; }
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 22px; filter: grayscale(1); opacity: 0.6; }
.nav-item.active .nav-icon { filter: grayscale(0); opacity: 1; }

.modal-backdrop { display: none; position: fixed; z-index: 200; inset: 0; align-items: flex-end; justify-content: center; padding: 16px; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(8px); }
.modal-backdrop.open { display: flex; }
.modal-sheet { width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 22px 20px; border-radius: var(--radius-lg); background: var(--bg-card); animation: modalUp 0.25s; }
@keyframes modalUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
.modal-handle { width: 38px; height: 4px; margin: -8px auto 18px; border-radius: 999px; background: var(--border-color); }
.modal-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title-row h2 { font-size: 20px; font-weight: 800; color: var(--text-main); }
.modal-close { width: 34px; height: 34px; border-radius: 10px; background: var(--bg-body); color: var(--text-muted); font-size: 20px; }

.toast { position: fixed; bottom: 100px; left: 50%; transform: translate(-50%, 20px); background: var(--text-main); color: var(--bg-card); padding: 12px 24px; border-radius: 24px; font-size: 14px; font-weight: 700; opacity: 0; transition: 0.3s; pointer-events: none; z-index: 100; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.hw-card { background: var(--bg-card); border-radius: 16px; padding: 16px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.hw-title { font-size: 16px; font-weight: 800; margin-bottom: 8px; color: var(--primary); }
.hw-desc { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }
.hw-image { width: 100%; border-radius: 12px; margin-bottom: 16px; }
.hw-inline-text { background: var(--bg-body); padding: 16px; border-radius: 12px; font-size: 15px; line-height: 2.2; font-family: Georgia, serif; margin-bottom: 16px; color: var(--text-main); }
.hw-inline-input { display: inline-block; min-width: 80px; max-width: 140px; padding: 2px 8px; margin: 0 4px; border: 2px solid var(--border-color); border-radius: 6px; font-size: 14px; font-weight: 700; text-align: center; background: var(--bg-card); color: var(--text-main); }
.hw-input { padding: 10px 14px; border: 2px solid var(--border-color); border-radius: 12px; font-size: 15px; font-weight: 600; background: var(--bg-body); color: var(--text-main); }
.hw-btn-group { display: flex; gap: 8px; margin-top: 12px; }
.hw-btn-ai { flex: 1; padding: 12px; border-radius: 12px; background: var(--primary-light); color: var(--primary); font-weight: 800; font-size: 14px; cursor: pointer; border: none; display: flex; align-items: center; justify-content: center; }
.hw-btn-check { flex: 1; padding: 12px; border-radius: 12px; background: var(--primary-gradient); color: white; font-weight: 800; font-size: 14px; cursor: pointer; border: none; }
.hw-keys { display: none; margin-top: 16px; padding: 16px; border-radius: 12px; background: #DCFCE7; border: 1px solid #22C55E; }
.hw-keys.visible { display: block; }
.hw-keys-title { font-weight: 800; color: #15803D; margin-bottom: 8px; font-size: 14px; }
.hw-keys-list { font-size: 14px; font-weight: 600; color: #15803D; line-height: 1.8; columns: 2; }

.hw-inline-input.correct, .hw-input.correct { border-color: #22C55E !important; background: #DCFCE7 !important; color: #15803D !important; }
.hw-inline-input.wrong, .hw-input.wrong { border-color: #EF4444 !important; background: #FEE2E2 !important; color: #B91C1C !important; }
[data-theme="dark"] .hw-inline-input.correct, [data-theme="dark"] .hw-input.correct { background: #064e3b !important; color: #6ee7b7 !important; border-color: #059669 !important; }
[data-theme="dark"] .hw-inline-input.wrong, [data-theme="dark"] .hw-input.wrong { background: #7f1d1d !important; color: #fca5a5 !important; border-color: #ef4444 !important; }

.hw-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; padding: 12px; background: var(--bg-card); border-radius: 16px; border: 1px solid var(--border-color); }
.hw-nav-btn { padding: 10px 16px; border-radius: 12px; background: var(--bg-body); font-weight: 800; color: var(--text-main); }
.hw-nav-next { background: var(--primary-gradient); color: white; }

/* =========================================
   Форматирование сообщений ИИ (markdown)
   ========================================= */
.chat-msg.ai .chat-bubble hr {
  border: none;
  border-top: 1px dashed var(--border-color);
  margin: 14px 0;
}
.chat-msg.ai .chat-bubble blockquote {
  margin: 10px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
  border-radius: 8px;
  font-style: italic;
  color: var(--text-main);
  font-size: 14px;
}
[data-theme="dark"] .chat-msg.ai .chat-bubble blockquote {
  background: rgba(30, 58, 138, 0.35);
}
.chat-msg.ai .chat-bubble h3 {
  font-size: 16px;
  font-weight: 800;
  margin: 14px 0 6px;
  color: var(--primary);
}
.chat-msg.ai .chat-bubble h4 {
  font-size: 14px;
  font-weight: 800;
  margin: 10px 0 4px;
  color: var(--text-main);
}
.chat-msg.ai .chat-bubble strong { color: var(--primary); font-weight: 800; }
.chat-msg.ai .chat-bubble em { color: var(--text-muted); font-style: italic; }
.chat-msg.ai .chat-bubble code {
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.chat-msg.ai .chat-bubble ul,
.chat-msg.ai .chat-bubble ol {
  margin: 8px 0;
  padding-left: 22px;
}
.chat-msg.ai .chat-bubble li { margin: 4px 0; }
.chat-msg.ai .chat-bubble p { margin: 8px 0; }

.hw-select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  transition: border-color 0.2s;
}
.hw-select:focus {
  outline: none;
  border-color: var(--primary);
}
.hw-select.correct {
  border-color: #22C55E !important;
  background: #DCFCE7 !important;
  color: #15803D !important;
}
.hw-select.wrong {
  border-color: #EF4444 !important;
  background: #FEE2E2 !important;
  color: #B91C1C !important;
}
[data-theme="dark"] .hw-select.correct {
  background: #064e3b !important;
  color: #6ee7b7 !important;
}
[data-theme="dark"] .hw-select.wrong {
  background: #7f1d1d !important;
  color: #fca5a5 !important;
}