:root {
  --bg-page: #f0f4ff;
  --bg-container: #ffffff;
  --bg-header: linear-gradient(135deg, #0f0c29 0%, #1a1a3e 50%, #24243e 100%);
  --bg-msg-area: #f8faff;
  --text-primary: #1a1a2e;
  --text-secondary: #555;
  --text-muted: #999;
  --bubble-user: linear-gradient(135deg, #4f46e5, #6366f1);
  --bubble-user-text: #fff;
  --bubble-ai: #ffffff;
  --bubble-ai-border: #e8ecf5;
  --bubble-ai-shadow: 0 2px 12px rgba(0,0,0,0.05);
  --accent: #4f46e5;
  --accent-light: #eef0ff;
  --input-bg: #f8faff;
  --input-border: #e0e4ec;
  --input-focus: #4f46e5;
  --chip-bg: #eef0ff;
  --chip-border: #d0d4ff;
  --chip-text: #4f46e5;
  --chip-hover-bg: #4f46e5;
  --chip-hover-text: #fff;
  --scrollbar-thumb: #c0c6d4;
  --shadow: 0 4px 24px rgba(79, 70, 229, 0.08);
  --divider: #e8ecf5;
  --avatar-user: linear-gradient(135deg, #4f46e5, #6366f1);
  --avatar-ai: linear-gradient(135deg, #06b6d4, #22d3ee);
  --danger: #ef4444;
  --success: #10b981;
  --glass-bg: rgba(255,255,255,0.6);
  --glass-border: rgba(255,255,255,0.3);
  --header-height: 50px;
}

[data-theme="dark"] {
  --bg-page: #09091a;
  --bg-container: #111127;
  --bg-msg-area: #0c0c1f;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0c8;
  --text-muted: #5c5c7a;
  --bubble-user: linear-gradient(135deg, #6366f1, #818cf8);
  --bubble-user-text: #fff;
  --bubble-ai: #1a1a36;
  --bubble-ai-border: #252550;
  --bubble-ai-shadow: 0 2px 12px rgba(0,0,0,0.25);
  --accent: #818cf8;
  --accent-light: #1a1a3e;
  --input-bg: #151530;
  --input-border: #252552;
  --input-focus: #818cf8;
  --chip-bg: #1a1a3e;
  --chip-border: #252552;
  --chip-text: #818cf8;
  --chip-hover-bg: #818cf8;
  --chip-hover-text: #fff;
  --scrollbar-thumb: #252550;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --divider: #1f1f42;
  --avatar-user: linear-gradient(135deg, #6366f1, #818cf8);
  --avatar-ai: linear-gradient(135deg, #06b6d4, #22d3ee);
  --glass-bg: rgba(17,17,39,0.8);
  --glass-border: rgba(255,255,255,0.06);
  --header-height: 50px;
}

.ai-teacher-page {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: env(safe-area-inset-top, 0px) 0 0;
  background: var(--bg-page);
  font-family: 'Hind Siliguri', sans-serif;
  display: flex;
  align-items: stretch;
  justify-content: center;
  box-sizing: border-box;
  transition: background 0.4s;
  overflow: hidden;
  overscroll-behavior: none;
}

/* AI Teacher page as a full-screen app shell */
body:has(.ai-teacher-page) {
  padding: 0 !important;
  margin: 0 !important;
  min-height: 100vh !important;
  min-height: 100dvh !important;
  overflow: hidden !important;
}

body:has(.ai-teacher-page) .site-header {
  display: none;
}

body:has(.ai-teacher-page) #navigation-placeholder {
  display: none;
}

body:has(.ai-teacher-page) .nb-bot-toggle,
body:has(.ai-teacher-page) .nb-bot-popup {
  display: none;
}

.ai-teacher-container {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: none;
  background: var(--bg-container);
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.4s;
}

/* ===== HEADER ===== */
.ai-teacher-header {
  background: var(--bg-header);
  padding: 0 16px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  height: var(--header-height);
  min-height: 50px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  box-shadow: 0 1px 20px rgba(0,0,0,0.2);
}

.ai-teacher-header-icon {
  width: 34px;
  height: 34px;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  backdrop-filter: blur(4px);
  flex-shrink: 0;
}

.ai-teacher-header-text {
  min-width: 0;
  flex-shrink: 1;
}

.ai-teacher-header h2 {
  margin: 0;
  font-family: 'Baloo Da 2', cursive;
  font-size: 1.05rem;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.ai-teacher-header .subtitle {
  display: none;
}

.ai-chapter-context {
  margin: 2px 0 0;
  font-size: 0.72rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.ai-teacher-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.header-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.06);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.header-btn:hover {
  background: rgba(255,255,255,0.18);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.header-btn:active {
  transform: scale(0.9);
}

.header-btn .tooltip {
  position: absolute;
  bottom: -26px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.65rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  font-family: 'Hind Siliguri', sans-serif;
  z-index: 20;
}

.header-btn:hover .tooltip {
  opacity: 1;
}

/* ===== SUBJECT SELECTOR ===== */
.subject-selector {
  margin-left: 6px;
  flex-shrink: 0;
}

.subject-select {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: #fff;
  padding: 4px 24px 4px 10px;
  border-radius: 8px;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.72rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='%23fff'%3E%3Cpath d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 0.25s;
  height: 28px;
}

.subject-select:hover {
  background-color: rgba(255,255,255,0.15);
}

.subject-select option {
  background: #1a1a2e;
  color: #fff;
}

.subject-select:focus {
  border-color: rgba(255,255,255,0.4);
  background-color: rgba(255,255,255,0.15);
}

/* ===== MESSAGES AREA ===== */
.ai-teacher-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--bg-msg-area);
  transition: background 0.4s;
  position: relative;
  scroll-behavior: smooth;
}

.ai-teacher-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-teacher-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-teacher-messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
}

.ai-teacher-messages::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ===== WELCOME ===== */
.ai-teacher-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  text-align: center;
  padding: 30px 20px;
  animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: linear-gradient(135deg, #4f46e5, #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: #fff;
  margin-bottom: 18px;
  box-shadow: 0 12px 40px rgba(79, 70, 229, 0.3);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.ai-teacher-welcome h3 {
  font-family: 'Baloo Da 2', cursive;
  color: var(--text-primary);
  font-size: 1.4rem;
  margin-bottom: 6px;
}

.ai-teacher-welcome p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  max-width: 420px;
  line-height: 1.7;
  margin-bottom: 22px;
}

.ai-teacher-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 500px;
}

.suggestion-chip {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--chip-text);
  padding: 8px 18px;
  border-radius: 100px;
  cursor: pointer;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.suggestion-chip::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 100px;
  background: var(--chip-hover-bg);
  opacity: 0;
  transition: opacity 0.3s;
}

.suggestion-chip:hover::before {
  opacity: 1;
}

.suggestion-chip:hover {
  color: var(--chip-hover-text);
  border-color: var(--chip-hover-bg);
  transform: translateY(-2px);
  box-shadow: 0 4px 18px rgba(79, 70, 229, 0.25);
}

.suggestion-chip span {
  position: relative;
  z-index: 1;
}

/* ===== MESSAGE BUBBLES ===== */
.ai-teacher-message {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  animation: messageSlide 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.user-message {
  flex-direction: row-reverse;
}

@keyframes messageSlide {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  color: #fff;
  margin-top: 4px;
}

.user-message .message-avatar {
  background: var(--avatar-user);
}

.assistant-message .message-avatar {
  background: var(--avatar-ai);
}

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

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  padding: 0 4px;
}

.user-message .message-header {
  flex-direction: row-reverse;
}

.message-sender {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
}

.message-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.message-text {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.75;
  word-wrap: break-word;
  position: relative;
}

.user-message .message-text {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 15px rgba(0, 82, 204, 0.2);
}

.assistant-message .message-text {
  background: var(--bubble-ai);
  color: var(--text-primary);
  border: 1px solid var(--bubble-ai-border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--bubble-ai-shadow);
}

/* Streaming badge */
.streaming-badge {
  font-size: 0.65rem;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 4px;
  animation: pulse 1.2s ease-in-out infinite;
}

.streaming-badge i {
  font-size: 0.5rem;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Streaming cursor */
.stream-cursor {
  display: inline-block;
  color: var(--accent);
  animation: blink 0.7s step-end infinite;
  font-weight: 300;
  margin-left: 1px;
}

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

.stream-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-text strong {
  color: var(--accent);
}

.user-message .message-text strong {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-text ul, .message-text ol {
  margin: 6px 0;
  padding-left: 20px;
}

.message-text li {
  margin-bottom: 4px;
}

.message-text code {
  background: rgba(0,82,204,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'Courier New', monospace;
}

.user-message .message-text code {
  background: rgba(255,255,255,0.15);
}

.message-text pre {
  background: #1a1a2e;
  color: #e8e8f0;
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

.message-text pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* ===== MESSAGE ACTIONS ===== */
.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding-left: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.user-message .message-actions {
  justify-content: flex-end;
  padding-left: 0;
  padding-right: 4px;
}

.ai-teacher-message:hover .message-actions {
  opacity: 1;
}

.msg-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.7rem;
  font-family: 'Hind Siliguri', sans-serif;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.msg-action-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.msg-action-btn.copied {
  color: var(--success);
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator-container .message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  background: var(--bubble-ai);
  border: 1px solid var(--bubble-ai-border);
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  width: fit-content;
  box-shadow: var(--bubble-ai-shadow);
}

.typing-dots span {
  width: 9px;
  height: 9px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-10px); opacity: 1; }
}

.typing-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-left: 4px;
}

/* ===== FOLLOW-UP SUGGESTIONS ===== */
.follow-up-section {
  margin-top: 8px;
  padding-left: 4px;
}

.follow-up-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.follow-up-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.follow-up-chip {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--chip-text);
  padding: 6px 14px;
  border-radius: 100px;
  cursor: pointer;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.75rem;
  transition: all 0.3s;
}

.follow-up-chip:hover {
  background: var(--chip-hover-bg);
  color: var(--chip-hover-text);
  border-color: var(--chip-hover-bg);
}

/* ===== INPUT AREA ===== */
.ai-teacher-input-area {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-container);
  border-top: 1px solid var(--divider);
  flex-shrink: 0;
  transition: background 0.4s;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#ai-teacher-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: 14px;
  transition: all 0.3s;
  padding: 2px 4px;
}

.input-wrapper:focus-within {
  border-color: var(--input-focus);
  background: var(--bg-container);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

[data-theme="dark"] .input-wrapper:focus-within {
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
}

.voice-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s;
  margin-left: 2px;
}

.voice-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.voice-btn.listening {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  animation: micPulse 1s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

#ai-teacher-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 4px;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.9rem;
  outline: none;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

#ai-teacher-input::placeholder {
  color: var(--text-muted);
}

#ai-teacher-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.3);
}

#ai-teacher-send:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(79, 70, 229, 0.45);
  background: linear-gradient(135deg, #6366f1, #818cf8);
}

#ai-teacher-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

#ai-teacher-send:active:not(:disabled) {
  transform: scale(0.9);
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  padding: 0 4px;
}

