/* ────────────────────────────────────────────────────────────────
   AIMath Student Engagement — fun feedback UI styles.
   Self-contained, no global resets, no overrides of question UI.
   All selectors prefixed .aimath-eng-* to avoid collisions.
   ──────────────────────────────────────────────────────────────── */

/* Top-right chip bar (level + mute) */
.aimath-eng-topbar {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 9998;
  pointer-events: none;
}
.aimath-eng-chip {
  pointer-events: auto;
  background: linear-gradient(135deg, #ffd166 0%, #ff9f1c 100%);
  color: #2b2b2b;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  box-shadow: 0 4px 14px rgba(255, 159, 28, 0.35);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  font-family: inherit;
  user-select: none;
}
.aimath-eng-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(255, 159, 28, 0.45);
}
.aimath-eng-mute {
  background: linear-gradient(135deg, #cce3f5 0%, #8ec5e6 100%);
  box-shadow: 0 4px 14px rgba(142, 197, 230, 0.4);
}

/* Mascot */
.aimath-eng-mascot {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff5e1 0%, #ffd9a8 60%, #ff9f5a 100%);
  box-shadow: 0 10px 24px rgba(255, 134, 70, 0.35), inset 0 -6px 12px rgba(255, 134, 70, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9998;
  transition: transform 0.2s ease;
  user-select: none;
}
.aimath-eng-mascot:hover { transform: scale(1.06) rotate(-4deg); }
.aimath-eng-mascot.hidden { display: none; }
.aimath-eng-mascot-face {
  font-size: 40px;
  line-height: 1;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.2));
}
@keyframes aimath-eng-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.18) rotate(-6deg); }
  55% { transform: scale(0.92) rotate(4deg); }
  80% { transform: scale(1.06) rotate(-2deg); }
  100% { transform: scale(1); }
}
.aimath-eng-mascot.bounce { animation: aimath-eng-bounce 0.7s ease; }

/* Mascot speech bubble */
.aimath-eng-bubble {
  position: fixed;
  right: 100px;
  bottom: 38px;
  max-width: 220px;
  background: #fff;
  color: #333;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(8px) scale(0.92);
  transform-origin: bottom right;
  pointer-events: none;
  z-index: 9998;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.aimath-eng-bubble::after {
  content: '';
  position: absolute;
  right: -8px;
  bottom: 14px;
  width: 0;
  height: 0;
  border-left: 10px solid #fff;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  filter: drop-shadow(2px 0 1px rgba(0, 0, 0, 0.05));
}
.aimath-eng-bubble.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Toasts */
.aimath-eng-toast-wrap {
  position: fixed;
  top: 60px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}
.aimath-eng-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #ffffff 0%, #fff4e0 100%);
  color: #333;
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  border-left: 5px solid #ffb547;
  min-width: 220px;
  max-width: 320px;
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.32s ease, transform 0.32s ease;
}
.aimath-eng-toast.in { opacity: 1; transform: translateX(0); }
.aimath-eng-toast.out { opacity: 0; transform: translateX(40px); }
.aimath-eng-toast.badge { border-left-color: #f4a261; background: linear-gradient(135deg, #fffbe6 0%, #ffe9b6 100%); }
.aimath-eng-toast.level { border-left-color: #6ec1a7; background: linear-gradient(135deg, #ecfff5 0%, #c9f0d6 100%); }
.aimath-eng-toast-emoji { font-size: 30px; line-height: 1; }
.aimath-eng-toast-body { display: flex; flex-direction: column; gap: 2px; }
.aimath-eng-toast-title { font-size: 14px; font-weight: 700; }
.aimath-eng-toast-desc { font-size: 12px; color: #666; }

/* Profile modal */
.aimath-eng-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 16px;
  animation: aimath-eng-fade 0.2s ease;
}
@keyframes aimath-eng-fade { from { opacity: 0; } to { opacity: 1; } }
.aimath-eng-modal-card {
  background: #fff;
  border-radius: 18px;
  padding: 22px 22px 18px;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  animation: aimath-eng-pop 0.28s cubic-bezier(.2,1.2,.4,1);
  font-family: inherit;
}
@keyframes aimath-eng-pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.aimath-eng-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.aimath-eng-modal-title { font-size: 18px; font-weight: 800; color: #333; }
.aimath-eng-close {
  background: #f1f1f1; border: none; border-radius: 50%;
  width: 32px; height: 32px; font-size: 20px; line-height: 1;
  cursor: pointer; color: #555;
}
.aimath-eng-close:hover { background: #e3e3e3; }
.aimath-eng-modal-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.aimath-eng-stat {
  background: #fff7e6;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  border: 1px solid #ffd99c;
}
.aimath-eng-stat .num { font-size: 20px; font-weight: 800; color: #d97706; }
.aimath-eng-stat .lbl { font-size: 11px; color: #777; margin-top: 2px; }

.aimath-eng-modal-bar {
  position: relative;
  background: #eee;
  border-radius: 999px;
  height: 22px;
  overflow: hidden;
  margin-bottom: 14px;
}
.aimath-eng-modal-bar-fill {
  background: linear-gradient(90deg, #ffd166 0%, #ff9f1c 100%);
  height: 100%;
  transition: width 0.5s ease;
}
.aimath-eng-modal-bar-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #333;
}
.aimath-eng-modal-section {
  font-size: 13px; font-weight: 700; color: #555; margin: 8px 0 8px;
}
.aimath-eng-badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.aimath-eng-badge {
  background: #fafafa;
  border-radius: 12px;
  padding: 10px 4px 6px;
  text-align: center;
  border: 1px solid #ececec;
  transition: transform 0.2s ease;
}
.aimath-eng-badge.owned {
  background: linear-gradient(135deg, #fff8e1 0%, #ffe0a3 100%);
  border-color: #ffcd6b;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(255, 205, 107, 0.4);
}
.aimath-eng-badge.locked { opacity: 0.55; filter: grayscale(0.4); }
.aimath-eng-badge-emoji { font-size: 26px; line-height: 1; }
.aimath-eng-badge-label { font-size: 11px; font-weight: 600; color: #555; margin-top: 4px; }

.aimath-eng-modal-foot {
  display: flex; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid #eee; padding-top: 12px;
}
.aimath-eng-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: #555; cursor: pointer;
}
.aimath-eng-toggle input { cursor: pointer; }

/* Mobile tweaks */
@media (max-width: 480px) {
  .aimath-eng-mascot { width: 56px; height: 56px; right: 12px; bottom: 12px; }
  .aimath-eng-mascot-face { font-size: 32px; }
  .aimath-eng-bubble { right: 78px; bottom: 30px; max-width: 180px; font-size: 13px; }
  .aimath-eng-topbar { top: 8px; right: 8px; }
  .aimath-eng-chip { font-size: 12px; padding: 5px 10px; }
  .aimath-eng-toast-wrap { top: 48px; right: 8px; }
  .aimath-eng-toast { min-width: 180px; }
  .aimath-eng-modal-row { grid-template-columns: repeat(2, 1fr); }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .aimath-eng-mascot.bounce { animation: none; }
  .aimath-eng-bubble { transition: none; }
  .aimath-eng-toast { transition: opacity 0.2s ease; transform: none !important; }
}
