/* ============================================================
   Athenaeum Assistant — Personal Teacher Assistant
   Styles for: floating button, chat panel, quiz modal, teaser
   Color palette: matches Athenaeum design tokens
============================================================ */

/* ── Design tokens (mirrored from styles.css) ─────────────── */
:root {
  --ustad-primary: #005088;
  --ustad-secondary: #00D2FF;
  --ustad-accent: #FFD700;
  --ustad-purple: #7B2CBF;
  --ustad-pink: #FF0076;
  --ustad-green: #11CAA0;
  --ustad-surface: #ffffff;
  --ustad-surface-alt: #f0f4f8;
  --ustad-border: rgba(0, 80, 136, 0.12);
  --ustad-text: #0f172a;
  --ustad-text-muted: #64748b;
  --ustad-shadow: 0 20px 60px rgba(0, 80, 136, 0.20);
  --ustad-shadow-lg: 0 32px 80px rgba(0, 80, 136, 0.28);
  --ustad-radius: 20px;
  --ustad-radius-sm: 12px;
  --ustad-radius-xs: 8px;
  --ustad-transition: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  --ustad-transition-fast: 0.2s ease;
  --ustad-font: 'Urbanist', system-ui, sans-serif;
  --ustad-font-heading: 'Merriweather', Georgia, serif;
  --ustad-z: 9999;
}

/* ── Floating Wrapper ──────────────────────────────────────── */
#athenaeum-assistant-wrapper {
  position: fixed;
  bottom: 28px;
  right: 100px; /* Moved left to avoid WhatsApp overlap */
  z-index: var(--ustad-z);
  font-family: var(--ustad-font);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ── Teaser (Logged-out State) ─────────────────────────────── */
#ustad-teaser-btn, #assistant-fab {
  position: fixed;
  transform: translateZ(0);
  will-change: transform;
  bottom: 27px; /* Align vertically with wa-fab */
  right: 54px; /* Align right edge to center of wa-fab */
  z-index: 9998; /* Ensure it stays behind wa-fab */
  height: 62px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  /* backdrop-filter: blur(24px) saturate(200%); (Removed for performance) */
  /* -webkit-backdrop-filter: blur(24px) saturate(200%); (Removed for performance) */
  color: #1d1d1f;
  
  /* Apply borders to all except right side */
  border-top: 1px solid #ffffff;
  border-left: 1px solid #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  border-right: none;
  
  padding: 0 42px 0 16px; /* Extra right padding for the bite */
  border-radius: 50px 0 0 50px; /* Flat right edge, rounded left */
  
  box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.4);
  filter: drop-shadow(-4px 8px 16px rgba(0, 0, 0, 0.1));
  
  /* The "Bite" Cutout (Concave right edge) */
  -webkit-mask-image: radial-gradient(circle at 100% 50%, transparent 33px, black 33.5px);
  mask-image: radial-gradient(circle at 100% 50%, transparent 33px, black 33.5px);
  
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  text-decoration: none;
  max-width: 280px;
  outline: none;
}

#ustad-teaser-btn:hover, #assistant-fab:hover {
  transform: translateY(-2px); /* Slight lift */
  background: rgba(255, 255, 255, 0.2);
  filter: drop-shadow(-4px 12px 20px rgba(0, 0, 0, 0.15));
}

#ustad-teaser-btn .teaser-icon, #assistant-fab .teaser-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ustad-surface);
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  transition: all 0.3s ease;
  overflow: hidden;
}

#ustad-teaser-btn .teaser-text, #assistant-fab .teaser-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  text-align: left;
  transition: all 0.3s ease;
}

#ustad-teaser-btn .teaser-text strong, #assistant-fab .teaser-text strong {
  font-size: 13px;
  font-weight: 700;
  color: #1d1d1f;
}

#ustad-teaser-btn .teaser-text span, #assistant-fab .teaser-text span {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.6);
}

/* #assistant-fab specific open state */
#assistant-fab.open {
  background: transparent;
  box-shadow: none;
  border-color: transparent;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0);
}