.input-status {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.char-count {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.char-count.limit {
  color: var(--danger);
  opacity: 1;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-container);
  border: 1px solid var(--divider);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.1);
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.85rem;
  animation: toastSlide 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes toastSlide {
  from { opacity: 0; transform: translateX(50px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== MATH FRACTION STYLING ===== */
.fraction {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  margin: 0 3px;
  font-size: 0.9em;
  line-height: 1.3;
}

.fraction .top {
  display: block;
  border-bottom: 1.5px solid var(--text-primary);
  padding: 0 4px 1px;
}

.fraction .bottom {
  display: block;
  padding: 1px 4px 0;
}

.user-message .fraction .top {
  border-color: rgba(255,255,255,0.7);
}

[data-theme="dark"] .fraction .top {
  border-color: var(--text-primary);
}

.math-inline {
  display: inline;
  font-style: normal;
  font-weight: 500;
  color: var(--accent);
  padding: 0 2px;
}

.user-message .math-inline {
  color: rgba(255,255,255,0.95);
}

.math-block sup, .math-inline sup,
.step-content sup, .message-text sup {
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
}

.math-block sub, .math-inline sub,
.step-content sub, .message-text sub {
  font-size: 0.72em;
  vertical-align: sub;
  line-height: 0;
}

/* ===== STEP BLOCK ===== */
.step-block {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  transition: background 0.3s;
}

[data-theme="dark"] .step-block {
  background: rgba(108, 159, 255, 0.08);
}

.step-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 1px;
}

.step-content {
  flex: 1;
  line-height: 1.7;
}

.step-content .step-label {
  font-weight: 700;
  color: var(--accent);
}

/* ===== MATH EQUATION BLOCK ===== */
.math-block {
  display: block;
  padding: 10px 16px;
  margin: 8px 0;
  background: var(--input-bg);
  border: 1px solid var(--bubble-ai-border);
  border-radius: 12px;
  text-align: center;
  font-size: 1.05em;
  font-weight: 500;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--text-primary);
  transition: background 0.3s;
}

[data-theme="dark"] .math-block {
  background: rgba(30, 30, 58, 0.8);
}

/* ===== FORMULA BOX ===== */
.formula-box {
  display: block;
  padding: 12px 16px;
  margin: 10px 0;
  background: linear-gradient(135deg, rgba(0, 82, 204, 0.06), rgba(0, 123, 255, 0.04));
  border: 1px solid var(--accent);
  border-radius: 14px;
  text-align: center;
  font-size: 1.1em;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.3px;
}

[data-theme="dark"] .formula-box {
  background: linear-gradient(135deg, rgba(108, 159, 255, 0.1), rgba(108, 159, 255, 0.05));
  color: var(--accent);
}

.formula-box .formula-label {
  display: block;
  font-size: 0.75em;
  font-weight: 400;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ===== MATH LIST ===== */
.math-list {
  margin: 6px 0;
  padding: 0;
  list-style: none;
}

.math-list li {
  padding: 4px 0 4px 20px;
  position: relative;
  line-height: 1.7;
}

.math-list li::before {
  content: '▸';
  position: absolute;
  left: 2px;
  color: var(--accent);
  font-weight: 700;
}

/* ===== BULLET LIST ===== */
.bullet-list {
  margin: 6px 0;
  padding: 0;
  list-style: none;
}

.bullet-list li {
  padding: 3px 0 3px 22px;
  position: relative;
  line-height: 1.7;
}

.bullet-list li::before {
  content: '•';
  position: absolute;
  left: 6px;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.2em;
}

/* ===== PRESET ACTIONS ===== */
.preset-actions {
  display: flex;
  gap: 6px;
  padding: 4px 16px 2px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.preset-actions::-webkit-scrollbar { display: none; }

.preset-btn {
  flex-shrink: 0;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--chip-text);
  padding: 5px 12px;
  border-radius: 100px;
  cursor: pointer;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.75rem;
  white-space: nowrap;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}
.preset-btn i {
  font-size: 0.8em;
}
.preset-btn:hover {
  background: var(--chip-hover-bg);
  color: var(--chip-hover-text);
  border-color: var(--chip-hover-bg);
  transform: translateY(-1px);
  box-shadow: 0 2px 12px rgba(79, 70, 229, 0.2);
}
.preset-btn.active {
  background: var(--chip-hover-bg);
  color: var(--chip-hover-text);
  border-color: var(--chip-hover-bg);
  box-shadow: 0 2px 12px rgba(79, 70, 229, 0.25);
}

/* ===== IMAGE PREVIEW ===== */
.image-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 0;
  flex-shrink: 0;
}
.image-preview img {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--accent);
}
.remove-image-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}
.remove-image-btn:hover {
  transform: scale(1.15);
}

