:root {
  --primary: #E63946;
  --primary-dark: #c92f3b;
  --background: #F8F9FA;
  --text: #1f2933;
  --muted: #6b7280;
  --card: #ffffff;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--background);
  position: relative;
  padding-bottom: 88px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 18px 14px;
  background: rgba(248, 249, 250, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.75);
}

.app-header h1 {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.xp-pill {
  flex: 0 0 auto;
  padding: 8px 12px;
  color: var(--primary);
  background: #fff0f2;
  border-radius: 999px;
  font-weight: 800;
}

.app-content {
  padding: 16px;
}

.teacher-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 16px 0;
  padding: 10px 12px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.teacher-bubble {
  min-width: 0;
  overflow: hidden;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card,
.lesson-card,
.exercise-card,
.chat-message,
.stat-card,
.loading-card,
.error-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card,
.lesson-card,
.exercise-card,
.stat-card,
.loading-card,
.error-card {
  padding: 16px;
}

.stack {
  display: grid;
  gap: 14px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 18px;
}

.muted {
  color: var(--muted);
}

.lesson-card {
  width: 100%;
  border: 0;
  text-align: left;
}

.lesson-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.lesson-card h2,
.lesson-detail h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.completed {
  background: #dcfce7;
  color: #166534;
}

.vocab-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.vocab-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.hanzi {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.pinyin {
  display: block;
  color: var(--primary);
  font-weight: 700;
}

.primary-btn,
.secondary-btn,
.icon-btn,
.choice-btn,
.character-btn,
.send-btn,
.skip-link {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  transition: transform 0.15s ease, background 0.15s ease;
}

.primary-btn:active,
.secondary-btn:active,
.icon-btn:active,
.choice-btn:active,
.lesson-card:active {
  transform: scale(0.98);
}

.primary-btn {
  width: 100%;
  padding: 13px 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

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

.secondary-btn {
  padding: 10px 12px;
  background: #fff0f2;
  color: var(--primary);
  font-weight: 800;
}

.icon-btn {
  width: 48px;
  height: 48px;
  background: #fff0f2;
  color: var(--primary);
  font-size: 18px;
}

.avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fff0f2;
  box-shadow: inset 0 0 0 2px rgba(230, 57, 70, 0.12);
  vertical-align: middle;
}

.avatar-large {
  width: 86px;
  height: 86px;
  font-size: 46px;
}

.avatar-normal {
  font-size: 24px;
}

.avatar-online {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 11px;
  height: 11px;
  background: var(--success);
  border: 2px solid #fff;
  border-radius: 50%;
}

.avatar-bounce {
  animation: bounce 0.65s ease;
}

.avatar-pulse,
.audio-pulse {
  animation: pulse-audio 1s ease-in-out infinite;
}

.lesson-intro {
  text-align: center;
}

.intro-avatar {
  display: flex;
  justify-content: center;
}

.skip-link {
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
}

.hidden {
  display: none;
}

.choice-list {
  display: grid;
  gap: 10px;
}

.choice-btn {
  width: 100%;
  padding: 14px;
  background: #f9fafb;
  border: 1px solid var(--border);
  text-align: left;
}

.choice-btn.correct {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.choice-btn.wrong {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.feedback {
  padding: 12px;
  border-radius: var(--radius);
  font-weight: 700;
}

.feedback.success {
  background: #dcfce7;
  color: #166534;
}

.feedback.error {
  background: #fee2e2;
  color: #991b1b;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  background: #e5e7eb;
  border-radius: 999px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width 0.25s ease;
}

.character-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.character-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  font-weight: 800;
}

.character-btn.active {
  border-color: var(--primary);
  background: #fff0f2;
  color: var(--primary);
}

.selected-character-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chat-window {
  display: grid;
  gap: 10px;
  min-height: 320px;
  align-content: start;
}

.chat-message {
  padding: 12px;
  max-width: 88%;
}

.chat-message.user {
  justify-self: end;
  background: var(--primary);
  color: #fff;
}

.chat-message.assistant {
  justify-self: start;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-message.user .chat-meta {
  color: rgba(255, 255, 255, 0.8);
}

.chat-actions {
  margin-top: 8px;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 12px;
}

.chat-form input {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.send-btn {
  width: 52px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}

.skeleton {
  display: inline-block;
  min-width: 150px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, #eeeeee 25%, #f8f8f8 50%, #eeeeee 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}

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

.stat-card strong {
  display: block;
  margin-top: 6px;
  color: var(--primary);
  font-size: 28px;
}

.teacher-presence {
  border-left: 4px solid var(--primary);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
}

.nav-item {
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 7px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #8b95a1;
  font-size: 12px;
  font-weight: 700;
}

.nav-item.active {
  color: var(--primary);
  background: #fff0f2;
}

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 10px;
  border: 3px solid #fde2e5;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-card,
.error-card {
  text-align: center;
}

.error-card {
  color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 41, 51, 0.38);
}

.vocab-modal {
  position: relative;
  width: min(100%, 420px);
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 48px;
  height: 48px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
}

.modal-hanzi {
  font-size: 64px;
  font-weight: 900;
}

.modal-pinyin {
  color: var(--primary);
  font-size: 20px;
  font-weight: 800;
}

.tone-arrows {
  color: var(--muted);
}

.modal-kazakh {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 800;
}

.translit {
  color: var(--muted);
}

.phonetic-inline {
  color: var(--muted);
  font-style: italic;
}

.modal-actions {
  display: grid;
  grid-template-columns: 48px 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
}

.xp-float {
  position: fixed;
  left: 50%;
  top: 45%;
  z-index: 90;
  color: var(--success);
  font-size: 22px;
  font-weight: 900;
  pointer-events: none;
  transform: translateX(-50%);
  animation: xp-float 0.95s ease-out forwards;
}

.confetti-burst {
  position: fixed;
  inset: 0;
  z-index: 75;
  pointer-events: none;
  overflow: hidden;
}

.confetti-burst span {
  position: absolute;
  top: 16%;
  left: 50%;
  width: 10px;
  height: 16px;
  background: var(--primary);
  border-radius: 3px;
  animation: confetti 0.85s ease-out forwards;
}

.confetti-burst span:nth-child(2) {
  background: #f59e0b;
  animation-delay: 0.04s;
}

.confetti-burst span:nth-child(3) {
  background: #16a34a;
  animation-delay: 0.08s;
}

.confetti-burst span:nth-child(4) {
  background: #3b82f6;
  animation-delay: 0.12s;
}

.confetti-burst span:nth-child(5) {
  background: #a855f7;
  animation-delay: 0.16s;
}

.flash-green {
  animation: flash-green 0.6s ease;
}

.flash-red {
  animation: flash-red 0.6s ease;
}

.shake {
  animation: shake 0.42s ease;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@keyframes pulse-audio {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(230, 57, 70, 0.28);
  }

  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 8px rgba(230, 57, 70, 0);
  }
}

@keyframes xp-float {
  0% {
    opacity: 0;
    transform: translate(-50%, 14px) scale(0.92);
  }

  20% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -52px) scale(1.08);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  50% {
    transform: translateX(5px);
  }

  75% {
    transform: translateX(-3px);
  }
}

@keyframes confetti {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--spread, 42px)), 220px) rotate(260deg);
  }
}

.confetti-burst span:nth-child(1) {
  --spread: -92px;
}

.confetti-burst span:nth-child(2) {
  --spread: -44px;
}

.confetti-burst span:nth-child(3) {
  --spread: 0;
}

.confetti-burst span:nth-child(4) {
  --spread: 48px;
}

.confetti-burst span:nth-child(5) {
  --spread: 96px;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  45% {
    transform: translateY(-8px) scale(1.08);
  }
}

@keyframes flash-green {
  0%,
  100% {
    box-shadow: none;
  }

  45% {
    box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.22);
  }
}

@keyframes flash-red {
  0%,
  100% {
    box-shadow: none;
  }

  45% {
    box-shadow: 0 0 0 5px rgba(220, 38, 38, 0.2);
  }
}