#assistant-fab.open .teaser-icon {
  background: transparent;
  transform: rotate(90deg);
  font-size: 0; /* Hides the emoji */
  color: white;
  width: auto;
  height: auto;
}

#assistant-fab.open .teaser-icon::after {
  content: "✕";
  font-size: 24px;
  font-family: system-ui, sans-serif;
}

#assistant-fab.open .teaser-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  display: none;
}

/* Pulse ring around FAB - Disabled for pill shape to avoid weird overlap */
#assistant-fab::before {
  display: none;
}

@keyframes ustad-pulse-ring {
  0%   { opacity: 0.6; transform: scale(0.9); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* Notification badge on FAB */
#assistant-fab .ustad-notif {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: var(--ustad-accent);
  border-radius: 50%;
  border: 2px solid white;
  font-size: 8px;
  font-weight: 800;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Chat Panel ────────────────────────────────────────────── */
#assistant-chat-panel {
  position: fixed;
  bottom: 104px;
  right: 100px; /* Aligned with moved button */
  width: 390px;
  max-width: calc(100vw - 24px);
  max-height: 620px;
  height: 620px;
  background: #ffffff;
  /* backdrop-filter: blur(20px); (Removed for performance) */
  /* -webkit-backdrop-filter: blur(20px); (Removed for performance) */
  border-radius: var(--ustad-radius);
  box-shadow: var(--ustad-shadow-lg);
  border: 1px solid var(--ustad-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: calc(var(--ustad-z) - 1);
  transform: scale(0.85) translateY(30px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#assistant-chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Panel Header */
#ustad-chat-header {
  background: linear-gradient(135deg, var(--ustad-primary) 0%, var(--ustad-purple) 100%);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

#ustad-chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Ccircle cx='30' cy='30' r='30'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E") repeat;
  pointer-events: none;
}

.athenaeum-assistant-avatar {
  width: 50px;
  height: 50px;
  background: var(--ustad-surface);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.ustad-header-info {
  flex: 1;
  position: relative;
  z-index: 1;
}

.ustad-header-info h4 {
  color: #fff;
  font-family: var(--ustad-font);
  font-weight: 700;
  font-size: 15px;
  margin: 0 0 2px;
}

.ustad-header-info p {
  color: rgba(255, 255, 255, 0.75);
  font-size: 11px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ustad-online-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  animation: ustad-blink 2s ease-in-out infinite;
}

@keyframes ustad-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.ustad-header-actions {
  display: flex;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.ustad-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 16px;
  line-height: 1;
}

.ustad-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Trial Banner */
#ustad-trial-banner {
  background: linear-gradient(90deg, rgba(251, 146, 60, 0.12), rgba(239, 68, 68, 0.08));
  border-bottom: 1px solid rgba(251, 146, 60, 0.25);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#ustad-trial-banner.hidden { display: none; }

#ustad-trial-banner .trial-text {
  font-size: 12px;
  font-weight: 600;
  color: #d97706;
  display: flex;
  align-items: center;
  gap: 6px;
}

#ustad-trial-banner .trial-upgrade {
  font-size: 10px;
  font-weight: 700;
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #fff;
  padding: 3px 10px;
  border-radius: 20px;
  text-decoration: none;
  transition: opacity 0.2s;
}

#ustad-trial-banner .trial-upgrade:hover { opacity: 0.85; }

/* Messages Area */
#ustad-messages {
  flex: 1;
  height: calc(100% - 120px);
  overflow-y: auto !important;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#ustad-messages::-webkit-scrollbar { width: 4px; }
#ustad-messages::-webkit-scrollbar-track { background: transparent; }
#ustad-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 80, 136, 0.15);
  border-radius: 4px;
}

/* Message Bubbles */
.ustad-msg {
  display: flex;
  gap: 8px;
  animation: ustad-msg-in 0.3s ease forwards;
  max-width: 100%;
}

@keyframes ustad-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ustad-msg.user-msg {
  flex-direction: row-reverse;
}

.ustad-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ustad-surface);
  border: 1px solid var(--ustad-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  align-self: flex-end;
  overflow: hidden;
}