/* Image in chat */
.image-attachment-preview {
  max-width: 240px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--divider);
}
.image-attachment-preview img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  transition: transform 0.2s;
}
.image-attachment-preview img:hover {
  transform: scale(1.02);
}

.user-message .image-attachment-preview {
  border-color: rgba(255,255,255,0.2);
}

/* ===== MOBILE PRESET & IMAGE ===== */
@media (max-width: 768px) {
  .preset-actions {
    padding: 6px 10px 0;
    gap: 5px;
  }
  .preset-btn {
    font-size: 0.72rem;
    padding: 5px 10px;
    gap: 4px;
  }
  .preset-btn i {
    font-size: 0.75em;
  }
  .image-preview {
    padding: 4px 10px 0;
  }
  .image-preview img {
    width: 40px;
    height: 40px;
  }
  .image-attachment-preview {
    max-width: 180px;
  }
}
@media (max-width: 380px) {
  .preset-actions {
    padding: 4px 8px 0;
    gap: 4px;
  }
  .preset-btn {
    font-size: 0.65rem;
    padding: 4px 8px;
    gap: 3px;
  }
}

/* ===== RESPONSIVE - MOBILE FIRST ===== */

/* Mobile portrait (most phones) */
@media (max-width: 768px) {
  .ai-teacher-header {
    padding: 8px 10px;
    gap: 6px;
    height: 44px;
    min-height: 44px;
  }
  .ai-teacher-header-icon {
    width: 30px;
    height: 30px;
    font-size: 13px;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .ai-teacher-header-text {
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
  }
  .ai-teacher-header h2 {
    font-size: 0.9rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .subject-selector {
    margin-left: auto;
    flex-shrink: 0;
  }
  .subject-select {
    font-size: 0.6rem;
    padding: 3px 18px 3px 7px;
    border-radius: 7px;
    max-width: 68px;
    background-position: right 7px center;
    background-size: 8px 5px;
  }

  .ai-teacher-header-actions {
    gap: 2px;
    flex-shrink: 0;
    justify-content: flex-end;
  }
  .header-btn {
    width: 26px;
    height: 26px;
    font-size: 10px;
    border-radius: 6px;
    flex-shrink: 0;
  }

  .ai-teacher-messages {
    padding: 10px 8px;
  }

  .ai-teacher-message {
    gap: 8px;
    margin-bottom: 14px;
  }
  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
    margin-top: 2px;
  }
  .message-content {
    max-width: calc(100% - 36px);
  }
  .message-text {
    font-size: 0.92rem;
    padding: 10px 12px;
    border-radius: 12px;
    line-height: 1.8;
  }
  .message-header {
    margin-bottom: 2px;
  }
  .message-sender {
    font-size: 0.7rem;
  }
  .message-time {
    font-size: 0.6rem;
  }

  .message-actions {
    gap: 2px;
    margin-top: 4px;
    opacity: 1;
  }
  .msg-action-btn {
    font-size: 0.65rem;
    padding: 4px 6px;
  }

  .welcome-logo {
    width: 60px;
    height: 60px;
    font-size: 26px;
    border-radius: 18px;
  }
  .ai-teacher-welcome {
    padding: 20px 10px;
    min-height: 60vh;
  }
  .ai-teacher-welcome h3 {
    font-size: 1.1rem;
  }
  .ai-teacher-welcome p {
    font-size: 0.82rem;
    padding: 0 8px;
  }

  .ai-teacher-suggestions {
    gap: 8px;
  }
  .suggestion-chip {
    font-size: 0.78rem;
    padding: 8px 14px;
  }

  .ai-teacher-input-area {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  #ai-teacher-form {
    gap: 6px;
  }
  .input-wrapper {
    border-radius: 12px;
    padding: 2px;
  }
  #ai-teacher-input {
    padding: 8px 4px;
    font-size: 0.9rem;
  }
  #ai-teacher-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 14px;
  }
  .voice-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
    margin-left: 1px;
  }
  .input-footer {
    display: none;
  }
  .input-status {
    font-size: 0.6rem;
  }
  .char-count {
    font-size: 0.6rem;
  }

  /* Step blocks mobile */
  .step-block {
    padding: 8px 10px;
    margin: 6px 0;
    gap: 8px;
    border-left-width: 3px;
  }
  .step-icon {
    width: 24px;
    height: 24px;
    font-size: 11px;
    margin-top: 1px;
  }
  .step-content {
    font-size: 0.9rem;
    line-height: 1.7;
  }

  /* Math block mobile */
  .math-block {
    padding: 8px 12px;
    margin: 6px 0;
    font-size: 0.92rem;
    white-space: normal;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Formula box mobile */
  .formula-box {
    padding: 10px 12px;
    margin: 8px 0;
    font-size: 0.95rem;
  }

  /* Fractions mobile */
  .fraction {
    font-size: 0.85em;
  }

  /* Toast mobile */
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }
  .toast {
    font-size: 0.8rem;
    padding: 10px 14px;
  }
}

/* Small phones (iPhone SE, etc.) */
@media (max-width: 380px) {
  .ai-teacher-header {
    padding: 6px 8px;
    gap: 4px;
    height: 40px;
    min-height: 40px;
  }
  .ai-teacher-header-icon {
    width: 24px;
    height: 24px;
    font-size: 10px;
    border-radius: 6px;
  }
  .ai-teacher-header-text {
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
  }
  .ai-teacher-header h2 {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .subject-select {
    font-size: 0.5rem;
    padding: 2px 12px 2px 5px;
    max-width: 50px;
    background-position: right 5px center;
    background-size: 6px 4px;
  }
  .ai-teacher-header-actions {
    gap: 2px;
    justify-content: flex-end;
  }
  .header-btn {
    width: 22px;
    height: 22px;
    font-size: 9px;
    border-radius: 5px;
  }

  .ai-teacher-messages {
    padding: 8px 6px;
  }
  .ai-teacher-messages {
    padding: 8px 6px;
  }
  .ai-teacher-message {
    gap: 6px;
    margin-bottom: 12px;
  }
  .message-avatar {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }
  .message-content {
    max-width: calc(100% - 30px);
  }
  .message-text {
    font-size: 0.88rem;
    padding: 8px 10px;
    line-height: 1.7;
  }
  .ai-teacher-input-area {
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 4px));
  }
  #ai-teacher-input {
    font-size: 0.88rem;
    padding: 7px 4px;
  }
  #ai-teacher-send {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }
  .voice-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .suggestion-chip {
    font-size: 0.72rem;
    padding: 6px 10px;
  }
  .ai-teacher-welcome h3 {
    font-size: 1rem;
  }
  .welcome-logo {
    width: 50px;
    height: 50px;
    font-size: 22px;
  }

  .step-block {
    padding: 6px 8px;
    gap: 6px;
  }
  .step-icon {
    width: 20px;
    height: 20px;
    font-size: 10px;
  }
  .step-content {
    font-size: 0.85rem;
  }
  .math-block {
    padding: 6px 10px;
    font-size: 0.88rem;
  }
  .fraction {
    font-size: 0.8em;
  }
}