.ustad-msg-avatar img, .athenaeum-assistant-avatar img, .teaser-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.ustad-msg-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: calc(100% - 40px);
}

.ustad-msg.user-msg .ustad-msg-content {
  align-items: flex-end;
}

.ustad-msg.ai-msg .ustad-msg-content {
  align-items: flex-start;
}

.ustad-msg-bubble {
  max-width: 85%;
  width: fit-content;
  padding: 12px 16px;
  border-radius: 20px;
  font-size: 14.5px;
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: pre-wrap;
}

.ustad-msg.ai-msg .ustad-msg-bubble {
  background: var(--ustad-surface-alt);
  color: var(--ustad-text);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(0, 80, 136, 0.08);
}

.ustad-msg.user-msg .ustad-msg-bubble {
  background: linear-gradient(135deg, var(--ustad-primary), var(--ustad-purple));
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 80, 136, 0.25);
}

/* Markdown-like formatting in AI messages */
.ustad-msg-bubble strong { font-weight: 700; }
.ustad-msg-bubble em { font-style: italic; }

.ustad-msg-bubble .step-block {
  background: rgba(0, 80, 136, 0.06);
  border-left: 3px solid var(--ustad-secondary);
  padding: 8px 10px;
  border-radius: 0 8px 8px 0;
  margin: 6px 0;
  font-size: 13px;
}

.ustad-msg-bubble .encourage-line {
  color: var(--ustad-green);
  font-weight: 600;
  margin-top: 8px;
  font-size: 13px;
}

/* Timestamp */
.ustad-msg-time {
  font-size: 10px;
  color: var(--ustad-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.user-msg .ustad-msg-time { text-align: right; }

/* Typing Indicator */
#ustad-typing {
  display: none;
  align-items: center;
  gap: 8px;
}

#ustad-typing.visible { display: flex; }

.ustad-typing-bubble {
  background: var(--ustad-surface-alt);
  border: 1px solid rgba(0, 80, 136, 0.08);
  padding: 10px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.ustad-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--ustad-text-muted);
  border-radius: 50%;
  animation: ustad-dot-bounce 1.2s ease-in-out infinite;
}

.ustad-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ustad-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ustad-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* Subject Context Pill */
#ustad-subject-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  flex-shrink: 0;
}

.subject-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1.5px solid transparent;
}

.subject-tag.math    { background: rgba(59, 130, 246, 0.1); color: #2563eb; border-color: rgba(59, 130, 246, 0.2); }
.subject-tag.science { background: rgba(16, 185, 129, 0.1); color: #059669; border-color: rgba(16, 185, 129, 0.2); }
.subject-tag.english { background: rgba(139, 92, 246, 0.1); color: #7c3aed; border-color: rgba(139, 92, 246, 0.2); }
.subject-tag.general { background: rgba(0, 80, 136, 0.08); color: var(--ustad-primary); border-color: rgba(0, 80, 136, 0.15); }

.subject-tag.active  { font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.subject-tag.math.active    { background: #2563eb; color: #fff; border-color: #2563eb; }
.subject-tag.science.active { background: #059669; color: #fff; border-color: #059669; }
.subject-tag.english.active { background: #7c3aed; color: #fff; border-color: #7c3aed; }
.subject-tag.general.active { background: var(--ustad-primary); color: #fff; border-color: var(--ustad-primary); }

/* Input Area */
#ustad-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--ustad-border);
  flex-shrink: 0;
  background: #ffffff;
}

#ustad-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--ustad-surface-alt);
  border: 1.5px solid var(--ustad-border);
  border-radius: 14px;
  padding: 8px 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#ustad-input-row:focus-within {
  border-color: var(--ustad-secondary);
  box-shadow: 0 0 0 3px rgba(0, 210, 255, 0.12);
}

#ustad-text-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--ustad-font);
  font-size: 13.5px;
  color: var(--ustad-text);
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 22px;
  line-height: 1.5;
  padding: 2px 0;
}

#ustad-text-input::placeholder { color: #94a3b8; }

.ustad-quiz-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--ustad-purple), var(--ustad-pink));
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  font-family: var(--ustad-font);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.ustad-quiz-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.ustad-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ustad-primary), var(--ustad-secondary));
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 80, 136, 0.3);
}