/* Landscape phone optimization */
@media (max-height: 500px) and (orientation: landscape) {
  .ai-teacher-page {
    height: 100vh;
    min-height: 0;
  }
  .ai-teacher-container {
    height: 100%;
  }
  .ai-teacher-header {
    padding: 6px 12px;
    min-height: 40px;
  }
  .ai-teacher-header-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  .ai-teacher-header h2 {
    font-size: 0.85rem;
  }
  .ai-teacher-messages {
    padding: 6px 10px;
  }
  .ai-teacher-message {
    margin-bottom: 8px;
  }
  .message-text {
    font-size: 0.82rem;
    padding: 6px 10px;
    line-height: 1.5;
  }
  .ai-teacher-input-area {
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 2px));
  }
  #ai-teacher-input {
    font-size: 0.82rem;
    padding: 6px 4px;
  }
  #ai-teacher-send {
    width: 34px;
    height: 34px;
  }
  .welcome-logo {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
  .ai-teacher-welcome {
    padding: 10px;
    min-height: auto;
  }
  .ai-teacher-welcome h3 {
    font-size: 0.9rem;
    margin-bottom: 4px;
  }
  .ai-teacher-welcome p {
    font-size: 0.75rem;
    margin-bottom: 10px;
  }
  .step-block {
    padding: 5px 8px;
    margin: 4px 0;
  }
  .math-block {
    padding: 5px 8px;
    margin: 4px 0;
  }
}

/* ===== SCROLL DOWN BUTTON ===== */
.scroll-down-btn {
  position: absolute;
  bottom: 10px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0, 82, 204, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 5;
}

.scroll-down-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.scroll-down-btn:hover {
  transform: scale(1.1);
}

/* ===== EDIT MODE ===== */
.edit-textarea {
  width: 100%;
  background: var(--input-bg);
  border: 2px solid var(--input-focus);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  resize: vertical;
  min-height: 60px;
}

.edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.edit-save-btn, .edit-cancel-btn {
  padding: 4px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.75rem;
  border: none;
  transition: all 0.2s;
}

.edit-save-btn {
  background: var(--accent);
  color: #fff;
}

.edit-cancel-btn {
  background: var(--chip-bg);
  color: var(--text-secondary);
  border: 1px solid var(--divider);
}

@media (max-width: 768px) {
  .ai-teacher-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: env(safe-area-inset-top, 0px) 0 0;
  }

  .ai-teacher-container {
    height: 100%;
    min-height: 0;
  }

  .history-panel {
    width: 100vw;
    max-width: 100vw;
    border-radius: 0;
  }
  .history-header {
    padding: 16px 16px 14px;
  }
  .history-header-title {
    font-size: 0.95rem;
  }
  .history-list {
    padding: 10px 10px 16px;
    gap: 6px;
  }
  .history-item {
    padding: 12px 14px;
    border-radius: 12px;
  }
  .history-item-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 13px;
  }
  .history-item-title {
    font-size: 0.8rem;
  }
  .history-item-meta {
    font-size: 0.65rem;
  }
  .history-empty-icon-wrap {
    width: 56px;
    height: 56px;
    font-size: 1.3rem;
  }
}