.ustad-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 18px rgba(0, 80, 136, 0.4);
}

.ustad-send-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ustad-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Input footer hint */
.ustad-input-hint {
  font-size: 10px;
  color: #94a3b8;
  text-align: center;
  margin-top: 6px;
}

/* ── Quiz Modal ────────────────────────────────────────────── */
#ustad-quiz-modal {
  position: fixed;
  inset: 0;
  z-index: calc(var(--ustad-z) + 10);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#ustad-quiz-modal.open {
  opacity: 1;
  pointer-events: all;
}

#ustad-quiz-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  /* backdrop-filter: blur(6px); (Removed for performance) */
  /* -webkit-backdrop-filter: blur(6px); (Removed for performance) */
}

#ustad-quiz-card {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 24px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.25);
  transform: scale(0.92) translateY(20px);
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
}

#ustad-quiz-modal.open #ustad-quiz-card {
  transform: scale(1) translateY(0);
}

#ustad-quiz-card::-webkit-scrollbar { width: 4px; }
#ustad-quiz-card::-webkit-scrollbar-track { background: transparent; }
#ustad-quiz-card::-webkit-scrollbar-thumb {
  background: rgba(0, 80, 136, 0.15);
  border-radius: 4px;
}

/* Quiz Modal Header */
.quiz-modal-header {
  background: linear-gradient(135deg, var(--ustad-primary), var(--ustad-purple));
  padding: 20px 24px;
  border-radius: 24px 24px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.quiz-modal-header h3 {
  color: #fff;
  font-family: var(--ustad-font);
  font-weight: 700;
  font-size: 18px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background 0.2s;
}

.quiz-close-btn:hover { background: rgba(255, 255, 255, 0.25); }

/* Quiz Setup Screen */
#ustad-quiz-setup {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.quiz-setup-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ustad-primary);
  margin-bottom: 10px;
  display: block;
}

.quiz-subject-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.quiz-subject-option {
  border: 2px solid var(--ustad-border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.quiz-subject-option:hover {
  border-color: var(--ustad-secondary);
  background: rgba(0, 210, 255, 0.04);
}

.quiz-subject-option.selected {
  border-color: var(--ustad-primary);
  background: rgba(0, 80, 136, 0.06);
  box-shadow: 0 0 0 3px rgba(0, 80, 136, 0.12);
}

.quiz-subject-option .subj-emoji { font-size: 26px; }
.quiz-subject-option .subj-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--ustad-text);
}

.quiz-topic-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--ustad-border);
  border-radius: 10px;
  font-family: var(--ustad-font);
  font-size: 13.5px;
  color: var(--ustad-text);
  outline: none;
  transition: border-color 0.2s ease;
}

.quiz-topic-input:focus {
  border-color: var(--ustad-secondary);
  box-shadow: 0 0 0 3px rgba(0, 210, 255, 0.12);
}

.quiz-topic-input::placeholder { color: #94a3b8; }

.quiz-start-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--ustad-primary), var(--ustad-purple));
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: var(--ustad-font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.25s ease;
  box-shadow: 0 4px 16px rgba(0, 80, 136, 0.3);
}

.quiz-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 80, 136, 0.4);
}

.quiz-start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Quiz Loading */
#ustad-quiz-loading {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  gap: 20px;
}

#ustad-quiz-loading.active { display: flex; }

.quiz-loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(0, 80, 136, 0.12);
  border-top-color: var(--ustad-primary);
  border-radius: 50%;
  animation: ustad-spin 0.9s linear infinite;
}

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

.quiz-loading-text {
  font-size: 14px;
  color: var(--ustad-text-muted);
  font-weight: 600;
  text-align: center;
}