@media (max-width: 480px) {
  .ai-teacher-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
  }

  .ai-teacher-header {
    height: 42px;
    min-height: 42px;
  }

  .preset-actions {
    padding: 5px 8px 4px;
  }

  .ai-teacher-messages {
    padding: 8px;
  }
}

@media (max-height: 620px) {
  .preset-actions {
    display: none;
  }

  .ai-teacher-header {
    height: 42px;
    min-height: 42px;
  }
}

/* ===== PAGE TRANSITION FIX ===== */
.page-transition {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 99999;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

.transition-circle {
  position: absolute;
  width: 100px;
  height: 100px;
  background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-transition.active .transition-circle {
  transform: scale(30);
}

.transition-logo {
  position: relative;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.5) rotate(-180deg);
  transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 1;
}

.page-transition.active .transition-logo {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* ===== HISTORY PANEL ===== */
.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.history-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg-container);
  z-index: 101;
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 50px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.history-panel.open {
  transform: translateX(0);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 16px;
  background: linear-gradient(135deg, var(--bg-header), color-mix(in srgb, var(--bg-header) 85%, #000));
  color: #fff;
  font-family: 'Baloo Da 2', cursive;
  flex-shrink: 0;
  position: relative;
}

.history-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 22px;
  right: 22px;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.history-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
}

.history-header-title i {
  font-size: 1.1rem;
  opacity: 0.9;
}

.history-header-badge {
  background: rgba(255, 255, 255, 0.15);
  font-family: 'Hind Siliguri', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 100px;
  margin-left: 4px;
}

.history-close-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s;
}

.history-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 2px; }
.history-list::-webkit-scrollbar-track { background: transparent; }

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 14px;
  padding: 40px 20px;
  text-align: center;
}

.history-empty-icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.history-empty p {
  font-size: 0.85rem;
  opacity: 0.7;
  line-height: 1.5;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  cursor: pointer;
  border: 1.5px solid transparent;
  background: var(--bg-msg-area);
  transition: all 0.25s;
  position: relative;
}

.history-item:hover {
  background: var(--accent-light);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  transform: translateX(3px);
}

.history-item.active {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: 0 2px 12px color-mix(in srgb, var(--accent) 15%, transparent);
}

.history-item-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  transition: all 0.25s;
}

.history-item.active .history-item-icon {
  background: var(--accent);
  color: #fff;
}

.history-item-body {
  flex: 1;
  min-width: 0;
}

.history-item-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.history-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.history-item-meta i {
  font-size: 0.6rem;
  opacity: 0.6;
}

.history-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.25s;
  flex-shrink: 0;
}

.history-item:hover .history-delete-btn {
  opacity: 0.6;
}

.history-delete-btn:hover {
  opacity: 1 !important;
  background: rgba(231, 76, 60, 0.12);
  color: var(--danger);
  transform: scale(1.1);
}

.md-heading { margin: 0.6em 0 0.3em; font-weight: 700; color: var(--primary, #6c63ff); }
h3.md-heading { font-size: 1.05rem; }
h4.md-heading { font-size: 0.97rem; }
h5.md-heading { font-size: 0.92rem; }

.math-preview {
  margin: 0 0 6px;
  padding: 8px 12px;
  background: var(--math-bg, #f0eeff);
  border-left: 3px solid var(--primary, #6c63ff);
  border-radius: 6px;
  font-size: 0.95rem;
  color: var(--text, #333);
  min-height: 36px;
  word-break: break-word;
}