/* Quiz Questions Screen */
#ustad-quiz-questions {
  display: none;
  flex-direction: column;
  gap: 0;
}

#ustad-quiz-questions.active { display: flex; }

/* Progress bar */
.quiz-progress-bar {
  height: 4px;
  background: rgba(0, 80, 136, 0.1);
  flex-shrink: 0;
}

.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ustad-secondary), var(--ustad-primary));
  transition: width 0.4s ease;
  border-radius: 0 4px 4px 0;
}

.quiz-questions-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.quiz-question-block {
  background: var(--ustad-surface-alt);
  border-radius: 14px;
  padding: 16px;
  border: 1px solid rgba(0, 80, 136, 0.08);
}

.quiz-q-number {
  font-size: 11px;
  font-weight: 700;
  color: var(--ustad-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.quiz-q-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--ustad-text);
  line-height: 1.5;
  margin-bottom: 12px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-option-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--ustad-border);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 13.5px;
  background: #fff;
}

.quiz-option-label:hover {
  border-color: var(--ustad-secondary);
  background: rgba(0, 210, 255, 0.04);
}

.quiz-option-label input[type="radio"] {
  accent-color: var(--ustad-primary);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.quiz-option-label.correct {
  border-color: #059669;
  background: rgba(5, 150, 105, 0.08);
  color: #059669;
  font-weight: 600;
}

.quiz-option-label.wrong {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
  font-weight: 600;
}

.quiz-submit-btn {
  margin: 0 24px 24px;
  padding: 14px;
  background: linear-gradient(135deg, var(--ustad-green), var(--ustad-primary));
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: var(--ustad-font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.25s ease;
  box-shadow: 0 4px 16px rgba(17, 202, 160, 0.3);
  flex-shrink: 0;
}

.quiz-submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(17, 202, 160, 0.4);
}

/* Quiz Results Screen */
#ustad-quiz-results {
  display: none;
  flex-direction: column;
  gap: 0;
}

#ustad-quiz-results.active { display: flex; }

.quiz-score-banner {
  background: linear-gradient(135deg, var(--ustad-primary), var(--ustad-purple));
  padding: 28px 24px;
  text-align: center;
  color: #fff;
}

.quiz-score-emoji { font-size: 48px; margin-bottom: 8px; }

.quiz-score-fraction {
  font-family: var(--ustad-font-heading);
  font-size: 42px;
  font-weight: 900;
  color: var(--ustad-accent);
  line-height: 1;
  margin-bottom: 4px;
}

.quiz-score-label {
  font-size: 13px;
  color: #ffffff;
  font-weight: 600;
}

.quiz-encourage-msg {
  font-size: 15px;
  color: #ffffff;
  margin-top: 10px;
  font-weight: 600;
}

.quiz-results-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.quiz-result-item {
  background: var(--ustad-surface-alt);
  border-radius: 12px;
  padding: 14px;
  border: 1px solid rgba(0, 80, 136, 0.08);
}

.quiz-result-q {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ustad-text);
  margin-bottom: 8px;
}

.quiz-result-answer {
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 4px;
}

.quiz-result-answer.correct {
  background: rgba(5, 150, 105, 0.1);
  color: #059669;
  font-weight: 600;
}

.quiz-result-answer.wrong {
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
  font-weight: 600;
}

.quiz-result-explanation {
  font-size: 12px;
  color: var(--ustad-text-muted);
  line-height: 1.5;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(0, 80, 136, 0.12);
}

.quiz-results-actions {
  display: flex;
  gap: 10px;
  padding: 0 24px 24px;
  flex-shrink: 0;
}

.quiz-retry-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--ustad-primary);
  border-radius: 12px;
  background: transparent;
  color: var(--ustad-primary);
  font-family: var(--ustad-font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quiz-retry-btn:hover {
  background: rgba(0, 80, 136, 0.06);
}

.quiz-done-btn {
  flex: 1;
  padding: 12px;
  background: linear-gradient(135deg, var(--ustad-primary), var(--ustad-purple));
  border: none;
  border-radius: 12px;
  color: #fff;
  font-family: var(--ustad-font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quiz-done-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Limit Reached Message */
.ustad-limit-msg {
  text-align: center;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ustad-limit-msg .limit-icon { font-size: 36px; }

.ustad-limit-msg h4 {
  font-family: var(--ustad-font);
  font-size: 15px;
  font-weight: 700;
  color: var(--ustad-text);
  margin: 0;
}

.ustad-limit-msg p {
  font-size: 13px;
  color: var(--ustad-text-muted);
  margin: 0;
  line-height: 1.5;
}

.ustad-upgrade-btn {
  padding: 10px 22px;
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-family: var(--ustad-font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-block;
}

.ustad-upgrade-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(249, 115, 22, 0.35);
}

/* Disclaimer text */
.ustad-disclaimer {
  font-size: 9.5px;
  color: #94a3b8;
  text-align: center;
  padding: 6px 16px 10px;
  flex-shrink: 0;
}

/* ── Welcome message system ────────────────────────────────── */
.ustad-welcome-card {
  background: linear-gradient(135deg, rgba(0, 80, 136, 0.06), rgba(123, 44, 191, 0.06));
  border: 1px solid rgba(0, 80, 136, 0.12);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  margin: 4px 0;
}

.ustad-welcome-card .welcome-emoji { font-size: 32px; margin-bottom: 8px; }

.ustad-welcome-card h4 {
  font-family: var(--ustad-font);
  font-size: 14px;
  font-weight: 700;
  color: var(--ustad-primary);
  margin: 0 0 6px;
}

.ustad-welcome-card p {
  font-size: 12.5px;
  color: var(--ustad-text-muted);
  line-height: 1.5;
  margin: 0;
}

/* Suggested questions */
.ustad-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-start;
  margin-left: 42px;
}

.ustad-suggestion-chip {
  padding: 5px 12px;
  background: #fff;
  border: 1.5px solid rgba(0, 80, 136, 0.15);
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ustad-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.ustad-suggestion-chip:hover {
  background: var(--ustad-primary);
  color: #fff;
  border-color: var(--ustad-primary);
  transform: translateY(-1px);
}

/* ── Responsive / Mobile ───────────────────────────────────── */
@media (max-width: 480px) {
  #assistant-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 92vh;
    max-height: 92vh;
    border-radius: 24px 24px 0 0;
    transform: scale(1) translateY(100%);
    transform-origin: bottom center;
    border-bottom: none;
  }

  #assistant-chat-panel.open {
    transform: scale(1) translateY(0);
  }

  #athenaeum-assistant-wrapper {
    bottom: 16px;
    right: 16px;
  }

  #ustad-teaser-btn, #assistant-fab {
    bottom: 90px;
    right: 20px;
    border-radius: 50px;
    padding: 0 16px;
    /* Reset the bite cutout */
    -webkit-mask-image: none;
    mask-image: none;
    border: 1px solid rgba(255, 255, 255, 0.5);
  }

  #assistant-chat-panel {
    right: 20px;
    bottom: 160px;
    width: calc(100vw - 40px);
    height: 500px;
  }

  #ustad-quiz-modal {
    align-items: flex-end;
    padding: 0;
  }

  #ustad-quiz-card {
    border-radius: 24px 24px 0 0;
    max-height: 92vh;
  }

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

/* ── Round FAB for non-index pages ─────────────────────────────── */
#ustad-teaser-btn.round-fab, #assistant-fab.round-fab {
  border-radius: 50%;
  padding: 0;
  width: 62px;
  right: 20px;
  justify-content: center;
  -webkit-mask-image: none;
  mask-image: none;
  border-right: 1px solid #ffffff;
}

#ustad-teaser-btn.round-fab .teaser-text, #assistant-fab.round-fab .teaser-text {
  display: none;
}

#ustad-teaser-btn.round-fab .teaser-icon, #assistant-fab.round-fab .teaser-icon {
  margin: 0;
}
